Author: acumiskey
Date: Wed Sep 3 09:34:56 2008
New Revision: 691674
URL: http://svn.apache.org/viewvc?rev=691674&view=rev
Log:
Toggleable support for AFP native image flavours.
Added:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java
Removed:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoFactory.java
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPState.java
Added:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java?rev=691674&view=auto
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java
(added)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPDataObjectInfoProvider.java
Wed Sep 3 09:34:56 2008
@@ -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;
+ }
+}
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRawStreamFactory.java
Wed Sep 3 09:34:56 2008
@@ -27,7 +27,7 @@
/**
* A raw stream image configurator
*/
-public class AFPImageRawStreamFactory extends AFPAbstractImageFactory {
+public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java
Wed Sep 3 09:34:56 2008
@@ -30,7 +30,7 @@
/**
* A buffered image configurator
*/
-public class AFPImageRenderedFactory extends AFPAbstractImageFactory {
+public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRawCCITTFaxFactory.java
Wed Sep 3 09:34:56 2008
@@ -26,7 +26,7 @@
/**
* An CITT fax image configurator
*/
-public class AFPRawCCITTFaxFactory extends AFPAbstractImageFactory {
+public class AFPRawCCITTFaxFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRenderer.java
Wed Sep 3 09:34:56 2008
@@ -155,7 +155,7 @@
private DataStream dataStream;
/** data object information factory */
- private final AFPDataObjectInfoFactory dataObjectInfoFactory;
+ private final AFPDataObjectInfoProvider dataObjectInfoProvider;
/**
@@ -165,7 +165,7 @@
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 @@
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 };
+
/** [EMAIL PROTECTED] */
public void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
uri = URISpecification.getURL(uri);
@@ -404,11 +409,13 @@
// 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 @@
// Try and get the encoding to use for the font
String encoding = null;
-
try {
encoding = font.getCharacterSet(fontSize).getEncoding();
} catch (Throwable ex) {
@@ -753,6 +759,16 @@
}
/**
+ * Sets whether images are supported natively or not
+ *
+ * @param nativeImages
+ * native image support
+ */
+ public void setNativeImages(boolean nativeImages) {
+ state.setNativeImages(nativeImages);
+ }
+
+ /**
* Returns the AFPDataStream
*
* @return the AFPDataStream
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
Wed Sep 3 09:34:56 2008
@@ -239,6 +239,7 @@
} else {
afpRenderer.setColorImages(true);
}
+
afpRenderer.setNativeImages(imagesCfg.getAttributeAsBoolean("native", false));
// renderer resolution
Configuration rendererResolutionCfg =
cfg.getChild("renderer-resolution", false);
Modified:
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPState.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPState.java?rev=691674&r1=691673&r2=691674&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPState.java
(original)
+++
xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/AFPState.java
Wed Sep 3 09:34:56 2008
@@ -34,27 +34,31 @@
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.
@@ -159,6 +163,24 @@
}
/**
+ * 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
*
* @param resolution
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]