fix document font loading for scripting engine
This commit is contained in:
parent
2d6961e848
commit
b13aa5f3ef
3 changed files with 28 additions and 18 deletions
|
@ -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,14 +118,20 @@ public class Document implements Element, Closeable, RenderListener {
|
|||
Iterable<FontEmbedder> fontEmbedders = ServiceLoader.load(FontEmbedder.class, classLoader);
|
||||
boolean serviceLoaded = false;
|
||||
for (String alias : aliases) {
|
||||
// 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;
|
||||
fonts.addAll(fontEmbedder.getFonts());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
|
@ -135,6 +142,8 @@ public class Document implements Element, Closeable, RenderListener {
|
|||
StreamSupport.stream(fontEmbedders.spliterator(), false).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (serviceLoaded) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
org.xbib.settings.datastructures.PropertiesSettingsLoader
|
||||
org.xbib.settings.datastructures.json.JsonSettingsLoader
|
Loading…
Reference in a new issue