mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-22 01:09:41 +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.HeadlessToolkit;
|
||||
import sun.lwawt.macosx.*;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
public final class CFontManager extends SunFontManager {
|
||||
private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
|
||||
@@ -140,15 +141,45 @@ public final class CFontManager extends SunFontManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSystemFontVersion(TrueTypeFont bundledFont) {
|
||||
String version = getNativeFontVersion(bundledFont.getPostscriptName());
|
||||
return version != null ? TrueTypeFont.parseVersion(version) : "0";
|
||||
protected void registerJREFonts() {
|
||||
@SuppressWarnings("removal")
|
||||
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
|
||||
new File(jreFontDirName).list(getTrueTypeFilter()));
|
||||
if (files != null) {
|
||||
PlatformLogger logger = FontUtilities.getLogger();
|
||||
boolean versionCheckEnabled = !("true".equals(System.getProperty("java2d.font.noVersionCheck")));
|
||||
int [] ver = new int[3];
|
||||
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 + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadJREFonts(String[] fonts) {
|
||||
for (String name : fonts) {
|
||||
loadNativeDirFonts(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +207,12 @@ public final class CFontManager extends SunFontManager {
|
||||
|
||||
void registerFont(String fontName, String fontFamilyName, String faceName) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* 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.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.math.BigInteger;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
@@ -58,7 +54,6 @@ import sun.awt.FontConfiguration;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.util.ThreadGroupUtils;
|
||||
import sun.java2d.FontSupport;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
/**
|
||||
@@ -68,6 +63,39 @@ import sun.util.logging.PlatformLogger;
|
||||
* methods that have to be implemented by specific implementations.
|
||||
*/
|
||||
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 {
|
||||
public boolean accept(File dir,String name) {
|
||||
/* all conveniently have the same suffix length */
|
||||
@@ -192,8 +220,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
private boolean loaded1dot0Fonts = false;
|
||||
boolean loadedAllFonts = false;
|
||||
boolean loadedAllFontFiles = false;
|
||||
private HashSet<String> jreBundledFontFiles = new HashSet<>();
|
||||
HashMap<String,String> jreFamilyMap = new HashMap<>();
|
||||
private HashMap<String,BundledFontInfo> jreFontMap;
|
||||
private HashSet<String> jreBundledFontFiles;
|
||||
HashMap<String,String> jreFamilyMap;
|
||||
String[] jreOtherFontFiles;
|
||||
boolean noOtherJREFontFiles = false; // initial assumption.
|
||||
|
||||
@@ -203,7 +232,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
private String defaultFontName;
|
||||
private String defaultFontFileName;
|
||||
protected HashSet<String> registeredFontFiles = new HashSet<>();
|
||||
protected static boolean versionCheckEnabled = false;
|
||||
|
||||
private ArrayList<String> badFonts;
|
||||
/* 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
|
||||
* no evidence they are useful in practice.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
|
||||
new File(jreFontDirName).list(getTrueTypeFilter()));
|
||||
Collections.addAll(jreBundledFontFiles, files);
|
||||
jreFontMap = new HashMap<>();
|
||||
jreBundledFontFiles = new HashSet<String>();
|
||||
jreFamilyMap = new HashMap<>();
|
||||
|
||||
/* 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-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 {
|
||||
initStatic();
|
||||
versionCheckEnabled = !Boolean.parseBoolean(
|
||||
GetPropertyAction.privilegedGetProperty("java2d.font.noVersionCheck", "false"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@@ -378,6 +457,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
* registerFonts method as on-screen these JRE fonts
|
||||
* always go through the JDK rasteriser.
|
||||
*/
|
||||
if (FontUtilities.isLinux) {
|
||||
/* Linux font configuration uses these fonts */
|
||||
registerFontDir(jreFontDirName);
|
||||
}
|
||||
registerJREFonts();
|
||||
|
||||
/* Create the font configuration and get any font path
|
||||
@@ -713,7 +796,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
newFont instanceof TrueTypeFont) {
|
||||
TrueTypeFont oldTTFont = (TrueTypeFont)oldFont;
|
||||
TrueTypeFont newTTFont = (TrueTypeFont)newFont;
|
||||
if (isFontNewer(oldTTFont.getVersion(), newTTFont.getVersion())) {
|
||||
if (oldTTFont.fileSize >= newTTFont.fileSize) {
|
||||
return oldFont;
|
||||
}
|
||||
} else {
|
||||
@@ -1386,7 +1469,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
*/
|
||||
HashMap<String,String> fontToFileMap2 = null;
|
||||
HashMap<String,String> fontToFamilyNameMap2 = null;
|
||||
HashMap<String,ArrayList<String>> familyToFontListMap2 = null;
|
||||
HashMap<String,ArrayList<String>> familyToFontListMap2 = null;;
|
||||
|
||||
for (String pathFile : getFontFilesFromPath(false)) {
|
||||
if (!registryFiles.contains(pathFile)) {
|
||||
@@ -2906,8 +2989,12 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
/*
|
||||
* helper function for registerFonts
|
||||
*/
|
||||
private void addDirFonts(String[] ls, int fontFormat, boolean useJavaRasterizer,
|
||||
int fontRank, boolean defer, boolean resolveSymLinks) {
|
||||
private void addDirFonts(String dirName, File dirFile,
|
||||
FilenameFilter filter,
|
||||
int fontFormat, boolean useJavaRasterizer,
|
||||
int fontRank,
|
||||
boolean defer, boolean resolveSymLinks) {
|
||||
String[] ls = dirFile.list(filter);
|
||||
if (ls == null || ls.length == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -2915,8 +3002,8 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
String[][] nativeNames = new String[ls.length][];
|
||||
int fontCount = 0;
|
||||
|
||||
for (String file : ls) {
|
||||
File theFile = new File(file);
|
||||
for (int i=0; i < ls.length; i++ ) {
|
||||
File theFile = new File(dirFile, ls[i]);
|
||||
String fullName = null;
|
||||
if (resolveSymLinks) {
|
||||
try {
|
||||
@@ -2925,7 +3012,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
}
|
||||
}
|
||||
if (fullName == null) {
|
||||
fullName = file;
|
||||
fullName = dirName + File.separator + ls[i];
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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
|
||||
protected void registerFontsInDir(String dirName, boolean useJavaRasterizer,
|
||||
// MACOSX end
|
||||
int fontRank,
|
||||
boolean defer, boolean resolveSymLinks) {
|
||||
addDirFonts(addPathToFiles(ttFilter, dirName),
|
||||
File pathFile = new File(dirName);
|
||||
addDirFonts(dirName, pathFile, ttFilter,
|
||||
FONTFORMAT_TRUETYPE, useJavaRasterizer,
|
||||
fontRank==Font2D.UNKNOWN_RANK ?
|
||||
Font2D.TTF_RANK : fontRank,
|
||||
defer, resolveSymLinks);
|
||||
addDirFonts(addPathToFiles(t1Filter, dirName),
|
||||
addDirFonts(dirName, pathFile, t1Filter,
|
||||
FONTFORMAT_TYPE1, useJavaRasterizer,
|
||||
fontRank==Font2D.UNKNOWN_RANK ?
|
||||
Font2D.TYPE1_RANK : fontRank,
|
||||
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() {
|
||||
List<String> fontsToLoad = new ArrayList<>();
|
||||
PlatformLogger logger = FontUtilities.getLogger();
|
||||
boolean isLogging = logger != null && FontUtilities.isLogging();
|
||||
|
||||
if (!versionCheckEnabled && isLogging) {
|
||||
logger.info("Skip version checking in font loading");
|
||||
registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
|
||||
true, false);
|
||||
}
|
||||
|
||||
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]));
|
||||
protected void registerFontDir(String path) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3676,4 +3696,78 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
||||
{
|
||||
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.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
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.DisposerRecord;
|
||||
@@ -116,7 +112,6 @@ public class TrueTypeFont extends FileFont {
|
||||
public static final int SUBFAMILY_NAME_ID = 2;
|
||||
// public static final int STYLE_WEIGHT_ID = 2; // currently unused.
|
||||
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 TYPOGRAPHIC_FAMILY_NAME_ID = 16;
|
||||
public static final int TYPOGRAPHIC_SUBFAMILY_NAME_ID = 17;
|
||||
@@ -191,8 +186,6 @@ public class TrueTypeFont extends FileFont {
|
||||
private String localeFullName;
|
||||
private String typographicFamilyName;
|
||||
private String typographicSubfamilyName;
|
||||
private String version;
|
||||
private String postScriptName;
|
||||
|
||||
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() {
|
||||
|
||||
byte[] name = new byte[256];
|
||||
@@ -1248,22 +1225,6 @@ public class TrueTypeFont extends FileFont {
|
||||
}
|
||||
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:
|
||||
if (typographicFamilyName == null || langID == ENGLISH_LOCALE_ID) {
|
||||
buffer.position(namePtr);
|
||||
@@ -1290,12 +1251,6 @@ public class TrueTypeFont extends FileFont {
|
||||
if (typographicSubfamilyName == null) {
|
||||
typographicSubfamilyName = subfamilyName;
|
||||
}
|
||||
if (version == null) {
|
||||
version = "0";
|
||||
}
|
||||
if (postScriptName == null) {
|
||||
postScriptName = fullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1368,7 +1323,12 @@ public class TrueTypeFont extends FileFont {
|
||||
*/
|
||||
@Override
|
||||
public String getPostscriptName() {
|
||||
return postScriptName;
|
||||
String name = lookupName(ENGLISH_LOCALE_ID, POSTSCRIPT_NAME_ID);
|
||||
if (name == null) {
|
||||
return fullName;
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
|
||||
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.
|
||||
@@ -43,13 +45,6 @@ public class FcFontManager extends SunFontManager {
|
||||
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
|
||||
protected FontConfiguration createFontConfiguration() {
|
||||
FcFontConfiguration fcFontConfig = new FcFontConfiguration(this);
|
||||
|
||||
@@ -38,7 +38,6 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import sun.font.MFontConfiguration;
|
||||
@@ -51,8 +50,6 @@ import sun.font.FontUtilities;
|
||||
import sun.font.NativeFont;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
import static sun.font.SunFontManager.jreFontDirName;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
*/
|
||||
private void registerFontDir(String path) {
|
||||
@Override
|
||||
protected void registerFontDir(String path) {
|
||||
/* fonts.dir file format looks like :-
|
||||
* 47
|
||||
* 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
|
||||
public void loadFonts() {
|
||||
super.loadFonts();
|
||||
|
||||
@@ -454,7 +454,6 @@ public class FontConfigManager {
|
||||
return fcInfo;
|
||||
}
|
||||
|
||||
private static native int getFontConfigAASettings(String locale, String fcFamily);
|
||||
|
||||
public static native String getFontProperty(String name, String pattern);
|
||||
private static native int
|
||||
getFontConfigAASettings(String locale, String fcFamily);
|
||||
}
|
||||
|
||||
@@ -511,7 +511,6 @@ typedef FcPattern* (*FcFontMatchFuncType)(FcConfig *config,
|
||||
FcResult *result);
|
||||
typedef FcFontSet* (*FcFontSetCreateFuncType)();
|
||||
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
|
||||
typedef void (*FcStrFreeFuncType)(FcChar8 *str);
|
||||
|
||||
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p,
|
||||
const char *object,
|
||||
@@ -534,11 +533,6 @@ typedef FcStrList* (*FcConfigGetCacheDirsFuncType)(FcConfig *config);
|
||||
typedef FcChar8* (*FcStrListNextFuncType)(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() {
|
||||
|
||||
char **fontdirs;
|
||||
@@ -798,90 +792,6 @@ Java_sun_font_FontConfigManager_getFontConfigVersion
|
||||
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
|
||||
Java_sun_font_FontConfigManager_getFontConfig
|
||||
|
||||
@@ -31,18 +31,14 @@ import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import sun.awt.windows.WFontConfiguration;
|
||||
import sun.font.FontManager;
|
||||
import sun.font.FontUtilities;
|
||||
import sun.font.SunFontManager;
|
||||
import sun.font.TrueTypeFont;
|
||||
|
||||
@@ -51,7 +47,6 @@ import sun.font.TrueTypeFont;
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public final class Win32FontManager extends SunFontManager {
|
||||
private HashMap<String, String> windowsSystemVersion = null;
|
||||
|
||||
private static TrueTypeFont eudcFont;
|
||||
|
||||
@@ -195,28 +190,6 @@ public final class Win32FontManager extends SunFontManager {
|
||||
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
|
||||
populateFontFileNameMap(HashMap<String,String> fontToFileMap,
|
||||
HashMap<String,String> fontToFamilyNameMap,
|
||||
|
||||
Reference in New Issue
Block a user