]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3061: AFP invoke-medium-map missing when using page-group=false
authorSimon Steiner <ssteiner@apache.org>
Fri, 1 Apr 2022 11:15:52 +0000 (11:15 +0000)
committerSimon Steiner <ssteiner@apache.org>
Fri, 1 Apr 2022 11:15:52 +0000 (11:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1899483 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/afp/DataStream.java
fop-core/src/main/java/org/apache/fop/afp/modca/AbstractPageObject.java
fop-core/src/main/java/org/apache/fop/afp/modca/PageObject.java
fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java [new file with mode: 0644]

index 46b1cb22344fff6f5741d490fae1101398462f77..226f431cc7e9b1526e0c7a24eb44b01ec3e7dd9c 100644 (file)
@@ -496,6 +496,10 @@ public class DataStream {
     public void createInvokeMediumMap(String name) {
         if (currentPageGroup != null) {
             currentPageGroup.createInvokeMediumMap(name);
+        } else if (currentPage != null) {
+            currentPage.createInvokeMediumMap(name);
+        } else {
+            document.createInvokeMediumMap(name);
         }
     }
 
index 55457a1ae7f34e87a463ec2da2f75f6a6ac3c519..7697d0cb09cae952b6c998ad08dcd0a677b3b239 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.fop.afp.modca;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.fop.afp.AFPLineDataInfo;
@@ -58,7 +59,8 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen
     private PresentationTextObject currentPresentationTextObject;
 
     /** The list of objects within this resource container */
-    protected List objects = new java.util.ArrayList();
+    protected List objects = new ArrayList();
+    protected List<InvokeMediumMap> invokeMediumMaps = new ArrayList<>();
 
     /** The page width */
     private int width;
@@ -180,6 +182,11 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen
 
     }
 
+    public void createInvokeMediumMap(String name) {
+        InvokeMediumMap invokeMediumMap = factory.createInvokeMediumMap(name);
+        invokeMediumMaps.add(invokeMediumMap);
+    }
+
     /**
      * Helper method to mark the end of the page. This should end the control
      * sequence on the current presentation text object.
index 5c76e07363ee24aaf0159182f7cc50c65a604ce4..bae75f9fe2783717cfa22a6c0e128f9a607c2ae0 100644 (file)
@@ -183,6 +183,7 @@ public class PageObject extends AbstractResourceGroupContainer {
     protected void writeContent(OutputStream os) throws IOException {
         writeTriplets(os);
 
+        writeObjects(invokeMediumMaps, os);
         getActiveEnvironmentGroup().writeToStream(os);
 
         writeObjects(objects, os);
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
new file mode 100644 (file)
index 0000000..4c6eae9
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.afp;
+
+import java.awt.Color;
+import java.awt.Point;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.afp.fonts.CharacterSet;
+import org.apache.fop.afp.fonts.CharacterSetBuilder;
+import org.apache.fop.afp.modca.InterchangeSet;
+import org.apache.fop.afp.modca.InvokeMediumMap;
+import org.apache.fop.afp.modca.PageGroup;
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.util.CharUtilities;
+
+public class DataStreamTestCase {
+
+    private DataStream ds;
+    private ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+    private AFPTextDataInfo textInfo = new AFPTextDataInfo();
+    private CharacterSet cs1146;
+    private AFPPaintingState paintState = mock(AFPPaintingState.class);
+
+    @Before
+    public void setUp() throws Exception {
+        when(paintState.getRotation()).thenReturn(90);
+        when(paintState.getPoint(50, 50)).thenReturn(new Point(50, 50));
+        AFPUnitConverter unitConv = new AFPUnitConverter(paintState);
+        when(paintState.getUnitConverter()).thenReturn(unitConv);
+        ds = new DataStream(new Factory(), paintState, outStream);
+        textInfo.setEncoding("WinAnsiEncoding");
+        textInfo.setRotation(0);
+        char ch = '\u3000';
+        textInfo.setString("Test String" + CharUtilities.NBSPACE + "blah" + ch + "hello" + '\u2000'
+                + "end.");
+        textInfo.setX(50);
+        textInfo.setY(50);
+        textInfo.setColor(Color.black);
+        CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
+        cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
+                Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
+                        .getDeclaredConstructor().newInstance(), null);
+        ds.startPage(1000, 1000, 0, 300, 300);
+    }
+
+    @Test
+    public void testCreateText() throws Exception {
+        Font font = mock(Font.class);
+        ds.createText(textInfo, 100, 300, font, cs1146);
+        ds.createShading(10, 10, 300, 300, Color.white);
+        ds.createIncludePageOverlay("testings", 10, 10);
+        ds.startDocument();
+        ds.startPageGroup();
+        ds.createInvokeMediumMap("test");
+        ds.createIncludePageSegment("test", 10, 10, 300, 300);
+        ds.createTagLogicalElement("test", "test", 0);
+        PageGroup pg = ds.getCurrentPageGroup();
+        InterchangeSet is = ds.getInterchangeSet();
+        ds.getResourceGroup(AFPResourceLevel.valueOf(AFPResourceLevel.ResourceType.DOCUMENT.name()));
+    }
+
+    @Test
+    public void testMediumMapOnPage() throws Exception {
+        ds.createInvokeMediumMap("test");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ds.getCurrentPage().writeToStream(bos);
+        ByteArrayInputStream data = new ByteArrayInputStream(bos.toByteArray());
+        data.skip(21);
+        Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
+        Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
+    }
+
+    @Test
+    public void testMediumMapOnDocument() throws Exception {
+        ds = new DataStream(new Factory(), paintState, outStream);
+        ds.startDocument();
+        ds.createInvokeMediumMap("test");
+        ds.endDocument();
+        ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
+        data.skip(21);
+        Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
+        Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
+    }
+}