|
33 | 33 | import java.util.HashMap; |
34 | 34 | import java.util.Hashtable; |
35 | 35 | import java.util.Locale; |
| 36 | +import java.util.Map; |
36 | 37 | import java.util.TreeMap; |
37 | 38 | import java.util.Vector; |
| 39 | +import java.util.concurrent.ConcurrentHashMap; |
38 | 40 |
|
39 | 41 | import javax.swing.plaf.FontUIResource; |
40 | 42 |
|
|
45 | 47 |
|
46 | 48 | public final class CFontManager extends SunFontManager { |
47 | 49 | private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>(); |
| 50 | + private final Map<String, Font2D> fallbackFonts = new ConcurrentHashMap<>(); |
48 | 51 |
|
49 | 52 | @Override |
50 | 53 | protected FontConfiguration createFontConfiguration() { |
@@ -321,4 +324,17 @@ protected FontUIResource getFontConfigFUIR( |
321 | 324 | @Override |
322 | 325 | protected void populateFontFileNameMap(HashMap<String, String> fontToFileMap, HashMap<String, String> fontToFamilyNameMap, |
323 | 326 | HashMap<String, ArrayList<String>> familyToFontListMap, Locale locale) {} |
| 327 | + |
| 328 | + Font2D getOrCreateFallbackFont(String fontName) { |
| 329 | + Font2D font2D = findFont2D(fontName, Font.PLAIN, FontManager.NO_FALLBACK); |
| 330 | + if (font2D != null || fontName.startsWith(".")) { |
| 331 | + return font2D; |
| 332 | + } else { |
| 333 | + // macOS doesn't list some system fonts in [NSFontManager availableFontFamilies] output, |
| 334 | + // so they are not registered in font manager as part of 'loadNativeFonts'. |
| 335 | + // These fonts are present in [NSFontManager availableFonts] output though, |
| 336 | + // and can be accessed in the same way as other system fonts. |
| 337 | + return fallbackFonts.computeIfAbsent(fontName, name -> new CFont(name, null)); |
| 338 | + } |
| 339 | + } |
324 | 340 | } |
0 commit comments