Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #263

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.97
JAR_VERSION := 1.98
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-1.98.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--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
Expand Down Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.97</version>
<version>1.98</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.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:
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.97</version>
<version>1.98</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public class PDFGenerator {
final private String inputXMLFilePath;

SourceXMLDocument sourceXMLDocument;


String sourceDocumentFilePath = "";

final private String inputXSLFilePath;

final private String outputPDFFilePath;
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -283,6 +292,7 @@ public boolean process() {

isApplyAutolayoutAlgorithm = xsltConverter.isApplyAutolayoutAlgorithm();

isComplexScriptsFeatures = !xsltConverter.isIgnoreComplexScripts();

if (isSyntaxHighlight) {
xsltParams.put("syntax-highlight", "true");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/metanorma/fop/XSLTconverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/metanorma/fop/fontConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class fontConfig {

private String fontConfigPath = "";

private boolean isComplexScriptsFeatures = true;
public fontConfig() {

setFontPath(DEFAULT_FONT_PATH);
Expand Down Expand Up @@ -531,7 +532,9 @@ private void updateConfig() throws IOException, Exception {
updateFontsForGraphicsEnvironment();

updateFontsInFOPConfig(FOPconfigXML);


updateComplexScriptsInFOPConfig(FOPconfigXML);

//write updated FOP config file
writeFOPConfigFile(FOPconfigXML);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(){
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/pdf_fonts_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Relative config URLs are resolved relative to location of this file.
<source-resolution>96</source-resolution>
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
<target-resolution>96</target-resolution>

<complex-scripts disabled="false"/>
<!-- Default page-height and page-width, in case value is specified as auto -->
<default-page-settings height="11.00in" width="8.50in"/>
<fonts>
Expand Down
Loading