Java Code Examples for sun.awt.FcFontManager#getFontConfigManager()

The following examples show how to use sun.awt.FcFontManager#getFontConfigManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FcFontConfiguration.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 2
Source File: FcFontConfiguration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 3
Source File: FcFontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 4
Source File: FcFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 5
Source File: FcFontConfiguration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 6
Source File: FcFontConfiguration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getPlatformFontNames() {
    HashSet<String> nameSet = new HashSet<String>();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();
    for (int i=0; i<fcCompFonts.length; i++) {
        for (int j=0; j<fcCompFonts[i].allFonts.length; j++) {
            nameSet.add(fcCompFonts[i].allFonts[j].fontFile);
        }
    }
    return nameSet.toArray(new String[0]);
}
 
Example 7
Source File: FcFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void writeFcInfo() {
    Properties props = new Properties();
    props.setProperty("version", fileVersion);
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FontConfigInfo fcInfo = fcm.getFontConfigInfo();
    props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
    if (fcInfo.cacheDirs != null) {
        for (int i=0;i<fcInfo.cacheDirs.length;i++) {
            if (fcInfo.cacheDirs[i] != null) {
               props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
            }
        }
    }
    for (int i=0; i<fcCompFonts.length; i++) {
        FcCompFont fci = fcCompFonts[i];
        String styleKey = fci.jdkName+"."+fci.style;
        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);
        }
    }
    try {
        /* This writes into a temp file then renames when done.
         * Since the rename is an atomic action within the same
         * directory no client will ever see a partially written file.
         */
        File fcInfoFile = getFcInfoFile();
        File dir = fcInfoFile.getParentFile();
        dir.mkdirs();
        File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        props.store(fos,
                  "JDK Font Configuration Generated File: *Do Not Edit*");
        fos.close();
        boolean renamed = tempFile.renameTo(fcInfoFile);
        if (!renamed && FontUtilities.debugFonts()) {
            System.out.println("rename failed");
            warning("Failed renaming file to "+ getFcInfoFile());
        }
    } catch (Exception e) {
        if (FontUtilities.debugFonts()) {
            warning("IOException writing to "+ getFcInfoFile());
        }
    }
}
 
Example 8
Source File: FcFontConfiguration.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized boolean init() {
    if (fcCompFonts != null) {
        return true;
    }

    setFontConfiguration();
    readFcInfo();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    if (fcCompFonts == null) {
        fcCompFonts = fcm.loadFontConfig();
        if (fcCompFonts != null) {
            try {
                writeFcInfo();
            } catch (Exception e) {
                if (FontUtilities.debugFonts()) {
                    warning("Exception writing fcInfo " + e);
                }
            }
        } else if (FontUtilities.debugFonts()) {
            warning("Failed to get info from libfontconfig");
        }
    } else {
        fcm.populateFontConfig(fcCompFonts);
    }

    if (fcCompFonts == null) {
        return false; // couldn't load fontconfig.
    }

    // NB already in a privileged block from SGE
    String javaHome = System.getProperty("java.home");
    if (javaHome == null) {
        throw new Error("java.home property not set");
    }
    String javaLib = javaHome + File.separator + "lib";
    getInstalledFallbackFonts(javaLib);

    return true;
}
 
