From 3c90ecea40316803e26bf21af97bef13d5a4e475 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Sat, 26 Oct 2024 12:38:18 +0300 Subject: [PATCH] add overloaded method addFontDirectory(... String encoding ...) ... for adding multiple fonts with a specific encoding. --- .../xhtmlrenderer/pdf/ITextFontResolver.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java index ec9f19e62..0a840ed92 100644 --- a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java +++ b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextFontResolver.java @@ -185,14 +185,23 @@ private void importFontFace(FontFaceRule rule, UserAgentCallback userAgentCallba } } - public void addFontDirectory(String dir, boolean embedded) - throws DocumentException, IOException { + /** + * Add all fonts from given directory with encoding "CP1252" (don't ask me why :) ) + */ + public void addFontDirectory(String dir, boolean embedded) throws DocumentException, IOException { + addFontDirectory(dir, BaseFont.CP1252, embedded); + } + + /** + * Add all fonts from given directory (all files with extension ".otf" and ".ttf") + */ + public void addFontDirectory(String dir, String encoding, boolean embedded) throws DocumentException, IOException { File f = new File(dir); if (!f.isDirectory()) { throw new IllegalArgumentException("%s is not a directory".formatted(dir)); } for (File file : filesWithExtensions(f, OTF, TTF)) { - addFont(file.getAbsolutePath(), embedded); + addFont(file.getAbsolutePath(), encoding, embedded); } } @@ -204,6 +213,9 @@ private File[] filesWithExtensions(File f, String... extensions) { })); } + /** + * Add the font with encoding "CP1252" (don't ask me why :) ) + */ public void addFont(String path, boolean embedded) throws DocumentException, IOException { addFont(path, BaseFont.CP1252, embedded);