aboutsummaryrefslogtreecommitdiffstats
path: root/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-07-24 13:16:23 +0000
committerJeremias Maerki <jeremias@apache.org>2006-07-24 13:16:23 +0000
commitfe9c40f495aee9919b86a746dfd587069f7cc3f3 (patch)
tree140ec1ebac55584dc3e5917b38856f0862c9c419 /src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
parent423453976de29088ee76156baec1a83bc58b9518 (diff)
downloadxmlgraphics-fop-fe9c40f495aee9919b86a746dfd587069f7cc3f3.tar.gz
xmlgraphics-fop-fe9c40f495aee9919b86a746dfd587069f7cc3f3.zip
Promoting the PCL renderer from sandbox to the main source tree.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@425038 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java')
-rw-r--r--src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java119
1 files changed, 0 insertions, 119 deletions
diff --git a/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java b/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
deleted file mode 100644
index d2e91f8e6..000000000
--- a/src/sandbox/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2006 The Apache Software Foundation.
- *
- * Licensed 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.render.pcl;
-
-import java.awt.Dimension;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.render.AbstractGraphics2DAdapter;
-import org.apache.fop.render.Graphics2DImagePainter;
-import org.apache.fop.render.RendererContext;
-import org.apache.fop.util.UnitConv;
-import org.apache.xmlgraphics.java2d.GraphicContext;
-
-/**
- * Graphics2DAdapter implementation for PCL and HP GL/2.
- */
-public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter {
-
- /** logging instance */
- private static Log log = LogFactory.getLog(PCLGraphics2DAdapter.class);
-
- /**
- * Main constructor
- */
- public PCLGraphics2DAdapter() {
- }
-
- /** @see org.apache.fop.render.Graphics2DAdapter */
- public void paintImage(Graphics2DImagePainter painter,
- RendererContext context,
- int x, int y, int width, int height) throws IOException {
- PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context);
- PCLRenderer pcl = (PCLRenderer)context.getRenderer();
- PCLGenerator gen = pcl.gen;
-
- // get the 'width' and 'height' attributes of the image/document
- Dimension dim = painter.getImageSize();
- float imw = (float)dim.getWidth();
- float imh = (float)dim.getHeight();
-
- boolean painted = false;
- boolean paintAsBitmap = pclContext.paintAsBitmap();
- if (!paintAsBitmap) {
- ByteArrayOutputStream baout = new ByteArrayOutputStream();
- PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
- try {
- GraphicContext ctx = (GraphicContext)pcl.getGraphicContext().clone();
-
- AffineTransform prepareHPGL2 = new AffineTransform();
- prepareHPGL2.scale(0.001, 0.001);
- ctx.setTransform(prepareHPGL2);
-
- PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
- graphics.setGraphicContext(ctx);
- graphics.setClippingDisabled(pclContext.isClippingDisabled());
- Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(graphics, area);
-
- //If we arrive here, the graphic is natively paintable, so write the graphic
- pcl.saveGraphicsState();
- pcl.setCursorPos(x, y);
- gen.writeCommand("*c" + gen.formatDouble4(width / 100f) + "x"
- + gen.formatDouble4(height / 100f) + "Y");
- gen.writeCommand("*c0T");
- gen.enterHPGL2Mode(false);
- gen.writeText("\nIN;");
- gen.writeText("SP1;");
- //One Plotter unit is 0.025mm!
- double scale = imw / UnitConv.mm2pt(imw * 0.025);
- gen.writeText("SC0," + gen.formatDouble4(scale)
- + ",0,-" + gen.formatDouble4(scale) + ",2;");
- gen.writeText("IR0,100,0,100;");
- gen.writeText("PU;PA0,0;\n");
- baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream
- gen.writeText("\n");
-
- gen.enterPCLMode(false);
- pcl.restoreGraphicsState();
- painted = true;
- } catch (UnsupportedOperationException uoe) {
- log.debug(
- "Cannot paint graphic natively. Falling back to bitmap painting. Reason: "
- + uoe.getMessage());
- }
- }
-
- if (!painted) {
- //Fallback solution: Paint to a BufferedImage
- int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
- BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, true, false);
-
- pcl.setCursorPos(x, y);
- gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency());
- }
- }
-
-}