Changeset 14328 in josm for trunk/src/com/kitfox/svg/util
- Timestamp:
- 2018-10-14T15:15:50+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/util/FontSystem.java
r11525 r14328 42 42 import java.awt.Canvas; 43 43 import java.awt.FontMetrics; 44 import java.awt.GraphicsEnvironment; 44 45 import java.awt.font.FontRenderContext; 45 46 import java.awt.font.GlyphMetrics; 46 47 import java.awt.font.GlyphVector; 47 48 import java.util.HashMap; 49 import java.util.HashSet; 48 50 49 51 /** … … 58 60 HashMap<String, Glyph> glyphCache = new HashMap<String, Glyph>(); 59 61 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) 61 92 { 62 93 int style; … … 82 113 break; 83 114 } 84 sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize); 115 116 sysFont = new java.awt.Font(fontFamily, style | weight, fontSize); 85 117 86 118 Canvas c = new Canvas(); … … 100 132 GlyphVector vec = sysFont.createGlyphVector(frc, unicode); 101 133 102 Glyph glyph = (Glyph)glyphCache.get(unicode);134 Glyph glyph = glyphCache.get(unicode); 103 135 if (glyph == null) 104 136 { … … 107 139 108 140 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()); 111 143 glyph.setVertOriginX(0); 112 144 glyph.setVertOriginY(0);
Note:
See TracChangeset
for help on using the changeset viewer.