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.
/**
*/
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;
}
}
-/*
- ============================================================================
- 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 <jtauber@jtauber.com>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
+/* $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;
* @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
* @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;
+ }
}
-/*
- ============================================================================
- 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 <jtauber@jtauber.com>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
+/* $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;
*/
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;
+ }
+ }
}
}
/**
- * 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));
/**
- * 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));
}
/**
- * 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));
}
/**
- * 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();
}
/**
- * 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;
if (page.hasLinks()) {
....
}
- */
+ */
}
public void renderAreaContainer(AreaContainer area) {
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 +=
}
}
- // 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;
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());
}
}
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) {
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();
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) {
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();
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() {
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;
}
/**
- * 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 {
MessageHandler.errorln("AWTRenderer: renderImage(): " +
ex.getMessage());
}
- }
+ }*/
public void renderForeignObjectArea(ForeignObjectArea area) {
area.getObject().render(this);
public void displayError(String message) {
System.err.println(message);
}
-
+
/**
* Displays an error resulting from the specified Exception.
*/
* 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();
}
* @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) {
}
}
}
import org.apache.fop.svg.SVGArea;
import org.w3c.dom.svg.SVGSVGElement;
+import org.w3c.dom.svg.SVGDocument;
// Java
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);
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) {
}
// 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;
" " + yOffset / 1000f + " cm\n");
- Document doc = area.getSVGDocument();
-
UserAgent userAgent = new MUserAgent(new AffineTransform());
GVTBuilder builder = new GVTBuilder();
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(
import org.apache.fop.svg.SVGArea;
import org.w3c.dom.svg.SVGSVGElement;
+import org.w3c.dom.svg.SVGDocument;
// Java
import java.io.IOException;
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);
+++ /dev/null
-/*-- $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 <jtauber@jtauber.com>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
-
- */
-
-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);
-}
}
};
((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();
svgRoot.appendChild(text);
}
}
-
+*/
float width = ((SVGSVGElement) svgRoot).getWidth().getBaseVal().
getValue();
float height = ((SVGSVGElement) svgRoot).getHeight().getBaseVal().
/* 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);
+ }
+ }
+
+ }
}