From: Keiron Liddle Date: Thu, 17 May 2001 12:20:59 +0000 (+0000) Subject: restored support for external svg images X-Git-Tag: PRE_CODEFORMATTING~125 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7249eb425a953e8f0ad56762b16875a8404bfdeb;p=xmlgraphics-fop.git restored support for external svg images fixed a few other problems git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194254 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/SVGTreeBuilder.java b/src/org/apache/fop/fo/SVGTreeBuilder.java index d6658ff11..2b882abd0 100644 --- a/src/org/apache/fop/fo/SVGTreeBuilder.java +++ b/src/org/apache/fop/fo/SVGTreeBuilder.java @@ -20,12 +20,19 @@ import org.xml.sax.SAXException; import org.xml.sax.InputSource; import org.xml.sax.Attributes; +import org.apache.batik.dom.svg.*; +import org.w3c.dom.*; import org.w3c.dom.svg.*; +import org.w3c.dom.svg.SVGLength; + +import org.w3c.dom.DOMImplementation; +import org.apache.batik.dom.svg.SVGDOMImplementation; // Java import java.util.Hashtable; import java.util.Stack; import java.io.IOException; +import java.io.File; // NOTE: This class is here since a number of FObj methods that // are called are protected. This should probably be fixed. @@ -255,10 +262,32 @@ public class SVGTreeBuilder extends DefaultHandler implements TreeBuilder { /** */ public SVGDocument getSVGDocument() { - SVGDocument doc = null; - /* doc = new SVGDocumentImpl(); - SVGSVGElement svg = (SVGSVGElement)((org.apache.fop.svg.SVG)rootFObj).createGraphic(); - doc.appendChild(svg);*/ - return doc; + DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); + String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; + Document doc = impl.createDocument(svgNS, "svg", null); + + Element svgRoot = doc.getDocumentElement(); + + try { + ((SVGOMDocument)doc).setURLObject(new File(".").toURL()); + } catch (Exception e) { + } + + DefaultSVGContext dc = new DefaultSVGContext() { + public float getPixelToMM() { + return 0.264583333333333333333f; + // 72 dpi + } + public float getViewportWidth() { + return 100; + } + public float getViewportHeight() { + return 100; + } + }; + ((SVGOMDocument)doc).setSVGContext(dc); + ((org.apache.fop.svg.SVGElement)rootFObj).buildTopLevel(doc, svgRoot); + + return (SVGDocument)doc; } } diff --git a/src/org/apache/fop/image/SVGImage.java b/src/org/apache/fop/image/SVGImage.java index 287e6994e..b88a7b92a 100644 --- a/src/org/apache/fop/image/SVGImage.java +++ b/src/org/apache/fop/image/SVGImage.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources." */ package org.apache.fop.image; @@ -59,15 +25,16 @@ import org.xml.sax.XMLReader; * @see FopImage */ public class SVGImage extends AbstractFopImage { - SVGDocument doc; + SVGDocument doc; - public SVGImage(URL href) throws FopImageException { - super(href); - } + public SVGImage(URL href) throws FopImageException { + super(href); + } - public SVGImage(URL href, ImageReader imgReader) throws FopImageException { - super(href, imgReader); - } + public SVGImage(URL href, + ImageReader imgReader) throws FopImageException { + super(href, imgReader); + } /** * creates a SAX parser, using the value of org.xml.sax.parser @@ -76,46 +43,46 @@ public class SVGImage extends AbstractFopImage { * @return the created SAX parser */ public static XMLReader createParser() { - String parserClassName = - System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) { - parserClassName = "org.apache.xerces.parsers.SAXParser"; - } - MessageHandler.logln("using SAX parser " + parserClassName); + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + MessageHandler.logln("using SAX parser " + parserClassName); - try { - return (XMLReader) - Class.forName(parserClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + parserClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + parserClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + parserClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(parserClassName + " is not a SAX driver"); - } - return null; + try { + return (XMLReader) Class.forName( + parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + parserClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + parserClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + parserClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(parserClassName + " is not a SAX driver"); + } + return null; } - protected void loadImage() throws FopImageException { - try { - SVGDriver driver = new SVGDriver(); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); - XMLReader parser = createParser(); - driver.buildSVGTree(parser, new InputSource(this.m_href.toString())); - doc = driver.getSVGDocument(); - } catch (Exception e) { - MessageHandler.errorln("ERROR LOADING EXTERNAL SVG: " + e.getMessage()); - } - } + protected void loadImage() throws FopImageException { + try { + SVGDriver driver = new SVGDriver(); + driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); + driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); + XMLReader parser = createParser(); + driver.buildSVGTree(parser, + new InputSource(this.m_href.toString())); + doc = driver.getSVGDocument(); + } catch (Exception e) { + MessageHandler.errorln("ERROR LOADING EXTERNAL SVG: " + + e.getMessage()); + } + } - public SVGDocument getSVGDocument() throws FopImageException - { - if(doc == null) - this.loadImage(); - return doc; - } + public SVGDocument getSVGDocument() throws FopImageException { + if (doc == null) + this.loadImage(); + return doc; + } } diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index 58fa26f9d..ef4d77e97 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources." */ package org.apache.fop.image.analyser; @@ -60,41 +26,43 @@ import org.xml.sax.XMLReader; */ public class SVGReader extends AbstractImageReader { - public boolean verifySignature(BufferedInputStream fis) throws IOException { - this.imageStream = fis; - return loadImage(); - } + public boolean verifySignature(BufferedInputStream fis) + throws IOException { + this.imageStream = fis; + return loadImage(); + } - public String getMimeType() { - return "image/svg-xml"; - } + public String getMimeType() { + return "image/svg-xml"; + } - /** - * This means the external svg document will be loaded twice. - * Possibly need a slightly different design for the image stuff. - */ - protected boolean loadImage() - { - // parse document and get the size attributes of the svg element - try { - // should check the stream contains text data - SVGDriver driver = new SVGDriver(); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); - XMLReader parser = SVGImage.createParser(); - driver.buildSVGTree(parser, new InputSource(this.imageStream)); - SVGDocument doc = driver.getSVGDocument(); - SVGSVGElement svg = doc.getRootElement(); - this.width = (int)svg.getWidth().getBaseVal().getValue() * 1000; - this.height = (int)svg.getHeight().getBaseVal().getValue() * 1000; - return true; - } catch (Exception e) { - //MessageHandler.errorln("ERROR LOADING EXTERNAL SVG: " + e.getMessage()); - // assuming any exception means this document is not svg - // or could not be loaded for some reason - return false; - } - } + /** + * This means the external svg document will be loaded twice. + * Possibly need a slightly different design for the image stuff. + */ + protected boolean loadImage() { + // parse document and get the size attributes of the svg element + try { + // should check the stream contains text data + SVGDriver driver = new SVGDriver(); + driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); + driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); + XMLReader parser = SVGImage.createParser(); + driver.buildSVGTree(parser, new InputSource(this.imageStream)); + SVGDocument doc = driver.getSVGDocument(); + SVGSVGElement svg = doc.getRootElement(); + this.width = + (int) svg.getWidth().getBaseVal().getValue() * 1000; + this.height = + (int) svg.getHeight().getBaseVal().getValue() * 1000; + return true; + } catch (Exception e) { + MessageHandler.errorln("ERROR LOADING EXTERNAL SVG: " + e.getMessage()); + // assuming any exception means this document is not svg + // or could not be loaded for some reason + return false; + } + } } diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index b00d1925b..f17e4db4f 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -146,17 +146,17 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } /** - * add a line to the current stream - * - * @param x1 the start x location in millipoints - * @param y1 the start y location in millipoints - * @param x2 the end x location in millipoints - * @param y2 the end y location in millipoints - * @param th the thickness in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ + * add a line to the current stream + * + * @param x1 the start x location in millipoints + * @param y1 the start y location in millipoints + * @param x2 the end x location in millipoints + * @param y2 the end y location in millipoints + * @param th the thickness in millipoints + * @param r the red component + * @param g the green component + * @param b the blue component + */ protected void addLine(int x1, int y1, int x2, int y2, int th, float r, float g, float b) { graphics.setColor(new Color (r, g, b)); @@ -168,16 +168,16 @@ public class AWTRenderer implements Renderer, Printable, Pageable { /** - * draw a filled rectangle - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param r the red component - * @param g the green component - * @param b the blue component - */ + * draw a filled rectangle + * + * @param x the x position of left edge in millipoints + * @param y the y position of top edge in millipoints + * @param w the width in millipoints + * @param h the height in millipoints + * @param r the red component + * @param g the green component + * @param b the blue component + */ protected void addRect(int x, int y, int w, int h, float r, float g, float b) { graphics.setColor(new Color (r, g, b)); @@ -188,19 +188,19 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } /** - * draw a filled rectangle - * - * @param x the x position of left edge in millipoints - * @param y the y position of top edge in millipoints - * @param w the width in millipoints - * @param h the height in millipoints - * @param r the red component of edges - * @param g the green component of edges - * @param b the blue component of edges - * @param fr the red component of the fill - * @param fg the green component of the fill - * @param fb the blue component of the fill - */ + * draw a filled rectangle + * + * @param x the x position of left edge in millipoints + * @param y the y position of top edge in millipoints + * @param w the width in millipoints + * @param h the height in millipoints + * @param r the red component of edges + * @param g the green component of edges + * @param b the blue component of edges + * @param fr the red component of the fill + * @param fg the green component of the fill + * @param fb the blue component of the fill + */ protected void addRect(int x, int y, int w, int h, float r, float g, float b, float fr, float fg, float fb) { graphics.setColor(new Color (r, g, b)); @@ -210,12 +210,12 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } /** - * To configure before print. - * - * Choose pages - * Zoom factor - * Page format / Landscape or Portrait - **/ + * To configure before print. + * + * Choose pages + * Zoom factor + * Page format / Landscape or Portrait + **/ public void transform(Graphics2D g2d, double zoomPercent, double angle) { AffineTransform at = g2d.getTransform(); @@ -241,10 +241,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } /** - * Retrieve the number of pages in this document. - * - * @return the number of pages - */ + * Retrieve the number of pages in this document. + * + * @return the number of pages + */ public int getPageCount() { if (tree == null) { return 0; @@ -319,7 +319,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { if (page.hasLinks()) { .... } - */ + */ } public void renderAreaContainer(AreaContainer area) { @@ -336,11 +336,11 @@ public class AWTRenderer implements Renderer, Printable, Pageable { 2 * area.getBorderTopWidth(); this.currentAreaContainerXPosition = area.getXPosition(); } else if (area.getPosition() == - org.apache.fop.fo.properties.Position.RELATIVE) { + org.apache.fop.fo.properties.Position.RELATIVE) { this.currentYPosition -= area.getYPosition(); this.currentAreaContainerXPosition += area.getXPosition(); } else if (area.getPosition() == - org.apache.fop.fo.properties.Position.STATIC) { + org.apache.fop.fo.properties.Position.STATIC) { this.currentYPosition -= area.getPaddingTop() + area.getBorderTopWidth(); this.currentAreaContainerXPosition += @@ -365,27 +365,30 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } } - // empty for now - public void renderBodyAreaContainer(BodyAreaContainer area) { - renderAreaContainer(area.getBeforeFloatReferenceArea()); - renderAreaContainer(area.getFootnoteReferenceArea()); - - // main reference area - Enumeration e = area.getMainReferenceArea().getChildren().elements(); - while (e.hasMoreElements()) { - org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); - b.render(this); // span areas - } - } - - // empty for now - public void renderSpanArea(SpanArea area) { - Enumeration e = area.getChildren().elements(); - while (e.hasMoreElements()) { - org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); - b.render(this); // column areas - } - } + // empty for now + public void renderBodyAreaContainer(BodyAreaContainer area) { + renderAreaContainer(area.getBeforeFloatReferenceArea()); + renderAreaContainer(area.getFootnoteReferenceArea()); + + // main reference area + Enumeration e = + area.getMainReferenceArea().getChildren().elements(); + while (e.hasMoreElements()) { + org.apache.fop.layout.Box b = + (org.apache.fop.layout.Box) e.nextElement(); + b.render(this); // span areas + } + } + + // empty for now + public void renderSpanArea(SpanArea area) { + Enumeration e = area.getChildren().elements(); + while (e.hasMoreElements()) { + org.apache.fop.layout.Box b = + (org.apache.fop.layout.Box) e.nextElement(); + b.render(this); // column areas + } + } private void doFrame(org.apache.fop.layout.Area area) { int w, h; @@ -417,31 +420,35 @@ public class AWTRenderer implements Renderer, Printable, Pageable { w = w + area.getBorderLeftWidth() + area.getBorderRightWidth(); h = h + area.getBorderTopWidth() + area.getBorderBottomWidth(); - BorderAndPadding bp = area.getBorderAndPadding(); - ColorType borderColor; + BorderAndPadding bp = area.getBorderAndPadding(); + ColorType borderColor; if (area.getBorderTopWidth() != 0) { - borderColor=bp.getBorderColor(BorderAndPadding.TOP); - addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(), - borderColor.red(), borderColor.green(), borderColor.blue()); + borderColor = bp.getBorderColor(BorderAndPadding.TOP); + addLine(rx, ry, rx + w, ry, area.getBorderTopWidth(), + borderColor.red(), borderColor.green(), + borderColor.blue()); } if (area.getBorderLeftWidth() != 0) { - borderColor=bp.getBorderColor(BorderAndPadding.LEFT); + borderColor = bp.getBorderColor(BorderAndPadding.LEFT); addLine(rx, ry, rx, ry - h, area.getBorderLeftWidth(), - borderColor.red(), borderColor.green(), borderColor.blue()); + borderColor.red(), borderColor.green(), + borderColor.blue()); } if (area.getBorderRightWidth() != 0) { - borderColor=bp.getBorderColor(BorderAndPadding.RIGHT); - addLine(rx + w, ry, rx + w, ry - h, area.getBorderRightWidth(), - borderColor.red(), borderColor.green(), borderColor.blue()); + borderColor = bp.getBorderColor(BorderAndPadding.RIGHT); + addLine(rx + w, ry, rx + w, ry - h, + area.getBorderRightWidth(), borderColor.red(), + borderColor.green(), borderColor.blue()); } if (area.getBorderBottomWidth() != 0) { - borderColor=bp.getBorderColor(BorderAndPadding.BOTTOM); - addLine(rx, ry - h, rx + w, ry - h, area.getBorderBottomWidth(), - borderColor.red(), borderColor.green(), borderColor.blue()); + borderColor = bp.getBorderColor(BorderAndPadding.BOTTOM); + addLine(rx, ry - h, rx + w, ry - h, + area.getBorderBottomWidth(), borderColor.red(), + borderColor.green(), borderColor.blue()); } } @@ -474,80 +481,51 @@ public class AWTRenderer implements Renderer, Printable, Pageable { public void renderImageArea(ImageArea area) { - int x = currentAreaContainerXPosition + - area.getXOffset(); - + int x = currentAreaContainerXPosition + area.getXOffset(); int y = currentYPosition; - int w = area.getContentWidth(); - int h = area.getHeight(); - - FopImage img = area.getImage(); - - if (img == null) { - MessageHandler.logln("Error while loading image : area.getImage() is null"); - - graphics.drawRect(x / 1000, - pageHeight - y / 1000, - w / 1000, - h / 1000); - + graphics.drawRect(x / 1000, pageHeight - y / 1000, + w / 1000, h / 1000); java.awt.Font f = graphics.getFont(); - java.awt.Font smallFont = new java.awt.Font(f.getFontName(), f.getStyle(), 8); - graphics.setFont(smallFont); - graphics.drawString("area.getImage() is null", x / 1000, pageHeight - y / 1000); - graphics.setFont(f); - } else { + if (img instanceof SVGImage) { + try { + SVGDocument svg = ((SVGImage) img).getSVGDocument(); + renderSVGDocument(svg, (int) x, (int) y); + } catch (FopImageException e) { + } + } else { + String urlString = img.getURL(); + try { + URL url = new URL(urlString); + ImageIcon icon = new ImageIcon(url); + Image image = icon.getImage(); - String urlString = img.getURL(); - - try { - - URL url = new URL(urlString); - - - - ImageIcon icon = new ImageIcon(url); - - Image image = icon.getImage(); - - - - graphics.drawImage(image, x / 1000, - pageHeight - y / 1000, - w / 1000, - h / 1000, - null); - - } catch (MalformedURLException mue) { - - // cannot normally occur because, if URL is wrong, constructing FopImage - - // will already have failed earlier on - + graphics.drawImage(image, x / 1000, + pageHeight - y / 1000, w / 1000, h / 1000, + null); + } catch (MalformedURLException mue) { + // cannot normally occur because, if URL is wrong, constructing FopImage + // will already have failed earlier on + } } - } - - currentYPosition -= h; - } public void renderWordArea(WordArea area) { @@ -636,9 +614,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { Enumeration e = area.getChildren().elements(); while (e.hasMoreElements()) { - org.apache.fop.layout.Box b = (org.apache.fop.layout.Box) e.nextElement(); - if(b instanceof InlineArea) { - InlineArea ia = (InlineArea)b; + org.apache.fop.layout.Box b = + (org.apache.fop.layout.Box) e.nextElement(); + if (b instanceof InlineArea) { + InlineArea ia = (InlineArea) b; this.currentYPosition = ry - ia.getYOffset(); } else { this.currentYPosition = ry - area.getPlacementOffset(); @@ -649,30 +628,31 @@ public class AWTRenderer implements Renderer, Printable, Pageable { this.currentYPosition = ry - h; } - /** - * render leader area into AWT - * - * @param area area to render - */ - public void renderLeaderArea(LeaderArea area) { - - int rx = this.currentXPosition; - int ry = this.currentYPosition; - int w = area.getLeaderLength(); - int h = area.getHeight(); - int th = area.getRuleThickness(); - int st = area.getRuleStyle(); //not used at the moment - float r = area.getRed(); - float g = area.getGreen(); - float b = area.getBlue(); - Color oldColor = graphics.getColor(); - - graphics.setColor(new Color(r, g, b)); - graphics.fillRect((int)(rx / 1000f), (int)(pageHeight - ry / 1000f), - (int)(w / 1000f), (int)(th / 1000f)); - graphics.setColor(oldColor); - this.currentXPosition += area.getContentWidth(); - } + /** + * render leader area into AWT + * + * @param area area to render + */ + public void renderLeaderArea(LeaderArea area) { + + int rx = this.currentXPosition; + int ry = this.currentYPosition; + int w = area.getLeaderLength(); + int h = area.getHeight(); + int th = area.getRuleThickness(); + int st = area.getRuleStyle(); //not used at the moment + float r = area.getRed(); + float g = area.getGreen(); + float b = area.getBlue(); + Color oldColor = graphics.getColor(); + + graphics.setColor(new Color(r, g, b)); + graphics.fillRect((int)(rx / 1000f), + (int)(pageHeight - ry / 1000f), (int)(w / 1000f), + (int)(th / 1000f)); + graphics.setColor(oldColor); + this.currentXPosition += area.getContentWidth(); + } public void renderSVGArea(SVGArea area) { @@ -681,10 +661,12 @@ public class AWTRenderer implements Renderer, Printable, Pageable { int w = area.getContentWidth(); int h = area.getHeight(); -// this.currentYPosition -= h; - Document doc = area.getSVGDocument(); + renderSVGDocument(doc, x, y); + this.currentXPosition += area.getContentWidth(); + } + protected void renderSVGDocument(Document doc, int x, int y) { UserAgent userAgent = new MUserAgent(new AffineTransform()); GVTBuilder builder = new GVTBuilder(); @@ -696,12 +678,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { try { root = builder.build(ctx, doc); root.paint(graphics, rc); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } graphics.translate(-x / 1000f, y / 1000f - pageHeight); - this.currentXPosition += area.getContentWidth(); - } public GraphicsNodeRenderContext getRenderContext() { @@ -709,27 +689,24 @@ public class AWTRenderer implements Renderer, Printable, Pageable { if (nodeRenderContext == null) { RenderingHints hints = new RenderingHints(null); hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BILINEAR); + RenderingHints.VALUE_INTERPOLATION_BILINEAR); FontRenderContext fontRenderContext = - new FontRenderContext(new AffineTransform(), true, true); + new FontRenderContext(new AffineTransform(), true, + true); TextPainter textPainter = new StrokingTextPainter(); GraphicsNodeRableFactory gnrFactory = - new ConcreteGraphicsNodeRableFactory(); - - nodeRenderContext = - new GraphicsNodeRenderContext(new AffineTransform(), - null, - hints, - fontRenderContext, - textPainter, - gnrFactory); - } + new ConcreteGraphicsNodeRableFactory(); + + nodeRenderContext = new GraphicsNodeRenderContext( + new AffineTransform(), null, hints, + fontRenderContext, textPainter, gnrFactory); + } return nodeRenderContext; } @@ -794,10 +771,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { /** - * Draws an image. - * TODO: protect other image formats (JIMI) - */ - public void renderImage(String href, float x, float y, float width, + * Draws an image. + * TODO: protect other image formats (JIMI) + */ +/* public void renderImage(String href, float x, float y, float width, float height, Vector transform) { // What is with transformations? try { @@ -831,7 +808,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { MessageHandler.errorln("AWTRenderer: renderImage(): " + ex.getMessage()); } - } + }*/ public void renderForeignObjectArea(ForeignObjectArea area) { area.getObject().render(this); @@ -852,7 +829,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { public void displayError(String message) { System.err.println(message); } - + /** * Displays an error resulting from the specified Exception. */ @@ -894,11 +871,10 @@ public class AWTRenderer implements Renderer, Printable, Pageable { * Returns the class name of the XML parser. */ public String getXMLParserClassName() { - String parserClassName = - System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) { - parserClassName = "org.apache.xerces.parsers.SAXParser"; - } + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } return parserClassName;//application.getXMLParserClassName(); } @@ -907,47 +883,38 @@ public class AWTRenderer implements Renderer, Printable, Pageable { * @param doc The current document. * @param uri The document URI. */ - public void openLink(SVGAElement elt) - { + public void openLink(SVGAElement elt) { //application.openLink(uri); } - public Point getClientAreaLocationOnScreen() - { + public Point getClientAreaLocationOnScreen() { return new Point(0, 0); } - public void setSVGCursor(java.awt.Cursor cursor) - { + public void setSVGCursor(java.awt.Cursor cursor) { } - public AffineTransform getTransform() - { + public AffineTransform getTransform() { return currentTransform; } - public Dimension2D getViewportSize() - { + public Dimension2D getViewportSize() { return new Dimension(100, 100); } - public EventDispatcher getEventDispatcher() - { + public EventDispatcher getEventDispatcher() { return null; } - public boolean supportExtension(String str) - { + public boolean supportExtension(String str) { return false; } - public boolean hasFeature(String str) - { - return false; + public boolean hasFeature(String str) { + return false; } - public void registerExtension(BridgeExtension be) - { + public void registerExtension(BridgeExtension be) { } } } diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index e3f3972db..59edf404c 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -23,6 +23,7 @@ import org.apache.fop.image.*; import org.apache.fop.svg.SVGArea; import org.w3c.dom.svg.SVGSVGElement; +import org.w3c.dom.svg.SVGDocument; // Java @@ -526,7 +527,7 @@ if ( debug ) System.out.println("PCLRenderer.renderSVGArea(" + area + ")"); int x = this.currentXPosition; int y = this.currentYPosition; - SVGSVGElement svg = area.getSVGDocument().getRootElement(); + SVGSVGElement svg = ((SVGDocument)area.getSVGDocument()).getRootElement(); int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index b49a05c6b..5087bbc84 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -235,13 +235,10 @@ public class PDFRenderer extends PrintRenderer { try { closeText(); - SVGSVGElement svg = - ((SVGImage) img).getSVGDocument().getRootElement(); - currentStream.add("ET\nq\n" + (((float) w) / 1000f) + - " 0 0 " + (((float) h) / 1000f) + " " + - (((float) x) / 1000f) + " " + - (((float)(y - h)) / 1000f) + " cm\n"); - // renderSVG(svg, (int) x, (int) y); + SVGDocument svg = + ((SVGImage) img).getSVGDocument(); + currentStream.add("ET\nq\n"); + renderSVGDocument(svg, (int) x, (int) y, area.getFontState()); currentStream.add("Q\nBT\n"); } catch (FopImageException e) { } @@ -329,7 +326,11 @@ public class PDFRenderer extends PrintRenderer { // place at the current instream offset int x = this.currentXPosition; int y = this.currentYPosition; - SVGSVGElement svg = ((SVGDocument)area.getSVGDocument()).getRootElement(); + renderSVGDocument(area.getSVGDocument(), x, y, area.getFontState()); + } + + protected void renderSVGDocument(Document doc, int x, int y, FontState fs) { + SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); float sx = 1, sy = -1; @@ -358,8 +359,6 @@ public class PDFRenderer extends PrintRenderer { " " + yOffset / 1000f + " cm\n"); - Document doc = area.getSVGDocument(); - UserAgent userAgent = new MUserAgent(new AffineTransform()); GVTBuilder builder = new GVTBuilder(); @@ -368,7 +367,7 @@ public class PDFRenderer extends PrintRenderer { GraphicsNode root; //System.out.println("creating PDFGraphics2D"); PDFGraphics2D graphics = - new PDFGraphics2D(true, area.getFontState(), pdfDoc, + new PDFGraphics2D(true, fs, pdfDoc, currentFontName, currentFontSize, currentXPosition, currentYPosition); graphics.setGraphicContext( diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index b1c5978c5..61d2b4a4c 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -23,6 +23,7 @@ import org.apache.fop.image.*; import org.apache.fop.svg.SVGArea; import org.w3c.dom.svg.SVGSVGElement; +import org.w3c.dom.svg.SVGDocument; // Java import java.io.IOException; @@ -956,7 +957,7 @@ if ( debug ) System.out.println("TXTRenderer.renderSVGArea(" + area + ")"); int x = this.currentAreaContainerXPosition; int y = this.currentYPosition; - SVGSVGElement svg = area.getSVGDocument().getRootElement(); + SVGSVGElement svg = ((SVGDocument)area.getSVGDocument()).getRootElement(); int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); diff --git a/src/org/apache/fop/svg/GraphicsCreator.java b/src/org/apache/fop/svg/GraphicsCreator.java deleted file mode 100644 index 295a80006..000000000 --- a/src/org/apache/fop/svg/GraphicsCreator.java +++ /dev/null @@ -1,62 +0,0 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . - - */ - -package org.apache.fop.svg; - -import org.w3c.dom.svg.SVGElement; -import org.w3c.dom.*; - -/** - * - */ -public interface GraphicsCreator { - public void addGraphic(Document doc, Element parent); -} diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index 4f6eadc02..4939eab8d 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -140,7 +140,8 @@ public class SVGElement extends Svg { } }; ((SVGOMDocument)doc).setSVGContext(dc); - + buildTopLevel(doc, svgRoot); +/* for (int count = 0; count < props.length; count++) { if (this.properties.get(props[count]) != null) { String rf = this.properties.get(props[count]).getString(); @@ -159,7 +160,7 @@ public class SVGElement extends Svg { svgRoot.appendChild(text); } } - +*/ float width = ((SVGSVGElement) svgRoot).getWidth().getBaseVal(). getValue(); float height = ((SVGSVGElement) svgRoot).getHeight().getBaseVal(). @@ -180,4 +181,28 @@ public class SVGElement extends Svg { /* return status */ return new Status(Status.OK); } + + public void buildTopLevel(Document doc, Element svgRoot) + { + // build up the info for the top level element + for (int count = 0; count < props.length; count++) { + if (this.properties.get(props[count]) != null) { + String rf = this.properties.get(props[count]).getString(); + if (rf != null) + svgRoot.setAttributeNS(null, props[count], rf); + } + } + //doc.appendChild(topLevel); + int numChildren = this.children.size(); + for (int i = 0; i < numChildren; i++) { + Object child = children.elementAt(i); + if (child instanceof SVGObj) { + ((SVGObj) child).addGraphic(doc, svgRoot); + } else if (child instanceof String) { + org.w3c.dom.Text text = doc.createTextNode((String) child); + svgRoot.appendChild(text); + } + } + + } }