Skip to content

Commit

Permalink
Merge pull request #161 from metanorma/svg_issue
Browse files Browse the repository at this point in the history
successSVGRendering test added, metanorma/metanorma-iso#878
  • Loading branch information
Intelligent2013 authored Dec 5, 2022
2 parents da6e3f2 + b044223 commit 7a68f9c
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 8 deletions.
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.52.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-1.53.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.52.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.53.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.52</version>
<version>1.53</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.52
git push origin v1.52
git tag v1.53
git push origin v1.53
----

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.52</version>
<version>1.53</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/fop/fonts/GlyphMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public GlyphMapping(int startIndex, int endIndex, int wordSpaceCount, int letter
MinOptMax areaIPD, boolean isHyphenated, boolean isSpace, boolean breakOppAfter,
Font font, int level, int[][] gposAdjustments, String mapping, List associations) {
this(startIndex, endIndex, wordSpaceCount, letterSpaceCount, areaIPD, isHyphenated,
isSpace, false, breakOppAfter, font, level, gposAdjustments, null, null);
isSpace, false, breakOppAfter, font, level, gposAdjustments, mapping, associations);
}

public GlyphMapping(int startIndex, int endIndex, int wordSpaceCount, int letterSpaceCount,
Expand Down
42 changes: 41 additions & 1 deletion src/test/java/org/metanorma/fop/mn2pdfTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import org.apache.pdfbox.pdmodel.encryption.PDEncryption;

import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -359,7 +360,46 @@ public void testSyntaxHighlight() throws TransformerException, TransformerConfig
String exprectedValue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><syntax><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">root</span>&gt;</span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a</span>&gt;</span><span class=\"hljs-tag\">&lt;/<span class=\"hljs-name\">a</span>&gt;</span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">b</span>&gt;</span>text<span class=\"hljs-tag\">&lt;/<span class=\"hljs-name\">b</span>&gt;</span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">c</span> <span class=\"hljs-attr\">key</span>=<span class=\"hljs-string\">'value'</span>/&gt;</span><span class=\"hljs-tag\">&lt;/<span class=\"hljs-name\">root</span>&gt;</span></syntax>";
assertTrue(value.equals(exprectedValue));
}


@Test
public void successSVGRendering() throws ParseException, IOException {
ClassLoader classLoader = getClass().getClassLoader();
String fontpath = Paths.get(System.getProperty("buildDirectory"), ".." , "fonts").toString();
String xml = classLoader.getResource("iso.svgtest.xml").getFile();
String xsl = classLoader.getResource("iso.international-standard.xsl").getFile();
Path pdf = Paths.get(System.getProperty("buildDirectory"), "iso.svgtest.pdf");

String[] args = new String[]{"--font-path", fontpath, "--xml-file", xml, "--xsl-file", xsl, "--pdf-file", pdf.toAbsolutePath().toString()};
mn2pdf.main(args);

String capturedLog = getTestCapturedLog();
assertTrue(!capturedLog.contains("SVG graphic could not be rendered"));
assertTrue(Files.exists(pdf));
}

@Test
public void checkSpacesInPDF() throws ParseException {
ClassLoader classLoader = getClass().getClassLoader();
String fontpath = Paths.get(System.getProperty("buildDirectory"), ".." , "fonts").toString();
String xml = classLoader.getResource("iso.zerowidthspacetest.xml").getFile();
String xsl = classLoader.getResource("iso.international-standard.xsl").getFile();
Path pdf = Paths.get(System.getProperty("buildDirectory"), "iso.zerowidthspacetest.pdf");

String[] args = new String[]{"--font-path", fontpath, "--xml-file", xml, "--xsl-file", xsl, "--pdf-file", pdf.toAbsolutePath().toString()};
mn2pdf.main(args);

String pdftext = "";
PDDocument doc;
try {
doc = PDDocument.load(pdf.toFile());
pdftext = new PDFTextStripper().getText(doc);
} catch (IOException ex) {
System.out.println(ex.toString());
}
assertTrue(pdftext.contains("the_integers") && pdftext.contains("elementary_space") && pdftext.contains("make_elementary_space"));
}



