1 7 8 package com.sun.java.swing.plaf.gtk; 9 10 import java.awt.*; 11 import java.awt.geom.AffineTransform ; 12 import javax.swing.plaf.FontUIResource ; 13 import java.util.StringTokenizer ; 14 import sun.font.FontManager; 15 16 21 class PangoFonts { 22 23 private static final String [][] nameMap = {{"sans", "sansserif"}, 26 {"monospace", "monospaced"}}; 27 28 41 private static double fontScale; 42 43 static { 44 GraphicsEnvironment ge = 45 GraphicsEnvironment.getLocalGraphicsEnvironment(); 46 GraphicsConfiguration gc = 47 ge.getDefaultScreenDevice().getDefaultConfiguration(); 48 AffineTransform at = gc.getNormalizingTransform(); 49 fontScale = at.getScaleY(); 50 } 51 52 private static String mapName(String name) { 53 for (int i = 0; i < nameMap.length; i++) { 54 if (name.equals(nameMap[i][0])) { 55 return nameMap[i][1]; 56 } 57 } 58 59 return null; 60 } 61 62 71 static Font lookupFont(String pangoName) { 72 String family = ""; 73 int style = Font.PLAIN; 74 int size = 10; 75 76 StringTokenizer tok = new StringTokenizer (pangoName); 77 78 while (tok.hasMoreTokens()) { 79 String word = tok.nextToken(); 80 81 if (word.equalsIgnoreCase("italic")) { 82 style |= Font.ITALIC; 83 } else if (word.equalsIgnoreCase("bold")) { 84 style |= Font.BOLD; 85 } else if (GTKScanner.CHARS_DIGITS.indexOf(word.charAt(0)) != -1) { 86 try { 87 size = Integer.parseInt(word); 88 } catch (NumberFormatException ex) { 89 } 90 } else { 91 if (family.length() > 0) { 92 family += " "; 93 } 94 95 family += word; 96 } 97 } 98 99 156 double dsize = size; 157 int dpi = 96; 158 Object value = 159 Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI"); 160 if (value instanceof Integer ) { 161 dpi = ((Integer )value).intValue() / 1024; 162 if (dpi == -1) { 163 dpi = 96; 164 } 165 if (dpi < 50) { 166 dpi = 50; 167 } 168 171 dsize = ((double)(dpi * size)/ 72.0); 172 } else { 173 177 dsize = size * fontScale; 178 } 179 180 181 size = (int)(dsize + 0.5); 182 if (size < 1) { 183 size = 1; 184 } 185 186 String mappedName = mapName(family.toLowerCase()); 187 if (mappedName != null) { 188 family = mappedName; 189 } 190 191 Font font = new FontUIResource (family, style, size); 192 if (!FontManager.fontSupportsDefaultEncoding(font)) { 193 font = FontManager.getCompositeFontUIResource(font); 194 } 195 return font; 196 } 197 } 198 199 | Popular Tags |