src/share/classes/sun/awt/FontConfiguration.java

Print this page
rev 1297 : [mq]: fontmanager.patch

@@ -28,11 +28,10 @@
 import java.awt.Font;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;

@@ -47,11 +46,13 @@
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 import java.util.Vector;
 import sun.font.CompositeFontDescriptor;
-import sun.java2d.SunGraphicsEnvironment;
+import sun.font.SunFontManager;
+import sun.font.FontManagerFactory;
+import sun.font.FontUtilities;
 
 /**
  * Provides the definitions of the five logical fonts: Serif, SansSerif,
  * Monospaced, Dialog, and DialogInput. The necessary information
  * is obtained from fontconfig files.

@@ -66,11 +67,11 @@
     protected static Hashtable localeMap = null;
     private static FontConfiguration fontConfig;
     private static Logger logger;
     protected static boolean isProperties = true;
 
-    protected SunGraphicsEnvironment environment;
+    protected SunFontManager fontManager;
     protected boolean preferLocaleFonts;
     protected boolean preferPropFonts;
 
     private File fontConfigFile;
     private boolean foundOsSpecificFile;

@@ -78,15 +79,15 @@
     private String javaLib;
 
     /* A default FontConfiguration must be created before an alternate
      * one to ensure proper static initialisation takes place.
      */
