]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3018: Allow to disable AFP page group
authorSimon Steiner <ssteiner@apache.org>
Sat, 26 Jun 2021 06:39:20 +0000 (06:39 +0000)
committerSimon Steiner <ssteiner@apache.org>
Sat, 26 Jun 2021 06:39:20 +0000 (06:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1891052 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/afp/DataStream.java
fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
fop-core/src/main/java/org/apache/fop/render/afp/extensions/AFPElementMapping.java
fop-core/src/test/java/org/apache/fop/afp/fonts/OutlineFontTestCase.java
fop-core/src/test/java/org/apache/fop/render/afp/AFPPainterTestCase.java

index d33673c0e414509bda09b0b79d735f967005e98a..239805c4a8175411c0015439004511117aeee15d 100644 (file)
@@ -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);
         }
     }
index 680d490a18090cbd4c93ffd3fa056f5a8997b785..e80dedd87f4b6eda149f16c8de6cbb1525b24d3d 100644 (file)
@@ -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);
         }
index cbb31bcb7d44a7981dc9d1d54946d200df5c3adc..a3e25844da99aa1cc9feb8ea87291cbb12fa0ddf 100644 (file)
@@ -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
      */
index 92571cf678e69228ee415ea29adcb81e3b01503c..f4c64d9f0987568ccd0919dd131ac8ee148ed71b 100644 (file)
@@ -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;
     }
index 6354a5909568828ceca5dafc456ab3842b87bd78..3f93deabec5278972d8ea2504a95156db7c6864e 100644 (file)
@@ -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<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");
+    }
 }