Fixed #1750 Application won't start when cannot access font file

This commit is contained in:
Jindra Petřík
2021-11-20 19:23:52 +01:00
parent 2586b4b364
commit 3eb1fb9d4b
2 changed files with 23 additions and 16 deletions

View File

@@ -51,7 +51,6 @@ public class FontHelper {
Class<?> clFmFactory = Class.forName("sun.font.FontManagerFactory");
return clFmFactory.getDeclaredMethod("getInstance").invoke(null);
}*/
/**
* Gets all available fonts in the system
*
@@ -89,7 +88,7 @@ public class FontHelper {
} catch (Throwable ex) {
// ignore
}
*/
*/
if (fonts == null) {
fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
@@ -312,23 +311,28 @@ public class FontHelper {
return ret;
}
private static List<File> getTtfFilesRecursively(File dir) {
List<File> ret = new ArrayList<>();
try {
File files[] = dir.listFiles();
for (File f : files) {
if (f.isDirectory()) {
ret.addAll(getTtfFilesRecursively(f));
} else if (f.getAbsolutePath().endsWith(".ttf") || f.getAbsolutePath().endsWith(".TTF")) {
ret.add(f);
}
}
} catch (Exception ex) {
//ignore any access errors
}
return ret;
}
private static List<File> getSystemFontFiles() {
List<File> dirs = getSystemFontDirectories();
List<File> ret = new ArrayList<>();
for (File d : dirs) {
try {
Object[] paths = Files.find(d.toPath(), Integer.MAX_VALUE, new BiPredicate<Path, BasicFileAttributes>() {
@Override
public boolean test(Path t, BasicFileAttributes u) {
return u.isRegularFile() && (t.toString().endsWith(".ttf") || t.toString().endsWith(".TTF"));
}
}).toArray();
for (Object o : paths) {
ret.add(((Path) o).toFile());
}
} catch (IOException ex) {
//ignore
}
ret.addAll(getTtfFilesRecursively(d));
}
return ret;
}