From 8ac86aa2513dc26a0691ce228dbba17c6c9cd080 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Wed, 15 Jun 2022 08:10:12 +0000 Subject: [PATCH] FOP-3080: Allow removing empty table elements from structure tree git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1901930 13f79535-47bb-0310-9956-ffa450edef68 --- .../fo/FO2StructureTreeConverter.java | 12 +++-- .../fo/FO2StructureTreeConverterTestCase.java | 37 +++++++++++++++ .../fop/accessibility/fo/fo2StructureTree.xsl | 2 + .../fop/accessibility/fo/table-artifact.fo | 46 +++++++++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 fop-core/src/test/resources/org/apache/fop/accessibility/fo/table-artifact.fo diff --git a/fop-core/src/main/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java b/fop-core/src/main/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java index 92c7cf7d9..060316bce 100644 --- a/fop-core/src/main/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java +++ b/fop-core/src/main/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java @@ -380,11 +380,12 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { @Override public void startHeader(final TableHeader header) { + handleStartArtifact(header); startContent(new Event(this) { public void run() { eventHandler.startHeader(header); } - }, true); + }, false); super.startHeader(header); } @@ -395,16 +396,18 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { eventHandler.endHeader(header); } }); + handleEndArtifact(header); super.endHeader(header); } @Override public void startFooter(final TableFooter footer) { + handleStartArtifact(footer); startContent(new Event(this) { public void run() { eventHandler.startFooter(footer); } - }, true); + }, false); super.startFooter(footer); } @@ -415,6 +418,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { eventHandler.endFooter(footer); } }); + handleEndArtifact(footer); super.endFooter(footer); } @@ -444,7 +448,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { public void run() { eventHandler.startRow(tr); } - }, true); + }, false); super.startRow(tr); } @@ -464,7 +468,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { public void run() { eventHandler.startCell(tc); } - }, true); + }, false); super.startCell(tc); } diff --git a/fop-core/src/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java b/fop-core/src/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java index 5d353a886..d00526b10 100644 --- a/fop-core/src/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java @@ -51,6 +51,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.apache.commons.io.IOUtils; + import org.apache.fop.accessibility.StructureTree2SAXEventAdapter; import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.apps.FOPException; @@ -114,6 +116,11 @@ public class FO2StructureTreeConverterTestCase { testConverter("table-header_scope.fo"); } + @Test + public void testTableArtifact() throws Exception { + testConverter("table-artifact.fo"); + } + @Test public void testLanguage() throws Exception { testConverter("language.fo"); @@ -173,6 +180,36 @@ public class FO2StructureTreeConverterTestCase { + "\n"); } + @Test + public void testRemoveTableHeader() throws Exception { + keepEmptyTags = false; + String fo = IOUtils.toString(getResource("table-artifact.fo")).replace("role=\"artifact\"", ""); + compare(fo, "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""); + } + private void compare(final String fo, String tree) throws Exception { foLoader = new FOLoader("") { public InputStream getFoInputStream() { diff --git a/fop-core/src/test/resources/org/apache/fop/accessibility/fo/fo2StructureTree.xsl b/fop-core/src/test/resources/org/apache/fop/accessibility/fo/fo2StructureTree.xsl index f21b079a4..7f058d4a3 100644 --- a/fop-core/src/test/resources/org/apache/fop/accessibility/fo/fo2StructureTree.xsl +++ b/fop-core/src/test/resources/org/apache/fop/accessibility/fo/fo2StructureTree.xsl @@ -145,6 +145,8 @@ + + diff --git a/fop-core/src/test/resources/org/apache/fop/accessibility/fo/table-artifact.fo b/fop-core/src/test/resources/org/apache/fop/accessibility/fo/table-artifact.fo new file mode 100644 index 000000000..98c5bccde --- /dev/null +++ b/fop-core/src/test/resources/org/apache/fop/accessibility/fo/table-artifact.fo @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a + + + + + + + + -- 2.39.5