aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-05-17 15:06:42 +0000
committerJeremias Maerki <jeremias@apache.org>2006-05-17 15:06:42 +0000
commit436c9f26ea62ed151f38a5eaf4e5e69fa67afda1 (patch)
tree76ac37816b1ba41fed1f6cae29aadfce8e68dfa7 /src/java/org/apache/fop
parentf0497748703427a76652ac82662a3613d9ef05a6 (diff)
downloadxmlgraphics-fop-436c9f26ea62ed151f38a5eaf4e5e69fa67afda1.tar.gz
xmlgraphics-fop-436c9f26ea62ed151f38a5eaf4e5e69fa67afda1.zip
Several bug fixes in PCLRenderer (border painting mostly).
Option in AbstractGraphics2DAdapter to work with or without alpha. Text Setup changed to the Java2D model. Custom font painting is now done through Java2D as bitmaps for all fonts which are not supported by the pre-defined set. This was done as a shortcut for full-fledged TrueType support which seems to be a little complicated in PCL. BTW, Microsoft PCL printer drivers do the same, i.e. paint text as bitmaps. Image printing refined, but my attempt at handling bitmasked images (transparency) didn't work out. While the previewers did the expected thing, the printer hardware flat-out ignored it, so it's disabled now. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@407277 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java b/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
index af5343f33..e7b126121 100644
--- a/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
@@ -20,12 +20,18 @@ package org.apache.fop.render;
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.Point;
import java.awt.RenderingHints;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
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.Raster;
+import java.awt.image.WritableRaster;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.Graphics2DImagePainter;
import org.apache.fop.render.RendererContext.RendererContextWrapper;
@@ -45,14 +51,22 @@ public abstract class AbstractGraphics2DAdapter implements Graphics2DAdapter {
* @return the generated BufferedImage
*/
protected BufferedImage paintToBufferedImage(Graphics2DImagePainter painter,
- RendererContextWrapper context, int resolution, boolean gray) {
+ RendererContextWrapper context, int resolution, boolean gray, boolean withAlpha) {
int bmw = UnitConv.mpt2px(context.getWidth(), resolution);
int bmh = UnitConv.mpt2px(context.getHeight(), resolution);
BufferedImage bi;
if (gray) {
- bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_BYTE_GRAY);
+ if (withAlpha) {
+ bi = createGrayBufferedImageWithAlpha(bmw, bmh);
+ } else {
+ bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_BYTE_GRAY);
+ }
} else {
- bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_ARGB);
+ if (withAlpha) {
+ bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_ARGB);
+ } else {
+ bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_RGB);
+ }
}
Graphics2D g2d = bi.createGraphics();
try {
@@ -62,7 +76,9 @@ public abstract class AbstractGraphics2DAdapter implements Graphics2DAdapter {
g2d.setBackground(Color.white);
g2d.setColor(Color.black);
- g2d.clearRect(0, 0, bmw, bmh);
+ if (!withAlpha) {
+ g2d.clearRect(0, 0, bmw, bmh);
+ }
double sx = (double)bmw / context.getWidth();
double sy = (double)bmh / context.getHeight();
g2d.scale(sx, sy);
@@ -77,6 +93,28 @@ public abstract class AbstractGraphics2DAdapter implements Graphics2DAdapter {
return bi;
}
+ private static BufferedImage createGrayBufferedImageWithAlpha(int width, int height) {
+ BufferedImage bi;
+ boolean alphaPremultiplied = true;
+ int bands = 2;
+ int[] bits = new int[bands];
+ for (int i = 0; i < bands; i++) {
+ bits[i] = 8;
+ }
+ ColorModel cm = new ComponentColorModel(
+ ColorSpace.getInstance(ColorSpace.CS_GRAY),
+ bits,
+ true, alphaPremultiplied,
+ Transparency.TRANSLUCENT,
+ DataBuffer.TYPE_BYTE);
+ WritableRaster wr = Raster.createInterleavedRaster(
+ DataBuffer.TYPE_BYTE,
+ width, height, bands,
+ new Point(0, 0));
+ bi = new BufferedImage(cm, wr, alphaPremultiplied, null);
+ return bi;
+ }
+
/**
* Sets rendering hints on the Graphics2D created for painting to a BufferedImage. Subclasses
* can modify the settings to customize the behaviour.