< prev index next >

src/java.desktop/unix/classes/sun/awt/X11FontManager.java

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


 207                         xVal.add(platName);
 208                         xlfdMap.put(fileName, xVal);
 209                     }
 210                 } else {
 211                     if (!xVal.contains(platName)) {
 212                         xVal.add(platName);
 213                     }
 214                 }
 215             }
 216             if (fileName != null) {
 217                 fontNameMap.put(fontID, fileName);
 218                 return fileName;
 219             }
 220         }
 221 
 222         if (fontID != null) {
 223             fileName = fontNameMap.get(fontID);
 224             if (fontPath == null &&
 225                 (fileName == null || !fileName.startsWith("/"))) {
 226                 if (FontUtilities.debugFonts()) {
 227                     FontUtilities.getLogger()
 228                           .warning("** Registering all font paths because " +
 229                                    "can't find file for " + platName);
 230                 }
 231                 fontPath = getPlatformFontPath(noType1Font);
 232                 registerFontDirs(fontPath);
 233                 if (FontUtilities.debugFonts()) {
 234                     FontUtilities.getLogger()
 235                             .warning("** Finished registering all font paths");
 236                 }
 237                 fileName = fontNameMap.get(fontID);
 238             }
 239             if (fileName == null && !isHeadless()) {
 240                 /* Query X11 directly to see if this font is available
 241                  * as a native font.
 242                  */
 243                 fileName = getX11FontName(platName);
 244             }
 245             if (fileName == null) {
 246                 fontID = switchFontIDForName(platName);
 247                 fileName = fontNameMap.get(fontID);
 248             }
 249             if (fileName != null) {
 250                 fontNameMap.put(fontID, fileName);
 251             }
 252         }
 253         return fileName;
 254     }
 255 


 272             int len = nativeNames.size();
 273             return nativeNames.toArray(new String[len]);
 274         }
 275     }
 276 
 277     /* NOTE: this method needs to be executed in a privileged context.
 278      * The superclass constructor which is the primary caller of
 279      * this method executes entirely in such a context. Additionally
 280      * the loadFonts() method does too. So all should be well.
 281 
 282      */
 283     @Override
 284     protected void registerFontDir(String path) {
 285         /* fonts.dir file format looks like :-
 286          * 47
 287          * Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1
 288          * Arial-Bold.ttf -monotype-arial-bold-r-normal--0-0-0-0-p-0-iso8859-1
 289          * ...
 290          */
 291         if (FontUtilities.debugFonts()) {
 292             FontUtilities.getLogger().info("ParseFontDir " + path);
 293         }
 294         File fontsDotDir = new File(path + File.separator + "fonts.dir");
 295         FileReader fr = null;
 296         try {
 297             if (fontsDotDir.canRead()) {
 298                 fr = new FileReader(fontsDotDir);
 299                 BufferedReader br = new BufferedReader(fr, 8192);
 300                 StreamTokenizer st = new StreamTokenizer(br);
 301                 st.eolIsSignificant(true);
 302                 int ttype = st.nextToken();
 303                 if (ttype == StreamTokenizer.TT_NUMBER) {
 304                     int numEntries = (int)st.nval;
 305                     ttype = st.nextToken();
 306                     if (ttype == StreamTokenizer.TT_EOL) {
 307                         st.resetSyntax();
 308                         st.wordChars(32, 127);
 309                         st.wordChars(128 + 32, 255);
 310                         st.whitespaceChars(0, 31);
 311 
 312                         for (int i=0; i < numEntries; i++) {


 351                                 continue;
 352                             }
 353                             String fileName = st.sval.substring(0, breakPos);
 354                             /* TurboLinux 8.0 uses some additional syntax to
 355                              * indicate algorithmic styling values.
 356                              * Ignore ':' separated files at the beginning
 357                              * of the fileName
 358                              */
 359                             int lastColon = fileName.lastIndexOf(':');
 360                             if (lastColon > 0) {
 361                                 if (lastColon+1 >= fileName.length()) {
 362                                     continue;
 363                                 }
 364                                 fileName = fileName.substring(lastColon+1);
 365                             }
 366                             String fontPart = st.sval.substring(breakPos+1);
 367                             String fontID = specificFontIDForName(fontPart);
 368                             String sVal = fontNameMap.get(fontID);
 369 
 370                             if (FontUtilities.debugFonts()) {
 371                                 PlatformLogger logger = FontUtilities.getLogger();
 372                                 logger.info("file=" + fileName +
 373                                             " xlfd=" + fontPart);
 374                                 logger.info("fontID=" + fontID +
 375                                             " sVal=" + sVal);
 376                             }
 377                             String fullPath = null;
 378                             try {
 379                                 File file = new File(path,fileName);
 380                                 /* we may have a resolved symbolic link
 381                                  * this becomes important for an xlfd we
 382                                  * still need to know the location it was
 383                                  * found to update the X server font path
 384                                  * for use by AWT heavyweights - and when 2D
 385                                  * wants to use the native rasteriser.
 386                                  */
 387                                 if (xFontDirsMap == null) {
 388                                     xFontDirsMap = new HashMap<>();
 389                                 }
 390                                 xFontDirsMap.put(fontID, path);
 391                                 fullPath = file.getCanonicalPath();
 392                             } catch (IOException e) {
 393                                 fullPath = path + File.separator + fileName;
 394                             }
 395                             Vector<String> xVal = xlfdMap.get(fullPath);
 396                             if (FontUtilities.debugFonts()) {
 397                                 FontUtilities.getLogger()
 398                                       .info("fullPath=" + fullPath +
 399                                             " xVal=" + xVal);
 400                             }
 401                             if ((xVal == null || !xVal.contains(fontPart)) &&
 402                                 (sVal == null) || !sVal.startsWith("/")) {
 403                                 if (FontUtilities.debugFonts()) {
 404                                     FontUtilities.getLogger()
 405                                           .info("Map fontID:"+fontID +
 406                                                 "to file:" + fullPath);
 407                                 }
 408                                 fontNameMap.put(fontID, fullPath);
 409                                 if (xVal == null) {
 410                                     xVal = new Vector<>();
 411                                     xlfdMap.put (fullPath, xVal);
 412                                 }
 413                                 xVal.add(fontPart);
 414                             }
 415 
 416                             ttype = st.nextToken();
 417                             if (ttype != StreamTokenizer.TT_EOL) {
 418                                 break;
 419                             }
 420                         }
 421                     }
 422                 }
 423                 fr.close();
 424             }
 425         } catch (IOException ioe1) {


 464             GraphicsEnvironment.getLocalGraphicsEnvironment();
 465         return GraphicsEnvironment.isHeadless();
 466     }
 467 
 468     private String specificFontIDForName(String name) {
 469 
 470         int[] hPos = new int[14];
 471         int hyphenCnt = 1;
 472         int pos = 1;
 473 
 474         while (pos != -1 && hyphenCnt < 14) {
 475             pos = name.indexOf('-', pos);
 476             if (pos != -1) {
 477                 hPos[hyphenCnt++] = pos;
 478                     pos++;
 479             }
 480         }
 481 
 482         if (hyphenCnt != 14) {
 483             if (FontUtilities.debugFonts()) {
 484                 FontUtilities.getLogger()
 485                     .severe("Font Configuration Font ID is malformed:" + name);
 486             }
 487             return name; // what else can we do?
 488         }
 489 
 490         StringBuffer sb =
 491             new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],
 492                                             hPos[SETWIDTH_NAME_FIELD]));
 493         sb.append(name.substring(hPos[CHARSET_REGISTRY_FIELD-1]));
 494         String retval = sb.toString().toLowerCase (Locale.ENGLISH);
 495         return retval;
 496     }
 497 
 498     private String switchFontIDForName(String name) {
 499 
 500         int[] hPos = new int[14];
 501         int hyphenCnt = 1;
 502         int pos = 1;
 503 
 504         while (pos != -1 && hyphenCnt < 14) {
 505             pos = name.indexOf('-', pos);
 506             if (pos != -1) {
 507                 hPos[hyphenCnt++] = pos;
 508                     pos++;
 509             }
 510         }
 511 
 512         if (hyphenCnt != 14) {
 513             if (FontUtilities.debugFonts()) {
 514                 FontUtilities.getLogger()
 515                     .severe("Font Configuration Font ID is malformed:" + name);
 516             }
 517             return name; // what else can we do?
 518         }
 519 
 520         String slant = name.substring(hPos[SLANT_FIELD-1]+1,
 521                                            hPos[SLANT_FIELD]);
 522         String family = name.substring(hPos[FAMILY_NAME_FIELD-1]+1,
 523                                            hPos[FAMILY_NAME_FIELD]);
 524         String registry = name.substring(hPos[CHARSET_REGISTRY_FIELD-1]+1,
 525                                            hPos[CHARSET_REGISTRY_FIELD]);
 526         String encoding = name.substring(hPos[CHARSET_ENCODING_FIELD-1]+1);
 527 
 528         if (slant.equals("i")) {
 529             slant = "o";
 530         } else if (slant.equals("o")) {
 531             slant = "i";
 532         }
 533         // workaround for #4471000
 534         if (family.equals("itc zapfdingbats")
 535             && registry.equals("sun")


 658     @Override
 659     protected void addFontToPlatformFontPath(String platformName) {
 660         // Lazily initialize fontConfigDirs.
 661         getPlatformFontPathFromFontConfig();
 662         if (xFontDirsMap != null) {
 663             String fontID = specificFontIDForName(platformName);
 664             String dirName = xFontDirsMap.get(fontID);
 665             if (dirName != null) {
 666                 fontConfigDirs.add(dirName);
 667             }
 668         }
 669         return;
 670     }
 671 
 672     private void getPlatformFontPathFromFontConfig() {
 673         if (fontConfigDirs == null) {
 674             fontConfigDirs = getFontConfiguration().getAWTFontPathSet();
 675             if (FontUtilities.debugFonts() && fontConfigDirs != null) {
 676                 String[] names = fontConfigDirs.toArray(new String[0]);
 677                 for (int i=0;i<names.length;i++) {
 678                     FontUtilities.getLogger().info("awtfontpath : " + names[i]);
 679                 }
 680             }
 681         }
 682     }
 683 
 684     @Override
 685     protected void registerPlatformFontsUsedByFontConfiguration() {
 686         // Lazily initialize fontConfigDirs.
 687         getPlatformFontPathFromFontConfig();
 688         if (fontConfigDirs == null) {
 689             return;
 690         }
 691         if (FontUtilities.isLinux) {
 692             fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts");
 693         }
 694         fontdirs = fontConfigDirs.toArray(new String[0]);
 695     }
 696 
 697     // Implements SunGraphicsEnvironment.createFontConfiguration.
 698     protected FontConfiguration createFontConfiguration() {




 207                         xVal.add(platName);
 208                         xlfdMap.put(fileName, xVal);
 209                     }
 210                 } else {
 211                     if (!xVal.contains(platName)) {
 212                         xVal.add(platName);
 213                     }
 214                 }
 215             }
 216             if (fileName != null) {
 217                 fontNameMap.put(fontID, fileName);
 218                 return fileName;
 219             }
 220         }
 221 
 222         if (fontID != null) {
 223             fileName = fontNameMap.get(fontID);
 224             if (fontPath == null &&
 225                 (fileName == null || !fileName.startsWith("/"))) {
 226                 if (FontUtilities.debugFonts()) {
 227                     FontUtilities.logWarning("** Registering all font paths because " +

 228                                              "can't find file for " + platName);
 229                 }
 230                 fontPath = getPlatformFontPath(noType1Font);
 231                 registerFontDirs(fontPath);
 232                 if (FontUtilities.debugFonts()) {
 233                     FontUtilities.logWarning("** Finished registering all font paths");

 234                 }
 235                 fileName = fontNameMap.get(fontID);
 236             }
 237             if (fileName == null && !isHeadless()) {
 238                 /* Query X11 directly to see if this font is available
 239                  * as a native font.
 240                  */
 241                 fileName = getX11FontName(platName);
 242             }
 243             if (fileName == null) {
 244                 fontID = switchFontIDForName(platName);
 245                 fileName = fontNameMap.get(fontID);
 246             }
 247             if (fileName != null) {
 248                 fontNameMap.put(fontID, fileName);
 249             }
 250         }
 251         return fileName;
 252     }
 253 


 270             int len = nativeNames.size();
 271             return nativeNames.toArray(new String[len]);
 272         }
 273     }
 274 
 275     /* NOTE: this method needs to be executed in a privileged context.
 276      * The superclass constructor which is the primary caller of
 277      * this method executes entirely in such a context. Additionally
 278      * the loadFonts() method does too. So all should be well.
 279 
 280      */
 281     @Override
 282     protected void registerFontDir(String path) {
 283         /* fonts.dir file format looks like :-
 284          * 47
 285          * Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1
 286          * Arial-Bold.ttf -monotype-arial-bold-r-normal--0-0-0-0-p-0-iso8859-1
 287          * ...
 288          */
 289         if (FontUtilities.debugFonts()) {
 290             FontUtilities.logInfo("ParseFontDir " + path);
 291         }
 292         File fontsDotDir = new File(path + File.separator + "fonts.dir");
 293         FileReader fr = null;
 294         try {
 295             if (fontsDotDir.canRead()) {
 296                 fr = new FileReader(fontsDotDir);
 297                 BufferedReader br = new BufferedReader(fr, 8192);
 298                 StreamTokenizer st = new StreamTokenizer(br);
 299                 st.eolIsSignificant(true);
 300                 int ttype = st.nextToken();
 301                 if (ttype == StreamTokenizer.TT_NUMBER) {
 302                     int numEntries = (int)st.nval;
 303                     ttype = st.nextToken();
 304                     if (ttype == StreamTokenizer.TT_EOL) {
 305                         st.resetSyntax();
 306                         st.wordChars(32, 127);
 307                         st.wordChars(128 + 32, 255);
 308                         st.whitespaceChars(0, 31);
 309 
 310                         for (int i=0; i < numEntries; i++) {


 349                                 continue;
 350                             }
 351                             String fileName = st.sval.substring(0, breakPos);
 352                             /* TurboLinux 8.0 uses some additional syntax to
 353                              * indicate algorithmic styling values.
 354                              * Ignore ':' separated files at the beginning
 355                              * of the fileName
 356                              */
 357                             int lastColon = fileName.lastIndexOf(':');
 358                             if (lastColon > 0) {
 359                                 if (lastColon+1 >= fileName.length()) {
 360                                     continue;
 361                                 }
 362                                 fileName = fileName.substring(lastColon+1);
 363                             }
 364                             String fontPart = st.sval.substring(breakPos+1);
 365                             String fontID = specificFontIDForName(fontPart);
 366                             String sVal = fontNameMap.get(fontID);
 367 
 368                             if (FontUtilities.debugFonts()) {
 369                                 FontUtilities.logInfo("file=" + fileName +

 370                                             " xlfd=" + fontPart);
 371                                 FontUtilities.logInfo("fontID=" + fontID +
 372                                             " sVal=" + sVal);
 373                             }
 374                             String fullPath = null;
 375                             try {
 376                                 File file = new File(path,fileName);
 377                                 /* we may have a resolved symbolic link
 378                                  * this becomes important for an xlfd we
 379                                  * still need to know the location it was
 380                                  * found to update the X server font path
 381                                  * for use by AWT heavyweights - and when 2D
 382                                  * wants to use the native rasteriser.
 383                                  */
 384                                 if (xFontDirsMap == null) {
 385                                     xFontDirsMap = new HashMap<>();
 386                                 }
 387                                 xFontDirsMap.put(fontID, path);
 388                                 fullPath = file.getCanonicalPath();
 389                             } catch (IOException e) {
 390                                 fullPath = path + File.separator + fileName;
 391                             }
 392                             Vector<String> xVal = xlfdMap.get(fullPath);
 393                             if (FontUtilities.debugFonts()) {
 394                                 FontUtilities.logInfo("fullPath=" + fullPath +

 395                                                       " xVal=" + xVal);
 396                             }
 397                             if ((xVal == null || !xVal.contains(fontPart)) &&
 398                                 (sVal == null) || !sVal.startsWith("/")) {
 399                                 if (FontUtilities.debugFonts()) {
 400                                     FontUtilities.logInfo("Map fontID:"+fontID +

 401                                                           "to file:" + fullPath);
 402                                 }
 403                                 fontNameMap.put(fontID, fullPath);
 404                                 if (xVal == null) {
 405                                     xVal = new Vector<>();
 406                                     xlfdMap.put (fullPath, xVal);
 407                                 }
 408                                 xVal.add(fontPart);
 409                             }
 410 
 411                             ttype = st.nextToken();
 412                             if (ttype != StreamTokenizer.TT_EOL) {
 413                                 break;
 414                             }
 415                         }
 416                     }
 417                 }
 418                 fr.close();
 419             }
 420         } catch (IOException ioe1) {


 459             GraphicsEnvironment.getLocalGraphicsEnvironment();
 460         return GraphicsEnvironment.isHeadless();
 461     }
 462 
 463     private String specificFontIDForName(String name) {
 464 
 465         int[] hPos = new int[14];
 466         int hyphenCnt = 1;
 467         int pos = 1;
 468 
 469         while (pos != -1 && hyphenCnt < 14) {
 470             pos = name.indexOf('-', pos);
 471             if (pos != -1) {
 472                 hPos[hyphenCnt++] = pos;
 473                     pos++;
 474             }
 475         }
 476 
 477         if (hyphenCnt != 14) {
 478             if (FontUtilities.debugFonts()) {
 479                 FontUtilities.logSevere("Font Configuration Font ID is malformed:" + name);

 480             }
 481             return name; // what else can we do?
 482         }
 483 
 484         StringBuffer sb =
 485             new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],
 486                                             hPos[SETWIDTH_NAME_FIELD]));
 487         sb.append(name.substring(hPos[CHARSET_REGISTRY_FIELD-1]));
 488         String retval = sb.toString().toLowerCase (Locale.ENGLISH);
 489         return retval;
 490     }
 491 
 492     private String switchFontIDForName(String name) {
 493 
 494         int[] hPos = new int[14];
 495         int hyphenCnt = 1;
 496         int pos = 1;
 497 
 498         while (pos != -1 && hyphenCnt < 14) {
 499             pos = name.indexOf('-', pos);
 500             if (pos != -1) {
 501                 hPos[hyphenCnt++] = pos;
 502                     pos++;
 503             }
 504         }
 505 
 506         if (hyphenCnt != 14) {
 507             if (FontUtilities.debugFonts()) {
 508                 FontUtilities.logSevere("Font Configuration Font ID is malformed:" + name);

 509             }
 510             return name; // what else can we do?
 511         }
 512 
 513         String slant = name.substring(hPos[SLANT_FIELD-1]+1,
 514                                            hPos[SLANT_FIELD]);
 515         String family = name.substring(hPos[FAMILY_NAME_FIELD-1]+1,
 516                                            hPos[FAMILY_NAME_FIELD]);
 517         String registry = name.substring(hPos[CHARSET_REGISTRY_FIELD-1]+1,
 518                                            hPos[CHARSET_REGISTRY_FIELD]);
 519         String encoding = name.substring(hPos[CHARSET_ENCODING_FIELD-1]+1);
 520 
 521         if (slant.equals("i")) {
 522             slant = "o";
 523         } else if (slant.equals("o")) {
 524             slant = "i";
 525         }
 526         // workaround for #4471000
 527         if (family.equals("itc zapfdingbats")
 528             && registry.equals("sun")


 651     @Override
 652     protected void addFontToPlatformFontPath(String platformName) {
 653         // Lazily initialize fontConfigDirs.
 654         getPlatformFontPathFromFontConfig();
 655         if (xFontDirsMap != null) {
 656             String fontID = specificFontIDForName(platformName);
 657             String dirName = xFontDirsMap.get(fontID);
 658             if (dirName != null) {
 659                 fontConfigDirs.add(dirName);
 660             }
 661         }
 662         return;
 663     }
 664 
 665     private void getPlatformFontPathFromFontConfig() {
 666         if (fontConfigDirs == null) {
 667             fontConfigDirs = getFontConfiguration().getAWTFontPathSet();
 668             if (FontUtilities.debugFonts() && fontConfigDirs != null) {
 669                 String[] names = fontConfigDirs.toArray(new String[0]);
 670                 for (int i=0;i<names.length;i++) {
 671                     FontUtilities.logInfo("awtfontpath : " + names[i]);
 672                 }
 673             }
 674         }
 675     }
 676 
 677     @Override
 678     protected void registerPlatformFontsUsedByFontConfiguration() {
 679         // Lazily initialize fontConfigDirs.
 680         getPlatformFontPathFromFontConfig();
 681         if (fontConfigDirs == null) {
 682             return;
 683         }
 684         if (FontUtilities.isLinux) {
 685             fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts");
 686         }
 687         fontdirs = fontConfigDirs.toArray(new String[0]);
 688     }
 689 
 690     // Implements SunGraphicsEnvironment.createFontConfiguration.
 691     protected FontConfiguration createFontConfiguration() {


< prev index next >