summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2019-09-09 13:20:08 +0000
committerSimon Steiner <ssteiner@apache.org>2019-09-09 13:20:08 +0000
commit7f7464bade4b0f5aff632f3207d5e6b323372972 (patch)
tree2a5d31c4b9545e77a0c5b453895c1daf36cfe6e1
parentb518b28e0ff2f75a36892ccd88fbd475b5138ab2 (diff)
downloadxmlgraphics-fop-7f7464bade4b0f5aff632f3207d5e6b323372972.tar.gz
xmlgraphics-fop-7f7464bade4b0f5aff632f3207d5e6b323372972.zip
FOP-2881: Add option for page segment for GOCA
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1866691 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java3
-rw-r--r--fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java9
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java4
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java1
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java11
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java3
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java1
-rw-r--r--fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java40
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java93
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java7
10 files changed, 172 insertions, 0 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java b/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
index ac15fa1b6..c34a7dff0 100644
--- a/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
+++ b/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
@@ -696,4 +696,7 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
LOG.debug("copyArea() NYI: ");
}
+
+ public void clearRect(int x, int y, int width, int height) {
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java b/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java
index 349ecc2dc..3b1354d91 100644
--- a/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java
+++ b/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java
@@ -95,6 +95,8 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState
/** use page segment with F11 and F45 images*/
private boolean pSeg;
+ private boolean gocaPSeg;
+
/** use FS45 images*/
private boolean fs45;
@@ -416,6 +418,13 @@ public class AFPPaintingState extends org.apache.fop.util.AbstractPaintingState
this.pSeg = pSeg;
}
+ public boolean getWrapGocaPSeg() {
+ return gocaPSeg;
+ }
+
+ public void setWrapGocaPSeg(boolean pSeg) {
+ this.gocaPSeg = pSeg;
+ }
/**
* gets whether images should be FS45
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
index a2c1389d7..680d490a1 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java
@@ -534,6 +534,10 @@ public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
paintingState.setWrapPSeg(pSeg);
}
+ public void setWrapGocaPSeg(boolean pSeg) {
+ paintingState.setWrapGocaPSeg(pSeg);
+ }
+
/** {@inheritDoc} */
public void setFS45(boolean fs45) {
paintingState.setFS45(fs45);
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
index ba0b5433f..18154b1d9 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
@@ -85,6 +85,7 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler implements ImageH
AFPDataObjectInfo info = createDataObjectInfo();
assert (info instanceof AFPGraphicsObjectInfo);
AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo) info;
+ graphicsObjectInfo.setCreatePageSegment(afpContext.getPaintingState().getWrapGocaPSeg());
// set resource information
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java
index d6b81e676..4eac4bae3 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java
@@ -48,6 +48,7 @@ import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE
import static org.apache.fop.render.afp.AFPRendererOption.DEFAULT_RESOURCE_LEVELS;
import static org.apache.fop.render.afp.AFPRendererOption.GOCA;
import static org.apache.fop.render.afp.AFPRendererOption.GOCA_TEXT;
+import static org.apache.fop.render.afp.AFPRendererOption.GOCA_WRAP_PSEG;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_DITHERING_QUALITY;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_FS45;
@@ -166,6 +167,10 @@ public final class AFPRendererConfig implements RendererConfig {
return getParam(IMAGES_WRAP_PSEG, Boolean.class);
}
+ public Boolean isGocaWrapPseg() {
+ return getParam(GOCA_WRAP_PSEG, Boolean.class);
+ }
+
public Boolean isFs45() {
return getParam(IMAGES_FS45, Boolean.class);
}
@@ -252,6 +257,7 @@ public final class AFPRendererConfig implements RendererConfig {
private void configure() throws ConfigurationException, FOPException {
configureImages();
+ configureGOCA();
setParam(SHADING, AFPShadingMode.getValueOf(
cfg.getChild(SHADING.getName()).getValue(AFPShadingMode.COLOR.getName())));
Configuration rendererResolutionCfg = cfg.getChild(RENDERER_RESOLUTION.getName(), false);
@@ -317,6 +323,11 @@ public final class AFPRendererConfig implements RendererConfig {
configureJpegImages(imagesCfg);
}
+ private void configureGOCA() {
+ Configuration gocaCfg = cfg.getChild(GOCA.getName());
+ setParam(GOCA_WRAP_PSEG, gocaCfg.getAttributeAsBoolean(GOCA_WRAP_PSEG.getName(), false));
+ }
+
private void configureJpegImages(Configuration imagesCfg) {
Configuration jpegConfig = imagesCfg.getChild(IMAGES_JPEG.getName());
float bitmapEncodingQuality = 1.0f;
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
index 57b65cdcd..46320779b 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
@@ -93,6 +93,9 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator {
if (config.isWrapPseg() != null) {
documentHandler.setWrapPSeg(config.isWrapPseg());
}
+ if (config.isGocaWrapPseg() != null) {
+ documentHandler.setWrapGocaPSeg(config.isGocaWrapPseg());
+ }
if (config.isFs45() != null) {
documentHandler.setFS45(config.isFs45());
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java
index 33e4da11c..b85ecf20b 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java
@@ -42,6 +42,7 @@ public enum AFPRendererOption implements RendererConfigOption {
SHADING("shading", AFPShadingMode.class),
LINE_WIDTH_CORRECTION("line-width-correction", Float.class),
GOCA("goca", Boolean.class),
+ GOCA_WRAP_PSEG("pseg", Boolean.class),
GOCA_TEXT("text", Boolean.class);
private final String name;
diff --git a/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java b/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
index 580bb23d0..87afac637 100644
--- a/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
+++ b/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
@@ -30,6 +30,8 @@ import org.apache.fop.render.afp.AFPShadingMode;
import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_GRAYSCALE;
import static org.apache.fop.render.afp.AFPRendererOption.DEFAULT_RESOURCE_LEVELS;
+import static org.apache.fop.render.afp.AFPRendererOption.GOCA;
+import static org.apache.fop.render.afp.AFPRendererOption.GOCA_WRAP_PSEG;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_DITHERING_QUALITY;
import static org.apache.fop.render.afp.AFPRendererOption.IMAGES_FS45;
@@ -52,6 +54,8 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
private ImagesBuilder images;
+ private GOCABuilder gocaBuilder;
+
public AFPRendererConfBuilder() {
super(MimeConstants.MIME_AFP);
}
@@ -87,6 +91,16 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
return this;
}
+ public GOCABuilder startGOCA() {
+ gocaBuilder = new GOCABuilder();
+ return gocaBuilder;
+ }
+
+ public AFPRendererConfBuilder endGOCA() {
+ gocaBuilder = null;
+ return this;
+ }
+
public AFPRendererConfBuilder setResourceGroupUri(String uri) {
createTextElement(RESOURCE_GROUP_URI, uri);
return this;
@@ -169,4 +183,30 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
return jpeg;
}
}
+
+ public final class GOCABuilder {
+
+ private final Element el;
+
+ private GOCABuilder() {
+ el = createElement(GOCA.getName());
+ }
+
+ private GOCABuilder setAttribute(String name, Object value) {
+ el.setAttribute(name, String.valueOf(value));
+ return this;
+ }
+
+ private GOCABuilder setAttribute(AFPRendererOption options, Object value) {
+ return setAttribute(options.getName(), value);
+ }
+
+ public GOCABuilder setWrapPseg(boolean value) {
+ return setAttribute(GOCA_WRAP_PSEG, value);
+ }
+
+ public AFPRendererConfBuilder endGOCA() {
+ return AFPRendererConfBuilder.this.endGOCA();
+ }
+ }
}
diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java
new file mode 100644
index 000000000..419607f7a
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * 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.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
+import org.apache.fop.afp.AFPPaintingState;
+import org.apache.fop.afp.AFPResourceLevel;
+import org.apache.fop.afp.AFPResourceLevelDefaults;
+import org.apache.fop.afp.AFPResourceManager;
+import org.apache.fop.afp.DataStream;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+
+public class AFPImageHandlerGraphics2DTestCase {
+
+ @Test
+ public void testWrapGocaPSeg() throws IOException {
+ ImageInfo info = new ImageInfo(null, null);
+ info.setSize(new ImageSize(100, 100, 72));
+ ImageGraphics2D imageGraphics2D = new ImageGraphics2D(info, new Graphics2DImagePainter() {
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ }
+ public Dimension getImageSize() {
+ return null;
+ }
+ });
+
+ AFPPaintingState paintingState = new AFPPaintingState();
+ paintingState.setWrapGocaPSeg(true);
+
+ FOUserAgent foUserAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+ AFPResourceManager resourceManager = new AFPResourceManager(foUserAgent.getResourceResolver());
+
+ AFPResourceLevelDefaults resourceLevelDefaults = new AFPResourceLevelDefaults();
+ resourceLevelDefaults.setDefaultResourceLevel("goca", AFPResourceLevel.valueOf("print-file"));
+ resourceManager.setResourceLevelDefaults(resourceLevelDefaults);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataStream dataStream = resourceManager.createDataStream(null, bos);
+ dataStream.startPage(0, 0, 0, 0, 0);
+ AFPRenderingContext afpRenderingContext =
+ new AFPRenderingContext(null, resourceManager, paintingState, null, null);
+ AFPImageHandlerGraphics2D imageHandlerGraphics2D = new AFPImageHandlerGraphics2D();
+ imageHandlerGraphics2D.handleImage(afpRenderingContext, imageGraphics2D, new Rectangle());
+
+ StringBuilder sb = new StringBuilder();
+ new AFPParser(true).read(new ByteArrayInputStream(bos.toByteArray()), sb);
+ Assert.assertEquals(sb.toString(), "BEGIN RESOURCE_GROUP RG000001\n"
+ + "BEGIN NAME_RESOURCE RES00001 Triplets: OBJECT_FUNCTION_SET_SPECIFICATION,\n"
+ + "BEGIN PAGE_SEGMENT S1000001\n"
+ + "BEGIN GRAPHICS S1000001\n"
+ + "BEGIN OBJECT_ENVIRONMENT_GROUP OEG00001\n"
+ + "DESCRIPTOR OBJECT_AREA Triplets: DESCRIPTOR_POSITION,MEASUREMENT_UNITS,OBJECT_AREA_SIZE,\n"
+ + "POSITION OBJECT_AREA\n"
+ + "DESCRIPTOR GRAPHICS\n"
+ + "END OBJECT_ENVIRONMENT_GROUP OEG00001\n"
+ + "END GRAPHICS S1000001\n"
+ + "END PAGE_SEGMENT S1000001\n"
+ + "END NAME_RESOURCE RES00001\n");
+ }
+}
diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
index 48cf89240..817d7ab0c 100644
--- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
@@ -210,4 +210,11 @@ public class AFPRendererConfiguratorTestCase extends
verify(getDocHandler()).canEmbedJpeg(false);
}
+ @Test
+ public void testWrapGocaPSeg() throws Exception {
+ parseConfig(createBuilder().startGOCA()
+ .setWrapPseg(true)
+ .endGOCA());
+ verify(getDocHandler()).setWrapGocaPSeg(true);
+ }
}