/** * Returns which Fonts on the system can display the sample string. * * @param language the numerical code for the language to check * @return a list of Fonts which can display the sample String */ public static List<Font> supportedFonts(int language) { if (language < 0 || language > NUM_LANGUAGES) { throw new IllegalArgumentException(); } List<Font> fonts = new ArrayList<>(); Font[] systemFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font systemFont : systemFonts) { boolean canDisplay = true; for (int j = 0; j < unicodeRanges[language].length; j++) { if (systemFont.canDisplayUpTo(unicodeRanges[language][j]) != -1) { canDisplay = false; break; } } if (canDisplay) { fonts.add(systemFont); } } return fonts; }
for (int i = 0; i < fonts.length; ) { Font font = fonts[i]; int newPosition = font.canDisplayUpTo(chars, start, chars.length); if (newPosition == -1) { result.add(new FontRange(text, start, chars.length, font));
boolean singleFont = fonts.length == 1 || textLength == fonts[0].canDisplayUpTo(text.toCharArray(), 0, textLength); if (!(text.contains("\n") || labelItem.getAutoWrap() > 0) && singleFont) { FontRenderContext frc = graphics.getFontRenderContext();
/** * Indicates whether or not this font can display a specified String. */ public int canDisplayUpTo(String str) { return awtFont.canDisplayUpTo(str); }
/** * Indicates whether or not this font can display the the characters in * the specified CharacterIterator starting at start and ending at limit. */ public int canDisplayUpTo(CharacterIterator iter, int start, int limit) { return awtFont.canDisplayUpTo(iter, start, limit); }
/** * Indicates whether or not this font can display a specified String. */ public int canDisplayUpTo(String str) { return awtFont.canDisplayUpTo(str); }
/** * Indicates whether or not this font can display the the characters in * the specified CharacterIterator starting at start and ending at limit. */ public int canDisplayUpTo(CharacterIterator iter, int start, int limit) { return awtFont.canDisplayUpTo(iter, start, limit); }
/** * Indicates whether or not this font can display the the characters in * the specified CharacterIterator starting at start and ending at limit. */ public int canDisplayUpTo(CharacterIterator iter, int start, int limit) { return awtFont.canDisplayUpTo(iter, start, limit); }
/** * Indicates whether or not this font can display a specified String. */ public int canDisplayUpTo(String str) { return awtFont.canDisplayUpTo(str); }
private boolean canDisplayWithFont(String str, Font fnt) { return fnt.canDisplayUpTo(str) == -1; }
/** * Indicates whether or not this font can display the characters in the * specified text starting at start and ending at limit. * * @param text An array containing the characters to check. * @param start The index of the first character to check. * @param limit The index of the last character to check. * * @return The index of the first char this font cannot display. Will be * -1 if it can display all characters in the specified range. */ public int canDisplayUpTo(char[] text, int start, int limit) { return awtFont.canDisplayUpTo(text, start, limit); }
/** * Indicates whether or not this font can display the characters in the * specified text starting at start and ending at limit. * * @param text An array containing the characters to check. * @param start The index of the first character to check. * @param limit The index of the last character to check. * * @return The index of the first char this font cannot display. Will be * -1 if it can display all characters in the specified range. */ public int canDisplayUpTo(char[] text, int start, int limit) { return awtFont.canDisplayUpTo(text, start, limit); }
/** * Indicates whether or not this font can display the characters in the * specified text starting at start and ending at limit. * * @param text An array containing the characters to check. * @param start The index of the first character to check. * @param limit The index of the last character to check. * * @return The index of the first char this font cannot display. Will be * -1 if it can display all characters in the specified range. */ public int canDisplayUpTo(char[] text, int start, int limit) { return awtFont.canDisplayUpTo(text, start, limit); }
private boolean goodToUse(String fontFamily) { Font font = new Font(fontFamily, Font.PLAIN, 10); return -1 == font.canDisplayUpTo(RandomTextGenerator.SPACE); } }
private boolean goodToUse(String fontFamily) { Font font = new Font(fontFamily, Font.PLAIN, 10); return -1 == font.canDisplayUpTo(RandomTextGenerator.SPACE); } }
private static boolean needFontFallback(Font font, String text) { return font.canDisplayUpTo(text) != -1 && text.indexOf(CharacterIterator.DONE) == -1; // see IDEA-137517, TextLayout does not support this character }
Font font = new Font("TamilFont", Font.PLAIN, 12); for (String s : choices) assert font.canDisplayUpTo(s) < 0; choiceBox.setFont(font);
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Font font = new Font((String) value, Font.PLAIN, 20); if (font.canDisplayUpTo(label.getText()) == -1) { // -1 means, can display all of the string label.setFont(font); } return label; } }
public static Font getFallbackFontIfNecessary(final String stringToWrite, final float textSize, final Font primaryFont, final Font fallbackFont) { Font fontToReturn; if (primaryFont.canDisplayUpTo(stringToWrite) == -1) { fontToReturn = primaryFont.deriveFont(textSize); } else { fontToReturn = fallbackFont.deriveFont(textSize); } return fontToReturn; }
@Override public void addDisplayName(String code, Locale locale, Map<String, String> displayNames) { String name = locale.getDisplayLanguage(locale); if (font.canDisplayUpTo(name) > -1) { // Font cannot render it; use language name in the spelling of the default locale. name = locale.getDisplayLanguage(); } displayNames.put(code, name); }