From ef417ff708b890491bb6d65e97255ddfb1b84c38 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Tue, 26 Oct 2021 10:19:57 +0000 Subject: GI-6017: AFP page overlay was written twice git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1894575 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/fop/afp/DataStream.java | 1 - .../apache/fop/render/afp/PageOverlayTestCase.java | 72 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java 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 239805c4a..46b1cb223 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 @@ -485,7 +485,6 @@ public class DataStream { */ public void createIncludePageOverlay(String name, int x, int y) { currentPageObject.createIncludePageOverlay(name, x, y, paintingState.getRotation()); - currentPageObject.getActiveEnvironmentGroup().createOverlay(name); } /** diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java new file mode 100644 index 000000000..673c64313 --- /dev/null +++ b/fop-core/src/test/java/org/apache/fop/render/afp/PageOverlayTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.render.afp; + +import java.awt.Dimension; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; + +import javax.xml.transform.stream.StreamResult; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.render.afp.extensions.AFPPageOverlay; +import org.apache.fop.render.intermediate.IFContext; + +public class PageOverlayTestCase { + @Test + public void testPageOverlay() throws Exception { + Assert.assertEquals(getPageOverlay(), "BEGIN DOCUMENT DOC00001\n" + + "BEGIN PAGE_GROUP PGP00001\n" + + "END PAGE_GROUP PGP00001\n" + + "BEGIN PAGE PGN00001\n" + + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "MAP PAGE_OVERLAY Triplets: FULLY_QUALIFIED_NAME,RESOURCE_LOCAL_IDENTIFIER,\n" + + "DESCRIPTOR PAGE\n" + + "MIGRATION PRESENTATION_TEXT\n" + + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n" + + "INCLUDE PAGE_OVERLAY\n" + + "END PAGE PGN00001\n" + + "END DOCUMENT DOC00001\n"); + } + + private String getPageOverlay() throws Exception { + FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); + FOUserAgent ua = fopFactory.newFOUserAgent(); + AFPDocumentHandler documentHandler = new AFPDocumentHandler(new IFContext(ua)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + documentHandler.setResult(new StreamResult(outputStream)); + documentHandler.startDocument(); + documentHandler.startPageSequence(""); + documentHandler.startPage(0, "", "", new Dimension()); + documentHandler.startPageHeader(); + AFPPageOverlay pageOverlay = new AFPPageOverlay(); + pageOverlay.setName("testtest"); + documentHandler.handleExtensionObject(pageOverlay); + documentHandler.endPageSequence(); + documentHandler.endDocument(); + StringBuilder sb = new StringBuilder(); + new AFPParser(true).read(new ByteArrayInputStream(outputStream.toByteArray()), sb); + return sb.toString(); + } +} -- cgit v1.2.3