Example 9
Source File: FcFontConfiguration.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeFontDescriptor[] get2DCompositeFontInfo() {

    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();

    CompositeFontDescriptor[] result =
            new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];

    for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
        String fontName = publicFontNames[fontIndex];

        for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {

            String faceName = fontName + "." + styleNames[styleIndex];
            FontConfigFont[] fcFonts =
                getFcFontList(fcCompFonts,
                              fontNames[fontIndex], styleIndex);

            int numFonts = fcFonts.length;
            // fall back fonts listed in the lib/fonts/fallback directory
            if (installedFallbackFontFiles != null) {
                numFonts += installedFallbackFontFiles.length;
            }

            String[] fileNames = new String[numFonts];
            String[] faceNames = new String[numFonts];

            int index;
            for (index = 0; index < fcFonts.length; index++) {
                fileNames[index] = fcFonts[index].fontFile;
                faceNames[index] = fcFonts[index].familyName;
            }

            if (installedFallbackFontFiles != null) {
                System.arraycopy(installedFallbackFontFiles, 0,
                                 fileNames, fcFonts.length,
                                 installedFallbackFontFiles.length);
            }

            result[fontIndex * NUM_STYLES + styleIndex]
                    = new CompositeFontDescriptor(
                        faceName,
                        1,
                        faceNames,
                        fileNames,
                        null, null);
        }
    }
    return result;
}
 
Example 10
Source File: FcFontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void writeFcInfo() {
    Properties props = new Properties();
    props.setProperty("version", fileVersion);
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FontConfigInfo fcInfo = fcm.getFontConfigInfo();
    props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
    if (fcInfo.cacheDirs != null) {
        for (int i=0;i<fcInfo.cacheDirs.length;i++) {
            if (fcInfo.cacheDirs[i] != null) {
               props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
            }
        }
    }
    for (int i=0; i<fcCompFonts.length; i++) {
        FcCompFont fci = fcCompFonts[i];
        String styleKey = fci.jdkName+"."+fci.style;
        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);
        }
    }
    try {
        /* This writes into a temp file then renames when done.
         * Since the rename is an atomic action within the same
         * directory no client will ever see a partially written file.
         */
        File fcInfoFile = getFcInfoFile();
        File dir = fcInfoFile.getParentFile();
        dir.mkdirs();
        File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        props.store(fos,
                  "JDK Font Configuration Generated File: *Do Not Edit*");
        fos.close();
        boolean renamed = tempFile.renameTo(fcInfoFile);
        if (!renamed && FontUtilities.debugFonts()) {
            System.out.println("rename failed");
            warning("Failed renaming file to "+ getFcInfoFile());
        }
    } catch (Exception e) {
        if (FontUtilities.debugFonts()) {
            warning("IOException writing to "+ getFcInfoFile());
        }
    }
}
 
Example 11
Source File: FcFontConfiguration.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized boolean init() {
    if (fcCompFonts != null) {
        return true;
    }

    setFontConfiguration();
    readFcInfo();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    if (fcCompFonts == null) {
        fcCompFonts = fcm.loadFontConfig();
        if (fcCompFonts != null) {
            try {
                writeFcInfo();
            } catch (Exception e) {
                if (FontUtilities.debugFonts()) {
                    warning("Exception writing fcInfo " + e);
                }
            }
        } else if (FontUtilities.debugFonts()) {
            warning("Failed to get info from libfontconfig");
        }
    } else {
        fcm.populateFontConfig(fcCompFonts);
    }

    if (fcCompFonts == null) {
        return false; // couldn't load fontconfig.
    }

    // NB already in a privileged block from SGE
    String javaHome = System.getProperty("java.home");
    if (javaHome == null) {
        throw new Error("java.home property not set");
    }
    String javaLib = javaHome + File.separator + "lib";
    getInstalledFallbackFonts(javaLib);

    return true;
}
 
