aboutsummaryrefslogtreecommitdiffstats
path: root/src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-04-28 08:51:27 +0000
committerJeremias Maerki <jeremias@apache.org>2006-04-28 08:51:27 +0000
commite15428a90dd3e0298e30fa84aa318f527b3bbec4 (patch)
tree8ef3034ab4c1b76e331b4a682e17b7c946af9104 /src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java
parente78675dcc1066e879d99ab030bd2f5731141ce6c (diff)
downloadxmlgraphics-fop-e15428a90dd3e0298e30fa84aa318f527b3bbec4.tar.gz
xmlgraphics-fop-e15428a90dd3e0298e30fa84aa318f527b3bbec4.zip
Introduced "ignored namespaces" list on FopFactory. Attributes from ignored namespaces are not complained about. Not done for elements, yet.
Added support for foreign attributes (attributes in a non-FO namespace) on formatting objects, for example to specify additional (proprietary) hints for rendering i-f-o and e-g. First usage example is PCLRendererContext which the PCLGraphics2DAdapter uses to decide whether to paint natively using HP GL/2 or using a bitmap. PCL Renderer revived: Basic framework constructed based on the old one. Still incomplete (no border painting, incomplete Graphics2D implementation, problems with reference orientation, no kerning etc.). The PCL Renderer implements PCL5 (monochrome) and HP GL/2. Work in progress! Added UnitConv helper class which could also be useful elsewhere (Could be a candidate for Commons). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@397806 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java')
-rw-r--r--src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java b/src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java
new file mode 100644
index 000000000..2e187d482
--- /dev/null
+++ b/src/sandbox/org/apache/fop/render/pcl/PCLSVGHandler.java
@@ -0,0 +1,144 @@
+/*
+ * 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;
+
+// Java
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+// DOM
+import org.w3c.dom.Document;
+
+// Batik
+import org.apache.batik.bridge.GVTBuilder;
+import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.gvt.GraphicsNode;
+
+// FOP
+import org.apache.fop.render.Graphics2DAdapter;
+import org.apache.fop.render.Graphics2DImagePainter;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererContextConstants;
+import org.apache.fop.render.XMLHandler;
+import org.apache.fop.render.RendererContext;
+import org.apache.fop.svg.SVGUserAgent;
+
+// Commons-Logging
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * PCL XML handler for SVG. Uses Apache Batik for SVG processing.
+ * This handler handles XML for foreign objects when rendering to HP GL/2.
+ * It renders SVG to HP GL/2 using the PCLGraphics2D.
+ *
+ * @version $Id$
+ */
+public class PCLSVGHandler implements XMLHandler, RendererContextConstants {
+
+ /** logging instance */
+ private static Log log = LogFactory.getLog(PCLSVGHandler.class);
+
+ /**
+ * Create a new XML handler for use by the PCL renderer.
+ */
+ public PCLSVGHandler() {
+ }
+
+ /** @see org.apache.fop.render.XMLHandler */
+ public void handleXML(RendererContext context,
+ Document doc, String ns) throws Exception {
+ PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context);
+
+ if (SVGDOMImplementation.SVG_NAMESPACE_URI.equals(ns)) {
+ renderSVGDocument(context, doc, pclContext);
+ }
+ }
+
+ /**
+ * Render the SVG document.
+ * @param context the renderer context
+ * @param doc the SVG document
+ * @param pclContext the information of the current context
+ */
+ protected void renderSVGDocument(final RendererContext context,
+ final Document doc, final PCLRendererContext pclContext) {
+ int x = pclContext.getCurrentXPosition();
+ int y = pclContext.getCurrentYPosition();
+
+ Graphics2DImagePainter painter = new Graphics2DImagePainter() {
+
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ SVGUserAgent ua = new SVGUserAgent(
+ context.getUserAgent().getSourcePixelUnitToMillimeter(),
+ new AffineTransform());
+ GVTBuilder builder = new GVTBuilder();
+ BridgeContext ctx = new BridgeContext(ua);
+
+ GraphicsNode root;
+ try {
+ root = builder.build(ctx, doc);
+
+ // If no viewbox is defined in the svg file, a viewbox of 100x100 is
+ // assumed, as defined in SVGUserAgent.getViewportSize()
+ float iw = (float) ctx.getDocumentSize().getWidth() * 1000f;
+ float ih = (float) ctx.getDocumentSize().getHeight() * 1000f;
+ float w = (float) area.getWidth();
+ float h = (float) area.getHeight();
+ g2d.scale(w / iw, h / ih);
+
+ root.paint(g2d);
+ } catch (Exception e) {
+ log.error("SVG graphic could not be built: "
+ + e.getMessage(), e);
+ return;
+ }
+ }
+
+ public Dimension getImageSize() {
+ return new Dimension(pclContext.getWidth(), pclContext.getHeight());
+ }
+
+ };
+
+ try {
+ Graphics2DAdapter adapter = context.getRenderer().getGraphics2DAdapter();
+ adapter.paintImage(painter, context,
+ x, y, pclContext.getWidth(), pclContext.getHeight());
+ } catch (IOException ioe) {
+ ((PCLRenderer)context.getRenderer()).handleIOTrouble(ioe);
+ }
+ }
+
+ /** @see org.apache.fop.render.XMLHandler#supportsRenderer(org.apache.fop.render.Renderer) */
+ public boolean supportsRenderer(Renderer renderer) {
+ return (renderer instanceof PCLRenderer);
+ }
+
+ /** @see org.apache.fop.render.XMLHandler#getNamespace() */
+ public String getNamespace() {
+ return SVGDOMImplementation.SVG_NAMESPACE_URI;
+ }
+
+}
+