From: Simon Steiner Date: Sat, 26 Jun 2021 06:39:20 +0000 (+0000) Subject: FOP-3018: Allow to disable AFP page group X-Git-Tag: fop-2_7~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=623169e4d96680930179c0e98e072d2674947cd4;p=xmlgraphics-fop.git FOP-3018: Allow to disable AFP page group git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1891052 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/afp/DataStream.java b/fop-core/src/main/java/org/apache/fop/afp/DataStream.java index d33673c0e..239805c4a 100644 --- a/fop-core/src/main/java/org/apache/fop/afp/DataStream.java +++ b/fop-core/src/main/java/org/apache/fop/afp/DataStream.java @@ -495,7 +495,9 @@ public class DataStream { * the name of the medium map */ public void createInvokeMediumMap(String name) { - currentPageGroup.createInvokeMediumMap(name); + if (currentPageGroup != null) { + currentPageGroup.createInvokeMediumMap(name); + } } /** @@ -576,13 +578,10 @@ public class DataStream { * @param encoding The CCSID character set encoding */ public void createTagLogicalElement(String name, String value, int encoding) { - TagLogicalElement.State tleState = new TagLogicalElement.State(name, value, encoding); if (currentPage != null) { - currentPage.createTagLogicalElement(tleState); - - } else { + } else if (currentPageGroup != null) { currentPageGroup.createTagLogicalElement(tleState); } } diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java index 680d490a1..e80dedd87 100644 --- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -215,7 +215,9 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler /** {@inheritDoc} */ public void startPageSequence(String id) throws IFException { try { - dataStream.startPageGroup(); + if (!"false".equals(getContext().getForeignAttribute(AFPElementMapping.PAGE_GROUP))) { + dataStream.startPageGroup(); + } } catch (IOException ioe) { throw new IFException("I/O error in startPageSequence()", ioe); } diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java b/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java index cbb31bcb7..a3e25844d 100644 --- a/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java +++ b/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java @@ -19,6 +19,8 @@ package org.apache.fop.render.afp.extensions; +import org.apache.xmlgraphics.util.QName; + import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.FONode; @@ -56,6 +58,8 @@ public class AFPElementMapping extends ElementMapping { */ public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/extensions/afp"; + public static final QName PAGE_GROUP = new QName(NAMESPACE, null, "page-group"); + /** * The usual namespace prefix used for AFP extensions */ diff --git a/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java b/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java index 92571cf67..f4c64d9f0 100644 --- a/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java @@ -33,7 +33,7 @@ public class OutlineFontTestCase { } public static CharacterSet getCharacterSet() { - CharacterSet characterSet = new CharacterSet(null, "utf-8", CharacterSetType.SINGLE_BYTE, "", null, null); + CharacterSet characterSet = new CharacterSet("00000000", "utf-8", CharacterSetType.SINGLE_BYTE, "", null, null); characterSet.addCharacterSetOrientation(new CharacterSetOrientation(0, 0, 0, 0)); return characterSet; } diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java index 6354a5909..3f93deabe 100644 --- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java @@ -30,6 +30,7 @@ import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -51,6 +52,7 @@ import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext; import org.apache.xmlgraphics.image.loader.impl.DefaultImageSessionContext; import org.apache.xmlgraphics.image.loader.impl.ImageBuffered; +import org.apache.xmlgraphics.util.QName; import org.apache.fop.afp.AFPEventProducer; import org.apache.fop.afp.AFPPaintingState; @@ -67,6 +69,7 @@ import org.apache.fop.fo.expr.PropertyException; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.ImageHandlerRegistry; +import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.intermediate.IFContext; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.traits.BorderProps; @@ -333,4 +336,56 @@ public class AFPPainterTestCase { BorderProps border1 = new BorderProps(style, borderWidth, radiusStart, radiusEnd, color, mode); afpPainter.drawBorderRect(new Rectangle(0, 0, 552755, 16090), null, border1, null, null, Color.WHITE); } + + @Test + public void testPageGroup() throws IFException, IOException { + FOUserAgent ua = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent(); + AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua)); + Map attributes = new HashMap<>(); + attributes.put(AFPElementMapping.PAGE_GROUP, "false"); + documentHandler.getContext().setForeignAttributes(attributes); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + documentHandler.setResult(new StreamResult(os)); + documentHandler.startDocument(); + documentHandler.startPageSequence(null); + documentHandler.startPage(0, "", "", new Dimension()); + AFPPainter afpPainter = new AFPPainter(documentHandler); + setFont(documentHandler, afpPainter); + afpPainter.drawText(0, 0, 0, 0, null, "a"); + documentHandler.endPage(); + documentHandler.endPageSequence(); + attributes.clear(); + documentHandler.startPageSequence(null); + documentHandler.startPage(0, "", "", new Dimension()); + afpPainter.drawText(0, 0, 0, 0, null, "a"); + documentHandler.endDocument(); + + InputStream bis = new ByteArrayInputStream(os.toByteArray()); + StringBuilder sb = new StringBuilder(); + new AFPParser(false).read(bis, sb); + Assert.assertEquals(sb.toString(), "BEGIN DOCUMENT DOC00001\n" + + "BEGIN PAGE PGN00001\n" + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "MAP CODED_FONT Triplets: " + + "FULLY_QUALIFIED_NAME,FULLY_QUALIFIED_NAME,CHARACTER_ROTATION,RESOURCE_LOCAL_IDENTIFIER,\n" + + "DESCRIPTOR PAGE\n" + + "MIGRATION PRESENTATION_TEXT\n" + + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "BEGIN PRESENTATION_TEXT PT000001\n" + + "DATA PRESENTATION_TEXT\n" + + "END PRESENTATION_TEXT PT000001\n" + + "END PAGE PGN00001\n" + + "BEGIN PAGE_GROUP PGP00001\n" + + "BEGIN PAGE PGN00002\n" + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00002\n" + + "DESCRIPTOR PAGE\n" + + "MIGRATION PRESENTATION_TEXT\n" + + "END ACTIVE_ENVIRONMENT_GROUP AEG00002\n" + + "BEGIN PRESENTATION_TEXT PT000002\n" + + "DATA PRESENTATION_TEXT\n" + + "END PRESENTATION_TEXT PT000002\n" + + "END PAGE PGN00002\n" + + "END PAGE_GROUP PGP00001\n" + + "END DOCUMENT DOC00001\n"); + } }