Skip to content

Commit 0bddd8a

Browse files
author
Dmitry Batrak
committed
8278050: Armenian text isn't rendered on macOS if text layout is performed
Reviewed-by: prr, serb
1 parent f6fbb5a commit 0bddd8a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/java.desktop/macosx/classes/sun/font/CFont.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private CompositeFont createCompositeFont() {
206206

207207
// In some italic cases the standard Mac cascade list is missing Arabic.
208208
listOfString.add("GeezaPro");
209-
FontManager fm = FontManagerFactory.getInstance();
209+
CFontManager fm = (CFontManager) FontManagerFactory.getInstance();
210210
int numFonts = 1 + listOfString.size();
211211
PhysicalFont[] fonts = new PhysicalFont[numFonts];
212212
fonts[0] = this;
@@ -222,7 +222,7 @@ private CompositeFont createCompositeFont() {
222222
// Don't know why we get the weird name above .. replace.
223223
s = "AppleSymbols";
224224
}
225-
Font2D f2d = fm.findFont2D(s, Font.PLAIN, FontManager.NO_FALLBACK);
225+
Font2D f2d = fm.getOrCreateFallbackFont(s);
226226
if (f2d == null || f2d == this) {
227227
continue;
228228
}

src/java.desktop/macosx/classes/sun/font/CFontManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import java.util.HashMap;
3434
import java.util.Hashtable;
3535
import java.util.Locale;
36+
import java.util.Map;
3637
import java.util.TreeMap;
3738
import java.util.Vector;
39+
import java.util.concurrent.ConcurrentHashMap;
3840

3941
import javax.swing.plaf.FontUIResource;
4042

@@ -45,6 +47,7 @@
4547

4648
public final class CFontManager extends SunFontManager {
4749
private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
50+
private final Map<String, Font2D> fallbackFonts = new ConcurrentHashMap<>();
4851

4952
@Override
5053
protected FontConfiguration createFontConfiguration() {
@@ -321,4 +324,17 @@ protected FontUIResource getFontConfigFUIR(
321324
@Override
322325
protected void populateFontFileNameMap(HashMap<String, String> fontToFileMap, HashMap<String, String> fontToFamilyNameMap,
323326
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+
}
324340
}

0 commit comments

Comments
 (0)