From 52f63fea95d0feef5fe0367811d21940f772f147 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Thu, 23 Jan 2025 14:28:09 +0000 Subject: [PATCH] FOP-3232: Allow instream-foreign-object role as artifact --- .../fo/FO2StructureTreeConverter.java | 2 + .../fo/FO2StructureTreeConverterTestCase.java | 39 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) 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 4e2690b1c96..d20e4d37a6f 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 @@ -626,6 +626,7 @@ public void run() { @Override public void startInstreamForeignObject(final InstreamForeignObject ifo) { + handleStartArtifact(ifo); startContent(new Event(this) { public void run() { eventHandler.startInstreamForeignObject(ifo); @@ -641,6 +642,7 @@ public void run() { eventHandler.endInstreamForeignObject(ifo); } }); + handleEndArtifact(ifo); super.endInstreamForeignObject(ifo); } 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 bc01abd5136..57443e15df3 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 @@ -42,12 +42,13 @@ import javax.xml.transform.stream.StreamSource; import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.XMLAssert; +import org.custommonkey.xmlunit.XMLUnit; import org.junit.Test; import org.w3c.dom.Document; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -163,8 +164,7 @@ public void testRemoveBlocks() throws Exception { + " \n" + " \n" + "\n", - "" - + "\n" + "\n" + "\n" @@ -184,8 +184,7 @@ public void testRemoveBlocks() throws Exception { public void testRemoveTableHeader() throws Exception { keepEmptyTags = false; String fo = IOUtils.toString(getResource("table-artifact.fo"), "utf8").replace("role=\"artifact\"", ""); - compare(fo, "\n" - + "\n" + compare(fo, "\n" + "\n" @@ -224,7 +223,7 @@ public void testExternalGraphicArtifact() throws Exception { + "\n" + " \n" + "\n"; - compare(fo, "" + compare(fo, "" + "" @@ -232,6 +231,31 @@ public void testExternalGraphicArtifact() throws Exception { + ""); } + @Test + public void testSVGArtifact() throws Exception { + String fo = "" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + compare(fo, "" + + "" + + "" + + ""); + } + private void compare(final String fo, String tree) throws Exception { foLoader = new FOLoader("") { public InputStream getFoInputStream() { @@ -244,7 +268,8 @@ public InputStream getFoInputStream() { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(new DOMSource(doc), new StreamResult(sw)); - assertEquals(tree.replace("\n", ""), sw.toString().replace("\n", "")); + XMLUnit.setIgnoreWhitespace(true); + XMLAssert.assertXMLEqual(tree, sw.toString()); } private void testConverter(String foResourceName) throws Exception {