diff --git a/Makefile b/Makefile index beade65..f8a8e8c 100644 --- a/Makefile +++ b/Makefile @@ -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.97 +JAR_VERSION := 1.98 JAR_FILE := mn2pdf-$(JAR_VERSION).jar all: target/$(JAR_FILE) diff --git a/README.adoc b/README.adoc index 9ef1587..bbc9ba4 100644 --- a/README.adoc +++ b/README.adoc @@ -17,14 +17,14 @@ You will need the Java Development Kit (JDK) version 8, Update 241 (8u241) or hi [source,sh] ---- -java -Xss5m -Xmx2048m -jar target/mn2pdf-1.97.jar --xml-file --xsl-file --pdf-file [--syntax-highlight] +java -Xss5m -Xmx2048m -jar target/mn2pdf-1.98.jar --xml-file --xsl-file --pdf-file [--syntax-highlight] ---- e.g. [source,sh] ---- -java -Xss5m -Xmx2048m -jar target/mn2pdf-1.97.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf +java -Xss5m -Xmx2048m -jar target/mn2pdf-1.98.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf ---- === PDF encryption features @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.: ---- org.metanorma.fop mn2pdf -1.97 +1.98 Metanorma XML to PDF converter ---- @@ -111,8 +111,8 @@ Tag the same version in Git: [source,xml] ---- -git tag v1.97 -git push origin v1.97 +git tag v1.98 +git push origin v1.98 ---- Then the corresponding GitHub release will be automatically created at: diff --git a/pom.xml b/pom.xml index 70d5c52..f73d1ea 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.metanorma.fop mn2pdf - 1.97 + 1.98 Metanorma XML to PDF converter jar https://www.metanorma.org diff --git a/src/main/java/org/metanorma/fop/PDFGenerator.java b/src/main/java/org/metanorma/fop/PDFGenerator.java index d32a691..1f4782c 100644 --- a/src/main/java/org/metanorma/fop/PDFGenerator.java +++ b/src/main/java/org/metanorma/fop/PDFGenerator.java @@ -71,7 +71,9 @@ public class PDFGenerator { final private String inputXMLFilePath; SourceXMLDocument sourceXMLDocument; - + + String sourceDocumentFilePath = ""; + final private String inputXSLFilePath; final private String outputPDFFilePath; @@ -91,7 +93,9 @@ public class PDFGenerator { private boolean isAddMathAsAttachment = false; private boolean isApplyAutolayoutAlgorithm = true; - + + private boolean isComplexScriptsFeatures = true; + private boolean isAddAnnotations = false; private boolean isTableExists = false; @@ -267,6 +271,11 @@ public boolean process() { PDFResult pdfResult = PDFResult.PDFResult(fPDF); + sourceDocumentFilePath = fXML.getParent(); + if (sourceDocumentFilePath == null) { + sourceDocumentFilePath = System.getProperty("user.dir"); + } + //File fPresentationPartXML = getPresentationPartXML(fXML, fPDF.getParent()); File fPresentationPartXML = getPresentationPartXML(fXML, pdfResult.getOutFolder()); @@ -283,6 +292,7 @@ public boolean process() { isApplyAutolayoutAlgorithm = xsltConverter.isApplyAutolayoutAlgorithm(); + isComplexScriptsFeatures = !xsltConverter.isIgnoreComplexScripts(); if (isSyntaxHighlight) { xsltParams.put("syntax-highlight", "true"); @@ -415,8 +425,9 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File additionalXSLTparams.setProperty("external_index", fileXmlIF.getAbsolutePath()); } - String basepath = sourceXMLDocument.getDocumentFilePath() + File.separator; - // redefine basepath + //String basepath = sourceXMLDocument.getDocumentFilePath() + File.separator; + String basepath = sourceDocumentFilePath + File.separator; + // redefine basepath if (xsltParams.containsKey("baseassetpath")) { basepath = xsltParams.getProperty("baseassetpath") + File.separator; } @@ -456,7 +467,9 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File debugSaveXML(xmlFO, pdf.getAbsolutePath() + ".fo.xml"); fontcfg.setSourceDocumentFontList(sourceXMLDocument.getDocumentFonts()); - + + fontcfg.setComplexScriptFeatures(isComplexScriptsFeatures); + Source src = new StreamSource(new StringReader(xmlFO)); diff --git a/src/main/java/org/metanorma/fop/XSLTconverter.java b/src/main/java/org/metanorma/fop/XSLTconverter.java index 346c5cb..22f08be 100644 --- a/src/main/java/org/metanorma/fop/XSLTconverter.java +++ b/src/main/java/org/metanorma/fop/XSLTconverter.java @@ -192,6 +192,11 @@ public boolean isApplyAutolayoutAlgorithm() { return variable_isApplyAutolayoutAlgorithm.trim().equalsIgnoreCase("true"); } + public boolean isIgnoreComplexScripts() { + String variable_isIgnoreComplexScripts = readValue("/*[local-name() = 'stylesheet']/*[local-name() = 'variable'][@name = 'isIgnoreComplexScripts']"); + return variable_isIgnoreComplexScripts.trim().equalsIgnoreCase("true"); + } + public void deleteTmpXSL() { if (tmpfileXSL != null) { try { diff --git a/src/main/java/org/metanorma/fop/fontConfig.java b/src/main/java/org/metanorma/fop/fontConfig.java index 2b261a8..df0eace 100644 --- a/src/main/java/org/metanorma/fop/fontConfig.java +++ b/src/main/java/org/metanorma/fop/fontConfig.java @@ -104,6 +104,7 @@ class fontConfig { private String fontConfigPath = ""; + private boolean isComplexScriptsFeatures = true; public fontConfig() { setFontPath(DEFAULT_FONT_PATH); @@ -531,7 +532,9 @@ private void updateConfig() throws IOException, Exception { updateFontsForGraphicsEnvironment(); updateFontsInFOPConfig(FOPconfigXML); - + + updateComplexScriptsInFOPConfig(FOPconfigXML); + //write updated FOP config file writeFOPConfigFile(FOPconfigXML); @@ -803,7 +806,18 @@ private void updateFontsInFOPConfig(Document xmlDocument) { logger.severe(ex.toString()); } } - + + private void updateComplexScriptsInFOPConfig(Document xmlDocument) { + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "/fop/complex-scripts/@disabled"; + try { + Node nodeComplexScripts = (Node) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODE); + nodeComplexScripts.setTextContent(String.valueOf(!isComplexScriptsFeatures)); + } catch (XPathExpressionException ex) { + logger.severe(ex.toString()); + } + } + public void outputFOPFontsLog(Path logPath) { if(DEBUG) { Util.outputLog(logPath, fopFontsLog.toString()); @@ -877,7 +891,10 @@ public void setPDFUAmode(String mode) throws SAXException, IOException, ParserCo } writeFOPConfigFile(configXML); } - + + public void setComplexScriptFeatures(boolean value) { + this.isComplexScriptsFeatures = value; + } private void updateFontsForGraphicsEnvironment(){ diff --git a/src/main/resources/pdf_fonts_config.xml b/src/main/resources/pdf_fonts_config.xml index 889c381..920b3c8 100644 --- a/src/main/resources/pdf_fonts_config.xml +++ b/src/main/resources/pdf_fonts_config.xml @@ -15,7 +15,7 @@ Relative config URLs are resolved relative to location of this file. 96 96 - +