< prev index next >

src/java.desktop/share/classes/sun/font/FontUtilities.java

Print this page
rev 60064 : 8248802: Add log helper methods to FontUtilities.java


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.font;
  27 
  28 import java.awt.Font;
  29 import java.io.BufferedReader;
  30 import java.io.File;
  31 import java.io.FileInputStream;
  32 import java.io.InputStreamReader;
  33 import java.lang.ref.SoftReference;
  34 import java.util.concurrent.ConcurrentHashMap;
  35 import java.security.AccessController;
  36 
  37 import java.security.PrivilegedAction;
  38 import javax.swing.plaf.FontUIResource;
  39 
  40 import sun.util.logging.PlatformLogger;
  41 
  42 /**
  43  * A collection of utility methods.
  44  */
  45 public final class FontUtilities {
  46 
  47     public static boolean isLinux;
  48 
  49     public static boolean isMacOSX;
  50     public static boolean isMacOSX14;
  51 
  52     public static boolean useJDKScaler;


  95                  * effect is that on Windows, 2D will never use GDI.
  96                  */
  97                 String scalerStr = System.getProperty("sun.java2d.font.scaler");
  98                 if (scalerStr != null) {
  99                     useJDKScaler = "jdk".equals(scalerStr);
 100                 } else {
 101                     useJDKScaler = false;
 102                 }
 103                 isWindows = osName.startsWith("Windows");
 104                 String debugLevel =
 105                     System.getProperty("sun.java2d.debugfonts");
 106 
 107                 if (debugLevel != null && !debugLevel.equals("false")) {
 108                     debugFonts = true;
 109                     logger = PlatformLogger.getLogger("sun.java2d");
 110                     if (debugLevel.equals("warning")) {
 111                         logger.setLevel(PlatformLogger.Level.WARNING);
 112                     } else if (debugLevel.equals("severe")) {
 113                         logger.setLevel(PlatformLogger.Level.SEVERE);
 114                     }
 115                 }
 116 
 117                 if (debugFonts) {
 118                     logger = PlatformLogger.getLogger("sun.java2d");
 119                     logging = logger.isEnabled();
 120                 }
 121 
 122                 return null;
 123             }
 124         });
 125     }
 126 
 127     /**
 128      * Referenced by code in the JDK which wants to test for the
 129      * minimum char code for which layout may be required.
 130      * Note that even basic latin text can benefit from ligatures,
 131      * eg "ffi" but we presently apply those only if explicitly
 132      * requested with TextAttribute.LIGATURES_ON.
 133      * The value here indicates the lowest char code for which failing
 134      * to invoke layout would prevent acceptable rendering.
 135      */
 136     public static final int MIN_LAYOUT_CHARCODE = 0x0300;
 137 
 138     /**


 307             return true;
 308         }
 309         else if (code >= 0x206a && code <= 0x206f) { // directional control
 310             return true;
 311         }
 312         return false;
 313     }
 314 
 315     public static PlatformLogger getLogger() {
 316         return logger;
 317     }
 318 
 319     public static boolean isLogging() {
 320         return logging;
 321     }
 322 
 323     public static boolean debugFonts() {
 324         return debugFonts;
 325     }
 326 











 327 
 328     // The following methods are used by Swing.
 329 
 330     /* Revise the implementation to in fact mean "font is a composite font.
 331      * This ensures that Swing components will always benefit from the
 332      * fall back fonts
 333      */
 334     public static boolean fontSupportsDefaultEncoding(Font font) {
 335         return getFont2D(font) instanceof CompositeFont;
 336     }
 337 
 338     /**
 339      * This method is provided for internal and exclusive use by Swing.
 340      *
 341      * It may be used in conjunction with fontSupportsDefaultEncoding(Font)
 342      * In the event that a desktop properties font doesn't directly
 343      * support the default encoding, (ie because the host OS supports
 344      * adding support for the current locale automatically for native apps),
 345      * then Swing calls this method to get a font which  uses the specified
 346      * font for the code points it covers, but also supports this locale




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.font;
  27 
  28 import java.awt.Font;




  29 import java.lang.ref.SoftReference;
  30 import java.util.concurrent.ConcurrentHashMap;
  31 import java.security.AccessController;
  32 
  33 import java.security.PrivilegedAction;
  34 import javax.swing.plaf.FontUIResource;
  35 
  36 import sun.util.logging.PlatformLogger;
  37 
  38 /**
  39  * A collection of utility methods.
  40  */
  41 public final class FontUtilities {
  42 
  43     public static boolean isLinux;
  44 
  45     public static boolean isMacOSX;
  46     public static boolean isMacOSX14;
  47 
  48     public static boolean useJDKScaler;


  91                  * effect is that on Windows, 2D will never use GDI.
  92                  */
  93                 String scalerStr = System.getProperty("sun.java2d.font.scaler");
  94                 if (scalerStr != null) {
  95                     useJDKScaler = "jdk".equals(scalerStr);
  96                 } else {
  97                     useJDKScaler = false;
  98                 }
  99                 isWindows = osName.startsWith("Windows");
 100                 String debugLevel =
 101                     System.getProperty("sun.java2d.debugfonts");
 102 
 103                 if (debugLevel != null && !debugLevel.equals("false")) {
 104                     debugFonts = true;
 105                     logger = PlatformLogger.getLogger("sun.java2d");
 106                     if (debugLevel.equals("warning")) {
 107                         logger.setLevel(PlatformLogger.Level.WARNING);
 108                     } else if (debugLevel.equals("severe")) {
 109                         logger.setLevel(PlatformLogger.Level.SEVERE);
 110                     }




 111                     logging = logger.isEnabled();
 112                 }
 113 
 114                 return null;
 115             }
 116         });
 117     }
 118 
 119     /**
 120      * Referenced by code in the JDK which wants to test for the
 121      * minimum char code for which layout may be required.
 122      * Note that even basic latin text can benefit from ligatures,
 123      * eg "ffi" but we presently apply those only if explicitly
 124      * requested with TextAttribute.LIGATURES_ON.
 125      * The value here indicates the lowest char code for which failing
 126      * to invoke layout would prevent acceptable rendering.
 127      */
 128     public static final int MIN_LAYOUT_CHARCODE = 0x0300;
 129 
 130     /**


 299             return true;
 300         }
 301         else if (code >= 0x206a && code <= 0x206f) { // directional control
 302             return true;
 303         }
 304         return false;
 305     }
 306 
 307     public static PlatformLogger getLogger() {
 308         return logger;
 309     }
 310 
 311     public static boolean isLogging() {
 312         return logging;
 313     }
 314 
 315     public static boolean debugFonts() {
 316         return debugFonts;
 317     }
 318 
 319     public static void logWarning(String s) {
 320         getLogger().warning(s);
 321     }
 322 
 323     public static void logInfo(String s) {
 324         getLogger().info(s);
 325     }
 326 
 327     public static void logSevere(String s) {
 328         getLogger().severe(s);
 329     }
 330 
 331     // The following methods are used by Swing.
 332 
 333     /* Revise the implementation to in fact mean "font is a composite font.
 334      * This ensures that Swing components will always benefit from the
 335      * fall back fonts
 336      */
 337     public static boolean fontSupportsDefaultEncoding(Font font) {
 338         return getFont2D(font) instanceof CompositeFont;
 339     }
 340 
 341     /**
 342      * This method is provided for internal and exclusive use by Swing.
 343      *
 344      * It may be used in conjunction with fontSupportsDefaultEncoding(Font)
 345      * In the event that a desktop properties font doesn't directly
 346      * support the default encoding, (ie because the host OS supports
 347      * adding support for the current locale automatically for native apps),
 348      * then Swing calls this method to get a font which  uses the specified
 349      * font for the code points it covers, but also supports this locale


< prev index next >