-    public FontConfiguration(SunGraphicsEnvironment environment) {
-        if (SunGraphicsEnvironment.debugFonts && logger == null) {
+    public FontConfiguration(SunFontManager fm) {
+        if (FontUtilities.debugFonts() && logger == null) {
             logger = Logger.getLogger("sun.awt.FontConfiguration");
         }
-        this.environment = environment;
+        fontManager = fm;
         setOsNameAndVersion();  /* static initialization */
         setEncoding();          /* static initialization */
         /* Separating out the file location from the rest of the
          * initialisation, so the caller has the option of doing
          * something else if a suitable file isn't found.

@@ -104,14 +105,14 @@
             inited = true;
         }
         return true;
     }
 
-    public FontConfiguration(SunGraphicsEnvironment environment,
+    public FontConfiguration(SunFontManager fm,
                              boolean preferLocaleFonts,
                              boolean preferPropFonts) {
-        this.environment = environment;
+        fontManager = fm;
         this.preferLocaleFonts = preferLocaleFonts;
         this.preferPropFonts = preferPropFonts;
         /* fontConfig should be initialised by default constructor, and
          * its data tables can be shared, since readFontConfigFile doesn't
          * update any other state. Also avoid a doPrivileged block.

@@ -196,21 +197,21 @@
                     loadProperties(in);
                 } else {
                     loadBinary(in);
                 }
                 in.close();
-                if (SunGraphicsEnvironment.debugFonts) {
+                if (FontUtilities.debugFonts()) {
                     logger.config("Read logical font configuration from " + f);
                 }
             } catch (IOException e) {
-                if (SunGraphicsEnvironment.debugFonts) {
+                if (FontUtilities.debugFonts()) {
                     logger.config("Failed to read logical font configuration from " + f);
                 }
             }
         }
         String version = getVersion();
-        if (!"1".equals(version) && SunGraphicsEnvironment.debugFonts) {
+        if (!"1".equals(version) && FontUtilities.debugFonts()) {
             logger.config("Unsupported fontconfig version: " + version);
         }
     }
 
     protected void getInstalledFallbackFonts(String javaLib) {

@@ -217,12 +218,12 @@
         String fallbackDirName = javaLib + File.separator +
             "fonts" + File.separator + "fallback";
 
         File fallbackDir = new File(fallbackDirName);
         if (fallbackDir.exists() && fallbackDir.isDirectory()) {
-            String[] ttfs = fallbackDir.list(SunGraphicsEnvironment.ttFilter);
-            String[] t1s = fallbackDir.list(SunGraphicsEnvironment.t1Filter);
+            String[] ttfs = fallbackDir.list(fontManager.getTrueTypeFilter());
+            String[] t1s = fallbackDir.list(fontManager.getType1Filter());
             int numTTFs = (ttfs == null) ? 0 : ttfs.length;
             int numT1s = (t1s == null) ? 0 : t1s.length;
             int len = numTTFs + numT1s;
             if (numTTFs + numT1s == 0) {
                 return;

@@ -234,11 +235,11 @@
             }
             for (int i=0; i<numT1s; i++) {
                 installedFallbackFontFiles[i+numTTFs] =
                     fallbackDir + File.separator + t1s[i];
             }
-            environment.registerFontsInDir(fallbackDirName);
+            fontManager.registerFontsInDir(fallbackDirName);
         }
     }
 
     private File findImpl(String fname) {
         File f = new File(fname + ".properties");

@@ -463,11 +464,11 @@
                 //core
                 for (index = 0; index < coreScripts.length; index++) {
                     nameIDs[index] = getComponentFontID(coreScripts[index],
                                                fontIndex, styleIndex);
                     if (preferLocaleFonts && localeMap != null &&
-                        sun.font.FontManager.usingAlternateFontforJALocales()) {
+                            fontManager.usingAlternateFontforJALocales()) {
                         nameIDs[index] = remapLocaleMap(fontIndex, styleIndex,
                                                         coreScripts[index], nameIDs[index]);
                     }
                     if (preferPropFonts) {
                         nameIDs[index] = remapProportional(fontIndex, nameIDs[index]);

@@ -478,11 +479,11 @@
                 //fallback
                 for (int i = 0; i < fallbackScripts.length; i++) {
                     short id = getComponentFontID(fallbackScripts[i],
                                                fontIndex, styleIndex);
                     if (preferLocaleFonts && localeMap != null &&
-                        sun.font.FontManager.usingAlternateFontforJALocales()) {
+                            fontManager.usingAlternateFontforJALocales()) {
                         id = remapLocaleMap(fontIndex, styleIndex, fallbackScripts[i], id);
                     }
                     if (preferPropFonts) {
                         id = remapProportional(fontIndex, id);
                     }

@@ -971,12 +972,12 @@
      * or the given fallback font as component fonts, they are added here.
      */
     public CompositeFontDescriptor[] get2DCompositeFontInfo() {
         CompositeFontDescriptor[] result =
                 new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];
-        String defaultFontFile = environment.getDefaultFontFile();
-        String defaultFontFaceName = environment.getDefaultFontFaceName();
+        String defaultFontFile = fontManager.getDefaultFontFile();
+        String defaultFontFaceName = fontManager.getDefaultFontFaceName();
 
         for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
             String fontName = publicFontNames[fontIndex];
 
             // determine exclusion ranges for font

@@ -1119,11 +1120,11 @@
      * to search for it. If it doesn't then unless its a fallback font,
      * return that expensive code should be invoked to search for the font.
      */
     HashMap<String, Boolean> existsMap;
     public boolean needToSearchForFile(String fileName) {
-        if (!environment.isLinux) {
+        if (!FontUtilities.isLinux) {
             return false;
         } else if (existsMap == null) {
            existsMap = new HashMap<String, Boolean>();
         }
         Boolean exists = existsMap.get(fileName);

@@ -1137,11 +1138,11 @@
             if (!coreFontFileNames.contains(fileName)) {
                 exists = Boolean.TRUE;
             } else {
                 exists = Boolean.valueOf((new File(fileName)).exists());
                 existsMap.put(fileName, exists);
-                if (SunGraphicsEnvironment.debugFonts &&
+                if (FontUtilities.debugFonts() &&
                     exists == Boolean.FALSE) {
                     logger.warning("Couldn't locate font file " + fileName);
                 }
             }
         }

@@ -2065,11 +2066,12 @@
                     up = Integer.parseInt(upper, 16);
                     if (lo > up) {
                         throw new Exception();
                     }
                 } catch (Exception e) {
-                    if (SunGraphicsEnvironment.debugFonts && logger != null) {
+                    if (FontUtilities.debugFonts() && 
+                        logger != null) {
                         logger.config("Failed parsing " + key +
                                   " property of font configuration.");
 
                     }
                     return EMPTY_INT_ARRAY;