You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by sp...@apache.org on 2008/02/14 22:57:53 UTC
svn commit: r627882 [14/41] - in
/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking: ./
examples/embedding/ examples/embedding/java/embedding/
examples/embedding/java/embedding/intermediate/ examples/embedding/xml/xml/
examples/fo/ examples/...
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Thu Feb 14 13:55:44 2008
@@ -25,7 +25,6 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
-import java.awt.color.ColorSpace;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
@@ -33,14 +32,6 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
@@ -51,7 +42,15 @@
import java.util.Map;
import java.util.Stack;
-import org.w3c.dom.Document;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
@@ -65,13 +64,11 @@
import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.Typeface;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
@@ -184,7 +181,7 @@
/** {@inheritDoc} */
public Graphics2DAdapter getGraphics2DAdapter() {
- return new Java2DGraphics2DAdapter(state);
+ return new Java2DGraphics2DAdapter();
}
/**
@@ -402,9 +399,12 @@
state = (Java2DGraphicsState)stateStack.pop();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ protected void concatenateTransformationMatrix(AffineTransform at) {
+ state.transform(at);
+ }
+
+ /** {@inheritDoc} */
protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
saveGraphicsState();
@@ -884,76 +884,58 @@
/**
* {@inheritDoc}
*/
- protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
+ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
int x = currentIPPosition + (int)Math.round(pos.getX());
int y = currentBPPosition + (int)Math.round(pos.getY());
- url = ImageFactory.getURL(url);
-
- ImageFactory fact = userAgent.getFactory().getImageFactory();
- FopImage fopimage = fact.getImage(url, userAgent);
-
- if (fopimage == null) {
- return;
- }
- if (!fopimage.load(FopImage.DIMENSIONS)) {
- return;
- }
- int w = fopimage.getWidth();
- int h = fopimage.getHeight();
- String mime = fopimage.getMimeType();
- if ("text/xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
- return;
- }
- Document doc = ((XMLImage) fopimage).getDocument();
- String ns = ((XMLImage) fopimage).getNameSpace();
- renderDocument(doc, ns, pos, foreignAttributes);
-
- } else if ("image/svg+xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
- return;
- }
- Document doc = ((XMLImage) fopimage).getDocument();
- String ns = ((XMLImage) fopimage).getNameSpace();
-
- renderDocument(doc, ns, pos, foreignAttributes);
- } else if ("image/eps".equals(mime)) {
- log.warn("EPS images are not supported by this renderer");
- } else {
- if (!fopimage.load(FopImage.BITMAP)) {
- log.warn("Loading of bitmap failed: " + url);
- return;
+ uri = URISpecification.getURL(uri);
+
+ ImageManager manager = getUserAgent().getFactory().getImageManager();
+ ImageInfo info = null;
+ try {
+ ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+ info = manager.getImageInfo(uri, sessionContext);
+ final ImageFlavor[] flavors = new ImageFlavor[]
+ {ImageFlavor.GRAPHICS2D,
+ ImageFlavor.BUFFERED_IMAGE,
+ ImageFlavor.RENDERED_IMAGE,
+ ImageFlavor.XML_DOM};
+ Map hints = ImageUtil.getDefaultHints(sessionContext);
+ org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+ info, flavors, hints, sessionContext);
+ if (img instanceof ImageGraphics2D) {
+ ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+ int width = (int)pos.getWidth();
+ int height = (int)pos.getHeight();
+ RendererContext context = createRendererContext(
+ x, y, width, height, foreignAttributes);
+ getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+ context, x, y, width, height);
+ } else if (img instanceof ImageRendered) {
+ ImageRendered imgRend = (ImageRendered)img;
+ AffineTransform at = new AffineTransform();
+ at.translate(x / 1000f, y / 1000f);
+ double sx = pos.getWidth() / info.getSize().getWidthMpt();
+ double sy = pos.getHeight() / info.getSize().getHeightMpt();
+ sx *= userAgent.getSourceResolution() / info.getSize().getDpiHorizontal();
+ sy *= userAgent.getSourceResolution() / info.getSize().getDpiVertical();
+ at.scale(sx, sy);
+ state.getGraph().drawRenderedImage(imgRend.getRenderedImage(), at);
+ } else if (img instanceof ImageXMLDOM) {
+ ImageXMLDOM imgXML = (ImageXMLDOM)img;
+ renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+ pos, foreignAttributes);
}
-
- byte[] raw = fopimage.getBitmaps();
-
- // TODO Hardcoded color and sample models, FIX ME!
- ColorModel cm = new ComponentColorModel(
- ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
- new int[] {8, 8, 8},
- false, false,
- ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
- SampleModel sampleModel = new PixelInterleavedSampleModel(
- DataBuffer.TYPE_BYTE, w, h, 3, w * 3, new int[] {0, 1, 2});
- DataBuffer dbuf = new DataBufferByte(raw, w * h * 3);
-
- WritableRaster raster = Raster.createWritableRaster(sampleModel,
- dbuf, null);
-
- java.awt.Image awtImage;
- // Combine the color model and raster into a buffered image
- awtImage = new BufferedImage(cm, raster, false, null);
-
- state.getGraph().drawImage(awtImage,
- (int)(x / 1000f), (int)(y / 1000f),
- (int)(pos.getWidth() / 1000f), (int)(pos.getHeight() / 1000f), null);
+ } catch (ImageException ie) {
+ log.error("Error while processing image: "
+ + (info != null ? info.toString() : uri), ie);
+ } catch (IOException ioe) {
+ log.error("I/O error while processing image: "
+ + (info != null ? info.toString() : uri), ioe);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
protected RendererContext createRendererContext(int x, int y, int width, int height,
Map foreignAttributes) {
RendererContext context = super.createRendererContext(
@@ -962,9 +944,7 @@
return context;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex >= getNumberOfPages()) {
@@ -1004,6 +984,10 @@
//not necessary in Java2D
}
+ /**
+ * Controls the page background.
+ * @param transparentPageBackground true if the background should be transparent
+ */
public void setTransparentPageBackground(boolean transparentPageBackground) {
this.transparentPageBackground = transparentPageBackground;
}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Feb 14 13:55:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java Thu Feb 14 13:55:44 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.java2d;
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Feb 14 13:55:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/DefaultMonochromeBitmapConverter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/MonochromeBitmapConverter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGenerator.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java Thu Feb 14 13:55:44 2008
@@ -28,11 +28,13 @@
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
import org.apache.fop.render.AbstractGraphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.util.UnitConv;
-import org.apache.xmlgraphics.java2d.GraphicContext;
/**
* Graphics2DAdapter implementation for PCL and HP GL/2.
@@ -110,7 +112,8 @@
if (!painted) {
//Fallback solution: Paint to a BufferedImage
int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
- BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, true, false);
+ BufferedImage bi = paintToBufferedImage(painter, pclContext,
+ resolution, !pclContext.isColorCanvas(), false);
pcl.setCursorPos(x, y);
gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency());
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRenderer.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRenderer.java Thu Feb 14 13:55:44 2008
@@ -24,24 +24,17 @@
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
-import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
import java.awt.image.RenderedImage;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
@@ -52,7 +45,19 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
@@ -61,6 +66,7 @@
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.CTM;
import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.AbstractTextArea;
import org.apache.fop.area.inline.ForeignObject;
@@ -70,16 +76,12 @@
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.datatypes.URISpecification;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.image.EPSImage;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.image.ImageFactory;
-import org.apache.fop.image.XMLImage;
import org.apache.fop.render.Graphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
import org.apache.fop.render.PrintRenderer;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.RendererContextConstants;
@@ -91,6 +93,12 @@
import org.apache.fop.util.QName;
import org.apache.fop.util.UnitConv;
+/* Note:
+ * There are some commonalities with AbstractPathOrientedRenderer but it's not possible
+ * to derive from it due to PCL's restrictions. We may need an additional common subclass to
+ * avoid methods copied from AbstractPathOrientedRenderer. Or we wait until after the IF redesign.
+ */
+
/**
* Renderer for the PCL 5 printer language. It also uses HP GL/2 for certain graphic elements.
*/
@@ -135,6 +143,13 @@
private boolean allTextAsBitmaps = false;
/**
+ * Controls whether an RGB canvas is used when converting Java2D graphics to bitmaps.
+ * This can be used to work around problems with Apache Batik, for example, but setting
+ * this to true will increase memory consumption.
+ */
+ private boolean useColorCanvas = false;
+
+ /**
* Controls whether the generation of PJL commands gets disabled.
*/
private boolean disabledPJL = false;
@@ -574,6 +589,24 @@
/**
* {@inheritDoc}
+ * @todo Copied from AbstractPathOrientedRenderer
+ */
+ protected void handleRegionTraits(RegionViewport region) {
+ Rectangle2D viewArea = region.getViewArea();
+ float startx = (float)(viewArea.getX() / 1000f);
+ float starty = (float)(viewArea.getY() / 1000f);
+ float width = (float)(viewArea.getWidth() / 1000f);
+ float height = (float)(viewArea.getHeight() / 1000f);
+
+ if (region.getRegionReference().getRegionClass() == FO_REGION_BODY) {
+ currentBPPosition = region.getBorderAndPaddingWidthBefore();
+ currentIPPosition = region.getBorderAndPaddingWidthStart();
+ }
+ drawBackAndBorders(region, startx, starty, width, height);
+ }
+
+ /**
+ * {@inheritDoc}
*/
protected void renderText(final TextArea text) {
renderInlineAreaBackAndBorders(text);
@@ -873,14 +906,10 @@
// save positions
int saveIP = currentIPPosition;
int saveBP = currentBPPosition;
- //String saveFontName = currentFontName;
CTM ctm = bv.getCTM();
int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
- float x, y;
- x = (float)(bv.getXOffset() + containingIPPosition) / 1000f;
- y = (float)(bv.getYOffset() + containingBPPosition) / 1000f;
//This is the content-rect
float width = (float)bv.getIPD() / 1000f;
float height = (float)bv.getBPD() / 1000f;
@@ -889,9 +918,6 @@
if (bv.getPositioning() == Block.ABSOLUTE
|| bv.getPositioning() == Block.FIXED) {
- currentIPPosition = bv.getXOffset();
- currentBPPosition = bv.getYOffset();
-
//For FIXED, we need to break out of the current viewports to the
//one established by the page. We save the state stack for restoration
//after the block-container has been painted. See below.
@@ -900,36 +926,42 @@
breakOutList = breakOutOfStateStack();
}
- CTM tempctm = new CTM(containingIPPosition, containingBPPosition);
- ctm = tempctm.multiply(ctm);
-
- //Adjust for spaces (from margin or indirectly by start-indent etc.
- x += bv.getSpaceStart() / 1000f;
- currentIPPosition += bv.getSpaceStart();
+ AffineTransform positionTransform = new AffineTransform();
+ positionTransform.translate(bv.getXOffset(), bv.getYOffset());
- y += bv.getSpaceBefore() / 1000f;
- currentBPPosition += bv.getSpaceBefore();
+ //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle
+ positionTransform.translate(-borderPaddingStart, -borderPaddingBefore);
+ saveGraphicsState();
+ //Viewport position
+ concatenateTransformationMatrix(mptToPt(positionTransform));
+
+ //Background and borders
float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
+ drawBackAndBorders(bv, 0, 0, width + bpwidth, height + bpheight);
- drawBackAndBorders(bv, x, y, width + bpwidth, height + bpheight);
-
- //Now adjust for border/padding
- currentIPPosition += borderPaddingStart;
- currentBPPosition += borderPaddingBefore;
+ //Shift to content rectangle after border painting
+ AffineTransform contentRectTransform = new AffineTransform();
+ contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
+ concatenateTransformationMatrix(mptToPt(contentRectTransform));
- Rectangle2D clippingRect = null;
+ //Clipping
if (bv.getClip()) {
- clippingRect = new Rectangle(currentIPPosition, currentBPPosition,
- bv.getIPD(), bv.getBPD());
+ clipRect(0f, 0f, width, height);
}
- startVParea(ctm, clippingRect);
+ saveGraphicsState();
+ //Set up coordinate system for content rectangle
+ AffineTransform contentTransform = ctm.toAffineTransform();
+ concatenateTransformationMatrix(mptToPt(contentTransform));
+
currentIPPosition = 0;
currentBPPosition = 0;
renderBlocks(bv, children);
- endVParea();
+
+ restoreGraphicsState();
+ restoreGraphicsState();
if (breakOutList != null) {
restoreStateStackAfterBreakOut(breakOutList);
@@ -973,6 +1005,18 @@
//currentFontName = saveFontName;
}
+ /**
+ * Concatenates the current transformation matrix with the given one, therefore establishing
+ * a new coordinate system.
+ * @param at the transformation matrix to process (coordinates in points)
+ */
+ protected void concatenateTransformationMatrix(AffineTransform at) {
+ if (!at.isIdentity()) {
+ graphicContext.transform(ptToMpt(at));
+ changePrintDirection();
+ }
+ }
+
private List breakOutOfStateStack() {
log.debug("Block.FIXED --> break out");
List breakOutList = new java.util.ArrayList();
@@ -991,87 +1035,88 @@
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ protected RendererContext createRendererContext(int x, int y, int width, int height,
+ Map foreignAttributes) {
+ RendererContext context = super.createRendererContext(
+ x, y, width, height, foreignAttributes);
+ context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS,
+ Boolean.valueOf(this.useColorCanvas));
+ return context;
+ }
+
+ /** {@inheritDoc} */
public void renderImage(Image image, Rectangle2D pos) {
drawImage(image.getURL(), pos, image.getForeignAttributes());
}
+ private static final ImageFlavor[] FLAVORS = new ImageFlavor[]
+ {ImageFlavor.GRAPHICS2D,
+ ImageFlavor.BUFFERED_IMAGE,
+ ImageFlavor.RENDERED_IMAGE,
+ ImageFlavor.XML_DOM};
/**
* Draw an image at the indicated location.
- * @param url the URI/URL of the image
+ * @param uri the URI/URL of the image
* @param pos the position of the image
* @param foreignAttributes an optional Map with foreign attributes, may be null
*/
- protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
- url = ImageFactory.getURL(url);
- ImageFactory fact = userAgent.getFactory().getImageFactory();
- FopImage fopimage = fact.getImage(url, userAgent);
- if (fopimage == null) {
- return;
- }
- if (!fopimage.load(FopImage.DIMENSIONS)) {
- return;
- }
- String mime = fopimage.getMimeType();
- if ("text/xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
- return;
- }
- Document doc = ((XMLImage) fopimage).getDocument();
- String ns = ((XMLImage) fopimage).getNameSpace();
-
- renderDocument(doc, ns, pos, foreignAttributes);
- } else if ("image/svg+xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
- return;
- }
- Document doc = ((XMLImage) fopimage).getDocument();
- String ns = ((XMLImage) fopimage).getNameSpace();
-
- renderDocument(doc, ns, pos, foreignAttributes);
- } else if (fopimage instanceof EPSImage) {
- log.warn("EPS images are not supported by this renderer");
- } else {
- if (!fopimage.load(FopImage.BITMAP)) {
- log.error("Bitmap image could not be processed: " + fopimage);
- return;
- }
- byte[] imgmap = fopimage.getBitmaps();
+ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
+ uri = URISpecification.getURL(uri);
+ Rectangle posInt = new Rectangle(
+ (int)pos.getX(),
+ (int)pos.getY(),
+ (int)pos.getWidth(),
+ (int)pos.getHeight());
+ Point origin = new Point(currentIPPosition, currentBPPosition);
+ int x = origin.x + posInt.x;
+ int y = origin.y + posInt.y;
+
+ ImageManager manager = getUserAgent().getFactory().getImageManager();
+ ImageInfo info = null;
+ try {
+ ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+ info = manager.getImageInfo(uri, sessionContext);
- ColorModel cm = new ComponentColorModel(
- ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
- new int[] {8, 8, 8},
- false, false,
- ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
- int imgw = fopimage.getWidth();
- int imgh = fopimage.getHeight();
- SampleModel sampleModel = new PixelInterleavedSampleModel(
- DataBuffer.TYPE_BYTE, imgw, imgh, 3, imgw * 3, new int[] {0, 1, 2});
- DataBuffer dbuf = new DataBufferByte(imgmap, imgw * imgh * 3);
-
- WritableRaster raster = Raster.createWritableRaster(sampleModel,
- dbuf, null);
-
- // Combine the color model and raster into a buffered image
- RenderedImage img = new BufferedImage(cm, raster, false, null);
-
- try {
- setCursorPos(this.currentIPPosition + (int)pos.getX(),
- this.currentBPPosition + (int)pos.getY());
- gen.paintBitmap(img,
- new Dimension((int)pos.getWidth(), (int)pos.getHeight()),
+ //Only now fully load/prepare the image
+ Map hints = ImageUtil.getDefaultHints(sessionContext);
+ org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
+ info, FLAVORS, hints, sessionContext);
+
+ //...and process the image
+ if (img instanceof ImageGraphics2D) {
+ ImageGraphics2D imageG2D = (ImageGraphics2D)img;
+ RendererContext context = createRendererContext(
+ posInt.x, posInt.y,
+ posInt.width, posInt.height, foreignAttributes);
+ getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
+ context, x, y, posInt.width, posInt.height);
+ } else if (img instanceof ImageRendered) {
+ ImageRendered imgRend = (ImageRendered)img;
+ RenderedImage ri = imgRend.getRenderedImage();
+ setCursorPos(x, y);
+ gen.paintBitmap(ri,
+ new Dimension(posInt.width, posInt.height),
false);
- } catch (IOException ioe) {
- handleIOTrouble(ioe);
+ } else if (img instanceof ImageXMLDOM) {
+ ImageXMLDOM imgXML = (ImageXMLDOM)img;
+ renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
+ pos, foreignAttributes);
+ } else {
+ throw new UnsupportedOperationException("Unsupported image type: " + img);
}
+
+ } catch (ImageException ie) {
+ log.error("Error while processing image: "
+ + (info != null ? info.toString() : uri), ie);
+ } catch (FileNotFoundException fe) {
+ log.error(fe.getMessage());
+ } catch (IOException ioe) {
+ handleIOTrouble(ioe);
}
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
Document doc = fo.getDocument();
String ns = fo.getNameSpace();
@@ -1153,52 +1198,45 @@
}
// background image
- if (back.getFopImage() != null) {
- FopImage fopimage = back.getFopImage();
- if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
- saveGraphicsState();
- clipRect(sx, sy, paddRectWidth, paddRectHeight);
- int horzCount = (int) ((paddRectWidth * 1000 / fopimage
- .getIntrinsicWidth()) + 1.0f);
- int vertCount = (int) ((paddRectHeight * 1000 / fopimage
- .getIntrinsicHeight()) + 1.0f);
- if (back.getRepeat() == EN_NOREPEAT) {
- horzCount = 1;
- vertCount = 1;
- } else if (back.getRepeat() == EN_REPEATX) {
- vertCount = 1;
- } else if (back.getRepeat() == EN_REPEATY) {
- horzCount = 1;
- }
- // change from points to millipoints
- sx *= 1000;
- sy *= 1000;
- if (horzCount == 1) {
- sx += back.getHoriz();
- }
- if (vertCount == 1) {
- sy += back.getVertical();
- }
- for (int x = 0; x < horzCount; x++) {
- for (int y = 0; y < vertCount; y++) {
- // place once
- Rectangle2D pos;
- // Image positions are relative to the currentIP/BP
- pos = new Rectangle2D.Float(
- sx - currentIPPosition
- + (x * fopimage.getIntrinsicWidth()),
- sy - currentBPPosition
- + (y * fopimage.getIntrinsicHeight()),
- fopimage.getIntrinsicWidth(),
- fopimage.getIntrinsicHeight());
- drawImage(back.getURL(), pos, null);
- }
+ if (back.getImageInfo() != null) {
+ ImageSize imageSize = back.getImageInfo().getSize();
+ saveGraphicsState();
+ clipRect(sx, sy, paddRectWidth, paddRectHeight);
+ int horzCount = (int) ((paddRectWidth * 1000 / imageSize.getWidthMpt()) + 1.0f);
+ int vertCount = (int) ((paddRectHeight * 1000 / imageSize.getHeightMpt()) + 1.0f);
+ if (back.getRepeat() == EN_NOREPEAT) {
+ horzCount = 1;
+ vertCount = 1;
+ } else if (back.getRepeat() == EN_REPEATX) {
+ vertCount = 1;
+ } else if (back.getRepeat() == EN_REPEATY) {
+ horzCount = 1;
+ }
+ // change from points to millipoints
+ sx *= 1000;
+ sy *= 1000;
+ if (horzCount == 1) {
+ sx += back.getHoriz();
+ }
+ if (vertCount == 1) {
+ sy += back.getVertical();
+ }
+ for (int x = 0; x < horzCount; x++) {
+ for (int y = 0; y < vertCount; y++) {
+ // place once
+ Rectangle2D pos;
+ // Image positions are relative to the currentIP/BP
+ pos = new Rectangle2D.Float(
+ sx - currentIPPosition
+ + (x * imageSize.getWidthMpt()),
+ sy - currentBPPosition
+ + (y * imageSize.getHeightMpt()),
+ imageSize.getWidthMpt(),
+ imageSize.getHeightMpt());
+ drawImage(back.getURL(), pos, null);
}
- restoreGraphicsState();
- } else {
- log.warn(
- "Can't find background image: " + back.getURL());
}
+ restoreGraphicsState();
}
}
@@ -1278,8 +1316,8 @@
final BorderProps bpsStart, final BorderProps bpsEnd) {
Graphics2DAdapter g2a = getGraphics2DAdapter();
final Rectangle.Float effBorderRect = new Rectangle2D.Float(
- borderRect.x - (currentIPPosition / 1000f),
- borderRect.y - (currentBPPosition / 1000f),
+ 0,
+ 0,
borderRect.width,
borderRect.height);
final Rectangle paintRect = new Rectangle(
@@ -1508,6 +1546,11 @@
}
}
+ /**
+ * Controls whether all text should be generated as bitmaps or only text for which there's
+ * no native font.
+ * @param allTextAsBitmaps true if all text should be painted as bitmaps
+ */
public void setAllTextAsBitmaps(boolean allTextAsBitmaps) {
this.allTextAsBitmaps = allTextAsBitmaps;
}
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java Thu Feb 14 13:55:44 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.pcl;
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererContext.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererContext.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererContext.java Thu Feb 14 13:55:44 2008
@@ -62,11 +62,28 @@
&& "true".equalsIgnoreCase((String)getForeignAttributes().get(qName));
}
+ /**
+ * Indicates whether the background should not be erased prior to painting.
+ * @return true if the background shouldn't be erased
+ */
public boolean isSourceTransparency() {
QName qName = new QName(ExtensionElementMapping.URI, null, "source-transparency");
return getForeignAttributes() != null
&& "true".equalsIgnoreCase((String)getForeignAttributes().get(qName));
}
+ /**
+ * Indicates whether an RGB canvas should be used rather than one with grayscales.
+ * This can be used to work around limitations of Apache Batik if you get error while
+ * processing SVG graphics. Note, however, that RGB mode will use more memory.
+ * @return true if an EGB canvas should be used
+ */
+ public boolean isColorCanvas() {
+ QName qName = new QName(ExtensionElementMapping.URI, null, "color-canvas");
+ Boolean prop = (Boolean)context.getProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS);
+ return Boolean.TRUE.equals(prop)
+ || (getForeignAttributes() != null
+ && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName)));
+ }
}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java Thu Feb 14 13:55:44 2008
@@ -1,57 +1,57 @@
-/*
- * 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.pcl;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererConfigurator;
-
-/**
- * RendererMaker for the PCL Renderer.
- */
-public class PCLRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {
- MimeConstants.MIME_PCL,
- MimeConstants.MIME_PCL_ALT
- };
-
- /**{@inheritDoc} */
- public Renderer makeRenderer(FOUserAgent userAgent) {
- return new PCLRenderer();
- }
-
- /** {@inheritDoc} */
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PCLRendererConfigurator(userAgent);
- }
-
- /** {@inheritDoc} */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** {@inheritDoc} */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-}
+/*
+ * 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.pcl;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the PCL Renderer.
+ */
+public class PCLRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {
+ MimeConstants.MIME_PCL,
+ MimeConstants.MIME_PCL_ALT
+ };
+
+ /**{@inheritDoc} */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PCLRenderer();
+ }
+
+ /** {@inheritDoc} */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PCLRendererConfigurator(userAgent);
+ }
+
+ /** {@inheritDoc} */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java Thu Feb 14 13:55:44 2008
@@ -22,6 +22,7 @@
// FOP
import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererContext;
/**
* PCL XML handler for SVG. Uses Apache Batik for SVG processing.
@@ -34,6 +35,13 @@
/** {@inheritDoc} */
public boolean supportsRenderer(Renderer renderer) {
return (renderer instanceof PCLRenderer);
+ }
+
+ /** {@inheritDoc} */
+ protected void updateRendererContext(RendererContext context) {
+ //Work around a problem in Batik: Gradients cannot be done in ColorSpace.CS_GRAY
+ context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS,
+ Boolean.TRUE);
}
}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java Thu Feb 14 13:55:44 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-/* $Id: AFPElementMapping.java 397875 2006-04-28 11:58:33Z manuel $ */
+/* $Id$ */
package org.apache.fop.render.pcl.extensions;
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java Thu Feb 14 13:55:44 2008
@@ -1,129 +1,130 @@
-/*
- * 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.pdf;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-import org.apache.fop.render.AbstractGraphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
-import org.apache.fop.render.RendererContext;
-import org.apache.fop.render.RendererContext.RendererContextWrapper;
-import org.apache.fop.svg.PDFGraphics2D;
-
-/**
- * Graphics2DAdapter implementation for PDF.
- */
-public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter {
-
- private PDFRenderer renderer;
-
- /**
- * Main constructor
- * @param renderer the Renderer instance to which this instance belongs
- */
- public PDFGraphics2DAdapter(PDFRenderer renderer) {
- this.renderer = renderer;
- }
-
- /** {@inheritDoc} */
- public void paintImage(Graphics2DImagePainter painter,
- RendererContext context,
- int x, int y, int width, int height) throws IOException {
-
- PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context);
- float fwidth = width / 1000f;
- float fheight = height / 1000f;
- float fx = x / 1000f;
- float fy = y / 1000f;
-
- // get the 'width' and 'height' attributes of the SVG document
- Dimension dim = painter.getImageSize();
- float imw = (float)dim.getWidth() / 1000f;
- float imh = (float)dim.getHeight() / 1000f;
-
- float sx = fwidth / (float)imw;
- float sy = fheight / (float)imh;
-
- renderer.saveGraphicsState();
- renderer.setColor(Color.black, false, null);
- renderer.setColor(Color.black, true, null);
-
- //TODO Clip to the image area.
-
- // transform so that the coordinates (0,0) is from the top left
- // and positive is down and to the right. (0,0) is where the
- // viewBox puts it.
- renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " "
- + fy + " cm\n");
-
-
- final boolean textAsShapes = false;
- if (pdfInfo.pdfContext == null) {
- pdfInfo.pdfContext = pdfInfo.pdfPage;
- }
- PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
- pdfInfo.fi, pdfInfo.pdfDoc,
- pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
- renderer.currentFontName,
- renderer.currentFontSize);
- graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
-
- AffineTransform transform = new AffineTransform();
- transform.translate(fx, fy);
- pdfInfo.pdfState.concatenate(transform);
- graphics.setPDFState(pdfInfo.pdfState);
- graphics.setOutputStream(pdfInfo.outputStream);
-
- if (pdfInfo.paintAsBitmap) {
- //Fallback solution: Paint to a BufferedImage
- int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
- RendererContextWrapper ctx = RendererContext.wrapRendererContext(context);
- BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false);
-
- float scale = PDFRenderer.NORMAL_PDF_RESOLUTION
- / context.getUserAgent().getTargetResolution();
- graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null);
- } else {
- Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(graphics, area);
- }
-
- pdfInfo.currentStream.add(graphics.getString());
- renderer.restoreGraphicsState();
- pdfInfo.pdfState.pop();
- }
-
- /** {@inheritDoc} */
- protected void setRenderingHintsForBufferedImage(Graphics2D g2d) {
- super.setRenderingHintsForBufferedImage(g2d);
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- }
-
-}
+/*
+ * 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.pdf;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
+import org.apache.fop.render.AbstractGraphics2DAdapter;
+import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContext.RendererContextWrapper;
+import org.apache.fop.svg.PDFGraphics2D;
+
+/**
+ * Graphics2DAdapter implementation for PDF.
+ */
+public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter {
+
+ private PDFRenderer renderer;
+
+ /**
+ * Main constructor
+ * @param renderer the Renderer instance to which this instance belongs
+ */
+ public PDFGraphics2DAdapter(PDFRenderer renderer) {
+ this.renderer = renderer;
+ }
+
+ /** {@inheritDoc} */
+ public void paintImage(Graphics2DImagePainter painter,
+ RendererContext context,
+ int x, int y, int width, int height) throws IOException {
+
+ PDFSVGHandler.PDFInfo pdfInfo = PDFSVGHandler.getPDFInfo(context);
+ float fwidth = width / 1000f;
+ float fheight = height / 1000f;
+ float fx = x / 1000f;
+ float fy = y / 1000f;
+
+ // get the 'width' and 'height' attributes of the SVG document
+ Dimension dim = painter.getImageSize();
+ float imw = (float)dim.getWidth() / 1000f;
+ float imh = (float)dim.getHeight() / 1000f;
+
+ float sx = fwidth / (float)imw;
+ float sy = fheight / (float)imh;
+
+ renderer.saveGraphicsState();
+ renderer.setColor(Color.black, false, null);
+ renderer.setColor(Color.black, true, null);
+
+ //TODO Clip to the image area.
+
+ // transform so that the coordinates (0,0) is from the top left
+ // and positive is down and to the right. (0,0) is where the
+ // viewBox puts it.
+ renderer.currentStream.add(sx + " 0 0 " + sy + " " + fx + " "
+ + fy + " cm\n");
+
+
+ final boolean textAsShapes = false;
+ if (pdfInfo.pdfContext == null) {
+ pdfInfo.pdfContext = pdfInfo.pdfPage;
+ }
+ PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
+ pdfInfo.fi, pdfInfo.pdfDoc,
+ pdfInfo.pdfContext, pdfInfo.pdfPage.referencePDF(),
+ renderer.currentFontName,
+ renderer.currentFontSize);
+ graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+ AffineTransform transform = new AffineTransform();
+ transform.translate(fx, fy);
+ pdfInfo.pdfState.concatenate(transform);
+ graphics.setPDFState(pdfInfo.pdfState);
+ graphics.setOutputStream(pdfInfo.outputStream);
+
+ if (pdfInfo.paintAsBitmap) {
+ //Fallback solution: Paint to a BufferedImage
+ int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
+ RendererContextWrapper ctx = RendererContext.wrapRendererContext(context);
+ BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false);
+
+ float scale = PDFRenderer.NORMAL_PDF_RESOLUTION
+ / context.getUserAgent().getTargetResolution();
+ graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null);
+ } else {
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
+ }
+
+ pdfInfo.currentStream.add(graphics.getString());
+ renderer.restoreGraphicsState();
+ pdfInfo.pdfState.pop();
+ }
+
+ /** {@inheritDoc} */
+ protected void setRenderingHintsForBufferedImage(Graphics2D g2d) {
+ super.setRenderingHintsForBufferedImage(g2d);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandler.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandler.java Thu Feb 14 13:55:44 2008
@@ -19,11 +19,15 @@
package org.apache.fop.render.pdf;
+import java.awt.Point;
+import java.awt.Rectangle;
import java.io.IOException;
-import org.apache.fop.image.FopImage;
-import org.apache.fop.pdf.PDFDocument;
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+
import org.apache.fop.pdf.PDFXObject;
+import org.apache.fop.render.RendererContext;
/**
* This interface is used for handling all sorts of image type for PDF output.
@@ -31,20 +35,38 @@
public interface PDFImageHandler {
/**
- * Returns the MIME type supported by this instance.
- * @return the MIME type
+ * Returns the priority for this image handler. A lower value means higher priority. This
+ * information is used to build the ordered/prioritized list of supported ImageFlavors for
+ * the PDF renderer. The built-in handlers use priorities between 100 and 999.
+ * @return a positive integer (>0) indicating the priority
+ */
+ int getPriority();
+
+ /**
+ * Returns the {@link ImageFlavor}s supported by this instance
+ * @return the supported image flavors
+ */
+ ImageFlavor[] getSupportedImageFlavors();
+
+ /**
+ * Returns the {@link Image} subclass supported by this instance.
+ * @return the Image type
*/
- String getSupportedMimeType();
+ Class getSupportedImageClass();
/**
- * Generates the PDF objects for the given FopImage instance and returns
- * the resulting XObject.
+ * Generates the PDF objects for the given {@link Image} instance. If the handler generates
+ * an XObject, it shall return it or otherwise return null. A generated XObject shall be
+ * placed in the current viewport according to the two parameters "origin" and "pos".
+ * @param context the PDF renderer context
* @param image the image to be handled
- * @param uri the URI of the image
- * @param pdfDoc the target PDF document
- * @return the generated XObject
+ * @param origin the current position in the current viewport (in millipoints)
+ * @param pos the position and scaling of the image relative to the origin point
+ * (in millipoints)
+ * @return the generated XObject or null if no XObject was generated
* @throws IOException if an I/O error occurs
*/
- PDFXObject generateImage(FopImage image, String uri, PDFDocument pdfDoc) throws IOException;
+ PDFXObject generateImage(RendererContext context, Image image,
+ Point origin, Rectangle pos) throws IOException;
}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java?rev=627882&r1=627881&r2=627882&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java (original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java Thu Feb 14 13:55:44 2008
@@ -19,11 +19,17 @@
package org.apache.fop.render.pdf;
+import java.util.Comparator;
import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.util.Service;
/**
@@ -36,8 +42,23 @@
/** the logger */
private static Log log = LogFactory.getLog(PDFImageHandlerRegistry.class);
+ private static final Comparator HANDLER_COMPARATOR = new Comparator() {
+ public int compare(Object o1, Object o2) {
+ PDFImageHandler h1 = (PDFImageHandler)o1;
+ PDFImageHandler h2 = (PDFImageHandler)o2;
+ return h1.getPriority() - h2.getPriority();
+ }
+ };
+
/** Map containing PDF image handlers for various MIME types */
private Map handlers = new java.util.HashMap();
+ /** List containing the same handlers as above but ordered by priority */
+ private List handlerList = new java.util.LinkedList();
+
+ /** Sorted Set of registered handlers */
+ private ImageFlavor[] supportedFlavors = new ImageFlavor[0];
+ private int handlerRegistrations;
+ private int lastSync;
/**
* Default constructor.
@@ -75,24 +96,73 @@
* Add an image handler. The handler itself is inspected to find out what it supports.
* @param handler the PDFImageHandler instance
*/
- public void addHandler(PDFImageHandler handler) {
- String mime = handler.getSupportedMimeType();
- handlers.put(mime, handler);
+ public synchronized void addHandler(PDFImageHandler handler) {
+ Class imageClass = handler.getSupportedImageClass();
+ this.handlers.put(imageClass, handler);
+
+ //Sorted insert
+ ListIterator iter = this.handlerList.listIterator();
+ while (iter.hasNext()) {
+ PDFImageHandler h = (PDFImageHandler)iter.next();
+ if (HANDLER_COMPARATOR.compare(handler, h) < 0) {
+ iter.previous();
+ break;
+ }
+ }
+ iter.add(handler);
+ this.handlerRegistrations++;
}
/**
* Returns an PDFImageHandler which handles an specific image type given the MIME type
* of the image.
- * @param mime the requested MIME type
+ * @param img the Image to be handled
* @return the PDFImageHandler responsible for handling the image or null if none is available
*/
- public PDFImageHandler getHandler(String mime) {
- PDFImageHandler handler;
+ public PDFImageHandler getHandler(Image img) {
+ return getHandler(img.getClass());
+ }
- handler = (PDFImageHandler)handlers.get(mime);
+ /**
+ * Returns an PDFImageHandler which handles an specific image type given the MIME type
+ * of the image.
+ * @param imageClass the Image subclass for which to get a handler
+ * @return the PDFImageHandler responsible for handling the image or null if none is available
+ */
+ protected synchronized PDFImageHandler getHandler(Class imageClass) {
+ PDFImageHandler handler = null;
+ Class cl = imageClass;
+ while (cl != null) {
+ handler = (PDFImageHandler)handlers.get(cl);
+ if (handler != null) {
+ break;
+ }
+ cl = cl.getSuperclass();
+ }
return handler;
}
+ /**
+ * Returns the ordered array of supported image flavors.
+ * @return the array of image flavors
+ */
+ public synchronized ImageFlavor[] getSupportedFlavors() {
+ if (this.lastSync != this.handlerRegistrations) {
+ //Extract all ImageFlavors into a single array
+ List flavors = new java.util.ArrayList();
+ Iterator iter = this.handlerList.iterator();
+ while (iter.hasNext()) {
+ ImageFlavor[] f = ((PDFImageHandler)iter.next()).getSupportedImageFlavors();
+ for (int i = 0; i < f.length; i++) {
+ flavors.add(f[i]);
+ }
+ }
+ this.supportedFlavors = (ImageFlavor[])flavors.toArray(new ImageFlavor[flavors.size()]);
+ this.lastSync = this.handlerRegistrations;
+ }
+ return this.supportedFlavors;
+ }
+
/**
* Discovers PDFImageHandler implementations through the classpath and dynamically
* registers them.
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/render/pdf/PDFImageHandlerRegistry.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org