summaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2020-03-25 14:29:15 +0000
committerSimon Steiner <ssteiner@apache.org>2020-03-25 14:29:15 +0000
commit150d1c19954a830324f6f353bb9c636be39911ae (patch)
treedc8b8885031cacbc6184abc705c0690c52fe263d /fop-core
parent791d39bd2c0f928f5ea940165a46c2f00a66b20b (diff)
downloadxmlgraphics-fop-150d1c19954a830324f6f353bb9c636be39911ae.tar.gz
xmlgraphics-fop-150d1c19954a830324f6f353bb9c636be39911ae.zip
FOP-2924: Images not scaled or rotated in PCL
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1875643 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pcl/PCLGenerator.java8
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java28
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java51
3 files changed, 83 insertions, 4 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/pcl/PCLGenerator.java b/fop-core/src/main/java/org/apache/fop/render/pcl/PCLGenerator.java
index bf45989f9..a9eedfba7 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pcl/PCLGenerator.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pcl/PCLGenerator.java
@@ -758,8 +758,12 @@ public class PCLGenerator {
boolean scaled = !orgDim.equals(effDim);
if (!monochrome) {
if (printerSupportsColor) {
+ RenderedImage effImg = img;
+ if (scaled) {
+ effImg = BitmapImageUtil.convertTosRGB(img, effDim);
+ }
selectCurrentPattern(0, 0); //Solid black
- renderImageAsColor(img, effResolution);
+ renderImageAsColor(effImg, effResolution);
} else {
//Transparency mask disabled. Doesn't work reliably
/*
@@ -784,7 +788,7 @@ public class PCLGenerator {
RenderedImage effImg = img;
if (scaled) {
effImg = BitmapImageUtil.convertToMonochrome(img, effDim);
- }
+ }
setSourceTransparencyMode(sourceTransparency);
selectCurrentPattern(0, 0); //Solid black
paintMonochromeBitmap(effImg, effResolution);
diff --git a/fop-core/src/main/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java b/fop-core/src/main/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java
index 66336955e..c71f2d2f3 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pcl/PCLImageHandlerGraphics2D.java
@@ -91,6 +91,17 @@ public class PCLImageHandlerGraphics2D implements ImageHandler {
AffineTransform prepareHPGL2 = new AffineTransform();
prepareHPGL2.scale(0.001, 0.001);
+
+ int direction = PCLRenderingUtil.determinePrintDirection(ctx.getTransform());
+ rotate(prepareHPGL2, imageDim, direction);
+ int height = pos.height;
+ int width = pos.width;
+ if (direction == 90 || direction == 270) {
+ int tmp = height;
+ height = width;
+ width = tmp;
+ }
+
ctx.setTransform(prepareHPGL2);
PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
@@ -101,8 +112,8 @@ public class PCLImageHandlerGraphics2D implements ImageHandler {
imageG2D.getGraphics2DImagePainter().paint(graphics, area);
//If we arrive here, the graphic is natively paintable, so write the graphic
- gen.writeCommand("*c" + gen.formatDouble4(pos.width / 100f) + "x"
- + gen.formatDouble4(pos.height / 100f) + "Y");
+ gen.writeCommand("*c" + gen.formatDouble4(width / 100f) + "x"
+ + gen.formatDouble4(height / 100f) + "Y");
gen.writeCommand("*c0T");
gen.enterHPGL2Mode(false);
gen.writeText("\nIN;");
@@ -143,6 +154,19 @@ public class PCLImageHandlerGraphics2D implements ImageHandler {
}
}
+ private void rotate(AffineTransform prepareHPGL2, Dimension imageDim, int direction) {
+ if (direction != 0) {
+ double rads = Math.toRadians(-direction);
+ double sin = Math.abs(Math.sin(rads));
+ double cos = Math.abs(Math.cos(rads));
+ double w = Math.floor(imageDim.getWidth() * cos + imageDim.getHeight() * sin);
+ double h = Math.floor(imageDim.getHeight() * cos + imageDim.getWidth() * sin);
+ prepareHPGL2.translate(w / 2d, h / 2d);
+ prepareHPGL2.rotate(rads, 0, 0);
+ prepareHPGL2.translate(-imageDim.getWidth() / 2d, -imageDim.getHeight() / 2d);
+ }
+ }
+
/** {@inheritDoc} */
public boolean isCompatible(RenderingContext targetContext, Image image) {
boolean supported = (image == null || image instanceof ImageGraphics2D)
diff --git a/fop-core/src/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java
index f69ab491a..03e76b329 100644
--- a/fop-core/src/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/render/pcl/PCLPainterTestCase.java
@@ -21,7 +21,10 @@ package org.apache.fop.render.pcl;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontFormatException;
+import java.awt.Graphics2D;
import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -33,6 +36,11 @@ import javax.xml.transform.stream.StreamResult;
import org.junit.Assert;
import org.junit.Test;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.fonts.EmbeddingMode;
@@ -68,6 +76,49 @@ public class PCLPainterTestCase {
}
@Test
+ public void testDrawImage() throws IFException {
+ Rectangle size = new Rectangle(1, 1);
+ PCLPageDefinition pclPageDef = new PCLPageDefinition("", 0, new Dimension(), size, true);
+ PCLDocumentHandler documentHandler = new PCLDocumentHandler(new IFContext(ua));
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ documentHandler.setResult(new StreamResult(output));
+ documentHandler.startDocument();
+ PCLPainter pclPainter = new PCLPainter(documentHandler, pclPageDef);
+ pclPainter.getPCLUtil().setColorEnabled(true);
+ pclPainter.drawImage("test/resources/images/fop-logo-color-24bit.png", new Rectangle(100, 100));
+ Assert.assertTrue(output.toString(), output.toString().contains("*r0f1t1S"));
+ }
+
+ @Test
+ public void testDrawGraphics() throws IOException, IFException {
+ Rectangle size = new Rectangle(1, 1);
+ PCLPageDefinition pclPageDef = new PCLPageDefinition("", 0, new Dimension(), size, true);
+ PCLDocumentHandler documentHandler = new PCLDocumentHandler(new IFContext(ua));
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ documentHandler.setResult(new StreamResult(output));
+ documentHandler.startDocument();
+ PCLPainter pclPainter = new PCLPainter(documentHandler, pclPageDef);
+ PCLImageHandlerGraphics2D graphics2D = new PCLImageHandlerGraphics2D();
+ ImageInfo info = new ImageInfo(null, null);
+ info.setSize(new ImageSize());
+ ImageGraphics2D imageGraphics2D = new ImageGraphics2D(info, new MyGraphics2DImagePainter());
+ graphics2D.handleImage(pclPainter.createRenderingContext(), imageGraphics2D, new Rectangle(50, 100));
+ Assert.assertTrue(output.toString().contains("*c0.5x1Y"));
+ output.reset();
+ pclPainter.startGroup(AffineTransform.getRotateInstance(-Math.PI / 2), null);
+ graphics2D.handleImage(pclPainter.createRenderingContext(), imageGraphics2D, new Rectangle(50, 100));
+ Assert.assertTrue(output.toString().contains("*c1x0.5Y"));
+ }
+
+ static class MyGraphics2DImagePainter implements Graphics2DImagePainter {
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ }
+ public Dimension getImageSize() {
+ return null;
+ }
+ }
+
+ @Test
public void testTruetype() throws IFException, IOException, FontFormatException, URISyntaxException {
String optimizeResources = getPCL(true).toString();
String notOptimizeResources = getPCL(false).toString();