diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java index be1a33b..3bce156 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/Document.java @@ -24,6 +24,7 @@ import java.util.Calendar; import java.util.Collection; import java.util.GregorianCalendar; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -85,7 +86,7 @@ public class Document implements Element, Closeable, RenderListener { public Document(PageFormat pageFormat) { this.pdDocument = new PDDocument(); this.pdDocumentInformation = new PDDocumentInformation(); - this.fonts = new ArrayList<>(); + this.fonts = new LinkedHashSet<>(); this.elements = new ArrayList<>(); this.customRenderer = new ArrayList<>(); this.renderListener = new ArrayList<>(); @@ -117,23 +118,31 @@ public class Document implements Element, Closeable, RenderListener { Iterable fontEmbedders = ServiceLoader.load(FontEmbedder.class, classLoader); boolean serviceLoaded = false; for (String alias : aliases) { - boolean found = false; - for (FontEmbedder fontEmbedder : fontEmbedders) { - try { - if (alias == null || alias.isEmpty() || fontEmbedder.getAlias().equals(alias)) { - fontEmbedder.embed(this.pdDocument); - found = true; - serviceLoaded = true; - fonts.addAll(fontEmbedder.getFonts()); + // fonts times, helvetica, courier are standard fonts without embedding + switch (alias) { + case "times" -> fonts.add(BaseFont.TIMES); + case "helvetica" -> fonts.add(BaseFont.HELVETICA); + case "courier" -> fonts.add(BaseFont.COURIER); + case null, default -> { + boolean found = false; + for (FontEmbedder fontEmbedder : fontEmbedders) { + try { + if (alias == null || alias.isEmpty() || fontEmbedder.getAlias().equals(alias)) { + fontEmbedder.embed(this.pdDocument); + fonts.addAll(fontEmbedder.getFonts()); + found = true; + serviceLoaded = true; + } + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + if (!found) { + logger.log(Level.WARNING, "font " + alias + " not found using embedders " + + StreamSupport.stream(fontEmbedders.spliterator(), false).toList()); } - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); } } - if (!found) { - logger.log(Level.WARNING, "font " + alias + " not found using embedders " + - StreamSupport.stream(fontEmbedders.spliterator(), false).toList()); - } } if (serviceLoaded) { break; diff --git a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java index 122bb9c..1015f49 100644 --- a/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java +++ b/graphics-pdfbox-layout/src/main/java/org/xbib/graphics/pdfbox/layout/element/scripting/command/DocumentCommand.java @@ -9,6 +9,7 @@ import org.xbib.settings.Settings; import java.io.IOException; import java.time.Instant; +import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -73,9 +74,7 @@ public class DocumentCommand implements Command { document.setModificationDate(instant); } String[] fonts = settings.getAsArray("font"); - for (String font : fonts) { - document.embedFonts(List.of(font)); - } + document.embedFonts(Arrays.asList(fonts)); state.getElements().push(document); engine.executeElements(settings); } diff --git a/graphics-pdfbox-layout/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader b/graphics-pdfbox-layout/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader new file mode 100644 index 0000000..5cbf3d5 --- /dev/null +++ b/graphics-pdfbox-layout/src/test/resources/META-INF/services/org.xbib.settings.SettingsLoader @@ -0,0 +1,2 @@ +org.xbib.settings.datastructures.PropertiesSettingsLoader +org.xbib.settings.datastructures.json.JsonSettingsLoader \ No newline at end of file