Skip to content

Commit

Permalink
fixed issue with missing fonts, #177
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Jul 16, 2023
1 parent 28c6c4f commit efa5fef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ?= /bin/bash
endif

#JAR_VERSION := $(shell mvn -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive exec:exec -DforceStdout)
JAR_VERSION := 1.78
JAR_VERSION := 1.79
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.78</version>
<version>1.79</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -111,8 +111,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v1.78
git push origin v1.78
git tag v1.79
git push origin v1.79
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.78</version>
<version>1.79</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
75 changes: 39 additions & 36 deletions src/main/java/org/metanorma/fop/fontConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ private void setFontsPaths() throws IOException, URISyntaxException {
List<String> machineFontList = getMachineFonts();

// remove unused fonts
fopFonts.removeIf(fopFont -> !fopFont.isUsing());
//fopFonts.removeIf(fopFont -> !fopFont.isUsing());

fopFonts.stream()
.filter(fopFont -> !fopFont.getEmbed_url().isEmpty())
Expand Down Expand Up @@ -695,7 +695,7 @@ private void setFontsPaths() throws IOException, URISyntaxException {
}
}
});

StringBuilder sb = new StringBuilder();
fopFonts.stream()
.filter(f -> f.isUsing())
Expand Down Expand Up @@ -742,48 +742,51 @@ private void updateFontsInFOPConfig(Document xmlDocument) {

// add 'font' from fopFonts array
for(FOPFont fopFont: fopFonts) {

String embed_url = fopFont.getEmbed_url();
String embed_url_updated = embed_url;
try {
if (!embed_url.startsWith("file:")) {
// add file: prefix and update xml attribute embed-url
embed_url_updated = new File(embed_url).toURI().toURL().toString();
}
}
catch (MalformedURLException ex) { }

fopFont.setEmbed_url(embed_url_updated);

try {
String fopFontString = new XmlMapper().writeValueAsString(fopFont);
//restore path
fopFont.setEmbed_url(embed_url);
if (DEBUG) {
//System.out.println("DEBUG: FOP config font entry:");
//System.out.println(fopFontString);
fopFontsLog.append(fopFontString).append("\n");

if(fopFont.isUsing()) {

String embed_url = fopFont.getEmbed_url();
String embed_url_updated = embed_url;
try {
if (!embed_url.startsWith("file:")) {
// add file: prefix and update xml attribute embed-url
embed_url_updated = new File(embed_url).toURI().toURL().toString();
}
} catch (MalformedURLException ex) {
}
Node newNodeFont = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(fopFontString.getBytes()))
.getDocumentElement();
//newNodeFont.getAttributes().getNamedItem("embed-url").setTextContent(embed_url);

Document doc = nodeFonts.getOwnerDocument();
newNodeFont = doc.importNode(newNodeFont, true);
nodeFonts.appendChild(newNodeFont);

fopFont.setEmbed_url(embed_url_updated);

try {
String fopFontString = new XmlMapper().writeValueAsString(fopFont);
//restore path
fopFont.setEmbed_url(embed_url);
if (DEBUG) {
//System.out.println("DEBUG: FOP config font entry:");
//System.out.println(fopFontString);
fopFontsLog.append(fopFontString).append("\n");
}
Node newNodeFont = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(fopFontString.getBytes()))
.getDocumentElement();
//newNodeFont.getAttributes().getNamedItem("embed-url").setTextContent(embed_url);

Document doc = nodeFonts.getOwnerDocument();
newNodeFont = doc.importNode(newNodeFont, true);
nodeFonts.appendChild(newNodeFont);

/*if (fopFont.isUsing()) {
String msg = fopFont.getMessages();
if(!msg.isEmpty()) {
System.out.println();
}
}*/

} catch (SAXException | IOException | ParserConfigurationException ex) {
logger.log(Level.SEVERE, "Error in FOP font xml processing: {0}", ex.toString());

} catch (SAXException | IOException | ParserConfigurationException ex) {
logger.log(Level.SEVERE, "Error in FOP font xml processing: {0}", ex.toString());
}
}
}
} catch (XPathExpressionException ex) {
Expand Down

0 comments on commit efa5fef

Please sign in to comment.