From 8234ed46e923e0e8029703be0c58752da7c49b45 Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Wed, 3 Sep 2008 16:34:56 +0000 Subject: Toggleable support for AFP native image flavours. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@691674 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/afp/AFPDataObjectInfoFactory.java | 81 ---------------------- .../fop/render/afp/AFPDataObjectInfoProvider.java | 80 +++++++++++++++++++++ .../fop/render/afp/AFPImageRawStreamFactory.java | 2 +- .../fop/render/afp/AFPImageRenderedFactory.java | 2 +- .../fop/render/afp/AFPRawCCITTFaxFactory.java | 2 +- .../org/apache/fop/render/afp/AFPRenderer.java | 28 ++++++-- .../fop/render/afp/AFPRendererConfigurator.java | 1 + src/java/org/apache/fop/render/afp/AFPState.java | 36 ++++++++-- 8 files changed, 135 insertions(+), 97 deletions(-) delete mode 100644 src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java create mode 100644 src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java (limited to 'src') diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java deleted file mode 100644 index d87fabeaf..000000000 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.util.Iterator; -import java.util.Map; - -import org.apache.xmlgraphics.image.loader.Image; -import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; -import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; -import org.apache.xmlgraphics.image.loader.impl.ImageRendered; - -/** - * AFP image configurator - */ -public class AFPDataObjectInfoFactory { - private final Map dataObjectInfoFactoryMap = new java.util.HashMap(); - private final AFPState state; - - /** - * Main constructor - * - * @param state the AFP state - */ - public AFPDataObjectInfoFactory(AFPState state) { - this.state = state; - init(); - } - - /** - * Initialises the configurators - */ - private void init() { - dataObjectInfoFactoryMap.put( - ImageRendered.class, new AFPImageRenderedFactory(state)); - dataObjectInfoFactoryMap.put( - ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state)); - dataObjectInfoFactoryMap.put( - ImageRawStream.class, new AFPImageRawStreamFactory(state)); - }; - - /** - * Returns the configurator for a given image - * - * @param img the image - * @return the image configurator for the image - */ - public AFPAbstractImageFactory getFactory(Image img) { - Class clazz = img.getClass(); - AFPAbstractImageFactory configurator - = (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(clazz); - // not directly matched so try to map ancestor - if (configurator == null) { - Iterator it = dataObjectInfoFactoryMap.keySet().iterator(); - while (it.hasNext()) { - Class imageClass = (Class)it.next(); - if (imageClass.isInstance(img)) { - return (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(imageClass); - } - } - } - return configurator; - } -} diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java new file mode 100644 index 000000000..525c3487f --- /dev/null +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java @@ -0,0 +1,80 @@ +/* + * 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.util.Iterator; +import java.util.Map; + +import org.apache.xmlgraphics.image.loader.Image; +import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; +import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; +import org.apache.xmlgraphics.image.loader.impl.ImageRendered; + +/** + * AFP data object info factory provider + */ +public class AFPDataObjectInfoProvider { + private final Map factoryMap = new java.util.HashMap(); + private final AFPState state; + + /** + * Main constructor + * + * @param state the AFP state + */ + public AFPDataObjectInfoProvider(AFPState state) { + this.state = state; + init(); + } + + /** + * Initialises the configurators + */ + private void init() { + factoryMap.put( + ImageRendered.class, new AFPImageRenderedFactory(state)); + factoryMap.put( + ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state)); + factoryMap.put( + ImageRawStream.class, new AFPImageRawStreamFactory(state)); + }; + + /** + * Returns the configurator for a given image + * + * @param img the image + * @return the image configurator for the image + */ + public AFPDataObjectInfoFactory getFactory(Image img) { + Class clazz = img.getClass(); + AFPDataObjectInfoFactory configurator = (AFPDataObjectInfoFactory)factoryMap.get(clazz); + // not directly matched so try to map ancestor + if (configurator == null) { + Iterator it = factoryMap.keySet().iterator(); + while (it.hasNext()) { + Class imageClass = (Class)it.next(); + if (imageClass.isInstance(img)) { + return (AFPDataObjectInfoFactory)factoryMap.get(imageClass); + } + } + } + return configurator; + } +} diff --git a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java index f90024e1a..43e678aab 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java @@ -27,7 +27,7 @@ import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; /** * A raw stream image configurator */ -public class AFPImageRawStreamFactory extends AFPAbstractImageFactory { +public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory { /** * Main constructor diff --git a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java index 93a509cc0..15d7a3173 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java @@ -30,7 +30,7 @@ import org.apache.xmlgraphics.ps.ImageEncodingHelper; /** * A buffered image configurator */ -public class AFPImageRenderedFactory extends AFPAbstractImageFactory { +public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory { /** * Main constructor diff --git a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java index e7ef5266a..6700f263d 100644 --- a/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java @@ -26,7 +26,7 @@ import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax; /** * An CITT fax image configurator */ -public class AFPRawCCITTFaxFactory extends AFPAbstractImageFactory { +public class AFPRawCCITTFaxFactory extends AFPDataObjectInfoFactory { /** * Main constructor diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 0a6476af0..056792fdd 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -155,7 +155,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { private DataStream dataStream; /** data object information factory */ - private final AFPDataObjectInfoFactory dataObjectInfoFactory; + private final AFPDataObjectInfoProvider dataObjectInfoProvider; /** @@ -165,7 +165,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { super(); this.resourceManager = new AFPResourceManager(); this.state = new AFPState(); - this.dataObjectInfoFactory = new AFPDataObjectInfoFactory(state); + this.dataObjectInfoProvider = new AFPDataObjectInfoProvider(state); this.unitConv = state.getUnitConverter(); } @@ -376,11 +376,16 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { return context; } - private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { + private static final ImageFlavor[] NATIVE_FLAVORS = new ImageFlavor[] { + /*ImageFlavor.RAW_PNG, */ // PNG not natively supported in AFP ImageFlavor.RAW_JPEG, ImageFlavor.RAW_CCITTFAX, ImageFlavor.RAW_EPS, ImageFlavor.GRAPHICS2D, ImageFlavor.BUFFERED_IMAGE, ImageFlavor.RENDERED_IMAGE, ImageFlavor.XML_DOM }; + private static final ImageFlavor[] FLAVORS = new ImageFlavor[] { + ImageFlavor.GRAPHICS2D, ImageFlavor.BUFFERED_IMAGE, ImageFlavor.RENDERED_IMAGE, + ImageFlavor.XML_DOM }; + /** {@inheritDoc} */ public void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) { uri = URISpecification.getURL(uri); @@ -404,11 +409,13 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { // Only now fully load/prepare the image Map hints = ImageUtil.getDefaultHints(sessionContext); + + ImageFlavor[] flavors = state.isNativeImages() ? NATIVE_FLAVORS : FLAVORS; org.apache.xmlgraphics.image.loader.Image img = manager.getImage( - info, FLAVORS, hints, sessionContext); + info, flavors, hints, sessionContext); Point origin = new Point(currentIPPosition, currentBPPosition); - AFPAbstractImageFactory factory = dataObjectInfoFactory.getFactory(img); + AFPDataObjectInfoFactory factory = dataObjectInfoProvider.getFactory(img); if (factory != null) { AFPImageInfo afpImageInfo = new AFPImageInfo(uri, pos, origin, info, img, foreignAttributes); @@ -563,7 +570,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { // Try and get the encoding to use for the font String encoding = null; - try { encoding = font.getCharacterSet(fontSize).getEncoding(); } catch (Throwable ex) { @@ -752,6 +758,16 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { state.setColorImages(colorImages); } + /** + * Sets whether images are supported natively or not + * + * @param nativeImages + * native image support + */ + public void setNativeImages(boolean nativeImages) { + state.setNativeImages(nativeImages); + } + /** * Returns the AFPDataStream * diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 95a210ce5..794f5bda8 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -239,6 +239,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { } else { afpRenderer.setColorImages(true); } + afpRenderer.setNativeImages(imagesCfg.getAttributeAsBoolean("native", false)); // renderer resolution Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false); diff --git a/src/java/org/apache/fop/render/afp/AFPState.java b/src/java/org/apache/fop/render/afp/AFPState.java index 129222b6a..709e151f6 100644 --- a/src/java/org/apache/fop/render/afp/AFPState.java +++ b/src/java/org/apache/fop/render/afp/AFPState.java @@ -34,27 +34,31 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo private static Log log = LogFactory.getLog("org.apache.fop.render.afp.AFPState"); - /** The portrait rotation */ + /** the portrait rotation */ private int portraitRotation = 0; - /** The landscape rotation */ + /** the landscape rotation */ private int landscapeRotation = 270; - /** Flag to the set the output object type for images */ + /** color image support */ private boolean colorImages = true; - /** Default value for image depth */ + /** images are supported in this AFP environment */ + private boolean nativeImages; + + /** default value for image depth */ private int bitsPerPixel = 8; - /** The output resolution */ + /** the output resolution */ private int resolution = 240; // 240 dpi - /** The current page */ + /** the current page */ private AFPPageState pageState = new AFPPageState(); - /** A unit converter */ + /** a unit converter */ private final transient AFPUnitConverter unitConv = new AFPUnitConverter(this); + /** * Sets the rotation to be used for portrait pages, valid values are 0 * (default), 90, 180, 270. @@ -158,6 +162,24 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo return this.colorImages; } + /** + * Sets whether images are natively supported or not in the AFP environment + * + * @param nativeImages true if images are natively supported in this AFP environment + */ + public void setNativeImages(boolean nativeImages) { + this.nativeImages = nativeImages; + } + + /** + * Returns true if images are supported natively in this AFP environment + * + * @return true if images are supported natively in this AFP environment + */ + protected boolean isNativeImages() { + return this.nativeImages; + } + /** * Sets the output/device resolution * -- cgit v1.2.3