FontUtils { public static final PDFont findFontFor(PDDocument document, String text) { for (FontResource font : TYPE0FONTS) { PDFont loaded = loadFont(document, font); if (canDisplay(text, loaded)) { LOG.debug("Found suitable font {} to display '{}'", loaded, text); return loaded; } } return null; } private  FontUtils(); static PDType1Font getStandardType1Font(StandardType1Font st1Font); static PDFont fontOrFallback(String text, PDFont font, PDDocument document); static void clearLoadedFontCache(); static void clearLoadedFontCache(PDDocument document); static PDFont loadFont(PDDocument document, FontResource font); static final PDFont findFontFor(PDDocument document, String text); static boolean isOnlyWhitespace(String text); static String removeWhitespace(String text); static boolean canDisplaySpace(PDFont font); static boolean canDisplay(String text, PDFont font); static double calculateBBoxHeight(String text, PDFont font); static boolean isBold(PDFont font); static boolean isItalic(PDFont font); static List<String> wrapLines(String rawLabel, PDFont font, float fontSize, double maxWidth,
            PDDocument document); static double getSimpleStringWidth(String text, PDFont font, double fontSize); static List<TextWithFont> resolveFonts(String label, PDFont font, PDDocument document); static String removeUnsupportedCharacters(String text, PDDocument doc); static String replaceUnsupportedCharacters(String text, PDDocument doc, String replacement); static PDFont HELVETICA; static final FontResource[] TYPE0FONTS; }
@Test public void testFindFontFor() { assertNotNull(findFontFor("ทดสอบ")); assertNotNull(findFontFor("αυτό είναι ένα τεστ")); assertNotNull(findFontFor("വീട്")); assertNotNull(findFontFor("मानक")); assertNotNull(findFontFor("జ")); assertNotNull(findFontFor("উ")); assertNotNull(findFontFor("עברית")); assertNotNull(findFontFor("latin ąćęłńóśźż")); assertNotNull(findFontFor("\uFFFD \u2997")); assertNotNull(findFontFor("Newlines\nare\r\nignored")); assertNotNull(findFontFor("\u2984 \u2583 \u2738 ☗⦄✸▃ ")); assertNotNull(findFontFor("ភាសាខ្មែរ")); assertNotNull(findFontFor("ጩ")); assertNotNull(findFontFor("پنجابی, ਪੰਜਾਬੀ")); assertNotNull(findFontFor("தமிழ்")); assertNotNull(findFontFor("ગુજરાતી")); assertNotNull(findFontFor("န\u103Aမာဘာသာ")); assertNotNull(findFontFor("සිංහල")); assertNotNull(findFontFor("ᠮᠣᠩᠭᠣᠯ")); assertNotNull(findFontFor("ಕನ್ನಡ")); assertNotNull(findFontFor("ଓଡ଼ିଆ ଭାଷା")); assertNotNull(findFontFor("ކުންފުނި")); }
@Test public void fontForMultipleLanguagesInOneString() { assertNotNull(findFontFor( "န\u103Aမာဘာသာ සිංහල ગુજરાતી தமிழ் پنجابی, ਪੰਜਾਬੀ ਹਰਜੋਤ ਸਿੰਘ ភាសាខ្មែរጩ latin ąćęłńóśźż ทดสอบ വീട मानक हिन्दी ് జ উ ភាសាខ្មែរ עברית")); }
@Test public void testCaching() { PDDocument doc = new PDDocument(); PDFont expected = FontUtils.findFontFor(doc, "ทดสอบ"); assertNotNull(expected); PDFont actual = FontUtils.findFontFor(doc, "ทด"); assertTrue("Font is cached, same instance is returned", expected == actual); }
@Test public void testCanDisplayThai() { assertThat(findFontFor("นี่คือการทดสอบ"), is(notNullValue())); }
@Test public void canDisplayGeorgian() { assertNotNull(findFontFor("ქართული ენა")); }