Example 12
Source File: FcFontConfiguration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void writeFcInfo() {
    Properties props = new Properties();
    props.setProperty("version", fileVersion);
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FontConfigInfo fcInfo = fcm.getFontConfigInfo();
    props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
    if (fcInfo.cacheDirs != null) {
        for (int i=0;i<fcInfo.cacheDirs.length;i++) {
            if (fcInfo.cacheDirs[i] != null) {
               props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
            }
        }
    }
    for (int i=0; i<fcCompFonts.length; i++) {
        FcCompFont fci = fcCompFonts[i];
        String styleKey = fci.jdkName+"."+fci.style;
        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);
        }
    }
    try {
        /* This writes into a temp file then renames when done.
         * Since the rename is an atomic action within the same
         * directory no client will ever see a partially written file.
         */
        File fcInfoFile = getFcInfoFile();
        File dir = fcInfoFile.getParentFile();
        dir.mkdirs();
        File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        props.store(fos,
                  "JDK Font Configuration Generated File: *Do Not Edit*");
        fos.close();
        boolean renamed = tempFile.renameTo(fcInfoFile);
        if (!renamed && FontUtilities.debugFonts()) {
            System.out.println("rename failed");
            warning("Failed renaming file to "+ getFcInfoFile());
        }
    } catch (Exception e) {
        if (FontUtilities.debugFonts()) {
            warning("IOException writing to "+ getFcInfoFile());
        }
    }
}
 
Example 13
Source File: FcFontConfiguration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeFontDescriptor[] get2DCompositeFontInfo() {

    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();

    CompositeFontDescriptor[] result =
            new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];

    for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
        String fontName = publicFontNames[fontIndex];

        for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {

            String faceName = fontName + "." + styleNames[styleIndex];
            FontConfigFont[] fcFonts =
                getFcFontList(fcCompFonts,
                              fontNames[fontIndex], styleIndex);

            int numFonts = fcFonts.length;
            // fall back fonts listed in the lib/fonts/fallback directory
            if (installedFallbackFontFiles != null) {
                numFonts += installedFallbackFontFiles.length;
            }

            String[] fileNames = new String[numFonts];
            String[] faceNames = new String[numFonts];

            int index;
            for (index = 0; index < fcFonts.length; index++) {
                fileNames[index] = fcFonts[index].fontFile;
                faceNames[index] = fcFonts[index].familyName;
            }

            if (installedFallbackFontFiles != null) {
                System.arraycopy(installedFallbackFontFiles, 0,
                                 fileNames, fcFonts.length,
                                 installedFallbackFontFiles.length);
            }

            result[fontIndex * NUM_STYLES + styleIndex]
                    = new CompositeFontDescriptor(
                        faceName,
                        1,
                        faceNames,
                        fileNames,
                        null, null);
        }
    }
    return result;
}
 
Example 14
Source File: FcFontConfiguration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized boolean init() {
    if (fcCompFonts != null) {
        return true;
    }

    setFontConfiguration();
    readFcInfo();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    if (fcCompFonts == null) {
        fcCompFonts = fcm.loadFontConfig();
        if (fcCompFonts != null) {
            try {
                writeFcInfo();
            } catch (Exception e) {
                if (FontUtilities.debugFonts()) {
                    warning("Exception writing fcInfo " + e);
                }
            }
        } else if (FontUtilities.debugFonts()) {
            warning("Failed to get info from libfontconfig");
        }
    } else {
        fcm.populateFontConfig(fcCompFonts);
    }

    if (fcCompFonts == null) {
        return false; // couldn't load fontconfig.
    }

    // NB already in a privileged block from SGE
    String javaHome = System.getProperty("java.home");
    if (javaHome == null) {
        throw new Error("java.home property not set");
    }
    String javaLib = javaHome + File.separator + "lib";
    getInstalledFallbackFonts(javaLib);

    return true;
}
 
Example 15
Source File: FcFontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized boolean init() {
    if (fcCompFonts != null) {
        return true;
    }

    setFontConfiguration();
    readFcInfo();
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    if (fcCompFonts == null) {
        fcCompFonts = fcm.loadFontConfig();
        if (fcCompFonts != null) {
            try {
                writeFcInfo();
            } catch (Exception e) {
                if (FontUtilities.debugFonts()) {
                    warning("Exception writing fcInfo " + e);
                }
            }
        } else if (FontUtilities.debugFonts()) {
            warning("Failed to get info from libfontconfig");
        }
    } else {
        fcm.populateFontConfig(fcCompFonts);
    }

    if (fcCompFonts == null) {
        return false; // couldn't load fontconfig.
    }

    // NB already in a privileged block from SGE
    String javaHome = System.getProperty("java.home");
    if (javaHome == null) {
        throw new Error("java.home property not set");
    }
    String javaLib = javaHome + File.separator + "lib";
    getInstalledFallbackFonts(javaLib);

    return true;
}
 
