mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-23 17:59:44 +01:00
Revert "JBR-1775: improved logic for choosing newer font between system and bundled ones"
This reverts commit 5ef38ed8fa.
This commit is contained in:
@@ -40,6 +40,7 @@ import javax.swing.plaf.FontUIResource;
|
|||||||
import sun.awt.FontConfiguration;
|
import sun.awt.FontConfiguration;
|
||||||
import sun.awt.HeadlessToolkit;
|
import sun.awt.HeadlessToolkit;
|
||||||
import sun.lwawt.macosx.*;
|
import sun.lwawt.macosx.*;
|
||||||
|
import sun.util.logging.PlatformLogger;
|
||||||
|
|
||||||
public final class CFontManager extends SunFontManager {
|
public final class CFontManager extends SunFontManager {
|
||||||
private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
|
private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
|
||||||
@@ -140,15 +141,45 @@ public final class CFontManager extends SunFontManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSystemFontVersion(TrueTypeFont bundledFont) {
|
protected void registerJREFonts() {
|
||||||
String version = getNativeFontVersion(bundledFont.getPostscriptName());
|
@SuppressWarnings("removal")
|
||||||
return version != null ? TrueTypeFont.parseVersion(version) : "0";
|
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
|
||||||
}
|
new File(jreFontDirName).list(getTrueTypeFilter()));
|
||||||
|
if (files != null) {
|
||||||
@Override
|
PlatformLogger logger = FontUtilities.getLogger();
|
||||||
protected void loadJREFonts(String[] fonts) {
|
boolean versionCheckEnabled = !("true".equals(System.getProperty("java2d.font.noVersionCheck")));
|
||||||
for (String name : fonts) {
|
int [] ver = new int[3];
|
||||||
loadNativeDirFonts(name);
|
for (String f : files) {
|
||||||
|
boolean loadFont = true;
|
||||||
|
BundledFontInfo fi = getBundledFontInfo(f);
|
||||||
|
if (versionCheckEnabled) {
|
||||||
|
if (fi != null) {
|
||||||
|
String verStr = getNativeFontVersion(fi.getPsName());
|
||||||
|
if (logger != null) {
|
||||||
|
logger.info("Checking bundled " + fi.getPsName());
|
||||||
|
}
|
||||||
|
if (verStr != null && parseFontVersion(verStr, ver) && !fi.isNewerThan(ver)) {
|
||||||
|
if (logger != null) {
|
||||||
|
logger.info("Skip loading. Newer or same version platform font detected " +
|
||||||
|
fi.getPsName() + " " + verStr);
|
||||||
|
}
|
||||||
|
loadFont = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (logger != null) {
|
||||||
|
FontUtilities.getLogger().warning("JREFonts: No BundledFontInfo for : " + f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loadFont) {
|
||||||
|
String fontPath = jreFontDirName + File.separator + f;
|
||||||
|
loadNativeDirFonts(fontPath);
|
||||||
|
if (logger != null && fi != null) {
|
||||||
|
String verStr = getNativeFontVersion(fi.getPsName());
|
||||||
|
logger.info("Loaded " + fi.getPsName() + " (" + verStr + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +207,12 @@ public final class CFontManager extends SunFontManager {
|
|||||||
|
|
||||||
void registerFont(String fontName, String fontFamilyName, String faceName) {
|
void registerFont(String fontName, String fontFamilyName, String faceName) {
|
||||||
// Use different family for specific font faces
|
// Use different family for specific font faces
|
||||||
final CFont font = new CFont(fontName, jreFamilyMap.getOrDefault(fontName, fontFamilyName), faceName);
|
String newFontFamily = jreFamilyMap.get(fontName);
|
||||||
|
if (newFontFamily != null) {
|
||||||
|
fontFamilyName = newFontFamily;
|
||||||
|
}
|
||||||
|
final CFont font = new CFont(fontName, fontFamilyName, faceName);
|
||||||
|
|
||||||
registerGenericFont(font);
|
registerGenericFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -33,13 +33,9 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@@ -58,7 +54,6 @@ import sun.awt.FontConfiguration;
|
|||||||
import sun.awt.SunToolkit;
|
import sun.awt.SunToolkit;
|
||||||
import sun.awt.util.ThreadGroupUtils;
|
import sun.awt.util.ThreadGroupUtils;
|
||||||
import sun.java2d.FontSupport;
|
import sun.java2d.FontSupport;
|
||||||
import sun.security.action.GetPropertyAction;
|
|
||||||
import sun.util.logging.PlatformLogger;
|
import sun.util.logging.PlatformLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +63,39 @@ import sun.util.logging.PlatformLogger;
|
|||||||
* methods that have to be implemented by specific implementations.
|
* methods that have to be implemented by specific implementations.
|
||||||
*/
|
*/
|
||||||
public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||||
|
protected static class BundledFontInfo {
|
||||||
|
private String psName;
|
||||||
|
private int [] version;
|
||||||
|
|
||||||
|
public BundledFontInfo(String psName, int major, int minor, int bugfix) {
|
||||||
|
this.psName = psName;
|
||||||
|
version = new int[3];
|
||||||
|
version[0] = major;
|
||||||
|
version[1] = minor;
|
||||||
|
version[2] = bugfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPsName() {
|
||||||
|
return psName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNewerThan(int[] version) {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (this.version[i] < version[i]) {
|
||||||
|
return false;
|
||||||
|
} else if (this.version[i] > version[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return psName + " v" + version[0] + "." + version[1] + "." + version[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class TTFilter implements FilenameFilter {
|
private static class TTFilter implements FilenameFilter {
|
||||||
public boolean accept(File dir,String name) {
|
public boolean accept(File dir,String name) {
|
||||||
/* all conveniently have the same suffix length */
|
/* all conveniently have the same suffix length */
|
||||||
@@ -192,8 +220,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
private boolean loaded1dot0Fonts = false;
|
private boolean loaded1dot0Fonts = false;
|
||||||
boolean loadedAllFonts = false;
|
boolean loadedAllFonts = false;
|
||||||
boolean loadedAllFontFiles = false;
|
boolean loadedAllFontFiles = false;
|
||||||
private HashSet<String> jreBundledFontFiles = new HashSet<>();
|
private HashMap<String,BundledFontInfo> jreFontMap;
|
||||||
HashMap<String,String> jreFamilyMap = new HashMap<>();
|
private HashSet<String> jreBundledFontFiles;
|
||||||
|
HashMap<String,String> jreFamilyMap;
|
||||||
String[] jreOtherFontFiles;
|
String[] jreOtherFontFiles;
|
||||||
boolean noOtherJREFontFiles = false; // initial assumption.
|
boolean noOtherJREFontFiles = false; // initial assumption.
|
||||||
|
|
||||||
@@ -203,7 +232,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
private String defaultFontName;
|
private String defaultFontName;
|
||||||
private String defaultFontFileName;
|
private String defaultFontFileName;
|
||||||
protected HashSet<String> registeredFontFiles = new HashSet<>();
|
protected HashSet<String> registeredFontFiles = new HashSet<>();
|
||||||
protected static boolean versionCheckEnabled = false;
|
|
||||||
|
|
||||||
private ArrayList<String> badFonts;
|
private ArrayList<String> badFonts;
|
||||||
/* fontPath is the location of all fonts on the system, excluding the
|
/* fontPath is the location of all fonts on the system, excluding the
|
||||||
@@ -284,19 +312,70 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
* are rarely used. Consider removing the other mappings if there's
|
* are rarely used. Consider removing the other mappings if there's
|
||||||
* no evidence they are useful in practice.
|
* no evidence they are useful in practice.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
jreFontMap = new HashMap<>();
|
||||||
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
|
jreBundledFontFiles = new HashSet<String>();
|
||||||
new File(jreFontDirName).list(getTrueTypeFilter()));
|
jreFamilyMap = new HashMap<>();
|
||||||
Collections.addAll(jreBundledFontFiles, files);
|
|
||||||
|
/* Droid Sans Mono Family */
|
||||||
|
jreFontMap.put("DroidSans.ttf", new BundledFontInfo("DroidSans", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSans-Bold.ttf", new BundledFontInfo("DroidSans-Bold", 1, 0, 0));
|
||||||
|
|
||||||
|
/* Droid Sans Mono Family */
|
||||||
|
jreFontMap.put("DroidSansMono.ttf", new BundledFontInfo("DroidSansMono", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSansMonoSlashed.ttf", new BundledFontInfo("DroidSansMonoSlashed", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSansMonoDotted.ttf", new BundledFontInfo("DroidSansMonoDotted", 1, 0, 0));
|
||||||
|
|
||||||
|
/* Droid Serif Family */
|
||||||
|
jreFontMap.put("DroidSerif-Regular.ttf", new BundledFontInfo("DroidSerif", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSerif-Bold.ttf", new BundledFontInfo("DroidSerif-Bold", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSerif-Italic.ttf", new BundledFontInfo("DroidSerif-Italic", 1, 0, 0));
|
||||||
|
jreFontMap.put("DroidSerif-BoldItalic.ttf", new BundledFontInfo("DroidSerif-BoldItalic", 1, 0, 0));
|
||||||
|
|
||||||
|
/* Idea bundled fonts */
|
||||||
|
jreFontMap.put("FiraCode-Bold.ttf", new BundledFontInfo("FiraCode-Bold", 1, 206, 0));
|
||||||
|
jreFontMap.put("FiraCode-Light.ttf", new BundledFontInfo("FiraCode-Light", 1, 206, 0));
|
||||||
|
jreFontMap.put("FiraCode-Medium.ttf", new BundledFontInfo("FiraCode-Medium", 1, 206, 0));
|
||||||
|
jreFontMap.put("FiraCode-Retina.ttf", new BundledFontInfo("FiraCode-Retina", 1, 206, 0));
|
||||||
|
jreFontMap.put("FiraCode-Regular.ttf", new BundledFontInfo("FiraCode-Regular", 1, 206, 0));
|
||||||
|
|
||||||
|
jreFontMap.put("SourceCodePro-BoldIt.ttf", new BundledFontInfo("SourceCodePro-BoldIt", 1, 30, 0));
|
||||||
|
jreFontMap.put("SourceCodePro-Regular.ttf", new BundledFontInfo("SourceCodePro-Regular", 2, 10, 0));
|
||||||
|
jreFontMap.put("SourceCodePro-Bold.ttf", new BundledFontInfo("SourceCodePro-Bold", 2, 10, 0));
|
||||||
|
jreFontMap.put("SourceCodePro-It.ttf", new BundledFontInfo("SourceCodePro-It", 1, 30, 0));
|
||||||
|
|
||||||
|
jreFontMap.put("Inconsolata.ttf", new BundledFontInfo("Inconsolata", 1, 10, 0));
|
||||||
|
|
||||||
|
jreFontMap.put("Roboto-Light.ttf", new BundledFontInfo("Roboto-Light", 1, 100141, 0));
|
||||||
|
jreFontMap.put("Roboto-Thin.ttf", new BundledFontInfo("Roboto-Thin", 1, 100141, 0));
|
||||||
|
|
||||||
jreFamilyMap.put("Roboto-Light", "Roboto Light");
|
jreFamilyMap.put("Roboto-Light", "Roboto Light");
|
||||||
jreFamilyMap.put("Roboto-Thin", "Roboto Thin");
|
jreFamilyMap.put("Roboto-Thin", "Roboto Thin");
|
||||||
|
|
||||||
|
jreFontMap.put("JetBrainsMono-Bold.ttf", new BundledFontInfo("JetBrainsMono-Bold", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-BoldItalic.ttf", new BundledFontInfo("JetBrainsMono-BoldItalic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-ExtraBold.ttf", new BundledFontInfo("JetBrainsMono-ExtraBold", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-ExtraBoldItalic.ttf", new BundledFontInfo("JetBrainsMono-ExtraBoldItalic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-ExtraLight.ttf", new BundledFontInfo("JetBrainsMono-ExtraLight", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-ExtraLightItalic.ttf", new BundledFontInfo("JetBrainsMono-ExtraLightItalic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-Italic.ttf", new BundledFontInfo("JetBrainsMono-Italic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-Light.ttf", new BundledFontInfo("JetBrainsMono-Light", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-LightItalic.ttf", new BundledFontInfo("JetBrainsMono-LightItalic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-Medium.ttf", new BundledFontInfo("JetBrainsMono-Medium", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-MediumItalic.ttf", new BundledFontInfo("JetBrainsMono-MediumItalic", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-Regular.ttf", new BundledFontInfo("JetBrainsMono-Regular", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-Thin.ttf", new BundledFontInfo("JetBrainsMono-Thin", 2, 242, 0));
|
||||||
|
jreFontMap.put("JetBrainsMono-ThinItalic.ttf", new BundledFontInfo("JetBrainsMono-ThinItalic", 2, 242, 0));
|
||||||
|
|
||||||
|
jreFontMap.put("Inter-SemiBold.otf", new BundledFontInfo("Inter-SemiBold", 3, 19, 0));
|
||||||
|
jreFontMap.put("Inter-Regular.otf", new BundledFontInfo("Inter-Regular", 3, 19, 0));
|
||||||
|
jreFontMap.put("Inter-Italic.otf", new BundledFontInfo("Inter-Italic", 3, 19, 0));
|
||||||
|
jreFontMap.put("Inter-SemiBoldItalic.otf", new BundledFontInfo("Inter-SemiBoldItalic", 3, 19, 0));
|
||||||
|
|
||||||
|
jreBundledFontFiles.addAll(jreFontMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
initStatic();
|
initStatic();
|
||||||
versionCheckEnabled = !Boolean.parseBoolean(
|
|
||||||
GetPropertyAction.privilegedGetProperty("java2d.font.noVersionCheck", "false"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
@@ -368,17 +447,21 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here we get the fonts in jre/lib/fonts and register
|
/* Here we get the fonts in jre/lib/fonts and register
|
||||||
* them so they are always available and preferred over
|
* them so they are always available and preferred over
|
||||||
* other fonts. This needs to be registered before the
|
* other fonts. This needs to be registered before the
|
||||||
* composite fonts as otherwise some native font that
|
* composite fonts as otherwise some native font that
|
||||||
* corresponds may be found as we don't have a way to
|
* corresponds may be found as we don't have a way to
|
||||||
* handle two fonts of the same name, so the JRE one
|
* handle two fonts of the same name, so the JRE one
|
||||||
* must be the first one registered. Pass "true" to
|
* must be the first one registered. Pass "true" to
|
||||||
* registerFonts method as on-screen these JRE fonts
|
* registerFonts method as on-screen these JRE fonts
|
||||||
* always go through the JDK rasteriser.
|
* always go through the JDK rasteriser.
|
||||||
*/
|
*/
|
||||||
registerJREFonts();
|
if (FontUtilities.isLinux) {
|
||||||
|
/* Linux font configuration uses these fonts */
|
||||||
|
registerFontDir(jreFontDirName);
|
||||||
|
}
|
||||||
|
registerJREFonts();
|
||||||
|
|
||||||
/* Create the font configuration and get any font path
|
/* Create the font configuration and get any font path
|
||||||
* that might be specified.
|
* that might be specified.
|
||||||
@@ -713,7 +796,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
newFont instanceof TrueTypeFont) {
|
newFont instanceof TrueTypeFont) {
|
||||||
TrueTypeFont oldTTFont = (TrueTypeFont)oldFont;
|
TrueTypeFont oldTTFont = (TrueTypeFont)oldFont;
|
||||||
TrueTypeFont newTTFont = (TrueTypeFont)newFont;
|
TrueTypeFont newTTFont = (TrueTypeFont)newFont;
|
||||||
if (isFontNewer(oldTTFont.getVersion(), newTTFont.getVersion())) {
|
if (oldTTFont.fileSize >= newTTFont.fileSize) {
|
||||||
return oldFont;
|
return oldFont;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1386,7 +1469,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
*/
|
*/
|
||||||
HashMap<String,String> fontToFileMap2 = null;
|
HashMap<String,String> fontToFileMap2 = null;
|
||||||
HashMap<String,String> fontToFamilyNameMap2 = null;
|
HashMap<String,String> fontToFamilyNameMap2 = null;
|
||||||
HashMap<String,ArrayList<String>> familyToFontListMap2 = null;
|
HashMap<String,ArrayList<String>> familyToFontListMap2 = null;;
|
||||||
|
|
||||||
for (String pathFile : getFontFilesFromPath(false)) {
|
for (String pathFile : getFontFilesFromPath(false)) {
|
||||||
if (!registryFiles.contains(pathFile)) {
|
if (!registryFiles.contains(pathFile)) {
|
||||||
@@ -2906,8 +2989,12 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
/*
|
/*
|
||||||
* helper function for registerFonts
|
* helper function for registerFonts
|
||||||
*/
|
*/
|
||||||
private void addDirFonts(String[] ls, int fontFormat, boolean useJavaRasterizer,
|
private void addDirFonts(String dirName, File dirFile,
|
||||||
int fontRank, boolean defer, boolean resolveSymLinks) {
|
FilenameFilter filter,
|
||||||
|
int fontFormat, boolean useJavaRasterizer,
|
||||||
|
int fontRank,
|
||||||
|
boolean defer, boolean resolveSymLinks) {
|
||||||
|
String[] ls = dirFile.list(filter);
|
||||||
if (ls == null || ls.length == 0) {
|
if (ls == null || ls.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2915,8 +3002,8 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
String[][] nativeNames = new String[ls.length][];
|
String[][] nativeNames = new String[ls.length][];
|
||||||
int fontCount = 0;
|
int fontCount = 0;
|
||||||
|
|
||||||
for (String file : ls) {
|
for (int i=0; i < ls.length; i++ ) {
|
||||||
File theFile = new File(file);
|
File theFile = new File(dirFile, ls[i]);
|
||||||
String fullName = null;
|
String fullName = null;
|
||||||
if (resolveSymLinks) {
|
if (resolveSymLinks) {
|
||||||
try {
|
try {
|
||||||
@@ -2925,7 +3012,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fullName == null) {
|
if (fullName == null) {
|
||||||
fullName = file;
|
fullName = dirName + File.separator + ls[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMIND: case compare depends on platform
|
// REMIND: case compare depends on platform
|
||||||
@@ -3059,97 +3146,30 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
registerFontsInDir(dirName, true, Font2D.JRE_RANK, true, false);
|
registerFontsInDir(dirName, true, Font2D.JRE_RANK, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] addPathToFiles(FilenameFilter filter, String path) {
|
|
||||||
String[] filteredFiles = (new File(path)).list(filter);
|
|
||||||
if (filteredFiles == null) {
|
|
||||||
return new String[0];
|
|
||||||
}
|
|
||||||
return Arrays.stream(filteredFiles).map((name) -> (path + File.separator + name)).toArray(String[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
// MACOSX begin -- need to access this in subclass
|
// MACOSX begin -- need to access this in subclass
|
||||||
protected void registerFontsInDir(String dirName, boolean useJavaRasterizer,
|
protected void registerFontsInDir(String dirName, boolean useJavaRasterizer,
|
||||||
// MACOSX end
|
// MACOSX end
|
||||||
int fontRank,
|
int fontRank,
|
||||||
boolean defer, boolean resolveSymLinks) {
|
boolean defer, boolean resolveSymLinks) {
|
||||||
addDirFonts(addPathToFiles(ttFilter, dirName),
|
File pathFile = new File(dirName);
|
||||||
|
addDirFonts(dirName, pathFile, ttFilter,
|
||||||
FONTFORMAT_TRUETYPE, useJavaRasterizer,
|
FONTFORMAT_TRUETYPE, useJavaRasterizer,
|
||||||
fontRank==Font2D.UNKNOWN_RANK ?
|
fontRank==Font2D.UNKNOWN_RANK ?
|
||||||
Font2D.TTF_RANK : fontRank,
|
Font2D.TTF_RANK : fontRank,
|
||||||
defer, resolveSymLinks);
|
defer, resolveSymLinks);
|
||||||
addDirFonts(addPathToFiles(t1Filter, dirName),
|
addDirFonts(dirName, pathFile, t1Filter,
|
||||||
FONTFORMAT_TYPE1, useJavaRasterizer,
|
FONTFORMAT_TYPE1, useJavaRasterizer,
|
||||||
fontRank==Font2D.UNKNOWN_RANK ?
|
fontRank==Font2D.UNKNOWN_RANK ?
|
||||||
Font2D.TYPE1_RANK : fontRank,
|
Font2D.TYPE1_RANK : fontRank,
|
||||||
defer, resolveSymLinks);
|
defer, resolveSymLinks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTrueTypeVersion(String path) {
|
|
||||||
try {
|
|
||||||
return (new TrueTypeFont(path, null, 0, false, false)).getVersion();
|
|
||||||
} catch (FontFormatException e) {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract protected String getSystemFontVersion(TrueTypeFont bundledFont);
|
|
||||||
|
|
||||||
protected void loadJREFonts(String[] fonts) {
|
|
||||||
addDirFonts(fonts, FONTFORMAT_TRUETYPE, true,
|
|
||||||
Font2D.JRE_RANK, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static int fontVersionComparator(String versionFirst, String versionSecond) {
|
|
||||||
return Arrays.compare(versionFirst.split("\\."), versionSecond.split("\\."),
|
|
||||||
Comparator.comparing(BigInteger::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isFontNewer(String versionFirst, String versionSecond) {
|
|
||||||
return fontVersionComparator(versionFirst, versionSecond) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerJREFonts() {
|
protected void registerJREFonts() {
|
||||||
List<String> fontsToLoad = new ArrayList<>();
|
registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
|
||||||
PlatformLogger logger = FontUtilities.getLogger();
|
true, false);
|
||||||
boolean isLogging = logger != null && FontUtilities.isLogging();
|
}
|
||||||
|
|
||||||
if (!versionCheckEnabled && isLogging) {
|
protected void registerFontDir(String path) {
|
||||||
logger.info("Skip version checking in font loading");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String fontName : jreBundledFontFiles) {
|
|
||||||
boolean loadFont = true;
|
|
||||||
String bundledVersion = "unknown";
|
|
||||||
String systemVersion = "0";
|
|
||||||
String path = jreFontDirName + File.separator + fontName;
|
|
||||||
if (versionCheckEnabled) {
|
|
||||||
try {
|
|
||||||
TrueTypeFont bundledFont = new TrueTypeFont(path, null, 0, false, false);
|
|
||||||
bundledVersion = bundledFont.getVersion();
|
|
||||||
systemVersion = getSystemFontVersion(bundledFont);
|
|
||||||
|
|
||||||
if (isFontNewer(systemVersion, bundledVersion)) {
|
|
||||||
if (isLogging) {
|
|
||||||
logger.info("Skip loading " + fontName + ", newer version font on platform were detected. " +
|
|
||||||
"System version = " + systemVersion + ", Bundled version = " + bundledVersion + ".");
|
|
||||||
}
|
|
||||||
loadFont = false;
|
|
||||||
}
|
|
||||||
} catch (FontFormatException e) {
|
|
||||||
if (isLogging) {
|
|
||||||
logger.warning("Internal error have appeared while reading bundled font " + fontName + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (loadFont) {
|
|
||||||
fontsToLoad.add(path);
|
|
||||||
if (isLogging) {
|
|
||||||
logger.info("Loaded " + fontName + " (" + bundledVersion + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadJREFonts(fontsToLoad.toArray(new String[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3676,4 +3696,78 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
{
|
{
|
||||||
return new FontUIResource(family, style, size);
|
return new FontUIResource(family, style, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected BundledFontInfo getBundledFontInfo(String fileName) {
|
||||||
|
return jreFontMap.get(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean parseFontVersion(String versionString, int[] version) {
|
||||||
|
int i = 0;
|
||||||
|
boolean foundDigit = false;
|
||||||
|
version[0] = version[1] = version[2] = 0;
|
||||||
|
|
||||||
|
// Skip prefix letters
|
||||||
|
while (i < versionString.length() &&
|
||||||
|
!(foundDigit = Character.isDigit(versionString.charAt(i)))) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (!foundDigit) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
|
boolean foundDot = false;
|
||||||
|
// Read major version
|
||||||
|
while (i < versionString.length() &&
|
||||||
|
!(foundDot = (versionString.charAt(i) == '.')) &&
|
||||||
|
Character.isDigit(versionString.charAt(i))) {
|
||||||
|
buf.append(versionString.charAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
version[0] = Integer.parseInt(buf.toString());
|
||||||
|
if (!foundDot) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
buf.setLength(0);
|
||||||
|
i++;
|
||||||
|
foundDigit = false;
|
||||||
|
|
||||||
|
// Read minor version
|
||||||
|
while (i < versionString.length() &&
|
||||||
|
!(foundDot = (versionString.charAt(i) == '.')) &&
|
||||||
|
Character.isDigit(versionString.charAt(i))) {
|
||||||
|
buf.append(versionString.charAt(i));
|
||||||
|
foundDigit = true;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (!foundDigit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
version[1] = Integer.parseInt(buf.toString());
|
||||||
|
|
||||||
|
if (!foundDot) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.setLength(0);
|
||||||
|
i++;
|
||||||
|
foundDigit = false;
|
||||||
|
|
||||||
|
// Read bugfix version
|
||||||
|
while (i < versionString.length() &&
|
||||||
|
!(versionString.charAt(i) == '.') &&
|
||||||
|
Character.isDigit(versionString.charAt(i))) {
|
||||||
|
buf.append(versionString.charAt(i));
|
||||||
|
foundDigit = true;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundDigit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
version[2] = Integer.parseInt(buf.toString());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,10 @@ import java.nio.channels.FileChannel;
|
|||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedActionException;
|
import java.security.PrivilegedActionException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import sun.java2d.Disposer;
|
import sun.java2d.Disposer;
|
||||||
import sun.java2d.DisposerRecord;
|
import sun.java2d.DisposerRecord;
|
||||||
@@ -116,7 +112,6 @@ public class TrueTypeFont extends FileFont {
|
|||||||
public static final int SUBFAMILY_NAME_ID = 2;
|
public static final int SUBFAMILY_NAME_ID = 2;
|
||||||
// public static final int STYLE_WEIGHT_ID = 2; // currently unused.
|
// public static final int STYLE_WEIGHT_ID = 2; // currently unused.
|
||||||
public static final int FULL_NAME_ID = 4;
|
public static final int FULL_NAME_ID = 4;
|
||||||
public static final int VERSION_NAME_ID = 5;
|
|
||||||
public static final int POSTSCRIPT_NAME_ID = 6;
|
public static final int POSTSCRIPT_NAME_ID = 6;
|
||||||
public static final int TYPOGRAPHIC_FAMILY_NAME_ID = 16;
|
public static final int TYPOGRAPHIC_FAMILY_NAME_ID = 16;
|
||||||
public static final int TYPOGRAPHIC_SUBFAMILY_NAME_ID = 17;
|
public static final int TYPOGRAPHIC_SUBFAMILY_NAME_ID = 17;
|
||||||
@@ -191,8 +186,6 @@ public class TrueTypeFont extends FileFont {
|
|||||||
private String localeFullName;
|
private String localeFullName;
|
||||||
private String typographicFamilyName;
|
private String typographicFamilyName;
|
||||||
private String typographicSubfamilyName;
|
private String typographicSubfamilyName;
|
||||||
private String version;
|
|
||||||
private String postScriptName;
|
|
||||||
|
|
||||||
private Byte supportedCharset;
|
private Byte supportedCharset;
|
||||||
|
|
||||||
@@ -1123,22 +1116,6 @@ public class TrueTypeFont extends FileFont {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseVersion(String str) {
|
|
||||||
// get first part sequence of digits and dots
|
|
||||||
Matcher matcher = Pattern.compile("\\d(\\p{XDigit}|\\.)*").matcher(str);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
// removing leading zeros and hex parts from version e.g. 00010.002.0ab12.300.040 -> 10.2.300.40
|
|
||||||
String res = Arrays.stream(matcher.group().split("\\.")).filter(s -> s.matches("\\d+")).
|
|
||||||
map(s -> (s.replaceFirst("^0*", ""))).map(s -> s.isEmpty() ? "0" : s).collect(Collectors.joining("."));
|
|
||||||
return !res.isEmpty() ? res : "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initNames() {
|
protected void initNames() {
|
||||||
|
|
||||||
byte[] name = new byte[256];
|
byte[] name = new byte[256];
|
||||||
@@ -1248,22 +1225,6 @@ public class TrueTypeFont extends FileFont {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VERSION_NAME_ID:
|
|
||||||
if (version == null || langID == ENGLISH_LOCALE_ID) {
|
|
||||||
buffer.position(namePtr);
|
|
||||||
buffer.get(name, 0, nameLen);
|
|
||||||
version = parseVersion(makeString(name, nameLen, platformID, encodingID));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case POSTSCRIPT_NAME_ID:
|
|
||||||
if (postScriptName == null || langID == ENGLISH_LOCALE_ID) {
|
|
||||||
buffer.position(namePtr);
|
|
||||||
buffer.get(name, 0, nameLen);
|
|
||||||
postScriptName = makeString(name, nameLen, platformID, encodingID);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TYPOGRAPHIC_FAMILY_NAME_ID:
|
case TYPOGRAPHIC_FAMILY_NAME_ID:
|
||||||
if (typographicFamilyName == null || langID == ENGLISH_LOCALE_ID) {
|
if (typographicFamilyName == null || langID == ENGLISH_LOCALE_ID) {
|
||||||
buffer.position(namePtr);
|
buffer.position(namePtr);
|
||||||
@@ -1290,12 +1251,6 @@ public class TrueTypeFont extends FileFont {
|
|||||||
if (typographicSubfamilyName == null) {
|
if (typographicSubfamilyName == null) {
|
||||||
typographicSubfamilyName = subfamilyName;
|
typographicSubfamilyName = subfamilyName;
|
||||||
}
|
}
|
||||||
if (version == null) {
|
|
||||||
version = "0";
|
|
||||||
}
|
|
||||||
if (postScriptName == null) {
|
|
||||||
postScriptName = fullName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1368,7 +1323,12 @@ public class TrueTypeFont extends FileFont {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getPostscriptName() {
|
public String getPostscriptName() {
|
||||||
return postScriptName;
|
String name = lookupName(ENGLISH_LOCALE_ID, POSTSCRIPT_NAME_ID);
|
||||||
|
if (name == null) {
|
||||||
|
return fullName;
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
package sun.awt;
|
package sun.awt;
|
||||||
|
|
||||||
import sun.font.*;
|
import sun.font.FcFontConfiguration;
|
||||||
|
import sun.font.FontConfigManager;
|
||||||
|
import sun.font.SunFontManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link sun.font.FontManager} that uses fontconfig to find system fonts.
|
* A {@link sun.font.FontManager} that uses fontconfig to find system fonts.
|
||||||
@@ -43,13 +45,6 @@ public class FcFontManager extends SunFontManager {
|
|||||||
return fcManager;
|
return fcManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSystemFontVersion(TrueTypeFont bundledFont) {
|
|
||||||
String query = bundledFont.getTypographicFamilyName() + ":style=" + bundledFont.getTypographicSubfamilyName();
|
|
||||||
String systemFont = FontConfigManager.getFontProperty(query, "%{file}");
|
|
||||||
return systemFont != null ? getTrueTypeVersion(systemFont) : "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FontConfiguration createFontConfiguration() {
|
protected FontConfiguration createFontConfiguration() {
|
||||||
FcFontConfiguration fcFontConfig = new FcFontConfiguration(this);
|
FcFontConfiguration fcFontConfig = new FcFontConfiguration(this);
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import java.util.Map;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import javax.swing.plaf.FontUIResource;
|
import javax.swing.plaf.FontUIResource;
|
||||||
import sun.font.MFontConfiguration;
|
import sun.font.MFontConfiguration;
|
||||||
@@ -51,8 +50,6 @@ import sun.font.FontUtilities;
|
|||||||
import sun.font.NativeFont;
|
import sun.font.NativeFont;
|
||||||
import sun.util.logging.PlatformLogger;
|
import sun.util.logging.PlatformLogger;
|
||||||
|
|
||||||
import static sun.font.SunFontManager.jreFontDirName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The X11 implementation of {@link FontManager}.
|
* The X11 implementation of {@link FontManager}.
|
||||||
*/
|
*/
|
||||||
@@ -281,7 +278,8 @@ public final class X11FontManager extends FcFontManager {
|
|||||||
* the loadFonts() method does too. So all should be well.
|
* the loadFonts() method does too. So all should be well.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
private void registerFontDir(String path) {
|
@Override
|
||||||
|
protected void registerFontDir(String path) {
|
||||||
/* fonts.dir file format looks like :-
|
/* fonts.dir file format looks like :-
|
||||||
* 47
|
* 47
|
||||||
* Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1
|
* Arial.ttf -monotype-arial-regular-r-normal--0-0-0-0-p-0-iso8859-1
|
||||||
@@ -430,12 +428,6 @@ public final class X11FontManager extends FcFontManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void registerJREFonts() {
|
|
||||||
registerFontDir(jreFontDirName);
|
|
||||||
super.registerJREFonts();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFonts() {
|
public void loadFonts() {
|
||||||
super.loadFonts();
|
super.loadFonts();
|
||||||
|
|||||||
@@ -454,7 +454,6 @@ public class FontConfigManager {
|
|||||||
return fcInfo;
|
return fcInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native int getFontConfigAASettings(String locale, String fcFamily);
|
private static native int
|
||||||
|
getFontConfigAASettings(String locale, String fcFamily);
|
||||||
public static native String getFontProperty(String name, String pattern);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -511,7 +511,6 @@ typedef FcPattern* (*FcFontMatchFuncType)(FcConfig *config,
|
|||||||
FcResult *result);
|
FcResult *result);
|
||||||
typedef FcFontSet* (*FcFontSetCreateFuncType)();
|
typedef FcFontSet* (*FcFontSetCreateFuncType)();
|
||||||
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
|
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
|
||||||
typedef void (*FcStrFreeFuncType)(FcChar8 *str);
|
|
||||||
|
|
||||||
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p,
|
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p,
|
||||||
const char *object,
|
const char *object,
|
||||||
@@ -534,11 +533,6 @@ typedef FcStrList* (*FcConfigGetCacheDirsFuncType)(FcConfig *config);
|
|||||||
typedef FcChar8* (*FcStrListNextFuncType)(FcStrList *list);
|
typedef FcChar8* (*FcStrListNextFuncType)(FcStrList *list);
|
||||||
typedef FcChar8* (*FcStrListDoneFuncType)(FcStrList *list);
|
typedef FcChar8* (*FcStrListDoneFuncType)(FcStrList *list);
|
||||||
|
|
||||||
typedef unsigned int (*FcFreeTypeQueryAllFuncType)(const FcChar8 *file, unsigned int id, FcBlanks *blanks,
|
|
||||||
int *count, FcFontSet *set);
|
|
||||||
|
|
||||||
typedef FcChar8* (*FcPatternFormatFuncType)(FcPattern *pat, const FcChar8 *format);
|
|
||||||
|
|
||||||
static char **getFontConfigLocations() {
|
static char **getFontConfigLocations() {
|
||||||
|
|
||||||
char **fontdirs;
|
char **fontdirs;
|
||||||
@@ -776,7 +770,7 @@ Java_sun_font_FontConfigManager_getFontConfigAASettings
|
|||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_sun_font_FontConfigManager_getFontConfigVersion
|
Java_sun_font_FontConfigManager_getFontConfigVersion
|
||||||
(JNIEnv *env, jclass obj) {
|
(JNIEnv *env, jclass obj) {
|
||||||
|
|
||||||
void* libfontconfig;
|
void* libfontconfig;
|
||||||
FcGetVersionFuncType FcGetVersion;
|
FcGetVersionFuncType FcGetVersion;
|
||||||
@@ -798,90 +792,6 @@ Java_sun_font_FontConfigManager_getFontConfigVersion
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
|
||||||
Java_sun_font_FontConfigManager_getFontProperty
|
|
||||||
(JNIEnv *env, jclass obj, jstring query, jstring property) {
|
|
||||||
|
|
||||||
void* libfontconfig = NULL;
|
|
||||||
FcNameParseFuncType FcNameParse;
|
|
||||||
FcPatternFormatFuncType FcPatternFormat;
|
|
||||||
FcConfigSubstituteFuncType FcConfigSubstitute;
|
|
||||||
FcDefaultSubstituteFuncType FcDefaultSubstitute;
|
|
||||||
FcFontMatchFuncType FcFontMatch;
|
|
||||||
FcStrFreeFuncType FcStrFree;
|
|
||||||
|
|
||||||
const char *queryPtr = NULL;
|
|
||||||
const char *propertyPtr = NULL;
|
|
||||||
FcChar8 *fontFamily = NULL;
|
|
||||||
FcChar8 *fontPath = NULL;
|
|
||||||
jstring res = NULL;
|
|
||||||
|
|
||||||
if ((libfontconfig = openFontConfig()) == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
FcPatternFormat = (FcPatternFormatFuncType)dlsym(libfontconfig, "FcPatternFormat");
|
|
||||||
FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse");
|
|
||||||
FcConfigSubstitute = (FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute");
|
|
||||||
FcDefaultSubstitute = (FcDefaultSubstituteFuncType)dlsym(libfontconfig, "FcDefaultSubstitute");
|
|
||||||
FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch");
|
|
||||||
FcStrFree = (FcStrFreeFuncType)dlsym(libfontconfig, "FcStrFree");
|
|
||||||
|
|
||||||
queryPtr = (*env)->GetStringUTFChars(env, query, 0);
|
|
||||||
propertyPtr = (*env)->GetStringUTFChars(env, property, 0);
|
|
||||||
if (queryPtr == NULL || propertyPtr == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
FcPattern *pattern = (*FcNameParse)((FcChar8 *) queryPtr);
|
|
||||||
if (pattern == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
(*FcConfigSubstitute)(NULL, pattern, FcMatchScan);
|
|
||||||
(*FcDefaultSubstitute)(pattern);
|
|
||||||
|
|
||||||
FcResult fcResult;
|
|
||||||
FcPattern *match = (*FcFontMatch)(0, pattern, &fcResult);
|
|
||||||
if (match == NULL || fcResult != FcResultMatch) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
fontFamily = (FcPatternFormat)(match, (FcChar8*) "%{family}");
|
|
||||||
if (fontFamily == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
// result of foundFontName could be set of families, so we left only first family
|
|
||||||
char *commaPos = strchr((char *) fontFamily, ',');
|
|
||||||
if (commaPos != NULL) {
|
|
||||||
*commaPos = '\0';
|
|
||||||
}
|
|
||||||
if (strstr(queryPtr, (char *) fontFamily) == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
fontPath = (FcPatternFormat)(match, (FcChar8*) propertyPtr);
|
|
||||||
if (fontPath == NULL) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
res = (*env)->NewStringUTF(env, (char *) fontPath);
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (fontPath) {
|
|
||||||
(FcStrFree)(fontPath);
|
|
||||||
}
|
|
||||||
if (fontFamily) {
|
|
||||||
(FcStrFree)(fontFamily);
|
|
||||||
}
|
|
||||||
if (propertyPtr) {
|
|
||||||
(*env)->ReleaseStringUTFChars(env, property, (const char*)propertyPtr);
|
|
||||||
}
|
|
||||||
if (queryPtr) {
|
|
||||||
(*env)->ReleaseStringUTFChars(env, query, (const char*)queryPtr);
|
|
||||||
}
|
|
||||||
if (libfontconfig) {
|
|
||||||
closeFontConfig(libfontconfig, JNI_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_sun_font_FontConfigManager_getFontConfig
|
Java_sun_font_FontConfigManager_getFontConfig
|
||||||
|
|||||||
@@ -31,18 +31,14 @@ import java.awt.GraphicsEnvironment;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import sun.awt.windows.WFontConfiguration;
|
import sun.awt.windows.WFontConfiguration;
|
||||||
import sun.font.FontManager;
|
import sun.font.FontManager;
|
||||||
import sun.font.FontUtilities;
|
|
||||||
import sun.font.SunFontManager;
|
import sun.font.SunFontManager;
|
||||||
import sun.font.TrueTypeFont;
|
import sun.font.TrueTypeFont;
|
||||||
|
|
||||||
@@ -51,7 +47,6 @@ import sun.font.TrueTypeFont;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
public final class Win32FontManager extends SunFontManager {
|
public final class Win32FontManager extends SunFontManager {
|
||||||
private HashMap<String, String> windowsSystemVersion = null;
|
|
||||||
|
|
||||||
private static TrueTypeFont eudcFont;
|
private static TrueTypeFont eudcFont;
|
||||||
|
|
||||||
@@ -195,28 +190,6 @@ public final class Win32FontManager extends SunFontManager {
|
|||||||
preferLocaleFonts,preferPropFonts);
|
preferLocaleFonts,preferPropFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void registerJREFonts() {
|
|
||||||
if (versionCheckEnabled) {
|
|
||||||
windowsSystemVersion = new HashMap<>();
|
|
||||||
HashMap<String, String> fontToFileMap = new HashMap<>(100);
|
|
||||||
populateFontFileNameMap(fontToFileMap, new HashMap<>(), new HashMap<>(), Locale.ENGLISH);
|
|
||||||
for (String key : fontToFileMap.keySet()) {
|
|
||||||
// find maximum observable platform font's version
|
|
||||||
Optional<String> version = Stream.concat(Arrays.stream(getPlatformFontDirs(true)), Stream.of("")).
|
|
||||||
map((path) -> (getTrueTypeVersion(path + File.separator + fontToFileMap.get(key)))).
|
|
||||||
max(SunFontManager::fontVersionComparator);
|
|
||||||
windowsSystemVersion.put(key, version.isPresent() ? version.get() : "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.registerJREFonts();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSystemFontVersion(TrueTypeFont bundledFont) {
|
|
||||||
return windowsSystemVersion.getOrDefault(bundledFont.getFullName().toLowerCase(), "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void
|
protected void
|
||||||
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
|
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
|
||||||
HashMap<String,String> fontToFamilyNameMap,
|
HashMap<String,String> fontToFamilyNameMap,
|
||||||
|
|||||||
Reference in New Issue
Block a user