src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47216 71c04702a3d5
child 58679 9c3209ff7550
--- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
 
 package sun.font;
 
-import java.awt.Font;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -37,6 +36,7 @@
 import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Locale;
 import java.util.Properties;
 import java.util.Scanner;
 import sun.awt.FcFontManager;
@@ -44,11 +44,9 @@
 import sun.awt.FontDescriptor;
 import sun.awt.SunToolkit;
 import sun.font.CompositeFontDescriptor;
-import sun.font.FontManager;
 import sun.font.FontConfigManager.FontConfigInfo;
 import sun.font.FontConfigManager.FcCompFont;
 import sun.font.FontConfigManager.FontConfigFont;
-import sun.java2d.SunGraphicsEnvironment;
 import sun.util.logging.PlatformLogger;
 
 public class FcFontConfiguration extends FontConfiguration {
@@ -264,7 +262,7 @@
                 int index;
                 for (index = 0; index < fcFonts.length; index++) {
                     fileNames[index] = fcFonts[index].fontFile;
-                    faceNames[index] = fcFonts[index].familyName;
+                    faceNames[index] = fcFonts[index].fullName;
                 }
 
                 if (installedFallbackFontFiles != null) {
@@ -288,12 +286,10 @@
     /**
      * Gets the OS version string from a Linux release-specific file.
      */
-    private String getVersionString(File f){
-        try {
-            Scanner sc  = new Scanner(f);
+    private String getVersionString(File f) {
+        try (Scanner sc  = new Scanner(f)) {
             return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
-        }
-        catch (Exception e){
+        } catch (Exception e) {
         }
         return null;
     }
@@ -357,9 +353,11 @@
             String version = System.getProperty("java.version");
             String fs = File.separator;
             String dir = userDir+fs+".java"+fs+"fonts"+fs+version;
-            String lang = SunToolkit.getStartupLocale().getLanguage();
+            Locale locale = SunToolkit.getStartupLocale();
+            String lang = locale.getLanguage();
+            String country = locale.getCountry();
             String name = "fcinfo-"+fileVersion+"-"+hostname+"-"+
-                osName+"-"+osVersion+"-"+lang+".properties";
+                osName+"-"+osVersion+"-"+lang+"-"+country+".properties";
             fcInfoFileName = dir+fs+name;
         }
         return new File(fcInfoFileName);
@@ -385,10 +383,12 @@
             props.setProperty(styleKey+".length",
                               Integer.toString(fci.allFonts.length));
             for (int j=0; j<fci.allFonts.length; j++) {
-                props.setProperty(styleKey+"."+j+".family",
-                                  fci.allFonts[j].familyName);
                 props.setProperty(styleKey+"."+j+".file",
                                   fci.allFonts[j].fontFile);
+                if (fci.allFonts[j].fullName != null) {
+                    props.setProperty(styleKey+"."+j+".fullName",
+                                      fci.allFonts[j].fullName);
+                }
             }
         }
         try {
@@ -424,23 +424,26 @@
     private void readFcInfo() {
         File fcFile = getFcInfoFile();
         if (!fcFile.exists()) {
+            if (FontUtilities.debugFonts()) {
+                warning("fontconfig info file " + fcFile.toString() + " does not exist");
+            }
             return;
         }
         Properties props = new Properties();
-        FcFontManager fm = (FcFontManager) fontManager;
-        FontConfigManager fcm = fm.getFontConfigManager();
-        try {
-            FileInputStream fis = new FileInputStream(fcFile);
+        try (FileInputStream fis = new FileInputStream(fcFile)) {
             props.load(fis);
-            fis.close();
         } catch (IOException e) {
             if (FontUtilities.debugFonts()) {
-                warning("IOException reading from "+fcFile.toString());
+                warning("IOException (" + e.getCause() + ") reading from " + fcFile.toString());
             }
             return;
         }
         String version = (String)props.get("version");
         if (version == null || !version.equals(fileVersion)) {
+            if (FontUtilities.debugFonts()) {
+                warning("fontconfig info file version mismatch (found: " + version +
+                    ", expected: " + fileVersion + ")");
+            }
             return;
         }
 
@@ -453,6 +456,9 @@
                 fcVersion = Integer.parseInt(fcVersionStr);
                 if (fcVersion != 0 &&
                     fcVersion != FontConfigManager.getFontConfigVersion()) {
+                    if (FontUtilities.debugFonts()) {
+                        warning("new, different fontconfig detected");
+                    }
                     return;
                 }
             } catch (Exception e) {
@@ -475,6 +481,9 @@
             }
             File dirFile = new File(dir);
             if (dirFile.exists() && dirFile.lastModified() > lastModified) {
+                if (FontUtilities.debugFonts()) {
+                    warning("out of date cache directories detected");
+                }
                 return;
             }
             cacheDirIndex++;
@@ -498,17 +507,23 @@
                     String lenStr = (String)props.get(key+".length");
                     int nfonts = Integer.parseInt(lenStr);
                     if (nfonts <= 0) {
+                        if (FontUtilities.debugFonts()) {
+                            warning("bad non-positive .length entry in fontconfig file " + fcFile.toString());
+                        }
                         return; // bad file
                     }
                     fci[index].allFonts = new FontConfigFont[nfonts];
                     for (int f=0; f<nfonts; f++) {
                         fci[index].allFonts[f] = new FontConfigFont();
-                        String fkey = key+"."+f+".family";
-                        String family = (String)props.get(fkey);
-                        fci[index].allFonts[f].familyName = family;
+                        String fkey = key+"."+f+".fullName";
+                        String fullName = (String)props.get(fkey);
+                        fci[index].allFonts[f].fullName = fullName;
                         fkey = key+"."+f+".file";
                         String file = (String)props.get(fkey);
                         if (file == null) {
+                            if (FontUtilities.debugFonts()) {
+                                warning("missing file value for key " + fkey + " in fontconfig file " + fcFile.toString());
+                            }
                             return; // bad file
                         }
                         fci[index].allFonts[f].fontFile = file;
@@ -523,6 +538,11 @@
                 warning(t.toString());
             }
         }
+
+        if (FontUtilities.debugFonts()) {
+            PlatformLogger logger = FontUtilities.getLogger();
+            logger.info("successfully parsed the fontconfig file at " + fcFile.toString());
+        }
     }
 
     private static void warning(String msg) {