diff options
author | Simon Steiner <ssteiner@apache.org> | 2025-01-16 12:49:48 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2025-01-16 12:49:48 +0000 |
commit | ebd103e1e1728bcca3e0e45a76066efd4541be70 (patch) | |
tree | 2d0a6b9406cb4c41a263bf30499a694df7e1629d /fop-core/src/test | |
parent | 3739dddfb4f9740253ca51240146b90cec908782 (diff) | |
download | xmlgraphics-fop-ebd103e1e1728bcca3e0e45a76066efd4541be70.tar.gz xmlgraphics-fop-ebd103e1e1728bcca3e0e45a76066efd4541be70.zip |
FOP-3231: Add option to combine AFP page groups
Diffstat (limited to 'fop-core/src/test')
3 files changed, 87 insertions, 6 deletions
diff --git a/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java b/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java index f178a815e..0f83e08b2 100644 --- a/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java @@ -80,7 +80,7 @@ public class DataStreamTestCase { ds.createShading(10, 10, 300, 300, Color.white); ds.createIncludePageOverlay("testings", 10, 10); ds.startDocument(); - ds.startPageGroup(); + ds.startPageGroup(true); ds.createInvokeMediumMap("test"); ds.createIncludePageSegment("test", 10, 10, 300, 300); ds.createTagLogicalElement("test", "test", 0); @@ -118,10 +118,10 @@ public class DataStreamTestCase { ds = new DataStream(new Factory(), paintState, outStream); ds.startDocument(); ds.createInvokeMediumMap("test"); - ds.startPageGroup(); + ds.startPageGroup(true); ds.startPage(1, 1, 0, 1, 1); ds.endPage(); - ds.endPageGroup(); + ds.endPageGroup(true); ds.endDocument(); ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray()); data.skip(21); @@ -134,10 +134,10 @@ public class DataStreamTestCase { public void testMandatoryTripletIsAddedToAFP() throws Exception { ds = new DataStream(new Factory(), paintState, outStream); ds.startDocument(); - ds.startPageGroup(); + ds.startPageGroup(true); ds.startPage(1, 1, 0, 1, 1); ds.endPage(); - ds.endPageGroup(); + ds.endPageGroup(true); ds.endDocument(); ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray()); data.skip(17); //skipping the begin document data diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java new file mode 100644 index 000000000..8383efa16 --- /dev/null +++ b/fop-core/src/test/java/org/apache/fop/render/afp/AddToPreviousPageGroupTestCase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.fop.render.afp; + +import java.awt.Dimension; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.transform.stream.StreamResult; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.xmlgraphics.util.QName; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.render.afp.extensions.AFPElementMapping; +import org.apache.fop.render.intermediate.IFContext; +import org.apache.fop.render.intermediate.IFException; + +public class AddToPreviousPageGroupTestCase extends AbstractAFPTest { + @Test + public void testAddToPreviousPageGroup() throws Exception { + Assert.assertEquals("BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n" + + "BEGIN PAGE_GROUP PGP00001\n" + + "BEGIN PAGE PGN00001\n" + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "DESCRIPTOR PAGE\n" + + "MIGRATION PRESENTATION_TEXT\n" + + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "END PAGE PGN00001\n" + + "BEGIN PAGE PGN00002\n" + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00002\n" + + "DESCRIPTOR PAGE\n" + + "MIGRATION PRESENTATION_TEXT\n" + + "END ACTIVE_ENVIRONMENT_GROUP AEG00002\n" + + "END PAGE PGN00002\n" + + "END PAGE_GROUP PGP00001\n" + + "END DOCUMENT DOC00001\n", render()); + } + + private String render() throws IFException, IOException { + FOUserAgent ua = fopFactory.newFOUserAgent(); + AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + documentHandler.setResult(new StreamResult(outputStream)); + documentHandler.startDocument(); + documentHandler.startPageSequence(""); + documentHandler.startPage(0, "", "", new Dimension()); + documentHandler.endPage(); + documentHandler.endPageSequence(); + Map<QName, String> attributes = new HashMap<>(); + attributes.put(AFPElementMapping.ADD_TO_PREVIOUS_PAGE_GROUP, "true"); + documentHandler.getContext().setForeignAttributes(attributes); + documentHandler.startPageSequence(""); + documentHandler.startPage(1, "", "", new Dimension()); + documentHandler.endPage(); + documentHandler.endPageSequence(); + documentHandler.endDocument(); + StringBuilder sb = new StringBuilder(); + new AFPParser(false).read(new ByteArrayInputStream(outputStream.toByteArray()), sb); + return sb.toString(); + } +} diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java index 9f60fd476..623a28b6e 100644 --- a/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java @@ -42,7 +42,6 @@ public class PageOverlayTestCase { public void testPageOverlay() throws Exception { Assert.assertEquals(getPageOverlay(), "BEGIN DOCUMENT DOC00001 Triplets: 0x01,\n" + "BEGIN PAGE_GROUP PGP00001\n" - + "END PAGE_GROUP PGP00001\n" + "BEGIN PAGE PGN00001\n" + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + "MAP PAGE_OVERLAY Triplets: FULLY_QUALIFIED_NAME,RESOURCE_LOCAL_IDENTIFIER,\n" @@ -51,6 +50,7 @@ public class PageOverlayTestCase { + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + "INCLUDE PAGE_OVERLAY\n" + "END PAGE PGN00001\n" + + "END PAGE_GROUP PGP00001\n" + "END DOCUMENT DOC00001\n"); } |