aboutsummaryrefslogtreecommitdiffstats
path: root/src/sandbox
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-05-25 14:03:44 +0000
committerJeremias Maerki <jeremias@apache.org>2006-05-25 14:03:44 +0000
commit3403067cdd510f73f5f28fe61d2d02d2a40a391c (patch)
tree69796210785c8a1be523c7c749bb29505fca3323 /src/sandbox
parentb3ccc681bf2c13922bd0c9f7a3fa175f9c0cbb95 (diff)
downloadxmlgraphics-fop-3403067cdd510f73f5f28fe61d2d02d2a40a391c.tar.gz
xmlgraphics-fop-3403067cdd510f73f5f28fe61d2d02d2a40a391c.zip
Images were not properly scaled.
Added borders and background for viewports (e-g, i-f-o etc.) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@409390 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox')
-rw-r--r--src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java39
-rw-r--r--src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java2
-rw-r--r--src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java39
3 files changed, 66 insertions, 14 deletions
diff --git a/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java b/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java
index 979644c86..373a70794 100644
--- a/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java
+++ b/src/sandbox/org/apache/fop/render/pcl/PCLGenerator.java
@@ -40,6 +40,7 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
+import org.apache.fop.util.UnitConv;
import org.apache.xmlgraphics.image.GraphicsUtil;
/**
@@ -506,7 +507,7 @@ public class PCLGenerator {
return resolution == calculatePCLResolution(resolution);
}
- private Dimension getAdjustedDimension(Dimension orgDim, int orgResolution,
+ private Dimension getAdjustedDimension(Dimension orgDim, double orgResolution,
int pclResolution) {
if (orgResolution == pclResolution) {
return orgDim;
@@ -576,17 +577,19 @@ public class PCLGenerator {
* Paint a bitmap at the current cursor position. The bitmap is converted to a monochrome
* (1-bit) bitmap image.
* @param img the bitmap image
- * @param resolution the original resolution of the image (in dpi)
+ * @param targetDim the target Dimention (in mpt)
* @throws IOException In case of an I/O error
*/
- public void paintBitmap(RenderedImage img, int resolution) throws IOException {
+ public void paintBitmap(RenderedImage img, Dimension targetDim) throws IOException {
+ double targetResolution = img.getWidth() / UnitConv.mpt2in(targetDim.width);
+ int resolution = (int)Math.round(targetResolution);
+ int effResolution = calculatePCLResolution(resolution, true);
+ Dimension orgDim = new Dimension(img.getWidth(), img.getHeight());
+ Dimension effDim = getAdjustedDimension(orgDim, targetResolution, effResolution);
+ boolean scaled = !orgDim.equals(effDim);
+
boolean monochrome = isMonochromeImage(img);
if (!monochrome) {
- int effResolution = calculatePCLResolution(resolution, true);
- Dimension orgDim = new Dimension(img.getWidth(), img.getHeight());
- Dimension effDim = getAdjustedDimension(orgDim, resolution, effResolution);
- boolean scaled = !orgDim.equals(effDim);
-
//Transparency mask disabled. Doesn't work reliably
final boolean transparencyDisabled = true;
RenderedImage mask = (transparencyDisabled ? null : getMask(img, effDim));
@@ -634,10 +637,26 @@ public class PCLGenerator {
setTransparencyMode(mask != null, true);
paintMonochromeBitmap(red, effResolution);
} else {
- int effResolution = calculatePCLResolution(resolution);
+ //TODO untested!
+ RenderedImage effImg = img;
+ if (scaled) {
+ BufferedImage buf = new BufferedImage(effDim.width, effDim.height,
+ BufferedImage.TYPE_BYTE_BINARY);
+ Graphics2D g2d = buf.createGraphics();
+ try {
+ AffineTransform at = new AffineTransform();
+ double sx = effDim.getWidth() / orgDim.getWidth();
+ double sy = effDim.getHeight() / orgDim.getHeight();
+ at.scale(sx, sy);
+ g2d.drawRenderedImage(img, at);
+ } finally {
+ g2d.dispose();
+ }
+ effImg = buf;
+ }
setSourceTransparencyMode(false);
selectCurrentPattern(0, 0); //Solid black
- paintMonochromeBitmap(img, effResolution);
+ paintMonochromeBitmap(effImg, effResolution);
}
}
diff --git a/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java b/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
index bded84098..4d2e950ab 100644
--- a/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
+++ b/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
@@ -112,7 +112,7 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter {
BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, true, false);
pcl.setCursorPos(x, y);
- gen.paintBitmap(bi, resolution);
+ gen.paintBitmap(bi, new Dimension(width, height));
}
}
diff --git a/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java b/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java
index 01c2bde73..d20b45a69 100644
--- a/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java
+++ b/src/sandbox/org/apache/fop/render/pcl/PCLRenderer.java
@@ -68,6 +68,7 @@ import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.SpaceArea;
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.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fonts.Font;
@@ -729,6 +730,40 @@ public class PCLRenderer extends PrintRenderer {
}
/**
+ * Render an inline viewport.
+ * This renders an inline viewport by clipping if necessary.
+ * @param viewport the viewport to handle
+ * @todo Copied from AbstractPathOrientedRenderer
+ */
+ public void renderViewport(Viewport viewport) {
+
+ float x = currentIPPosition / 1000f;
+ float y = (currentBPPosition + viewport.getOffset()) / 1000f;
+ float width = viewport.getIPD() / 1000f;
+ float height = viewport.getBPD() / 1000f;
+ // TODO: Calculate the border rect correctly.
+ float borderPaddingStart = viewport.getBorderAndPaddingWidthStart() / 1000f;
+ float borderPaddingBefore = viewport.getBorderAndPaddingWidthBefore() / 1000f;
+ float bpwidth = borderPaddingStart
+ + (viewport.getBorderAndPaddingWidthEnd() / 1000f);
+ float bpheight = borderPaddingBefore
+ + (viewport.getBorderAndPaddingWidthAfter() / 1000f);
+
+ drawBackAndBorders(viewport, x, y, width + bpwidth, height + bpheight);
+
+ if (viewport.getClip()) {
+ saveGraphicsState();
+
+ clipRect(x + borderPaddingStart, y + borderPaddingBefore, width, height);
+ }
+ super.renderViewport(viewport);
+
+ if (viewport.getClip()) {
+ restoreGraphicsState();
+ }
+ }
+
+ /**
* @see org.apache.fop.render.AbstractRenderer#renderBlockViewport(BlockViewport, List)
*/
protected void renderBlockViewport(BlockViewport bv, List children) {
@@ -924,9 +959,7 @@ public class PCLRenderer extends PrintRenderer {
try {
setCursorPos(this.currentIPPosition + (int)pos.getX(),
this.currentBPPosition + (int)pos.getY());
- int resolution = (int)Math.round(Math.max(fopimage.getHorizontalResolution(),
- fopimage.getVerticalResolution()));
- gen.paintBitmap(img, resolution);
+ gen.paintBitmap(img, new Dimension((int)pos.getWidth(), (int)pos.getHeight()));
} catch (IOException ioe) {
handleIOTrouble(ioe);
}