Author: ssteiner Date: Sat Jun 26 06:39:20 2021 New Revision: 1891052 URL: http://svn.apache.org/viewvc?rev=1891052&view=rev Log: FOP-3018: Allow to disable AFP page group
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/DataStream.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/DataStream.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/DataStream.java?rev=1891052&r1=1891051&r2=1891052&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/DataStream.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/DataStream.java Sat Jun 26 06:39:20 2021 @@ -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); } } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1891052&r1=1891051&r2=1891052&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java Sat Jun 26 06:39:20 2021 @@ -215,7 +215,9 @@ public class AFPDocumentHandler extends /** {@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); } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java?rev=1891052&r1=1891051&r2=1891052&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java Sat Jun 26 06:39:20 2021 @@ -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 E */ 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 */ Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java?rev=1891052&r1=1891051&r2=1891052&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java Sat Jun 26 06:39:20 2021 @@ -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; } Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java?rev=1891052&r1=1891051&r2=1891052&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java Sat Jun 26 06:39:20 2021 @@ -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.load 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.PropertyEx 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<QName, String> 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"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org