Skip to content

Commit

Permalink
FOP-3232: Allow instream-foreign-object role as artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsteiner1984 committed Jan 23, 2025
1 parent ebd103e commit 52f63fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -641,6 +642,7 @@ public void run() {
eventHandler.endInstreamForeignObject(ifo);
}
});
handleEndArtifact(ifo);
super.endInstreamForeignObject(ifo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -163,8 +164,7 @@ public void testRemoveBlocks() throws Exception {
+ " </fo:flow>\n"
+ " </fo:page-sequence>\n"
+ "</fo:root>\n",
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
+ "<structure-tree-sequence>\n"
"<structure-tree-sequence>\n"
+ "<structure-tree xmlns=\"http://xmlgraphics.apache.org/fop/intermediate\" "
+ "xmlns:foi=\"http://xmlgraphics.apache.org/fop/internal\" "
+ "xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\">\n"
Expand All @@ -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, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<structure-tree-sequence>\n"
compare(fo, "<structure-tree-sequence>\n"
+ "<structure-tree xmlns=\"http://xmlgraphics.apache.org/fop/intermediate\" "
+ "xmlns:foi=\"http://xmlgraphics.apache.org/fop/internal\" "
+ "xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\">\n"
Expand Down Expand Up @@ -224,14 +223,39 @@ public void testExternalGraphicArtifact() throws Exception {
+ "</fo:block></fo:flow>\n"
+ " </fo:page-sequence>\n"
+ "</fo:root>\n";
compare(fo, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><structure-tree-sequence>"
compare(fo, "<structure-tree-sequence>"
+ "<structure-tree xmlns=\"http://xmlgraphics.apache.org/fop/intermediate\" "
+ "xmlns:foi=\"http://xmlgraphics.apache.org/fop/internal\" "
+ "xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\">"
+ "<fo:flow xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" flow-name=\"xsl-region-body\">"
+ "<fo:block/></fo:flow></structure-tree></structure-tree-sequence>");
}

@Test
public void testSVGArtifact() throws Exception {
String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" xmlns:svg=\"http://www.w3.org/2000/svg\">"
+ " <fo:layout-master-set>\n"
+ " <fo:simple-page-master page-width=\"8.5in\" page-height=\"11in\" master-name=\"Page\">\n"
+ " <fo:region-body region-name=\"Body\"/>\n"
+ " </fo:simple-page-master>\n"
+ " </fo:layout-master-set>\n"
+ " <fo:page-sequence master-reference=\"Page\">\n"
+ " <fo:flow flow-name=\"Body\">\n"
+ " <fo:block>\n"
+ " <fo:instream-foreign-object role=\"artifact\">\n"
+ " <svg:svg width=\"12cm\" height=\"12cm\">\n"
+ " </svg:svg>\n"
+ " </fo:instream-foreign-object>\n"
+ " </fo:block>\n"
+ " </fo:flow>\n"
+ " </fo:page-sequence>\n"
+ "</fo:root>";
compare(fo, "<structure-tree-sequence><structure-tree xmlns=\"http://xmlgraphics.apache.org/fop/intermediate\">"
+ "<fo:flow xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" flow-name=\"xsl-region-body\">"
+ "<fo:block><marked-content/><marked-content/></fo:block></fo:flow></structure-tree>"
+ "</structure-tree-sequence>");
}

private void compare(final String fo, String tree) throws Exception {
foLoader = new FOLoader("") {
public InputStream getFoInputStream() {
Expand All @@ -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 {
Expand Down

0 comments on commit 52f63fe

Please sign in to comment.