Ignore:
Timestamp:
2018-10-14T15:15:50+02:00 (6 years ago)
Author:
Don-vip
Message:

see #14319, see #16838 - update to svgSalamander 1.1.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/util/FontSystem.java

    r11525 r14328  
    4242import java.awt.Canvas;
    4343import java.awt.FontMetrics;
     44import java.awt.GraphicsEnvironment;
    4445import java.awt.font.FontRenderContext;
    4546import java.awt.font.GlyphMetrics;
    4647import java.awt.font.GlyphVector;
    4748import java.util.HashMap;
     49import java.util.HashSet;
    4850
    4951/**
     
    5860    HashMap<String, Glyph> glyphCache = new HashMap<String, Glyph>();
    5961   
    60     public FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize)
     62    static HashSet<String> sysFontNames = new HashSet<String>();
     63
     64    public static boolean checkIfSystemFontExists(String fontName)
     65    {
     66        if (sysFontNames.isEmpty())
     67        {
     68            for (String name: GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
     69            {
     70                sysFontNames.add(name);
     71            }
     72        }
     73
     74        return sysFontNames.contains(fontName);
     75    }
     76
     77    public static FontSystem createFont(String fontFamily, int fontStyle, int fontWeight, int fontSize)
     78    {
     79        String[] families = fontFamily.split(",");
     80        for (String fontName: families)
     81        {
     82            if (checkIfSystemFontExists(fontName))
     83            {
     84                return new FontSystem(fontName, fontStyle, fontWeight, fontSize);
     85            }
     86        }
     87
     88        return null;
     89    }
     90
     91    private FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize)
    6192    {
    6293        int style;
     
    82113                break;
    83114        }
    84         sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize);
     115
     116        sysFont = new java.awt.Font(fontFamily, style | weight, fontSize);
    85117       
    86118        Canvas c = new Canvas();
     
    100132        GlyphVector vec = sysFont.createGlyphVector(frc, unicode);
    101133       
    102         Glyph glyph = (Glyph)glyphCache.get(unicode);
     134        Glyph glyph = glyphCache.get(unicode);
    103135        if (glyph == null)
    104136        {
     
    107139
    108140            GlyphMetrics gm = vec.getGlyphMetrics(0);
    109             glyph.setHorizAdvX((int)gm.getAdvanceX());
    110             glyph.setVertAdvY((int)gm.getAdvanceY());
     141            glyph.setHorizAdvX(gm.getAdvanceX());
     142            glyph.setVertAdvY(gm.getAdvanceY());
    111143            glyph.setVertOriginX(0);
    112144            glyph.setVertOriginY(0);
Note: See TracChangeset for help on using the changeset viewer.