@NotNull public static FontInfo getFontAbleToDisplay( int codePoint, @JdkConstants.FontStyle int style, @NotNull FontPreferences preferences) { boolean tryDefaultFont = true; List<String> fontFamilies = preferences.getEffectiveFontFamilies(); FontInfo result; //noinspection ForLoopReplaceableByForEach for (int i = 0, len = fontFamilies.size(); i < len; ++i) { // avoid foreach, it instantiates ArrayList$Itr, this traversal happens very often final String fontFamily = fontFamilies.get(i); result = doGetFontAbleToDisplay(codePoint, preferences.getSize(fontFamily), style, fontFamily); if (result != null) { return result; } tryDefaultFont &= !FontPreferences.DEFAULT_FONT_NAME.equals(fontFamily); } int size = FontPreferences.DEFAULT_FONT_SIZE; if (!fontFamilies.isEmpty()) { size = preferences.getSize(fontFamilies.get(0)); } if (tryDefaultFont) { result = doGetFontAbleToDisplay(codePoint, size, style, FontPreferences.DEFAULT_FONT_NAME); if (result != null) { return result; } } result = doGetFontAbleToDisplay(codePoint, size, style); if (LOG.isDebugEnabled()) { LOG.debug("Fallback font: " + result.getFont().getFontName()); } return result; }
@Override public void drawChars( @NotNull Graphics g, @NotNull char[] data, int start, int end, int x, int y, Color color, FontInfo fontInfo) { g.setFont(fontInfo.getFont()); g.setColor(color); g.drawChars(data, start, end - start, x, y); }
public void advance() { myCurrentFontFamilyName = myNextFontFamilyName; myCurrentStartOffset = myCurrentOffset; for (; myCurrentOffset < myEndOffset; myCurrentOffset++) { FontInfo fontInfo = ComplementaryFontsRegistry.getFontAbleToDisplay( myCharSequence.charAt(myCurrentOffset), myFontSize, myFontStyle, myDefaultFontFamilyName); String fontFamilyName = fontInfo.getFont().getFamily(); if (myCurrentFontFamilyName == null) { myCurrentFontFamilyName = fontFamilyName; } else if (!myCurrentFontFamilyName.equals(fontFamilyName)) { myNextFontFamilyName = fontFamilyName; break; } } }