fallback to second font, CJK demo

This commit is contained in:
Jörg Prante 2023-08-04 22:53:39 +02:00
parent 53a27c5792
commit 9eeebfac01
2 changed files with 5 additions and 4 deletions

View file

@ -224,7 +224,7 @@ public class Document implements Element, Closeable, RenderListener {
public boolean canWrite(String string) { public boolean canWrite(String string) {
try { try {
return regularFont.getStringWidth(string) > 0; return regularFont.getStringWidth(string) > 0;
} catch (IOException e) { } catch (IOException | IllegalArgumentException e) {
return false; return false;
} }
} }

View file

@ -16,14 +16,15 @@ public class HelloNotoSansCJKFontTest {
@Test @Test
public void testDocumentOne() throws Exception { public void testDocumentOne() throws Exception {
Document document = new Document(PageFormats.A4_PORTRAIT); Document document = new Document(PageFormats.A4_PORTRAIT);
document.registerNotoSansFont();
document.registerNotoSansCJKSCFont(); document.registerNotoSansCJKSCFont();
List<Font> font = List.of(document.getFont("notosanscjksc")); List<Font> font = List.of(document.getFont("notosans"), document.getFont("notosanscjksc"));
Paragraph paragraph = new Paragraph(); Paragraph paragraph = new Paragraph();
paragraph.add(new Indent(32, SpaceUnit.pt)); paragraph.add(new Indent(32, SpaceUnit.pt));
paragraph.addMarkup("Hello Noto Sans CJK Regular\n", 12, font); paragraph.addMarkup("Hello Noto Sans CJK Regular\n", 12, font);
paragraph.addMarkup("*Hello Noto Sans CJK Bold*\n", 12, font); paragraph.addMarkup("*Hello Noto Sans CJK Bold*\n", 12, font);
//paragraph.addText("Hello Unicode Text: Zwrotki dla Dorotki : arcyksiążę fiołków\n", 12, font); paragraph.addText("Hello Unicode Text: Zwrotki dla Dorotki : arcyksiążę fiołków\n", 12, font);
//paragraph.addMarkup("Hello Unicode Markup: _Zwrotki dla Dorotki : arcyksiążę fiołków_\n", 12, font); paragraph.addMarkup("Hello Unicode Markup: _Zwrotki dla Dorotki : arcyksiążę fiołków_\n", 12, font);
paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font); paragraph.addText("Hello CJK Text: 北京是中国古都,是拥有三千余年建城历史、八百六十余年建都史的历史文化名城\n", 12, font);
document.add(paragraph); document.add(paragraph);
Paragraph anotherParagraph = new Paragraph(); Paragraph anotherParagraph = new Paragraph();