Java Code Examples for java.awt.Font#canDisplayUpTo()

The following examples show how to use java.awt.Font#canDisplayUpTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FontLibrary.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a scaled {@code Font} which can display all characters
 * inside the given text string.
 * This is mostly necessary for the header font. Thats because the currently
 * used ShadowedBlack is missing support for CJK and others. Even some
 * special glyphs for European languages like the triple-dot are missing.
 * 
 * @param string The text to find a compatible font for.
 * @param fontType How the font should look like.
 * @param fontSize Its relative size.
 * @param style The font style for choosing plain, bold or italic.
 * @param scaleFactor The applied scale factor.
 * @return The created Font.
 */
private static Font createCompatibleFont(String string, FontType fontType,
                                         FontSize fontSize,
                                         int style, float scaleFactor) {
    // TODO: Consider testing the normal font for compatibility and try
    //       some or all other available fonts for complete/longest match:
    //       header/simple->main->normal->simple/header->emergency
    float scaledSize = calcScaledSize(fontSize, scaleFactor);
    String fontKey = getFontKey(fontType);
    Font font = null;
    if (fontType != FontType.NORMAL) {
        font = ResourceManager.getFont(fontKey);
        if (font.canDisplayUpTo(string) != -1)
            font = null;
    }
    if (font == null) {
        fontKey = getFontKey(FontType.NORMAL);
        font = (fontKey == null)
            ? mainFont
            : ResourceManager.getFont(fontKey);
    }
    return font.deriveFont(style, scaledSize);
}
 
Example 2
Source File: PhoneticExtensionsGlyphTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 3
Source File: PhoneticExtensionsGlyphTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 4
Source File: PhoneticExtensionsGlyphTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 5
Source File: LigatureCaretTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Font getFontForText(String s) {
    GraphicsEnvironment ge =
       GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();

    for (Font f : fonts) {
       if (f.canDisplayUpTo(s) == -1) {
           return f.deriveFont(Font.PLAIN, 24);
       }
    }
    return null;
}
 
Example 6
Source File: PhoneticExtensionsGlyphTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 7
Source File: MWPane.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * @return Flag indicating if all the text can be displayed.
 */
public boolean canDisplayAllText() {
  String text = getText();
  Font font = getFont();
  if ((text != null) && (font != null)) {
    return (font.canDisplayUpTo(text) == -1);
  }
  return true;
}
 
Example 8
Source File: MiscTests.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCompatibleFonts() {
    String s = "\u23EF";
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    System.out.println("Total fonts: \t" + fonts.length);
    int count = 0;
    for (Font font : fonts) {
        if (font.canDisplayUpTo(s) < 0) {
            count++;
            System.out.println(font.getName());
        }
    }
    System.out.println("Compatible fonts: \t" + count);
}