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

Print this page




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any 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.security.AccessController;
  34 

  35 import javax.swing.plaf.FontUIResource;
  36 
  37 import sun.security.action.GetPropertyAction;
  38 import sun.util.logging.PlatformLogger;
  39 
  40 /**
  41  * A collection of utility methods.
  42  */
  43 public final class FontUtilities {
  44 
  45     public static final boolean isSolaris;
  46 
  47     public static final boolean isLinux;
  48 
  49     public static final boolean isSolaris8;
  50 
  51     public static final boolean isSolaris9;
  52 
  53     public static final boolean isOpenSolaris;
  54 
  55     public static final boolean useT2K;
  56 
  57     public static final boolean isWindows;
  58 
  59     public static final boolean isOpenJDK;
  60 
  61     static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
  62 
  63     // This static initializer block figures out the OS constants.
  64     static {
  65 
  66         String osName = AccessController.doPrivileged(
  67                                 new GetPropertyAction("os.name", "unknownOS"));

  68         isSolaris = osName.startsWith("SunOS");
  69 
  70         isLinux = osName.startsWith("Linux");
  71 
  72         String t2kStr = AccessController.doPrivileged(
  73                               new GetPropertyAction("sun.java2d.font.scaler"));
  74         if (t2kStr != null) {
  75             useT2K = "t2k".equals(t2kStr);
  76         } else {
  77             useT2K = false;
  78         }
  79         if (isSolaris) {
  80             String version = AccessController.doPrivileged(
  81                                    new GetPropertyAction("os.version", "0.0"));
  82             isSolaris8 = version.startsWith("5.8");
  83             isSolaris9 = version.startsWith("5.9");
  84             float ver = Float.parseFloat(version);
  85             if (ver > 5.10f) {
  86                 File f = new File("/etc/release");
  87                 String line = null;
  88                 try {
  89                     FileInputStream fis = new FileInputStream(f);
  90                     InputStreamReader isr = new InputStreamReader(
  91                                                             fis, "ISO-8859-1");
  92                     BufferedReader br = new BufferedReader(isr);
  93                     line = br.readLine();
  94                     fis.close();
  95                 } catch (Exception ex) {
  96                     // Nothing to do here.
  97                 }
  98                 if (line != null && line.indexOf("OpenSolaris") >= 0) {
  99                     isOpenSolaris = true;
 100                 } else {
 101                     isOpenSolaris = false;
 102                 }
 103             } else {
 104                 isOpenSolaris= false;
 105             }
 106         } else {
 107             isSolaris8 = false;
 108             isSolaris9 = false;
 109             isOpenSolaris = false;
 110         }
 111         isWindows = osName.startsWith("Windows");
 112         String jreLibDirName = AccessController.doPrivileged(
 113                new GetPropertyAction("java.home","")) + File.separator + "lib";
 114         String jreFontDirName = jreLibDirName + File.separator + "fonts";
 115         File lucidaFile =
 116                 new File(jreFontDirName + File.separator + LUCIDA_FILE_NAME);

 117         isOpenJDK = !lucidaFile.exists();



 118     }
 119 
 120     /**
 121      * Referenced by code in the JDK which wants to test for the
 122      * minimum char code for which layout may be required.
 123      * Note that even basic latin text can benefit from ligatures,
 124      * eg "ffi" but we presently apply those only if explicitly
 125      * requested with TextAttribute.LIGATURES_ON.
 126      * The value here indicates the lowest char code for which failing
 127      * to invoke layout would prevent acceptable rendering.
 128      */
 129     public static final int MIN_LAYOUT_CHARCODE = 0x0300;
 130 
 131     /**
 132      * Referenced by code in the JDK which wants to test for the
 133      * maximum char code for which layout may be required.
 134      * Note this does not account for supplementary characters
 135      * where the caller interprets 'layout' to mean any case where
 136      * one 'char' (ie the java type char) does not map to one glyph
 137      */




  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any 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.security.AccessController;
  34 
  35 import java.security.PrivilegedAction;
  36 import javax.swing.plaf.FontUIResource;
  37 

  38 import sun.util.logging.PlatformLogger;
  39 
  40 /**
  41  * A collection of utility methods.
  42  */
  43 public final class FontUtilities {
  44 
  45     public static boolean isSolaris;
  46 
  47     public static boolean isLinux;
  48 
  49     public static boolean isSolaris8;
  50 
  51     public static boolean isSolaris9;
  52 
  53     public static boolean isOpenSolaris;
  54 
  55     public static boolean useT2K;
  56 
  57     public static boolean isWindows;
  58 
  59     public static boolean isOpenJDK;
  60 
  61     static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
  62 
  63     // This static initializer block figures out the OS constants.
  64     static {
  65 
  66         AccessController.doPrivileged(new PrivilegedAction () {
  67             public Object run() {
  68                 String osName = System.getProperty("os.name", "unknownOS");
  69                 isSolaris = osName.startsWith("SunOS");
  70 
  71                 isLinux = osName.startsWith("Linux");
  72 
  73                 String t2kStr = System.getProperty("sun.java2d.font.scaler");

  74                 if (t2kStr != null) {
  75                     useT2K = "t2k".equals(t2kStr);
  76                 } else {
  77                     useT2K = false;
  78                 }
  79                 if (isSolaris) {
  80                     String version = System.getProperty("os.version", "0.0");

  81                     isSolaris8 = version.startsWith("5.8");
  82                     isSolaris9 = version.startsWith("5.9");
  83                     float ver = Float.parseFloat(version);
  84                     if (ver > 5.10f) {
  85                         File f = new File("/etc/release");
  86                         String line = null;
  87                         try {
  88                             FileInputStream fis = new FileInputStream(f);
  89                             InputStreamReader isr = new InputStreamReader(
  90                                                             fis, "ISO-8859-1");
  91                             BufferedReader br = new BufferedReader(isr);
  92                             line = br.readLine();
  93                             fis.close();
  94                         } catch (Exception ex) {
  95                             // Nothing to do here.
  96                         }
  97                         if (line != null && line.indexOf("OpenSolaris") >= 0) {
  98                             isOpenSolaris = true;
  99                         } else {
 100                             isOpenSolaris = false;
 101                         }
 102                     } else {
 103                         isOpenSolaris = false;
 104                     }
 105                 } else {
 106                     isSolaris8 = false;
 107                     isSolaris9 = false;
 108                     isOpenSolaris = false;
 109                 }
 110                 isWindows = osName.startsWith("Windows");
 111                 String jreLibDirName = System.getProperty("java.home", "")
 112                                                       + File.separator + "lib";
 113                 String jreFontDirName =
 114                         jreLibDirName + File.separator + "fonts";
 115                 File lucidaFile = new File(jreFontDirName + File.separator
 116                                            + LUCIDA_FILE_NAME);
 117                 isOpenJDK = !lucidaFile.exists();
 118                 return null;
 119             }
 120         });
 121     }
 122 
 123     /**
 124      * Referenced by code in the JDK which wants to test for the
 125      * minimum char code for which layout may be required.
 126      * Note that even basic latin text can benefit from ligatures,
 127      * eg "ffi" but we presently apply those only if explicitly
 128      * requested with TextAttribute.LIGATURES_ON.
 129      * The value here indicates the lowest char code for which failing
 130      * to invoke layout would prevent acceptable rendering.
 131      */
 132     public static final int MIN_LAYOUT_CHARCODE = 0x0300;
 133 
 134     /**
 135      * Referenced by code in the JDK which wants to test for the
 136      * maximum char code for which layout may be required.
 137      * Note this does not account for supplementary characters
 138      * where the caller interprets 'layout' to mean any case where
 139      * one 'char' (ie the java type char) does not map to one glyph
 140      */