/** * Returns the component font name (face name plus charset) of the * font that should be used for AWT text components. May return null. */ public String getTextComponentFontName(String familyName, int style) { FontDescriptor[] fontDescriptors = getFontDescriptors(familyName, style); String fontName = findFontWithCharset(fontDescriptors, textInputCharset); if (fontName == null) { fontName = findFontWithCharset(fontDescriptors, "DEFAULT_CHARSET"); } return fontName; }
private String findFontWithCharset(FontDescriptor[] fontDescriptors, String charset) { String fontName = null; for (int i = 0; i < fontDescriptors.length; i++) { String componentFontName = fontDescriptors[i].getNativeName(); if (componentFontName.endsWith(charset)) { fontName = componentFontName; } } return fontName; }
@Override protected FontDescriptor[] buildFontDescriptors(int fontIndex, int styleIndex) { CompositeFontDescriptor[] cfi = get2DCompositeFontInfo(); int idx = fontIndex * NUM_STYLES + styleIndex; String[] componentFaceNames = cfi[idx].getComponentFaceNames(); FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length]; for (int i = 0; i < componentFaceNames.length; i++) { ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.UTF_8.newEncoder(), new int[0]); } return ret; }
@Override protected FontDescriptor[] buildFontDescriptors(int fontIndex, int styleIndex) { CompositeFontDescriptor[] cfi = get2DCompositeFontInfo(); int idx = fontIndex * NUM_STYLES + styleIndex; String[] componentFaceNames = cfi[idx].getComponentFaceNames(); FontDescriptor[] ret = new FontDescriptor[componentFaceNames.length]; for (int i = 0; i < componentFaceNames.length; i++) { ret[i] = new FontDescriptor(componentFaceNames[i], StandardCharsets.ISO_8859_1.newEncoder(), new int[0]); } return ret; }
@Override public FontDescriptor[] getFontDescriptors(String fontName, int style) { return new FontDescriptor[0]; }