diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-06-30 11:55:46 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-06-30 11:55:46 +0000 |
commit | 109c667f80e72c278fdaab7c2c090e601fdc2927 (patch) | |
tree | 9ec2410f3bd2be034802d9f775aecfedadf16117 /src/java/org | |
parent | 5253023d0f25f9e497c89eda3a014cc50bce4013 (diff) | |
download | xmlgraphics-fop-109c667f80e72c278fdaab7c2c090e601fdc2927.tar.gz xmlgraphics-fop-109c667f80e72c278fdaab7c2c090e601fdc2927.zip |
Bugzilla #35561
Print quality improvement especially for printing. The implementations don't create a bitmap image anymore, but draw directly.
Submitted by: Richard Wheeldon <richardw@geoquip-rnd.demon.co.uk>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@202539 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
3 files changed, 42 insertions, 56 deletions
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index d6c2a1a3c..b790d43a1 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -27,18 +27,14 @@ package org.apache.fop.render.awt; // Java import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Pageable; import java.awt.print.Paper; import java.awt.print.Printable; -import java.awt.print.PrinterException; import java.io.IOException; import org.apache.fop.apps.FOPException; @@ -56,7 +52,7 @@ import org.apache.fop.render.java2d.Java2DRenderer; * window. This Swing window serves as default viewer for the -awt switch and as * an example of how to embed the AWTRenderer into an AWT/Swing application. */ -public class AWTRenderer extends Java2DRenderer implements Pageable, Printable { +public class AWTRenderer extends Java2DRenderer implements Pageable { /** The MIME type for AWT-Rendering */ public static final String MIME_TYPE = "application/X-awt"; @@ -162,31 +158,6 @@ public class AWTRenderer extends Java2DRenderer implements Pageable, Printable { return frame; } - /** - * @see java.awt.print.Printable#print(java.awt.Graphics, - * java.awt.print.PageFormat, int) - */ - public int print(Graphics g, PageFormat pageFormat, int pageIndex) - throws PrinterException { - if (pageIndex >= getNumberOfPages()) { - return NO_SUCH_PAGE; - } - - Graphics2D g2 = (Graphics2D) g; - - BufferedImage image; - try { - image = getPageImage(pageIndex); - } catch (FOPException e) { - e.printStackTrace(); - return NO_SUCH_PAGE; - } - - g2.drawImage(image, null, 0, 0); - - return PAGE_EXISTS; - } - /** @see java.awt.print.Pageable#getPageFormat(int) */ public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException { diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 9952234fe..cda0db5db 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -20,6 +20,7 @@ package org.apache.fop.render.java2d; // Java import java.awt.Color; +import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.color.ColorSpace; @@ -36,6 +37,9 @@ 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; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; @@ -101,7 +105,7 @@ import org.w3c.dom.svg.SVGSVGElement; * }</code> * */ -public abstract class Java2DRenderer extends AbstractRenderer { +public abstract class Java2DRenderer extends AbstractRenderer implements Printable { /** The MIME type for Java2D-Rendering */ public static final String MIME_TYPE = "application/X-Java2D"; @@ -1121,4 +1125,36 @@ public abstract class Java2DRenderer extends AbstractRenderer { state.getGraph().translate(-(x + 500) / 1000, (y + 500) / 1000 - pageHeight); } + + /** + * @see java.awt.print.Printable#print(java.awt.Graphics, + * java.awt.print.PageFormat, int) + */ + public int print(Graphics g, PageFormat pageFormat, int pageIndex) + throws PrinterException { + if (pageIndex >= getNumberOfPages()) { + return NO_SUCH_PAGE; + } + + Graphics2D graphics = (Graphics2D) g; + Java2DGraphicsState oldState = state; + BufferedImage image; + try { + PageViewport viewport = getPageViewport(pageIndex); + AffineTransform at = graphics.getTransform(); + state = new Java2DGraphicsState(graphics, this.fontInfo, at); + + // reset the current Positions + currentBPPosition = 0; + currentIPPosition = 0; + + renderPageAreas(viewport.getPage()); + return PAGE_EXISTS; + } catch (FOPException e) { + e.printStackTrace(); + return NO_SUCH_PAGE; + } finally { + oldState = state; + } + } } diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java index bb52ac2ff..e604445ee 100644 --- a/src/java/org/apache/fop/render/print/PrintRenderer.java +++ b/src/java/org/apache/fop/render/print/PrintRenderer.java @@ -18,10 +18,7 @@ package org.apache.fop.render.print; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Pageable; import java.awt.print.Paper; @@ -36,8 +33,11 @@ import org.apache.fop.render.java2d.Java2DRenderer; /** * Renderer that prints through java.awt.PrintJob. + * The actual printing is handled by Java2DRenderer + * since both PrintRenderer and AWTRenderer need to + * support printing. */ -public class PrintRenderer extends Java2DRenderer implements Pageable, Printable { +public class PrintRenderer extends Java2DRenderer implements Pageable { private static final int EVEN_AND_ALL = 0; @@ -140,27 +140,6 @@ public class PrintRenderer extends Java2DRenderer implements Pageable, Printable return vec; } - public int print(Graphics g, PageFormat pageFormat, int pageIndex) - throws PrinterException { - if (pageIndex >= getNumberOfPages()) { - return NO_SUCH_PAGE; - } - - Graphics2D g2 = (Graphics2D) g; - - BufferedImage image; - try { - image = getPageImage(pageIndex); - } catch (FOPException e) { - e.printStackTrace(); - return NO_SUCH_PAGE; - } - - g2.drawImage(image, null, 0, 0); - - return PAGE_EXISTS; - } - /** @see java.awt.print.Pageable#getPageFormat(int) */ public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException { |