+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+}
/**
* A raw stream image configurator
*/
-public class AFPImageRawStreamFactory extends AFPAbstractImageFactory {
+public class AFPImageRawStreamFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
/**
* A buffered image configurator
*/
-public class AFPImageRenderedFactory extends AFPAbstractImageFactory {
+public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
/**
* An CITT fax image configurator
*/
-public class AFPRawCCITTFaxFactory extends AFPAbstractImageFactory {
+public class AFPRawCCITTFaxFactory extends AFPDataObjectInfoFactory {
/**
* Main constructor
private DataStream dataStream;
/** data object information factory */
- private final AFPDataObjectInfoFactory dataObjectInfoFactory;
+ private final AFPDataObjectInfoProvider dataObjectInfoProvider;
/**
super();
this.resourceManager = new AFPResourceManager();
this.state = new AFPState();
- this.dataObjectInfoFactory = new AFPDataObjectInfoFactory(state);
+ this.dataObjectInfoProvider = new AFPDataObjectInfoProvider(state);
this.unitConv = state.getUnitConverter();
}
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);
// 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);
// Try and get the encoding to use for the font
String encoding = null;
-
try {
encoding = font.getCharacterSet(fontSize).getEncoding();
} catch (Throwable ex) {
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
*
} else {
afpRenderer.setColorImages(true);
}
+ afpRenderer.setNativeImages(imagesCfg.getAttributeAsBoolean("native", false));
// renderer resolution
Configuration rendererResolutionCfg = cfg.getChild("renderer-resolution", false);
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.
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
*