Skip to content

Commit

Permalink
Merge pull request #298 from metanorma/pdf_ua1
Browse files Browse the repository at this point in the history
PDF UA1
  • Loading branch information
Intelligent2013 authored Oct 2, 2024
2 parents e9ce6f2 + 0af22eb commit 85ccc32
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 24 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 := 2.02
JAR_VERSION := 2.03
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-2.02.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.03.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-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
Expand Down Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>2.02</version>
<version>2.03</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -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:
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>2.02</version>
<version>2.03</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/apache/fop/pdf/PDFGoTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/fop/pdf/PDFLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 [ "
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/org/apache/fop/pdf/PDFStructElem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<PDFDictionary>(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<PDFDictionary>(attribute.entries.size());
}
attributes.add(attribute);
this.attributes.add(attribute);
}

public List<PDFObject> getKids() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 85ccc32

Please sign in to comment.