aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-01-11 11:31:24 +0000
committerJeremias Maerki <jeremias@apache.org>2009-01-11 11:31:24 +0000
commit25b82eeedf54b42083102ce9d4c3dad3a472d586 (patch)
tree31e89c33e88d6473d092a706c54a4851e148b112 /src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
parent04bb06d6912f18601d1623935ac0d202da372e67 (diff)
downloadxmlgraphics-fop-25b82eeedf54b42083102ce9d4c3dad3a472d586.tar.gz
xmlgraphics-fop-25b82eeedf54b42083102ce9d4c3dad3a472d586.zip
Started new IF implementation for AFP (incomplete, supporting filled rects, text and images). Work in progress!
Moved PTOCA (presentation text) command sequence production into the new "ptoca" package. The PtocaBuilder class allows more flexible command sequence production than if you have to pass in an "info object". git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@733456 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java')
-rw-r--r--src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java83
1 files changed, 71 insertions, 12 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
index 0780e8a59..572cc0415 100644
--- a/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
+++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerGraphics2D.java
@@ -19,23 +19,29 @@
package org.apache.fop.render.afp;
+import java.awt.Rectangle;
import java.io.IOException;
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.util.MimeConstants;
+
import org.apache.fop.afp.AFPDataObjectInfo;
import org.apache.fop.afp.AFPGraphics2D;
import org.apache.fop.afp.AFPGraphicsObjectInfo;
import org.apache.fop.afp.AFPPaintingState;
import org.apache.fop.afp.AFPResourceInfo;
import org.apache.fop.afp.AFPResourceLevel;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.util.MimeConstants;
+import org.apache.fop.render.ImageHandler;
+import org.apache.fop.render.ImageHandlerUtil;
+import org.apache.fop.render.RenderingContext;
/**
* PDFImageHandler implementation which handles Graphics2D images.
*/
-public class AFPImageHandlerGraphics2D extends AFPImageHandler {
+public class AFPImageHandlerGraphics2D extends AFPImageHandler implements ImageHandler {
private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
ImageFlavor.GRAPHICS2D
@@ -64,19 +70,13 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler {
AFPGraphicsObjectInfo graphicsObjectInfo
= (AFPGraphicsObjectInfo)super.generateDataObjectInfo(rendererImageInfo);
- AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
- //level not explicitly set/changed so default to inline for GOCA graphic objects
- // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
- if (!resourceInfo.levelChanged()) {
- resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
- }
+ setDefaultToInlineResourceLevel(graphicsObjectInfo);
// set mime type (unsupported by MOD:CA registry)
graphicsObjectInfo.setMimeType(MimeConstants.MIME_AFP_GOCA);
// set g2d
boolean textAsShapes = false;
-
AFPGraphics2D g2d = afpInfo.createGraphics2D(textAsShapes);
graphicsObjectInfo.setGraphics2D(g2d);
@@ -88,6 +88,15 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler {
}
}
+ private void setDefaultToInlineResourceLevel(AFPGraphicsObjectInfo graphicsObjectInfo) {
+ AFPResourceInfo resourceInfo = graphicsObjectInfo.getResourceInfo();
+ //level not explicitly set/changed so default to inline for GOCA graphic objects
+ // (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
+ if (!resourceInfo.levelChanged()) {
+ resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+ }
+ }
+
/** {@inheritDoc} */
public int getPriority() {
return 200;
@@ -107,4 +116,54 @@ public class AFPImageHandlerGraphics2D extends AFPImageHandler {
protected AFPDataObjectInfo createDataObjectInfo() {
return new AFPGraphicsObjectInfo();
}
+
+ /** {@inheritDoc} */
+ public void handleImage(RenderingContext context, Image image, Rectangle pos)
+ throws IOException {
+ AFPRenderingContext afpContext = (AFPRenderingContext)context;
+
+ AFPGraphicsObjectInfo graphicsObjectInfo = (AFPGraphicsObjectInfo)createDataObjectInfo();
+
+ // set resource information
+ setResourceInformation(graphicsObjectInfo,
+ image.getInfo().getOriginalURI(),
+ afpContext.getForeignAttributes());
+
+ // Positioning
+ graphicsObjectInfo.setObjectAreaInfo(
+ createObjectAreaInfo(afpContext.getPaintingState(), pos));
+
+ setDefaultToInlineResourceLevel(graphicsObjectInfo);
+
+ // Image content
+ ImageGraphics2D imageG2D = (ImageGraphics2D)image;
+ boolean textAsShapes = false; //TODO Make configurable
+ AFPGraphics2D g2d = new AFPGraphics2D(
+ textAsShapes,
+ afpContext.getPaintingState(),
+ afpContext.getResourceManager(),
+ graphicsObjectInfo.getResourceInfo(),
+ afpContext.getFontInfo());
+ g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+ graphicsObjectInfo.setGraphics2D(g2d);
+ graphicsObjectInfo.setPainter(imageG2D.getGraphics2DImagePainter());
+
+ // Create image
+ afpContext.getResourceManager().createObject(graphicsObjectInfo);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isCompatible(RenderingContext targetContext, Image image) {
+ boolean supported = (image == null || image instanceof ImageGraphics2D)
+ && targetContext instanceof AFPRenderingContext;
+ if (supported) {
+ String mode = (String)targetContext.getHint(ImageHandlerUtil.CONVERSION_MODE);
+ if (ImageHandlerUtil.isConversionModeBitmap(mode)) {
+ //Disabling this image handler automatically causes a bitmap to be generated
+ return false;
+ }
+ }
+ return supported;
+ }
}