Skip to content

Commit

Permalink
add overloaded method addFontDirectory(... String encoding ...)
Browse files Browse the repository at this point in the history
... for adding multiple fonts with a specific encoding.
  • Loading branch information
asolntsev committed Oct 26, 2024
1 parent ef850d0 commit 3c90ece
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
Expand Down

0 comments on commit 3c90ece

Please sign in to comment.