Skip to content

Commit

Permalink
Merge pull request #247 from metanorma/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Intelligent2013 authored May 22, 2024
2 parents 74d2f32 + b8120f9 commit 42e55a9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 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.87
JAR_VERSION := 1.88
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.87.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-1.88.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.87.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.88.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.87</version>
<version>1.88</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.87
git push origin v1.87
git tag v1.88
git push origin v1.88
----

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.87</version>
<version>1.88</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class PDFGenerator {
private boolean isAddCommentaryPageNumbers = false;

private boolean isAddMathAsAttachment = false;

private boolean isApplyAutolayoutAlgorithm = true;

private boolean isAddAnnotations = false;

Expand Down Expand Up @@ -275,6 +277,8 @@ public boolean process() {
isAddMathAsText = xsltConverter.hasParamAddMathAsText() && isMathExists;
isAddMathAsAttachment = xsltConverter.hasParamAddMathAsAttachment();

isApplyAutolayoutAlgorithm = xsltConverter.isApplyAutolayoutAlgorithm();

if (isSyntaxHighlight) {
xsltParams.put("syntax-highlight", "true");
}
Expand Down Expand Up @@ -418,6 +422,8 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File
additionalXSLTparams.setProperty("inputxml_basepath", fInputXMLParent);
additionalXSLTparams.setProperty("inputxml_filename", fInputXML.getName());

additionalXSLTparams.setProperty("output_path", pdf.getAbsolutePath());

xsltConverter.setParams(additionalXSLTparams);

setTablesWidths(fontcfg, xsltConverter, pdf);
Expand Down Expand Up @@ -1172,7 +1178,7 @@ private void setTablesWidths(fontConfig fontcfg, XSLTconverter xsltConverter, Fi
long startMethodTime = System.currentTimeMillis();

try {
if (isTableExists && xmlTableIF.isEmpty()) {
if (isTableExists && xmlTableIF.isEmpty() && isApplyAutolayoutAlgorithm) {
// generate IF with table width data
xsltConverter.setParam("table_if", "true");
logger.info("[INFO] Generation of XSL-FO with information about the table's widths ...");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/metanorma/fop/SourceXMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public SourceXMLDocument(String strXML) {
private void readMetaInformation() {
String element_review = readValue("//*[local-name() = 'review'][1]");
this.hasAnnotations = element_review.length() != 0;
String element_table = readValue("//*[local-name() = 'table' or local-name() = 'dl'][1]");
// check table without colgroup/col (width) or dl
String element_table = readValue("//*[(local-name() = 'table' and not(*[local-name() = 'colgroup']/*[local-name() = 'col'])) or local-name() = 'dl'][1]");
this.hasTables = element_table.length() != 0;
String element_math = readValue("//*[local-name() = 'math'][1]");
this.hasMath = element_math.length() != 0;
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 @@ -187,6 +187,11 @@ public boolean hasParamAddMathAsAttachment() {
return param_add_math_as_attachment.equalsIgnoreCase("true");
}

public boolean isApplyAutolayoutAlgorithm() {
String variable_isApplyAutolayoutAlgorithm = readValue("/*[local-name() = 'stylesheet']/*[local-name() = 'variable'][@name = 'isApplyAutolayoutAlgorithm_']");
return variable_isApplyAutolayoutAlgorithm.trim().equalsIgnoreCase("true");
}

public void deleteTmpXSL() {
if (tmpfileXSL != null) {
try {
Expand Down
27 changes: 26 additions & 1 deletion src/main/resources/tables_only.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

<xsl:output version="1.0" method="xml" encoding="UTF-8" indent="no"/>

<xsl:template match="/">
<xsl:variable name="xml">
<xsl:apply-templates />
</xsl:variable>
<xsl:apply-templates select="xalan:nodeset($xml)" mode="check_empty_elements"/>
</xsl:template>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
Expand All @@ -28,7 +35,8 @@
local-name() = 'sections' or
local-name() = 'annex' or
local-name() = 'indexsect'
]//*[local-name() = 'p' or
]//*[local-name() = 'clause' or
local-name() = 'p' or
local-name() = 'ul' or
local-name() = 'ol' or
local-name() = 'note' or
Expand Down Expand Up @@ -131,4 +139,21 @@
</xsl:for-each>
</xsl:template>

<xsl:template match="@*|node()" mode="check_empty_elements">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="check_empty_elements"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[local-name() = 'preface' or local-name = 'sections' or local-name() = 'annex' or local-name() = 'indexsect'][not(clause)]" mode="check_empty_elements">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:variable name="ns" select="namespace-uri()"/>
<xsl:element name="clause" namespace="{$ns}">
<xsl:element name="title" namespace="{$ns}">Clause</xsl:element>
</xsl:element>
<xsl:apply-templates mode="check_empty_elements"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 42e55a9

Please sign in to comment.