diff --git a/Makefile b/Makefile index 85bc515..2f3f10a 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 := 2.02 +JAR_VERSION := 2.03 JAR_FILE := mn2pdf-$(JAR_VERSION).jar all: target/$(JAR_FILE) diff --git a/README.adoc b/README.adoc index 7c86106..4fd3a0c 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-2.02.jar --xml-file --xsl-file --pdf-file [--syntax-highlight] +java -Xss5m -Xmx2048m -jar target/mn2pdf-2.03.jar --xml-file --xsl-file --pdf-file [--syntax-highlight] ---- e.g. [source,sh] ---- -java -Xss5m -Xmx2048m -jar target/mn2pdf-2.02.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-2.03.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 -2.02 +2.03 Metanorma XML to PDF converter ---- @@ -111,8 +111,8 @@ Tag the same version in Git: [source,xml] ---- -git tag v2.02 -git push origin v2.02 +git tag v2.03 +git push origin v2.03 ---- Then the corresponding GitHub release will be automatically created at: diff --git a/pom.xml b/pom.xml index 80184e8..8a9517d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.metanorma.fop mn2pdf - 2.02 + 2.03 Metanorma XML to PDF converter jar https://www.metanorma.org diff --git a/src/main/java/org/apache/fop/pdf/PDFGoTo.java b/src/main/java/org/apache/fop/pdf/PDFGoTo.java index 9e7297b..1101c6b 100644 --- a/src/main/java/org/apache/fop/pdf/PDFGoTo.java +++ b/src/main/java/org/apache/fop/pdf/PDFGoTo.java @@ -125,7 +125,11 @@ public void setDestination(String dest) { * @param str the PDF Contents key string */ public void setContents(String str) { - contents = str; + str = str + .replaceAll("[\\s\\u200b\\u00a0]+", " ") + .trim() + .replaceAll("[\\.,:;]+$",""); + contents = PDFText.escapeText(str, false); } /** diff --git a/src/main/java/org/apache/fop/pdf/PDFLink.java b/src/main/java/org/apache/fop/pdf/PDFLink.java index f0e85ef..a7c0d0c 100644 --- a/src/main/java/org/apache/fop/pdf/PDFLink.java +++ b/src/main/java/org/apache/fop/pdf/PDFLink.java @@ -112,8 +112,8 @@ public String toPDFString() { } else if (this.action instanceof PDFGoTo) { PDFGoTo pdfGoto = (PDFGoTo) this.action; String pdfGotoContents = pdfGoto.getContents(); - if (pdfGotoContents != null && !pdfGotoContents.isEmpty()) { - contents_key = "(" + pdfGoto.getContents() + ")"; + if (pdfGotoContents != null && !pdfGotoContents.equals("()")) { + contents_key = pdfGoto.getContents(); } } String s = "<< /Type /Annot\n" + "/Subtype /Link\n" + "/Rect [ " diff --git a/src/main/java/org/apache/fop/pdf/PDFStructElem.java b/src/main/java/org/apache/fop/pdf/PDFStructElem.java index fd5ef45..7895011 100644 --- a/src/main/java/org/apache/fop/pdf/PDFStructElem.java +++ b/src/main/java/org/apache/fop/pdf/PDFStructElem.java @@ -23,14 +23,13 @@ import java.io.OutputStream; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; +import java.util.*; import org.apache.fop.accessibility.StructureTreeElement; +import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.pdf.StandardStructureAttributes.Table; import org.apache.fop.util.LanguageTags; +import org.xml.sax.Attributes; /** * Class representing a PDF Structure Element. @@ -68,9 +67,23 @@ public PDFStructElem(PDFObject parent, StructureType structureType) { this(parent); this.structureType = structureType; put("S", structureType.getName()); + if (structureType.getName().getName().equals("Note")) { + // Note tag shall have ID entry (see https://github.com/metanorma/mn2pdf/issues/288) + put("ID", generateHexID(16)); + } setParent(parent); } + private String generateHexID(int length) { + Random r = new Random(); + StringBuilder result = new StringBuilder(); + for (int i = 0; i < length; i++) { + int value = r.nextInt(255); + result.append(Integer.toHexString(value)); + } + return result.toString().toUpperCase(); + } + private PDFStructElem(PDFObject parent) { if (parent instanceof PDFStructElem) { parentElement = (PDFStructElem) parent; @@ -227,22 +240,29 @@ protected boolean attachKids() { return kidsAttached; } - public void setTableAttributeColSpan(int colSpan) { - setTableAttributeRowColumnSpan("ColSpan", colSpan); + public void setTableAttributeColSpan(int colSpan, Attributes attributes) { + setTableAttributeRowColumnSpan("ColSpan", colSpan, attributes); } - public void setTableAttributeRowSpan(int rowSpan) { - setTableAttributeRowColumnSpan("RowSpan", rowSpan); + public void setTableAttributeRowSpan(int rowSpan, Attributes attributes) { + setTableAttributeRowColumnSpan("RowSpan", rowSpan, attributes); } - private void setTableAttributeRowColumnSpan(String typeSpan, int span) { + private void setTableAttributeRowColumnSpan(String typeSpan, int span, Attributes attributes) { PDFDictionary attribute = new PDFDictionary(); attribute.put("O", Table.NAME); attribute.put(typeSpan, span); - if (attributes == null) { - attributes = new ArrayList(2); + String scopeAttribute = attributes.getValue(InternalElementMapping.URI, + InternalElementMapping.SCOPE); + Table.Scope scope = (scopeAttribute == null) + ? Table.Scope.COLUMN + : Table.Scope.valueOf(scopeAttribute.toUpperCase(Locale.ENGLISH)); + attribute.put("Scope", scope.getName()); + + if (this.attributes == null) { + this.attributes = new ArrayList(attribute.entries.size()); } - attributes.add(attribute); + this.attributes.add(attribute); } public List getKids() { diff --git a/src/main/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java b/src/main/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java index 28832bf..0ac0941 100644 --- a/src/main/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java +++ b/src/main/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java @@ -338,11 +338,11 @@ protected void registerStructureElement(PDFStructElem structureElement, PDFFacto protected void setAttributes(PDFStructElem structElem, Attributes attributes) { String columnSpan = attributes.getValue("number-columns-spanned"); if (columnSpan != null) { - structElem.setTableAttributeColSpan(Integer.parseInt(columnSpan)); + structElem.setTableAttributeColSpan(Integer.parseInt(columnSpan), attributes); } String rowSpan = attributes.getValue("number-rows-spanned"); if (rowSpan != null) { - structElem.setTableAttributeRowSpan(Integer.parseInt(rowSpan)); + structElem.setTableAttributeRowSpan(Integer.parseInt(rowSpan), attributes); } }