@Test
public void testDates() throws IOException {
Expand Down
321 changes: 321 additions & 0 deletions src/test/resources/iso.svgtest.xml

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions src/test/resources/iso.zerowidthspacetest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<iso-standard xmlns="https://www.metanorma.org/ns/iso">
<bibdata type="standard">
<title language="en" format="text/plain" type="main">Cereals and pulses — Specifications and test methods — Rice (Final)</title>
<title language="en" format="text/plain" type="title-intro">Cereals and pulses</title>
<title language="en" format="text/plain" type="title-main">Specifications and test methods</title>
<title language="en" format="text/plain" type="title-part">Rice (Final)</title>
<title language="fr" format="text/plain" type="main">Céréales et légumineuses — Spécification et méthodes d’essai — Riz (Final)</title>
<title language="fr" format="text/plain" type="title-intro">Céréales et légumineuses</title>
<title language="fr" format="text/plain" type="title-main">Spécification et méthodes d’essai</title>
<title language="fr" format="text/plain" type="title-part">Riz (Final)</title>
<docidentifier type="iso">ISO 17301-1:2016</docidentifier>
<docidentifier type="iso-with-lang">ISO 17301-1:2016(E)</docidentifier>
<docidentifier type="iso-reference">ISO 17301-1:2016(E)</docidentifier>
<docidentifier type="iso-tc">17301</docidentifier>
<docnumber>17301</docnumber>
<contributor>
<role type="author"/>
<organization>
<name>International Organization for Standardization</name>
<abbreviation>ISO</abbreviation>
</organization>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>International Organization for Standardization</name>
<abbreviation>ISO</abbreviation>
</organization>
</contributor>
<edition>2</edition>
<version>
<revision-date>2016-05-01</revision-date>
</version>
<language>en</language>
<script>Latn</script>
<status>
<stage abbreviation="IS">60</stage>
<substage>60</substage>
</status>
<copyright>
<from>2016</from>
<owner>
<organization>
<name>International Organization for Standardization</name>
<abbreviation>ISO</abbreviation>
</organization>
</owner>
</copyright>
<ext>
<doctype>international-standard</doctype>
<editorialgroup>
<technical-committee number="34">Food products</technical-committee>
<subcommittee number="4">Cereals and pulses</subcommittee>
<workgroup number="4" type="WG">Amylose in rice</workgroup>
<secretariat>SAC</secretariat>
</editorialgroup>
<ics>
<code>67.060</code>
</ics>
<structuredidentifier>
<project-number part="1">ISO 17301</project-number>
</structuredidentifier>
<stagename>International standard</stagename>
</ext>
</bibdata>
<sections>

<clause id="_scope" obligation="normative"><title>Scope</title><p id="_f9c95d6b-bfc6-4a1c-9e75-fc5720c899f4">This document specifies minimum requirements and test methods for rice (<em>Oryza sativa L.</em>).</p>
<p id="_d8863fda-f169-44a7-b0fa-e2e4c4097a70">It is applicable to husked rice, husked parboiled rice, milled rice and milled parboiled rice, suitable for human consumption, directly or after reconditioning.</p>
<p id="_3e3e9b84-724f-43e4-8920-14beb0051161">It is not applicable to cooked rice products.</p>

<p id="the_elementary_spaces_constants">EXPRESS specification:</p>

<sourcecode id="_cf1747a8-ea02-bbd5-06b6-5662ccab8995" lang="express" unnumbered="true">*)
the_integers : elementary_space := make_elementary_space(es_integers);
the_reals : elementary_space := make_elementary_space(es_reals);
the_complex_numbers : elementary_space := make_elementary_space(es_complex_numbers);
the_numbers : elementary_space := make_elementary_space(es_numbers);
the_logicals : elementary_space := make_elementary_space(es_logicals);
the_booleans : elementary_space := make_elementary_space(es_booleans);
the_strings : elementary_space := make_elementary_space(es_strings);
the_binarys : elementary_space := make_elementary_space(es_binarys);
the_maths_spaces : elementary_space := make_elementary_space(es_maths_spaces);
the_generics : elementary_space := make_elementary_space(es_generics);
(*</sourcecode>

</clause>
</sections>
</iso-standard>

0 comments on commit 7a68f9c

Please sign in to comment.