< prev index next >

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

Print this page
rev 59383 : [mq]: final


 212         super(platname, nativeNames);
 213         useJavaRasterizer = javaRasterizer;
 214         fontRank = Font2D.TTF_RANK;
 215         try {
 216             verify(useFilePool);
 217             init(fIndex);
 218             if (!useFilePool) {
 219                close();
 220             }
 221         } catch (Throwable t) {
 222             close();
 223             if (t instanceof FontFormatException) {
 224                 throw (FontFormatException)t;
 225             } else {
 226                 throw new FontFormatException("Unexpected runtime exception.");
 227             }
 228         }
 229         Disposer.addObjectRecord(this, disposerRecord);
 230     }
 231 
 232     /* Enable natives just for fonts picked up from the platform that
 233      * may have external bitmaps on Solaris. Could do this just for
 234      * the fonts that are specified in font configuration files which
 235      * would lighten the burden (think about that).
 236      * The EBLCTag is used to skip natives for fonts that contain embedded
 237      * bitmaps as there's no need to use X11 for those fonts.
 238      * Skip all the latin fonts as they don't need this treatment.
 239      * Further refine this to fonts that are natively accessible (ie
 240      * as PCF bitmap fonts on the X11 font path).
 241      * This method is called when creating the first strike for this font.
 242      */
 243     @Override
 244     protected boolean checkUseNatives() {
 245         if (checkedNatives) {
 246             return useNatives;
 247         }
 248         if (!FontUtilities.isSolaris || useJavaRasterizer ||
 249             FontUtilities.useJDKScaler || nativeNames == null ||
 250             getDirectoryEntry(EBLCTag) != null ||
 251             GraphicsEnvironment.isHeadless()) {
 252             checkedNatives = true;
 253             return false; /* useNatives is false */
 254         } else if (nativeNames instanceof String) {
 255             String name = (String)nativeNames;
 256             /* Don't do this for Latin fonts */
 257             if (name.indexOf("8859") > 0) {
 258                 checkedNatives = true;
 259                 return false;
 260             } else if (NativeFont.hasExternalBitmaps(name)) {
 261                 nativeFonts = new NativeFont[1];
 262                 try {
 263                     nativeFonts[0] = new NativeFont(name, true);
 264                     /* If reach here we have an non-latin font that has
 265                      * external bitmaps and we successfully created it.
 266                      */
 267                     useNatives = true;
 268                 } catch (FontFormatException e) {
 269                     nativeFonts = null;
 270                 }
 271             }
 272         } else if (nativeNames instanceof String[]) {
 273             String[] natNames = (String[])nativeNames;
 274             int numNames = natNames.length;
 275             boolean externalBitmaps = false;
 276             for (int nn = 0; nn < numNames; nn++) {
 277                 if (natNames[nn].indexOf("8859") > 0) {
 278                     checkedNatives = true;
 279                     return false;
 280                 } else if (NativeFont.hasExternalBitmaps(natNames[nn])) {
 281                     externalBitmaps = true;
 282                 }
 283             }
 284             if (!externalBitmaps) {
 285                 checkedNatives = true;
 286                 return false;
 287             }
 288             useNatives = true;
 289             nativeFonts = new NativeFont[numNames];
 290             for (int nn = 0; nn < numNames; nn++) {
 291                 try {
 292                     nativeFonts[nn] = new NativeFont(natNames[nn], true);
 293                 } catch (FontFormatException e) {
 294                     useNatives = false;
 295                     nativeFonts = null;
 296                 }
 297             }
 298         }
 299         if (useNatives) {
 300             glyphToCharMap = new char[getMapper().getNumGlyphs()];
 301         }
 302         checkedNatives = true;
 303         return useNatives;
 304     }
 305 
 306 
 307     private synchronized FileChannel open() throws FontFormatException {
 308         return open(true);
 309      }
 310 
 311     /* This is intended to be called, and the returned value used,
 312      * from within a block synchronized on this font object.
 313      * ie the channel returned may be nulled out at any time by "close()"
 314      * unless the caller holds a lock.
 315      * Deadlock warning: FontManager.addToPool(..) acquires a global lock,
 316      * which means nested locks may be in effect.
 317      */
 318     private synchronized FileChannel open(boolean usePool)
 319                                      throws FontFormatException {
 320         if (disposerRecord.channel == null) {
 321             if (FontUtilities.isLogging()) {
 322                 FontUtilities.getLogger().info("open TTF: " + platName);
 323             }
 324             try {
 325                 RandomAccessFile raf = AccessController.doPrivileged(
 326                     new PrivilegedExceptionAction<RandomAccessFile>() {


1029         int italic  = fsSelection & fsSelectionItalicBit;
1030         int bold    = fsSelection & fsSelectionBoldBit;
1031         int regular = fsSelection & fsSelectionRegularBit;
1032 //      System.out.println("platname="+platName+" font="+fullName+
1033 //                         " family="+familyName+
1034 //                         " R="+regular+" I="+italic+" B="+bold);
1035         if (regular!=0 && ((italic|bold)!=0)) {
1036             /* This is inconsistent. Try using the font name algorithm */
1037             super.setStyle();
1038             return;
1039         } else if ((regular|italic|bold) == 0) {
1040             /* No style specified. Try using the font name algorithm */
1041             super.setStyle();
1042             return;
1043         }
1044         switch (bold|italic) {
1045         case fsSelectionItalicBit:
1046             style = Font.ITALIC;
1047             break;
1048         case fsSelectionBoldBit:
1049             if (FontUtilities.isSolaris && platName.endsWith("HG-GothicB.ttf")) {
1050                 /* Workaround for Solaris's use of a JA font that's marked as
1051                  * being designed bold, but is used as a PLAIN font.
1052                  */
1053                 style = Font.PLAIN;
1054             } else {
1055                 style = Font.BOLD;
1056             }
1057             break;
1058         case fsSelectionBoldBit|fsSelectionItalicBit:
1059             style = Font.BOLD|Font.ITALIC;
1060         }
1061     }
1062 
1063     private float stSize, stPos, ulSize, ulPos;
1064 
1065     private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
1066         if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
1067             stSize = .05f;
1068             stPos = -.4f;
1069             return;
1070         }
1071         ShortBuffer sb = os_2Table.asShortBuffer();
1072         stSize = sb.get(13) / (float)upem;
1073         stPos = -sb.get(14) / (float)upem;
1074     }
1075 
1076     private void setUnderlineMetrics(ByteBuffer postTable, int upem) {




 212         super(platname, nativeNames);
 213         useJavaRasterizer = javaRasterizer;
 214         fontRank = Font2D.TTF_RANK;
 215         try {
 216             verify(useFilePool);
 217             init(fIndex);
 218             if (!useFilePool) {
 219                close();
 220             }
 221         } catch (Throwable t) {
 222             close();
 223             if (t instanceof FontFormatException) {
 224                 throw (FontFormatException)t;
 225             } else {
 226                 throw new FontFormatException("Unexpected runtime exception.");
 227             }
 228         }
 229         Disposer.addObjectRecord(this, disposerRecord);
 230     }
 231 











































































 232     private synchronized FileChannel open() throws FontFormatException {
 233         return open(true);
 234     }
 235 
 236     /* This is intended to be called, and the returned value used,
 237      * from within a block synchronized on this font object.
 238      * ie the channel returned may be nulled out at any time by "close()"
 239      * unless the caller holds a lock.
 240      * Deadlock warning: FontManager.addToPool(..) acquires a global lock,
 241      * which means nested locks may be in effect.
 242      */
 243     private synchronized FileChannel open(boolean usePool)
 244                                      throws FontFormatException {
 245         if (disposerRecord.channel == null) {
 246             if (FontUtilities.isLogging()) {
 247                 FontUtilities.getLogger().info("open TTF: " + platName);
 248             }
 249             try {
 250                 RandomAccessFile raf = AccessController.doPrivileged(
 251                     new PrivilegedExceptionAction<RandomAccessFile>() {


 954         int italic  = fsSelection & fsSelectionItalicBit;
 955         int bold    = fsSelection & fsSelectionBoldBit;
 956         int regular = fsSelection & fsSelectionRegularBit;
 957 //      System.out.println("platname="+platName+" font="+fullName+
 958 //                         " family="+familyName+
 959 //                         " R="+regular+" I="+italic+" B="+bold);
 960         if (regular!=0 && ((italic|bold)!=0)) {
 961             /* This is inconsistent. Try using the font name algorithm */
 962             super.setStyle();
 963             return;
 964         } else if ((regular|italic|bold) == 0) {
 965             /* No style specified. Try using the font name algorithm */
 966             super.setStyle();
 967             return;
 968         }
 969         switch (bold|italic) {
 970         case fsSelectionItalicBit:
 971             style = Font.ITALIC;
 972             break;
 973         case fsSelectionBoldBit:






 974             style = Font.BOLD;

 975             break;
 976         case fsSelectionBoldBit|fsSelectionItalicBit:
 977             style = Font.BOLD|Font.ITALIC;
 978         }
 979     }
 980 
 981     private float stSize, stPos, ulSize, ulPos;
 982 
 983     private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
 984         if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
 985             stSize = .05f;
 986             stPos = -.4f;
 987             return;
 988         }
 989         ShortBuffer sb = os_2Table.asShortBuffer();
 990         stSize = sb.get(13) / (float)upem;
 991         stPos = -sb.get(14) / (float)upem;
 992     }
 993 
 994     private void setUnderlineMetrics(ByteBuffer postTable, int upem) {


< prev index next >