This commit is contained in:
2016-12-03 15:56:00 +01:00
parent 820ef1a5f1
commit 2690b658d0
8 changed files with 52 additions and 17 deletions
@@ -63,19 +63,19 @@ public class FontHelper {
Object fm = getFontManager();
Class<?> clFm = Class.forName("sun.font.SunFontManager");
//Delete cached installed names
// Delete cached installed names
Field inField = clFm.getDeclaredField("installedNames");
inField.setAccessible(true);
inField.set(null, null);
inField.setAccessible(false);
//Delete cached family names
// Delete cached family names
Field allFamField = clFm.getDeclaredField("allFamilies");
allFamField.setAccessible(true);
allFamField.set(fm, null);
allFamField.setAccessible(false);
//Delete cached fonts
// Delete cached fonts
Field allFonField = clFm.getDeclaredField("allFonts");
allFonField.setAccessible(true);
allFonField.set(fm, null);
@@ -93,7 +93,7 @@ public class FontHelper {
List<String> javaFonts = Arrays.asList("Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif");
for (Font f : fonts) {
String fam = f.getFamily(Locale.ENGLISH);
//Do not want Java logical fonts
// Do not want Java logical fonts
if (javaFonts.contains(fam)) {
continue;
}
@@ -107,6 +107,31 @@ public class FontHelper {
return ret;
}
public static String fontToString(Font font) {
int style = font.getStyle();
String styleString;
switch (style) {
case 1:
styleString = "Bold";
break;
case 2:
styleString = "Italic";
break;
case 3:
styleString = "BoldItalic";
break;
default:
styleString = "Plain";
break;
}
return font.getName() + "-" + styleString + "-" + font.getSize();
}
public static Font stringToFont(String fontString) {
return Font.decode(fontString);
}
/**
* Gets kerning offset for two characters of the font
*