From: Simon Steiner Date: Fri, 1 Apr 2022 11:15:52 +0000 (+0000) Subject: FOP-3061: AFP invoke-medium-map missing when using page-group=false X-Git-Tag: fop-2_8~2^2~44 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1c35037f340df7ad112da5af646c878d2cf927c9;p=xmlgraphics-fop.git FOP-3061: AFP invoke-medium-map missing when using page-group=false git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1899483 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 46b1cb223..226f431cc 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 @@ -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); } } diff --git a/fop-core/src/main/java/org/apache/fop/afp/modca/AbstractPageObject.java b/fop-core/src/main/java/org/apache/fop/afp/modca/AbstractPageObject.java index 55457a1ae..7697d0cb0 100644 --- a/fop-core/src/main/java/org/apache/fop/afp/modca/AbstractPageObject.java +++ b/fop-core/src/main/java/org/apache/fop/afp/modca/AbstractPageObject.java @@ -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 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. diff --git a/fop-core/src/main/java/org/apache/fop/afp/modca/PageObject.java b/fop-core/src/main/java/org/apache/fop/afp/modca/PageObject.java index 5c76e0736..bae75f9fe 100644 --- a/fop-core/src/main/java/org/apache/fop/afp/modca/PageObject.java +++ b/fop-core/src/main/java/org/apache/fop/afp/modca/PageObject.java @@ -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 index 000000000..4c6eae921 --- /dev/null +++ b/fop-core/src/test/java/org/apache/fop/afp/DataStreamTestCase.java @@ -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); + } +}