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 je...@apache.org on 2007/12/11 12:12:58 UTC
svn commit: r603208 - in
/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java:
META-INF/services/ org/apache/fop/image2/impl/
org/apache/fop/image2/impl/batik/ org/apache/fop/render/
org/apache/fop/render/ps/
Author: jeremias
Date: Tue Dec 11 03:12:50 2007
New Revision: 603208
URL: http://svn.apache.org/viewvc?rev=603208&view=rev
Log:
Precisely define the expectations for the area parameter in Graphics2DImagePainter.
New ImageConverter: Bitmap -> Graphics2D
Added:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java (with props)
Modified:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/Graphics2DImagePainter.java
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter?rev=603208&r1=603207&r2=603208&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/META-INF/services/org.apache.fop.image2.spi.ImageConverter Tue Dec 11 03:12:50 2007
@@ -1,5 +1,6 @@
org.apache.fop.image2.impl.ImageConverterBuffered2Rendered
org.apache.fop.image2.impl.ImageConverterG2D2Bitmap
+org.apache.fop.image2.impl.ImageConverterBitmap2G2D
org.apache.fop.image2.impl.ImageConverterRendered2PNG
org.apache.fop.image2.impl.batik.ImageConverterSVG2G2D
org.apache.fop.image2.impl.batik.ImageConverterWMF2G2D
Added: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java?rev=603208&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java (added)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java Tue Dec 11 03:12:50 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.image2.impl;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Dimension2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Map;
+
+import org.apache.fop.image2.Image;
+import org.apache.fop.image2.ImageFlavor;
+import org.apache.fop.image2.ImageSize;
+import org.apache.fop.render.Graphics2DImagePainter;
+
+/**
+ * This ImageConverter wraps a bitmap image in a Graphics2D image.
+ */
+public class ImageConverterBitmap2G2D extends AbstractImageConverter {
+
+ /** {@inheritDoc} */
+ public Image convert(Image src, Map hints) {
+ checkSourceFlavor(src);
+ final ImageRendered rendImage = (ImageRendered)src;
+
+ Graphics2DImagePainter painter = new Graphics2DImagePainter() {
+
+ public Dimension getImageSize() {
+ return rendImage.getSize().getDimensionMpt();
+ }
+
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ ImageSize imageSize = rendImage.getSize();
+ double w = area.getWidth();
+ double h = area.getHeight();
+
+ AffineTransform at = new AffineTransform();
+ //Fit in paint area
+ Dimension2D sizePt = imageSize.getDimensionPt();
+ double sx = w / sizePt.getWidth();
+ double sy = h / sizePt.getHeight();
+ if (sx != 1.0 || sy != 1.0) {
+ at.scale(sx, sy);
+ }
+ //Scale image to fit
+ sx = w / imageSize.getWidthPx();
+ sy = h / imageSize.getHeightPx();
+ if (sx != 1.0 || sy != 1.0) {
+ at.scale(sx, sy);
+ }
+ g2d.drawRenderedImage(rendImage.getRenderedImage(), at);
+ }
+
+ };
+
+ ImageGraphics2D g2dImage = new ImageGraphics2D(src.getInfo(), painter);
+ return g2dImage;
+ }
+
+ /** {@inheritDoc} */
+ public ImageFlavor getSourceFlavor() {
+ return ImageFlavor.RENDERED_IMAGE;
+ }
+
+ /** {@inheritDoc} */
+ public ImageFlavor getTargetFlavor() {
+ return ImageFlavor.GRAPHICS2D;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterBitmap2G2D.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java?rev=603208&r1=603207&r2=603208&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/ImageConverterG2D2Bitmap.java Tue Dec 11 03:12:50 2007
@@ -41,8 +41,7 @@
import org.apache.fop.util.UnitConv;
/**
- * This ImageConverter converts WMF images (represented by Batik's WMFRecordStore) to a
- * BufferedImage.
+ * This ImageConverter converts Graphics2D images to a BufferedImage.
*/
public class ImageConverterG2D2Bitmap extends AbstractImageConverter {
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java?rev=603208&r1=603207&r2=603208&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/image2/impl/batik/ImageConverterWMF2G2D.java Tue Dec 11 03:12:50 2007
@@ -21,6 +21,7 @@
import java.awt.Dimension;
import java.awt.Graphics2D;
+import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.util.Map;
@@ -28,6 +29,7 @@
import org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.image2.Image;
import org.apache.fop.image2.ImageFlavor;
import org.apache.fop.image2.impl.AbstractImageConverter;
@@ -85,8 +87,9 @@
double h = area.getHeight();
//Fit in paint area
- double sx = w / wmf.getSize().getWidthMpt();
- double sy = h / wmf.getSize().getHeightMpt();
+ Dimension2D imageSize = wmf.getSize().getDimensionPt();
+ double sx = w / imageSize.getWidth();
+ double sy = h / imageSize.getHeight();
if (sx != 1.0 || sy != 1.0) {
g2d.scale(sx, sy);
}
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/Graphics2DImagePainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/Graphics2DImagePainter.java?rev=603208&r1=603207&r2=603208&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/Graphics2DImagePainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/Graphics2DImagePainter.java Tue Dec 11 03:12:50 2007
@@ -33,7 +33,7 @@
* Called to paint the image. Implementations should scale so the image is
* painted fully inside the given area indicated by then Rectangle2D object.
* @param g2d the Graphics2D instance to paint on
- * @param area the target area for the image
+ * @param area the target area for the image (values are in points)
*/
void paint(Graphics2D g2d, Rectangle2D area);
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java?rev=603208&r1=603207&r2=603208&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java Tue Dec 11 03:12:50 2007
@@ -24,33 +24,43 @@
import java.awt.geom.Rectangle2D;
import java.io.IOException;
+import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
+import org.apache.xmlgraphics.ps.PSGenerator;
+
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.Graphics2DImagePainter;
import org.apache.fop.render.RendererContext;
-import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
-import org.apache.xmlgraphics.ps.PSGenerator;
/**
* Graphics2DAdapter implementation for PostScript.
*/
public class PSGraphics2DAdapter implements Graphics2DAdapter {
- private PSRenderer renderer;
+ private PSGenerator gen;
+ private boolean clip = true;
/**
* Main constructor
* @param renderer the Renderer instance to which this instance belongs
*/
public PSGraphics2DAdapter(PSRenderer renderer) {
- this.renderer = renderer;
+ this(renderer.gen, true);
+ }
+
+ /**
+ * Constructor for use without a PSRenderer instance.
+ * @param gen the PostScript generator
+ * @param clip true if the image should be clipped
+ */
+ public PSGraphics2DAdapter(PSGenerator gen, boolean clip) {
+ this.gen = gen;
+ this.clip = clip;
}
/** {@inheritDoc} */
public void paintImage(Graphics2DImagePainter painter,
RendererContext context,
int x, int y, int width, int height) throws IOException {
- PSGenerator gen = renderer.gen;
-
float fwidth = width / 1000f;
float fheight = height / 1000f;
float fx = x / 1000f;
@@ -66,10 +76,12 @@
gen.commentln("%FOPBeginGraphics2D");
gen.saveGraphicsState();
- // Clip to the image area.
- gen.writeln("newpath");
- gen.defineRect(fx, fy, fwidth, fheight);
- gen.writeln("clip");
+ if (clip) {
+ // Clip to the image area.
+ gen.writeln("newpath");
+ gen.defineRect(fx, fy, fwidth, fheight);
+ gen.writeln("clip");
+ }
// 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
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org