Example 16
Source File: FcFontConfiguration.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeFontDescriptor[] get2DCompositeFontInfo() {

    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();

    CompositeFontDescriptor[] result =
            new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];

    for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
        String fontName = publicFontNames[fontIndex];

        for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {

            String faceName = fontName + "." + styleNames[styleIndex];
            FontConfigFont[] fcFonts =
                getFcFontList(fcCompFonts,
                              fontNames[fontIndex], styleIndex);

            int numFonts = fcFonts.length;
            // fall back fonts listed in the lib/fonts/fallback directory
            if (installedFallbackFontFiles != null) {
                numFonts += installedFallbackFontFiles.length;
            }

            String[] fileNames = new String[numFonts];
            String[] faceNames = new String[numFonts];

            int index;
            for (index = 0; index < fcFonts.length; index++) {
                fileNames[index] = fcFonts[index].fontFile;
                faceNames[index] = fcFonts[index].familyName;
            }

            if (installedFallbackFontFiles != null) {
                System.arraycopy(installedFallbackFontFiles, 0,
                                 fileNames, fcFonts.length,
                                 installedFallbackFontFiles.length);
            }

            result[fontIndex * NUM_STYLES + styleIndex]
                    = new CompositeFontDescriptor(
                        faceName,
                        1,
                        faceNames,
                        fileNames,
                        null, null);
        }
    }
    return result;
}
 
Example 17
Source File: FcFontConfiguration.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void writeFcInfo() {
    Properties props = new Properties();
    props.setProperty("version", fileVersion);
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FontConfigInfo fcInfo = fcm.getFontConfigInfo();
    props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
    if (fcInfo.cacheDirs != null) {
        for (int i=0;i<fcInfo.cacheDirs.length;i++) {
            if (fcInfo.cacheDirs[i] != null) {
               props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
            }
        }
    }
    for (int i=0; i<fcCompFonts.length; i++) {
        FcCompFont fci = fcCompFonts[i];
        String styleKey = fci.jdkName+"."+fci.style;
        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);
        }
    }
    try {
        /* This writes into a temp file then renames when done.
         * Since the rename is an atomic action within the same
         * directory no client will ever see a partially written file.
         */
        File fcInfoFile = getFcInfoFile();
        File dir = fcInfoFile.getParentFile();
        dir.mkdirs();
        File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        props.store(fos,
                  "JDK Font Configuration Generated File: *Do Not Edit*");
        fos.close();
        boolean renamed = tempFile.renameTo(fcInfoFile);
        if (!renamed && FontUtilities.debugFonts()) {
            System.out.println("rename failed");
            warning("Failed renaming file to "+ getFcInfoFile());
        }
    } catch (Exception e) {
        if (FontUtilities.debugFonts()) {
            warning("IOException writing to "+ getFcInfoFile());
        }
    }
}
 
Example 18
Source File: FcFontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeFontDescriptor[] get2DCompositeFontInfo() {

    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();

    CompositeFontDescriptor[] result =
            new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];

    for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
        String fontName = publicFontNames[fontIndex];

        for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {

            String faceName = fontName + "." + styleNames[styleIndex];
            FontConfigFont[] fcFonts =
                getFcFontList(fcCompFonts,
                              fontNames[fontIndex], styleIndex);

            int numFonts = fcFonts.length;
            // fall back fonts listed in the lib/fonts/fallback directory
            if (installedFallbackFontFiles != null) {
                numFonts += installedFallbackFontFiles.length;
            }

            String[] fileNames = new String[numFonts];
            String[] faceNames = new String[numFonts];

            int index;
            for (index = 0; index < fcFonts.length; index++) {
                fileNames[index] = fcFonts[index].fontFile;
                faceNames[index] = fcFonts[index].familyName;
            }

            if (installedFallbackFontFiles != null) {
                System.arraycopy(installedFallbackFontFiles, 0,
                                 fileNames, fcFonts.length,
                                 installedFallbackFontFiles.length);
            }

            result[fontIndex * NUM_STYLES + styleIndex]
                    = new CompositeFontDescriptor(
                        faceName,
                        1,
                        faceNames,
                        fileNames,
                        null, null);
        }
    }
    return result;
}
 
