Author: ssteiner Date: Mon Sep 9 13:20:08 2019 New Revision: 1866691 URL: http://svn.apache.org/viewvc?rev=1866691&view=rev Log: FOP-2881: Add option for page segment for GOCA
Added: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java (with props) Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java Mon Sep 9 13:20:08 2019 @@ -696,4 +696,7 @@ public class AFPGraphics2D extends Abstr 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) { + } } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/afp/AFPPaintingState.java Mon Sep 9 13:20:08 2019 @@ -95,6 +95,8 @@ public class AFPPaintingState extends or /** 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 or this.pSeg = pSeg; } + public boolean getWrapGocaPSeg() { + return gocaPSeg; + } + + public void setWrapGocaPSeg(boolean pSeg) { + this.gocaPSeg = pSeg; + } /** * gets whether images should be FS45 Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPDocumentHandler.java Mon Sep 9 13:20:08 2019 @@ -534,6 +534,10 @@ public class AFPDocumentHandler extends paintingState.setWrapPSeg(pSeg); } + public void setWrapGocaPSeg(boolean pSeg) { + paintingState.setWrapGocaPSeg(pSeg); + } + /** {@inheritDoc} */ public void setFS45(boolean fs45) { paintingState.setFS45(fs45); Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java Mon Sep 9 13:20:08 2019 @@ -85,6 +85,7 @@ public class AFPImageHandlerGraphics2D e AFPDataObjectInfo info = createDataObjectInfo(); assert (info instanceof AFPGraphicsObjectInfo); AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo) info; + graphicsObjectInfo.setCreatePageSegment(afpContext.getPaintingState().getWrapGocaPSeg()); // set resource information Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfig.java Mon Sep 9 13:20:08 2019 @@ -48,6 +48,7 @@ import static org.apache.fop.render.afp. 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 imp 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 imp 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 imp 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; Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Mon Sep 9 13:20:08 2019 @@ -93,6 +93,9 @@ public class AFPRendererConfigurator ext if (config.isWrapPseg() != null) { documentHandler.setWrapPSeg(config.isWrapPseg()); } + if (config.isGocaWrapPseg() != null) { + documentHandler.setWrapGocaPSeg(config.isGocaWrapPseg()); + } if (config.isFs45() != null) { documentHandler.setFS45(config.isFs45()); } Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPRendererOption.java Mon Sep 9 13:20:08 2019 @@ -42,6 +42,7 @@ public enum AFPRendererOption implements 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; Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java Mon Sep 9 13:20:08 2019 @@ -30,6 +30,8 @@ import org.apache.fop.render.afp.AFPShad 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 AFPRendererConfBuilde private ImagesBuilder images; + private GOCABuilder gocaBuilder; + public AFPRendererConfBuilder() { super(MimeConstants.MIME_AFP); } @@ -87,6 +91,16 @@ public final class AFPRendererConfBuilde 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 AFPRendererConfBuilde 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(); + } + } } Added: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java?rev=1866691&view=auto ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java (added) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java Mon Sep 9 13:20:08 2019 @@ -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"); + } +} Propchange: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2DTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java?rev=1866691&r1=1866690&r2=1866691&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java Mon Sep 9 13:20:08 2019 @@ -210,4 +210,11 @@ public class AFPRendererConfiguratorTest verify(getDocHandler()).canEmbedJpeg(false); } + @Test + public void testWrapGocaPSeg() throws Exception { + parseConfig(createBuilder().startGOCA() + .setWrapPseg(true) + .endGOCA()); + verify(getDocHandler()).setWrapGocaPSeg(true); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org