Skip to content

Commit

Permalink
Fixed bug with transcluded document in first fragment + toc not appea…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
jbreure committed Oct 16, 2019
1 parent 8c8ae52 commit ff836b6
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,57 @@ public void testTranscludedDocument() throws IOException {

}

@Test
public void testTOC() throws IOException {

File lorem = new File(SOURCE, "toc.psml");
File fo = new File(WORKING, "fo.xml");
File output = new File(DESTINATION, "toc.pdf");

ExportTask task = new ExportTask();
task.setDebug(true);
task.setWorking(WORKING);
task.setSrc(lorem);
task.setDest(output);
task.execute();

Assert.assertTrue(output.exists());
Assert.assertTrue(fo.exists());

Map<String, String> ns = Collections.singletonMap("fo", "http://www.w3.org/1999/XSL/Format");
String xml = new String(Files.readAllBytes(fo.toPath()), StandardCharsets.UTF_8);
String tocBlock = "//fo:flow//fo:block[@id='toc-123456']";
MatcherAssert.assertThat(xml, XML.hasXPath("count("+tocBlock+")", equalTo("1")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("count("+tocBlock+"//fo:basic-link)", equalTo("11")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[1]", equalTo("1. heading 1")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[2]", equalTo("1.1. heading 2")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[3]", equalTo("1.1.1. heading 3")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[4]", equalTo("1.1.1.1. heading 4")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[5]", equalTo("1.1.1.1.1. heading 5")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[6]", equalTo("1.1.1.1.1.1. heading 6")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[7]", equalTo("2. heading 1")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[8]", equalTo("2.1. heading 2")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[9]", equalTo("2.2. heading 2")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[10]", equalTo("2.3.1. heading 3")).withNamespaceContext(ns));
MatcherAssert.assertThat(xml, XML.hasXPath("("+tocBlock+"//fo:basic-link)[11]", equalTo("2.3. heading 2")).withNamespaceContext(ns));

}

@Test
public void testABC() throws IOException {

File lorem = new File(SOURCE, "abc.psml");
File fo = new File(WORKING, "fo.xml");
File output = new File(DESTINATION, "abc.pdf");

ExportTask task = new ExportTask();
task.setDebug(true);
task.setWorking(WORKING);
task.setSrc(lorem);
task.setDest(output);
task.execute();
}

private File loadConfig(String path) {
File config = new File(CONFIGS, path);
Assert.assertTrue(config.exists());
Expand Down
78 changes: 78 additions & 0 deletions pso-pdf-ant/test/export/input/toc.psml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<document level="portable" id="123456">
<section id="1">
<fragment id="1">
<heading level="1">TOC testing document</heading>
</fragment>
</section>
<toc>
<toc-tree title="TOC testing document">
<toc-part level="1" title="heading 1" prefix="1." canonical="1." idref="123456-1-1-1">
<toc-part level="2" title="heading 2" prefix="1.1." canonical="1.1." idref="123456-1-1-2">
<toc-part level="3" title="heading 3" prefix="1.1.1." canonical="1.1.1." idref="123456-1-1-3">
<toc-part level="4" title="heading 4" prefix="1.1.1.1." canonical="1.1.1.1." idref="123456-1-1-4">
<toc-part level="5" title="heading 5" prefix="1.1.1.1.1." canonical="1.1.1.1.1." idref="123456-1-1-5">
<toc-part level="6" title="heading 6" prefix="1.1.1.1.1.1." canonical="1.1.1.1.1.1." idref="123456-1-1-6" />
</toc-part>
</toc-part>
</toc-part>
</toc-part>
</toc-part>
<toc-part level="1" title="heading 1" prefix="2." canonical="2." idref="123456-1-2-1">
<toc-part level="2" title="heading 2" prefix="2.1." canonical="2.1." idref="123456-1-2-2" />
<toc-part level="2" title="heading 2" prefix="2.2." canonical="2.2." idref="123456-1-2-3">
<toc-part level="3" title="heading 3" prefix="2.3.1." canonical="2.3.1." idref="123456-1-3-2" />
</toc-part>
<toc-part level="2" title="heading 2" prefix="2.3." canonical="2.3." idref="123456-1-2-4" />
</toc-part>
</toc-tree>
</toc>
<section id="2">
<fragment id="headings">
<heading level="1" prefix="1." numbered="true" id="123456-1-1-1">heading 1</heading>
<heading level="2" prefix="1.1." numbered="true" id="123456-1-1-2">heading 2</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="3" prefix="1.1.1." numbered="true" id="123456-1-1-3">heading 3</heading>
<heading level="4" prefix="1.1.1.1." numbered="true" id="123456-1-1-4">heading 4</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="5" prefix="1.1.1.1.1." numbered="true" id="123456-1-1-5">heading 5</heading>
<heading level="6" prefix="1.1.1.1.1.1." numbered="true" id="123456-1-1-6">heading 6</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="1" prefix="2." numbered="true" id="123456-1-2-1">heading 1</heading>
<heading level="2" prefix="2.1." numbered="true" id="123456-1-2-2">heading 2</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="2" prefix="2.2." numbered="true" id="123456-1-2-3">heading 2</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="3" prefix="2.2.1." numbered="true" id="123456-1-3-2">heading 3</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<heading level="2" prefix="2.3." numbered="true" id="123456-1-2-4">heading 2</heading>
<para>prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
</fragment>
<fragment id="paras">
<para prefix="a." indent="1">prefixed indented paragraph 1: Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo
vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</para>
<para prefix="a(1)." indent="2">prefixed indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
<para indent="1">indented paragraph 1: Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo
vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</para>
<para indent="2">indented paragraph 2: Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.
Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis,
massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</para>
</fragment>
</section>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@
<!-- go through each element and compare its config with the previous one -->
<xsl:for-each select="$fragments">
<!-- check for new config -->
<xsl:variable name="previous" select="(preceding::*[psf:is-fragment(.)][*])[last()]" />
<xsl:variable name="previous" select="(preceding::*[psf:is-fragment(.)][*])[last()] | (ancestor::*[psf:is-fragment(.)][*])[last()]" />
<xsl:variable name="previous-margin-config" select="psf:config-with-region($previous)" />
<xsl:variable name="this-margin-config" select="psf:config-with-region(.)" />
<xsl:choose>
<!-- if new config that defines new margin zone, then restart flow -->
<xsl:when test="empty($previous) or string($previous-margin-config) != string($this-margin-config)">
<id><xsl:value-of select="@id" /></id>
<id config="{$this-margin-config}"><xsl:value-of select="@id" /></id>
</xsl:when>
<xsl:when test="$label-mapping//config/label"> <!-- speed up -->
<xsl:variable name="this-elem" select="." />
Expand All @@ -165,7 +165,7 @@
<!-- ok filter duplicates -->
<ids>
<xsl:for-each select="distinct-values($all-fragment-ids//id)">
<id><xsl:value-of select="." /></id>
<id config="{$all-fragment-ids//id[. = current()][1]/@config}"><xsl:value-of select="." /></id>
</xsl:for-each>
</ids>
</xsl:variable>
Expand Down Expand Up @@ -226,7 +226,7 @@
<xsl:variable name="nextone" select="(following::*[psf:is-fragment(.)][string(@id) != ''][index-of($fragment-ids//id, @id) != -1])[1]/generate-id()" />
<!-- apply templates to this fragment's children and all the following until we reach then next one (if there's one) -->
<xsl:apply-templates select="." />
<xsl:variable name="next" select="following-sibling::*[psf:is-fragment(.)][string(@id) != ''][*] | following-sibling::toc |
<xsl:variable name="next" select="following-sibling::*[psf:is-fragment(.)][string(@id) != ''][*] | ../following-sibling::toc |
../following-sibling::section/*[psf:is-fragment(.)][string(@id) != ''][*]" />
<xsl:apply-templates select="$next[string($nextone) = '' or following::*[generate-id() = $nextone]]" />
<!-- last page ID -->
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.3
0.4.4

0 comments on commit ff836b6

Please sign in to comment.