Example 19
Source File: FcFontConfiguration.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void writeFcInfo() {
    Properties props = new Properties();
    props.setProperty("version", fileVersion);
    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FontConfigInfo fcInfo = fcm.getFontConfigInfo();
    props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
    if (fcInfo.cacheDirs != null) {
        for (int i=0;i<fcInfo.cacheDirs.length;i++) {
            if (fcInfo.cacheDirs[i] != null) {
               props.setProperty("cachedir."+i,  fcInfo.cacheDirs[i]);
            }
        }
    }
    for (int i=0; i<fcCompFonts.length; i++) {
        FcCompFont fci = fcCompFonts[i];
        String styleKey = fci.jdkName+"."+fci.style;
        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);
        }
    }
    try {
        /* This writes into a temp file then renames when done.
         * Since the rename is an atomic action within the same
         * directory no client will ever see a partially written file.
         */
        File fcInfoFile = getFcInfoFile();
        File dir = fcInfoFile.getParentFile();
        dir.mkdirs();
        File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        props.store(fos,
                  "JDK Font Configuration Generated File: *Do Not Edit*");
        fos.close();
        boolean renamed = tempFile.renameTo(fcInfoFile);
        if (!renamed && FontUtilities.debugFonts()) {
            System.out.println("rename failed");
            warning("Failed renaming file to "+ getFcInfoFile());
        }
    } catch (Exception e) {
        if (FontUtilities.debugFonts()) {
            warning("IOException writing to "+ getFcInfoFile());
        }
    }
}
 
Example 20
Source File: FcFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CompositeFontDescriptor[] get2DCompositeFontInfo() {

    FcFontManager fm = (FcFontManager) fontManager;
    FontConfigManager fcm = fm.getFontConfigManager();
    FcCompFont[] fcCompFonts = fcm.loadFontConfig();

    CompositeFontDescriptor[] result =
            new CompositeFontDescriptor[NUM_FONTS * NUM_STYLES];

    for (int fontIndex = 0; fontIndex < NUM_FONTS; fontIndex++) {
        String fontName = publicFontNames[fontIndex];

        for (int styleIndex = 0; styleIndex < NUM_STYLES; styleIndex++) {

            String faceName = fontName + "." + styleNames[styleIndex];
            FontConfigFont[] fcFonts =
                getFcFontList(fcCompFonts,
                              fontNames[fontIndex], styleIndex);

            int numFonts = fcFonts.length;
            // fall back fonts listed in the lib/fonts/fallback directory
            if (installedFallbackFontFiles != null) {
                numFonts += installedFallbackFontFiles.length;
            }

            String[] fileNames = new String[numFonts];
            String[] faceNames = new String[numFonts];

            int index;
            for (index = 0; index < fcFonts.length; index++) {
                fileNames[index] = fcFonts[index].fontFile;
                faceNames[index] = fcFonts[index].familyName;
            }

            if (installedFallbackFontFiles != null) {
                System.arraycopy(installedFallbackFontFiles, 0,
                                 fileNames, fcFonts.length,
                                 installedFallbackFontFiles.length);
            }

            result[fontIndex * NUM_STYLES + styleIndex]
                    = new CompositeFontDescriptor(
                        faceName,
                        1,
                        faceNames,
                        fileNames,
                        null, null);
        }
    }
    return result;
}