+++ /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.datatypes;
-
-import org.apache.fop.fo.Property;
-import org.apache.fop.svg.PathPoint;
-
-import java.util.*;
-
-/**
- * Parses the points information in polylines and polygons
- *
- */
-public class PointsData {
- Vector table = new Vector();
-
- public PointsData (String len)
- {
- convert(len);
- }
-
- protected void convert(String len)
- {
- // need to handle negatives
- StringTokenizer st = new StringTokenizer(len, ", \n\r\t");
- while(st.hasMoreTokens()) {
- String str1 = st.nextToken().trim();
- if(st.hasMoreTokens()) {
- String str2 = st.nextToken().trim();
- float x = 0;
- float y = 0;
- try {
- x = Float.valueOf(str1).floatValue();
- y = Float.valueOf(str2).floatValue();
- } catch(NumberFormatException nfe) {
- }
- addPoint(new PathPoint(x, y));
- }
- }
- }
-
- public Vector getPoints()
- {
- return table;
- }
-
- protected void addPoint(PathPoint pc)
- {
- table.addElement(pc);
- }
-}
-/*-- $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/>.
-
+/* $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.fo;
// FOP
* class that builds a property list for each formatting object
*/
protected Hashtable propertylistTable = new Hashtable();
-
+
/**
* current formatting object being handled
*/
protected Hashtable unknownFOs = new Hashtable();
// namespace implementation ideas pinched from John Cowan
-/* protected static class NSMap {
- String prefix;
- String uri;
- int level;
-
- NSMap(String prefix, String uri, int level) {
- this.prefix = prefix;
- this.uri = uri;
- this.level = level;
- }
- }
+ /* protected static class NSMap {
+ String prefix;
+ String uri;
+ int level;
- protected int level = 0;
- protected Stack namespaceStack = new Stack();
+ NSMap(String prefix, String uri, int level) {
+ this.prefix = prefix;
+ this.uri = uri;
+ this.level = level;
+ }
+ }
- {
- namespaceStack.push(new NSMap("xml",
- "http://www.w3.org/XML/1998/namespace",
- -1));
- namespaceStack.push(new NSMap("", "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd", -1));
- }
+ protected int level = 0;
+ protected Stack namespaceStack = new Stack();
- protected String findURI(String prefix) {
- for (int i = namespaceStack.size() - 1; i >= 0; i--) {
- NSMap nsMap = (NSMap) (namespaceStack.elementAt(i));
- if (prefix.equals(nsMap.prefix)) return nsMap.uri;
- }
- return null;
- }
+ {
+ namespaceStack.push(new NSMap("xml",
+ "http://www.w3.org/XML/1998/namespace",
+ -1));
+ namespaceStack.push(new NSMap("", "http://www.w3.org/2000/svg", -1));
+ }
+
+ protected String findURI(String prefix) {
+ for (int i = namespaceStack.size() - 1; i >= 0; i--) {
+ NSMap nsMap = (NSMap) (namespaceStack.elementAt(i));
+ if (prefix.equals(nsMap.prefix)) return nsMap.uri;
+ }
+ return null;
+ }
- protected String mapName(String name)
- throws SAXException {
- int colon = name.indexOf(':');
- String prefix = "";
- String localPart = name;
- if (colon != -1) {
- prefix = name.substring(0, colon);
- localPart = name.substring(colon + 1);
- }
- String uri = findURI(prefix);
- if (uri == null) {
- if (prefix.equals("")) {
- return "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd^" + name;
- } else {
- throw new SAXException(new FOPException("Unknown namespace prefix " + prefix));
- }
- }
- return uri + "^" + localPart;
- }*/
+ protected String mapName(String name)
+ throws SAXException {
+ int colon = name.indexOf(':');
+ String prefix = "";
+ String localPart = name;
+ if (colon != -1) {
+ prefix = name.substring(0, colon);
+ localPart = name.substring(colon + 1);
+ }
+ String uri = findURI(prefix);
+ if (uri == null) {
+ if (prefix.equals("")) {
+ return "http://www.w3.org/2000/svg^" + name;
+ } else {
+ throw new SAXException(new FOPException("Unknown namespace prefix " + prefix));
+ }
+ }
+ return uri + "^" + localPart;
+ }*/
/**
* add a mapping from element name to maker.
* @param namespaceURI namespace URI of formatting object element
* @param localName local name of formatting object element
* @param maker Maker for class representing formatting object
- */
+ */
public void addMapping(String namespaceURI, String localName,
- FObj.Maker maker) {
- this.fobjTable.put(namespaceURI + "^" + localName, maker);
+ FObj.Maker maker) {
+ this.fobjTable.put(namespaceURI + "^" + localName, maker);
}
/**
* @param namespaceURI namespace URI of formatting object element
* @param localName local name of formatting object element
* @param maker Maker for class representing formatting object
- */
+ */
public void addPropertyList(String namespaceURI, Hashtable list) {
PropertyListBuilder plb;
- plb = (PropertyListBuilder)this.propertylistTable.get(namespaceURI);
- if(plb == null) {
+ plb = (PropertyListBuilder) this.propertylistTable.get(
+ namespaceURI);
+ if (plb == null) {
plb = new PropertyListBuilder();
plb.addList(list);
this.propertylistTable.put(namespaceURI, plb);
* @param namespaceURI namespace URI of formatting object element
* @param localName local name of formatting object element
* @param maker Maker for class representing formatting object
- */
- public void addElementPropertyList(String namespaceURI, String localName, Hashtable list) {
+ */
+ public void addElementPropertyList(String namespaceURI,
+ String localName, Hashtable list) {
PropertyListBuilder plb;
- plb = (PropertyListBuilder)this.propertylistTable.get(namespaceURI);
- if(plb == null) {
+ plb = (PropertyListBuilder) this.propertylistTable.get(
+ namespaceURI);
+ if (plb == null) {
plb = new PropertyListBuilder();
plb.addElementList(localName, list);
this.propertylistTable.put(namespaceURI, plb);
/** SAX Handler for characters */
public void characters(char data[], int start, int length) {
- currentFObj.addCharacters(data, start, start + length);
+ currentFObj.addCharacters(data, start, start + length);
}
/** SAX Handler for the end of an element */
- public void endElement(
- String uri, String localName, String rawName) {
- currentFObj.end();
- currentFObj = (FObj) currentFObj.getParent();
-/* level--;
- while (((NSMap) namespaceStack.peek()).level > level) {
- namespaceStack.pop();
- }*/
+ public void endElement(String uri, String localName, String rawName) {
+ currentFObj.end();
+ currentFObj = (FObj) currentFObj.getParent();
+ /* level--;
+ while (((NSMap) namespaceStack.peek()).level > level) {
+ namespaceStack.pop();
+ }*/
}
/** SAX Handler for the start of the document */
public void startDocument() {
- MessageHandler.logln("building svg tree");
+ MessageHandler.logln("building svg tree");
}
/** SAX Handler for the start of an element */
- public void startElement(String uri,
- String localName, String rawName, Attributes attlist)
- throws SAXException {
- /* the formatting object started */
- FObj fobj;
- if(uri.equals("")) {
- uri = "http://www.w3.org/2000/svg";
- }
-
- /* the maker for the formatting object started */
- FObj.Maker fobjMaker;
-
-/* level++;
- int length = attlist.getLength();
- for (int i = 0; i < length; i++) {
- String att = attlist.getQName(i);
- if (att.equals("xmlns")) {
- namespaceStack.push( new NSMap("",
- attlist.getValue(i),
- level));
- } else if (att.startsWith("xmlns:")) {
- String value = attlist.getValue(i);
- namespaceStack.push(new NSMap(att.substring(6), value,
- level));
- }
- }*/
-
-// String fullName = mapName(rawName);
- String fullName = uri + "^" + localName;
- fobjMaker = (FObj.Maker) fobjTable.get(fullName);
- PropertyListBuilder currentListBuilder = (PropertyListBuilder)this.propertylistTable.get(uri);
-
- if (fobjMaker == null) {
- if (!this.unknownFOs.containsKey(fullName)) {
- this.unknownFOs.put(fullName, "");
- MessageHandler.errorln("WARNING: Unknown formatting object "
- + fullName);
- }
- fobjMaker = new FObjMixed.Maker(); // fall back
- }
-
- try {
- PropertyList list = null;
- if(currentListBuilder != null) {
- list = currentListBuilder.makeList(fullName, attlist,
- (currentFObj == null) ? null : currentFObj.properties, currentFObj);
- }
- fobj = fobjMaker.make(currentFObj, list);
- } catch (FOPException e) {
- throw new SAXException(e);
- }
-
- if (rootFObj == null) {
- rootFObj = fobj;
- if (!fobj.getName().equals("svg:svg")) {
- throw new SAXException(new FOPException("Root element must"
- + " be svg, not "
- + fobj.getName()));
- }
- } else {
- currentFObj.addChild(fobj);
- }
-
- currentFObj = fobj;
+ public void startElement(String uri, String localName,
+ String rawName, Attributes attlist) throws SAXException {
+ /* the formatting object started */
+ FObj fobj;
+ if (uri.equals("")) {
+ uri = "http://www.w3.org/2000/svg";
+ }
+
+ /* the maker for the formatting object started */
+ FObj.Maker fobjMaker;
+
+ /* level++;
+ int length = attlist.getLength();
+ for (int i = 0; i < length; i++) {
+ String att = attlist.getQName(i);
+ if (att.equals("xmlns")) {
+ namespaceStack.push( new NSMap("",
+ attlist.getValue(i),
+ level));
+ } else if (att.startsWith("xmlns:")) {
+ String value = attlist.getValue(i);
+ namespaceStack.push(new NSMap(att.substring(6), value,
+ level));
+ }
+ }*/
+
+ // String fullName = mapName(rawName);
+ String fullName = uri + "^" + localName;
+ fobjMaker = (FObj.Maker) fobjTable.get(fullName);
+ PropertyListBuilder currentListBuilder =
+ (PropertyListBuilder) this.propertylistTable.get(uri);
+
+ if (fobjMaker == null) {
+ if (!this.unknownFOs.containsKey(fullName)) {
+ this.unknownFOs.put(fullName, "");
+ MessageHandler.errorln(
+ "WARNING: Unknown formatting object " + fullName);
+ }
+ fobjMaker = new FObjMixed.Maker(); // fall back
+ }
+
+ try {
+ PropertyList list = null;
+ if (currentListBuilder != null) {
+ list = currentListBuilder.makeList(fullName, attlist,
+ (currentFObj == null) ? null :
+ currentFObj.properties, currentFObj);
+ }
+ fobj = fobjMaker.make(currentFObj, list);
+ } catch (FOPException e) {
+ throw new SAXException(e);
+ }
+
+ if (rootFObj == null) {
+ rootFObj = fobj;
+ if (!fobj.getName().equals("svg:svg")) {
+ throw new SAXException(
+ new FOPException("Root element must" +
+ " be svg, not " + fobj.getName()));
+ }
+ } else {
+ currentFObj.addChild(fobj);
+ }
+
+ currentFObj = fobj;
}
/**
*/
- public SVGDocument getSVGDocument()
- {
- SVGDocument doc = null;
-/* doc = new SVGDocumentImpl();
- SVGSVGElement svg = (SVGSVGElement)((org.apache.fop.svg.SVG)rootFObj).createGraphic();
- doc.appendChild(svg);*/
- return doc;
+ public SVGDocument getSVGDocument() {
+ SVGDocument doc = null;
+ /* doc = new SVGDocumentImpl();
+ SVGSVGElement svg = (SVGSVGElement)((org.apache.fop.svg.SVG)rootFObj).createGraphic();
+ doc.appendChild(svg);*/
+ return doc;
}
}
import org.apache.fop.apps.*;
import org.w3c.dom.svg.*;
+import org.w3c.dom.Document;
import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
// this.currentYPosition -= h;
- SVGDocument doc = area.getSVGDocument();
+ Document doc = area.getSVGDocument();
UserAgent userAgent = new MUserAgent(new AffineTransform());
// place at the current instream offset
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);
float sx = 1, sy = -1;
" " + yOffset / 1000f + " cm\n");
- SVGDocument doc = area.getSVGDocument();
+ Document doc = area.getSVGDocument();
UserAgent userAgent = new MUserAgent(new AffineTransform());
import org.apache.fop.layout.*;
import org.apache.fop.layout.inline.*;
import org.apache.fop.datatypes.*;
-import org.apache.fop.svg.PathPoint;
import org.apache.fop.pdf.PDFPathPaint;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.image.*;
// Add a polyline or polygon. Does not support fills yet!!!
protected void addPolyline(Vector points, int posx, int posy, PDFColor fc, PDFColor sc, float sw, boolean close)
{
- PathPoint pc;
- float lastx = 0;
- float lasty = 0;
- float curx = 0;
- float cury = 0;
- float startx = 0;
- float starty = 0;
- Enumeration e = points.elements();
- if(e.hasMoreElements())
- {
- pc = (PathPoint)e.nextElement();
- lastx = pc.x + posx / 1000;
- lasty = ((pageHeight / 10) - posy/1000) + pc.y;
- startx = lastx;
- starty = lasty;
- }
- while(e.hasMoreElements())
- {
- pc = (PathPoint)e.nextElement();
- curx = pc.x + posx / 1000;
- cury = ((pageHeight / 10) - posy/1000) + pc.y;
- addLine(lastx, lasty, curx, cury, sc, sw);
- lastx = curx;
- lasty = cury;
- }
- if(close)
- {
- addLine(lastx, lasty, startx, starty, sc, sw);
- }
}
boolean printBMP(FopImage img, int x, int y, int w, int h) throws FopImageException
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/* $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.svg;
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/* $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.svg;
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
- *****************************************************************************/
+/* $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.svg;
+++ /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;
-
-public class PathPoint {
- public float x;
- public float y;
- public PathPoint(float p1, float p2)
- {
- x = p1;
- y = p2;
- }
-}
+++ /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;
-
-// FOP
-import org.apache.fop.fo.*;
-import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.Area;
-import org.apache.fop.layout.FontState;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.layout.inline.*;
-
-import org.apache.batik.dom.svg.*;
-import org.w3c.dom.*;
-import org.w3c.dom.svg.*;
-import org.w3c.dom.svg.SVGLength;
-
-import java.io.File;
-
-/**
- * class representing svg:svg pseudo flow object.
- */
-public class SVG extends SVGObj implements GraphicsCreator {
-
- /**
- * inner class for making SVG objects.
- */
- public static class Maker extends FObj.Maker {
-
- /**
- * make an SVG object.
- *
- * @param parent the parent formatting object
- * @param propertyList the explicit properties of this object
- *
- * @return the SVG object
- */
- public FObj make(FObj parent,
- PropertyList propertyList) throws FOPException {
- return new SVG(parent, propertyList);
- }
- }
-
- /**
- * returns the maker for this object.
- *
- * @return the maker for SVG objects
- */
- public static FObj.Maker maker() {
- return new SVG.Maker();
- }
-
- FontState fs;
-
- /**
- * constructs an SVG object (called by Maker).
- *
- * @param parent the parent formatting object
- * @param propertyList the explicit properties of this object
- */
- public SVG(FObj parent, PropertyList propertyList) {
- super(parent, propertyList);
- this.name = "svg:svg";
- tagName = "svg";
- props = new String[] {"width", "height", "x", "y", "id", "style", "class", "visibility",
- "id",
- "class",
-
-
-
- "enable-background",
-
-
- "flood-color",
- "flood-opacity",
-
-
- "fill",
- "fill-opacity",
- "fill-rule",
- "stroke",
- "stroke-dasharray",
- "stroke-dashoffset",
- "stroke-linecap",
- "stroke-linejoin",
- "stroke-miterlimit",
- "stroke-opacity",
- "stroke-width",
-
-
- "font-family",
- "font-size",
- "font-size-adjust",
- "font-stretch",
- "font-style",
- "font-variant",
- "font-weight",
-
-
- "stop-color",
- "stop-opacity",
-
-
- "clip-path",
- "clip-rule",
- "color",
- "color-interpolation",
- "color-rendering",
- "cursor",
- "display",
- "filter",
- "image-rendering",
- "mask",
- "opacity",
- "pointer-events",
- "space-rendering",
- "text-rendering",
- "visibility",
-
-
- "color-profile",
-
-
- "lighting-color",
-
-
- "marker-start",
- "marker-mid",
- "marker-end",
-
-
- "alignment-baseline",
- "baseline-shift",
- "direction",
- "glyph-orientation-horizontal",
- "glyph-orientation-vertical",
- "kerning",
- "letter-spacing",
- "text-decoration",
- "unicode-bidi",
- "word-spacing",
-
-
- "writing-mode",
- "text-anchor",
- "dominant-baseline",
-
-
- "clip",
- "overflow",
-
-
- "id",
- "style",
- "transform",
- "class",
- };
- }
-
-/* public void addGraphic(Document doc, Element parent) {
- Element element = doc.createElement(tagName);
- for(int count = 0; count < props.length; count++) {
- String rf = this.properties.get(props[count]).getString();
- element.setAttribute(props[count], rf);
- }
- parent.appendChild(element);
- int numChildren = this.children.size();
- for (int i = 0; i < numChildren; i++) {
- Object child = children.elementAt(i);
- if (child instanceof GraphicsCreator) {
- ((GraphicsCreator)child).addGraphic(doc, element);
- } else if (child instanceof String) {
- org.w3c.dom.Text text = doc.createTextNode((String)child);
- element.appendChild(text);
- }
- }
- }*/
-
-/* public SVGElement createGraphic() {
- SVGSVGElementImpl svgArea = null;
- SVGLength w = ((SVGLengthProperty) this.properties.get("width")).
- getSVGLength();
- SVGLength h = ((SVGLengthProperty) this.properties.get("height")).
- getSVGLength();
- svgArea = new SVGSVGElementImpl();
- SVGAnimatedLengthImpl sal;
- if (w == null)
- w = new SVGLengthImpl();
- sal = new SVGAnimatedLengthImpl(w);
- sal.setBaseVal(w);
- svgArea.setWidth(sal);
- if (h == null)
- h = new SVGLengthImpl();
- sal = new SVGAnimatedLengthImpl(h);
- sal.setBaseVal(h);
- svgArea.setHeight(sal);
- SVGLength lengthProp =
- ((SVGLengthProperty) this.properties.get("x")).
- getSVGLength();
- SVGLength x = lengthProp == null ? new SVGLengthImpl() : lengthProp;
- sal = new SVGAnimatedLengthImpl(x);
- sal.setBaseVal(x);
- svgArea.setX(sal);
- lengthProp = ((SVGLengthProperty) this.properties.get("y")).
- getSVGLength();
- SVGLength y = lengthProp == null ? new SVGLengthImpl() : lengthProp;
- sal = new SVGAnimatedLengthImpl(y);
- sal.setBaseVal(y);
- svgArea.setY(sal);
-
- svgArea.setStyle(
- ((SVGStyle) this.properties.get("style")).getStyle());
- svgArea.setTransform(
- ((SVGTransform) this.properties.get("transform")).
- getTransform());
- svgArea.setId(this.properties.get("id").getString());
- int numChildren = this.children.size();
- for (int i = 0; i < numChildren; i++) {
- FONode fo = (FONode) children.elementAt(i);
- if (fo instanceof GraphicsCreator) {
- SVGElement impl = ((GraphicsCreator) fo).createGraphic();
- if (impl != null) {
- if (impl instanceof SVGElementImpl)
- ((SVGElementImpl) impl).setClassName(
- new SVGAnimatedStringImpl(
- ((FObj) fo).getProperty(
- "class").getString()));
- svgArea.appendChild((org.w3c.dom.Node) impl);
- }
- // } else if(fo instanceof Defs) {
- // svgArea.addDefs(((Defs)fo).createDefs());
- }
- Status status;
- }
- return svgArea;
- }*/
-
- /**
- * layout this formatting object.
- *
- * @param area the area to layout the object into
- *
- * @return the status of the layout
- */
- public Status layout(Area area) throws FOPException {
-
- if (!(area instanceof ForeignObjectArea)) {
- // this is an error
- throw new FOPException("SVG not in fo:instream-foreign-object");
- }
-
- if (this.marker == BREAK_AFTER) {
- return new Status(Status.OK);
- }
-
- if (this.marker == START) {
- /* retrieve properties */
- String id = this.properties.get("id").getString();
- String fontFamily =
- this.properties.get("font-family").getString();
- String fontStyle =
- this.properties.get("font-style").getString();
- String fontWeight =
- this.properties.get("font-weight").getString();
- String fontSz = this.properties.get("font-size").getString();
- int fontSize = area.getFontState().getFontSize();
- try {
- fontSize = Integer.parseInt(fontSz);
- } catch(Exception e) {
- }
-
- // FIX-ME: should get the font-variant property
- this.fs = new FontState(area.getFontInfo(), fontFamily,
- fontStyle, fontWeight, fontSize, FontVariant.NORMAL);
-
-// this.width = this.properties.get("width").getString();
-// this.height = this.properties.get("height").getString();
-
- this.marker = 0;
- }
-
- /* create an SVG area */
- /* if width and height are zero, may want to get the bounds of the content. */
- SVGOMDocument doc = new SVGOMDocument(null, SVGDOMImplementation.getDOMImplementation());
- try {
- 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;
- }
- };
- doc.setSVGContext(dc);
-
- Element topLevel = doc.createElementNS("http://www.w3.org/2000/svg", tagName);
- 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)
- topLevel.setAttribute(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 GraphicsCreator) {
- ((GraphicsCreator)child).addGraphic(doc, topLevel);
- } else if (child instanceof String) {
- org.w3c.dom.Text text = doc.createTextNode((String)child);
- topLevel.appendChild(text);
- }
- }
-
- float width = ((SVGSVGElement)topLevel).getWidth().getBaseVal().getValue();
- float height = ((SVGSVGElement)topLevel).getHeight().getBaseVal().getValue();
- SVGArea svg = new SVGArea(fs, width, height);
- svg.setSVGDocument(doc);
- svg.start();
-
- /* finish off the SVG area */
- svg.end();
-
- /* add the SVG area to the containing area */
- ForeignObjectArea foa = (ForeignObjectArea) area;
- foa.setObject(svg);
- foa.setIntrinsicWidth(svg.getWidth());
- foa.setIntrinsicHeight(svg.getHeight());
-
- /* return status */
- return new Status(Status.OK);
- }
-}
-/*-- $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/>.
-
+/* $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.svg;
// FOP
import org.w3c.dom.svg.*;
import org.w3c.dom.*;
-
/**
* class representing an SVG area in which the SVG graphics sit
*/
-public class SVGArea extends Area implements GetSVGDocument {
- SVGDocument doc;
-
- /**
- * construct an SVG area
- *
- * @param fontState the font state
- * @param width the width of the area
- * @param height the height of the area
- */
- public SVGArea(FontState fontState, float width, float height) {
- super(fontState, (int)width * 1000, (int)height * 1000);
- currentHeight = (int)height * 1000;
- contentRectangleWidth = (int)width * 1000;
- }
+public class SVGArea extends Area {
+ Document doc;
+
+ /**
+ * construct an SVG area
+ *
+ * @param fontState the font state
+ * @param width the width of the area
+ * @param height the height of the area
+ */
+ public SVGArea(FontState fontState, float width, float height) {
+ super(fontState, (int) width * 1000, (int) height * 1000);
+ currentHeight = (int) height * 1000;
+ contentRectangleWidth = (int) width * 1000;
+ }
- public void setSVGDocument(SVGDocument doc)
- {
- this.doc = doc;
- }
+ public void setSVGDocument(Document doc) {
+ this.doc = doc;
+ }
- public SVGDocument getSVGDocument() throws DOMException
- {
- return doc;
- }
+ public Document getSVGDocument() {
+ return doc;
+ }
- public int getWidth()
- {
-// return getSVGDocument().getRootElement().getWidth().getBaseVal().getValue();
+ public int getWidth() {
+ // return getSVGDocument().getRootElement().getWidth().getBaseVal().getValue();
return contentRectangleWidth;
}
- /**
- * render the SVG.
- *
- * @param renderer the Renderer to use
- */
- public void render(Renderer renderer) {
- renderer.renderSVGArea(this);
- }
+ /**
+ * render the SVG.
+ *
+ * @param renderer the Renderer to use
+ */
+ public void render(Renderer renderer) {
+ renderer.renderSVGArea(this);
+ }
}
-/*-- $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/>.
-
+/* $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.svg;
import java.io.IOException;
/**
- * <P>Primary class that drives overall FOP process.
- *
- * <P>Once this class is instantiated, methods are called to set the
- * Renderer to use, the (possibly multiple) ElementMapping(s) to
- * use and the PrintWriter to use to output the results of the
- * rendering (where applicable). In the case of the Renderer and
- * ElementMapping(s), the Driver may be supplied either with the
- * object itself, or the name of the class, in which case Driver will
- * instantiate the class itself. The advantage of the latter is it
- * enables runtime determination of Renderer and ElementMapping(s).
- *
- * <P>Once the Driver is set up, the buildFOTree method
- * is called. Depending on whether DOM or SAX is being used, the
- * invocation of the method is either buildFOTree(Document) or
- * buildFOTree(Parser, InputSource) respectively.
- *
- * <P>A third possibility may be used to build the FO Tree, namely
- * calling getDocumentHandler() and firing the SAX events yourself.
- *
- * <P>Once the FO Tree is built, the format() and render() methods may be
- * called in that order.
- *
- * <P>Here is an example use of Driver from CommandLine.java:
- *
- * <PRE>
- * Driver driver = new Driver();
- * driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version);
- * driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
- * driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
- * driver.setWriter(new PrintWriter(new FileWriter(args[1])));
- * driver.buildFOTree(parser, fileInputSource(args[0]));
- * driver.format();
- * driver.render();
- * </PRE>
*/
public class SVGDriver {
/** create a new Driver */
public SVGDriver() {
- this.treeBuilder = new SVGTreeBuilder();
+ this.treeBuilder = new SVGTreeBuilder();
}
-
+
/**
* add the given element mapping.
*
* an element mapping maps element names to Java classes
*/
public void addElementMapping(ElementMapping mapping) {
- mapping.addToBuilder(this.treeBuilder);
+ mapping.addToBuilder(this.treeBuilder);
}
-
+
/**
* add the element mapping with the given class name
*/
public void addElementMapping(String mappingClassName) {
- createElementMapping(mappingClassName).addToBuilder(this.treeBuilder);
+ createElementMapping(mappingClassName).addToBuilder(
+ this.treeBuilder);
}
/**
* protected method used by addElementMapping(String) to
* instantiate element mapping class
*/
- protected ElementMapping createElementMapping(String mappingClassName) {
- MessageHandler.logln("using element mapping " + mappingClassName);
-
- try {
- return (ElementMapping)
- Class.forName(mappingClassName).newInstance();
- } catch (ClassNotFoundException e) {
- MessageHandler.errorln("Could not find " + mappingClassName);
- } catch (InstantiationException e) {
- MessageHandler.errorln("Could not instantiate "
- + mappingClassName);
- } catch (IllegalAccessException e) {
- MessageHandler.errorln("Could not access " + mappingClassName);
- } catch (ClassCastException e) {
- MessageHandler.errorln(mappingClassName + " is not an element mapping");
- }
- return null;
+ protected ElementMapping createElementMapping(
+ String mappingClassName) {
+ MessageHandler.logln("using element mapping " + mappingClassName);
+
+ try {
+ return (ElementMapping) Class.forName(
+ mappingClassName).newInstance();
+ } catch (ClassNotFoundException e) {
+ MessageHandler.errorln("Could not find " + mappingClassName);
+ }
+ catch (InstantiationException e) {
+ MessageHandler.errorln("Could not instantiate " +
+ mappingClassName);
+ }
+ catch (IllegalAccessException e) {
+ MessageHandler.errorln("Could not access " + mappingClassName);
+ }
+ catch (ClassCastException e) {
+ MessageHandler.errorln(mappingClassName + " is not an element mapping");
+ }
+ return null;
}
/**
* add the element mapping with the given class name
*/
public void addPropertyList(String listClassName) {
- createPropertyList(listClassName).addToBuilder(this.treeBuilder);
+ createPropertyList(listClassName).addToBuilder(this.treeBuilder);
}
/**
* protected method used by addPropertyList(String) to
* instantiate list mapping class
*/
- protected PropertyListMapping createPropertyList(String listClassName) {
- MessageHandler.logln("using property list mapping " + listClassName);
-
- try {
- return (PropertyListMapping)
- Class.forName(listClassName).newInstance();
- } catch (ClassNotFoundException e) {
- MessageHandler.errorln("Could not find " + listClassName);
- } catch (InstantiationException e) {
- MessageHandler.errorln("Could not instantiate "
- + listClassName);
- } catch (IllegalAccessException e) {
- MessageHandler.errorln("Could not access " + listClassName);
- } catch (ClassCastException e) {
- MessageHandler.errorln(listClassName + " is not an property list");
- }
- return null;
+ protected PropertyListMapping createPropertyList(
+ String listClassName) {
+ MessageHandler.logln("using property list mapping " +
+ listClassName);
+
+ try {
+ return (PropertyListMapping) Class.forName(
+ listClassName).newInstance();
+ } catch (ClassNotFoundException e) {
+ MessageHandler.errorln("Could not find " + listClassName);
+ }
+ catch (InstantiationException e) {
+ MessageHandler.errorln("Could not instantiate " +
+ listClassName);
+ }
+ catch (IllegalAccessException e) {
+ MessageHandler.errorln("Could not access " + listClassName);
+ }
+ catch (ClassCastException e) {
+ MessageHandler.errorln(listClassName + " is not an property list");
+ }
+ return null;
}
/**
* events but isn't a SAX Parser itself.
*/
public ContentHandler getContentHandler() {
- return this.treeBuilder;
+ return this.treeBuilder;
}
/**
* build the formatting object tree using the given SAX Parser and
* SAX InputSource
*/
- public void buildSVGTree(XMLReader parser, InputSource source)
- throws FOPException {
-
- parser.setContentHandler(this.treeBuilder);
- try {
- parser.parse(source);
- } catch (SAXException e) {
-e.printStackTrace();
- if (e.getException() instanceof FOPException)
- throw (FOPException) e.getException();
- else
- throw new FOPException(e.getMessage());
- } catch (IOException e) {
- throw new FOPException(e.getMessage());
- }
+ public void buildSVGTree(XMLReader parser,
+ InputSource source) throws FOPException {
+
+ parser.setContentHandler(this.treeBuilder);
+ try {
+ parser.parse(source);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ if (e.getException() instanceof FOPException)
+ throw (FOPException) e.getException();
+ else
+ throw new FOPException(e.getMessage());
+ }
+ catch (IOException e) {
+ throw new FOPException(e.getMessage());
+ }
}
/**
* build the formatting object tree using the given DOM Document
*/
- public void buildSVGTree(Document document)
- throws FOPException {
-
- /* most of this code is modified from John Cowan's */
-
- Node currentNode;
- AttributesImpl currentAtts;
-
- /* temporary array for making Strings into character arrays */
- char[] array = null;
-
- currentAtts = new AttributesImpl();
-
- /* start at the document element */
- currentNode = document;
-
- try {
- while (currentNode != null) {
- switch (currentNode.getNodeType()) {
- case Node.DOCUMENT_NODE:
- this.treeBuilder.startDocument();
- break;
- case Node.CDATA_SECTION_NODE:
- case Node.TEXT_NODE:
- String data = currentNode.getNodeValue();
- int datalen = data.length();
- if (array == null || array.length < datalen) {
- /* if the array isn't big enough, make a new
- one */
- array = new char[datalen];
- }
- data.getChars(0, datalen, array, 0);
- this.treeBuilder.characters(array, 0, datalen);
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- this.treeBuilder.processingInstruction(
- currentNode.getNodeName(),
- currentNode.getNodeValue());
- break;
- case Node.ELEMENT_NODE:
- NamedNodeMap map = currentNode.getAttributes();
- currentAtts.clear();
- for (int i = map.getLength() - 1; i >= 0; i--) {
- Attr att = (Attr)map.item(i);
- currentAtts.addAttribute("",
- att.getName(),
- "",
- "CDATA",
- att.getValue());
- }
- this.treeBuilder.startElement(
- "", currentNode.getNodeName(), "", currentAtts);
- break;
- }
-
- Node nextNode = currentNode.getFirstChild();
- if (nextNode != null) {
- currentNode = nextNode;
- continue;
- }
-
- while (currentNode != null) {
- switch (currentNode.getNodeType()) {
- case Node.DOCUMENT_NODE:
- this.treeBuilder.endDocument();
- break;
- case Node.ELEMENT_NODE:
- this.treeBuilder.endElement(
- "", currentNode.getNodeName(), "" );
- break;
- }
-
- nextNode = currentNode.getNextSibling();
- if (nextNode != null) {
- currentNode = nextNode;
- break;
- }
-
- currentNode = currentNode.getParentNode();
- }
- }
- } catch (SAXException e) {
- throw new FOPException(e.getMessage());
- }
+ public void buildSVGTree(Document document) throws FOPException {
+
+ /* most of this code is modified from John Cowan's */
+
+ Node currentNode;
+ AttributesImpl currentAtts;
+
+ /* temporary array for making Strings into character arrays */
+ char[] array = null;
+
+ currentAtts = new AttributesImpl();
+
+ /* start at the document element */
+ currentNode = document;
+
+ try {
+ while (currentNode != null) {
+ switch (currentNode.getNodeType()) {
+ case Node.DOCUMENT_NODE:
+ this.treeBuilder.startDocument();
+ break;
+ case Node.CDATA_SECTION_NODE:
+ case Node.TEXT_NODE:
+ String data = currentNode.getNodeValue();
+ int datalen = data.length();
+ if (array == null || array.length < datalen) {
+ /* if the array isn't big enough, make a new
+ one */
+ array = new char[datalen];
+ }
+ data.getChars(0, datalen, array, 0);
+ this.treeBuilder.characters(array, 0, datalen);
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ this.treeBuilder.processingInstruction(
+ currentNode.getNodeName(),
+ currentNode.getNodeValue());
+ break;
+ case Node.ELEMENT_NODE:
+ NamedNodeMap map = currentNode.getAttributes();
+ currentAtts.clear();
+ for (int i = map.getLength() - 1; i >= 0; i--) {
+ Attr att = (Attr) map.item(i);
+ currentAtts.addAttribute("", att.getName(),
+ "", "CDATA", att.getValue());
+ }
+ this.treeBuilder.startElement("",
+ currentNode.getNodeName(), "", currentAtts);
+ break;
+ }
+
+ Node nextNode = currentNode.getFirstChild();
+ if (nextNode != null) {
+ currentNode = nextNode;
+ continue;
+ }
+
+ while (currentNode != null) {
+ switch (currentNode.getNodeType()) {
+ case Node.DOCUMENT_NODE:
+ this.treeBuilder.endDocument();
+ break;
+ case Node.ELEMENT_NODE:
+ this.treeBuilder.endElement("",
+ currentNode.getNodeName(), "");
+ break;
+ }
+
+ nextNode = currentNode.getNextSibling();
+ if (nextNode != null) {
+ currentNode = nextNode;
+ break;
+ }
+
+ currentNode = currentNode.getParentNode();
+ }
+ }
+ } catch (SAXException e) {
+ throw new FOPException(e.getMessage());
+ }
}
- public SVGDocument getSVGDocument()
- {
+ public SVGDocument getSVGDocument() {
return this.treeBuilder.getSVGDocument();
}
/**
* format the formatting object tree into an area tree
*/
- public void format()
- throws FOPException {
- FontInfo fontInfo = new FontInfo();
+ public void format() throws FOPException {
+ FontInfo fontInfo = new FontInfo();
}
}
--- /dev/null
+/* $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.svg;
+
+// FOP
+import org.apache.fop.fo.*;
+import org.apache.fop.fo.properties.*;
+import org.apache.fop.layout.Area;
+import org.apache.fop.layout.FontState;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.layout.inline.*;
+
+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;
+
+import java.io.File;
+
+/**
+ * class representing svg:svg pseudo flow object.
+ */
+public class SVGElement extends Svg {
+
+ /**
+ * inner class for making SVG objects.
+ */
+ public static class Maker extends FObj.Maker {
+
+ /**
+ * make an SVG object.
+ *
+ * @param parent the parent formatting object
+ * @param propertyList the explicit properties of this object
+ *
+ * @return the SVG object
+ */
+ public FObj make(FObj parent,
+ PropertyList propertyList) throws FOPException {
+ return new SVGElement(parent, propertyList);
+ }
+ }
+
+ /**
+ * returns the maker for this object.
+ *
+ * @return the maker for SVG objects
+ */
+ public static FObj.Maker maker() {
+ return new SVGElement.Maker();
+ }
+
+ FontState fs;
+
+ /**
+ * constructs an SVG object (called by Maker).
+ *
+ * @param parent the parent formatting object
+ * @param propertyList the explicit properties of this object
+ */
+ public SVGElement(FObj parent, PropertyList propertyList) {
+ super(parent, propertyList);
+ }
+
+ /**
+ * layout this formatting object.
+ *
+ * @param area the area to layout the object into
+ *
+ * @return the status of the layout
+ */
+ public Status layout(Area area) throws FOPException {
+
+ if (!(area instanceof ForeignObjectArea)) {
+ // this is an error
+ throw new FOPException("SVG not in fo:instream-foreign-object");
+ }
+
+ /*if (this.marker == BREAK_AFTER) {
+ return new Status(Status.OK);
+ }*/
+
+ if (this.marker == START) {
+ /* retrieve properties */
+ String id = this.properties.get("id").getString();
+ String fontFamily =
+ this.properties.get("font-family").getString();
+ String fontStyle =
+ this.properties.get("font-style").getString();
+ String fontWeight =
+ this.properties.get("font-weight").getString();
+ String fontSz = this.properties.get("font-size").getString();
+ int fontSize = area.getFontState().getFontSize();
+ try {
+ fontSize = Integer.parseInt(fontSz);
+ } catch (Exception e) {
+ }
+
+ // FIX-ME: should get the font-variant property
+ this.fs = new FontState(area.getFontInfo(), fontFamily,
+ fontStyle, fontWeight, fontSize, FontVariant.NORMAL);
+
+ // this.width = this.properties.get("width").getString();
+ // this.height = this.properties.get("height").getString();
+
+ this.marker = 0;
+ }
+
+ /* create an SVG area */
+ /* if width and height are zero, may want to get the bounds of the content. */
+
+ 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);
+
+ 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);
+ }
+ }
+
+ float width = ((SVGSVGElement) svgRoot).getWidth().getBaseVal().
+ getValue();
+ float height = ((SVGSVGElement) svgRoot).getHeight().getBaseVal().
+ getValue();
+ SVGArea svg = new SVGArea(fs, width, height);
+ svg.setSVGDocument(doc);
+ svg.start();
+
+ /* finish off the SVG area */
+ svg.end();
+
+ /* add the SVG area to the containing area */
+ ForeignObjectArea foa = (ForeignObjectArea) area;
+ foa.setObject(svg);
+ foa.setIntrinsicWidth(svg.getWidth());
+ foa.setIntrinsicHeight(svg.getHeight());
+
+ /* return status */
+ return new Status(Status.OK);
+ }
+}
-/*-- $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/>.
-
+/* $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.svg;
import org.apache.fop.fo.TreeBuilder;
public class SVGElementMapping implements ElementMapping {
- public void addToBuilder(TreeBuilder builder) {
- String uri = "http://www.w3.org/2000/svg";
- builder.addMapping(uri, "svg", SVG.maker());
- builder.addMapping(uri, "rect", Rect.maker());
- builder.addMapping(uri, "line", Line.maker());
- builder.addMapping(uri, "text", Text.maker());
+ public void addToBuilder(TreeBuilder builder) {
+ String uri = "http://www.w3.org/2000/svg";
+ builder.addMapping(uri, "svg", SVGElement.maker());
+ builder.addMapping(uri, "rect", Rect.maker());
+ builder.addMapping(uri, "line", Line.maker());
+ builder.addMapping(uri, "text", Text.maker());
- builder.addMapping(uri, "desc", Desc.maker());
- builder.addMapping(uri, "title", Title.maker());
- builder.addMapping(uri, "circle", Circle.maker());
- builder.addMapping(uri, "ellipse", Ellipse.maker());
- builder.addMapping(uri, "g", G.maker());
- builder.addMapping(uri, "polyline", Polyline.maker());
- builder.addMapping(uri, "polygon", Polygon.maker());
- builder.addMapping(uri, "defs", Defs.maker());
- builder.addMapping(uri, "path", Path.maker());
- builder.addMapping(uri, "use", Use.maker());
- builder.addMapping(uri, "tspan", Tspan.maker());
- builder.addMapping(uri, "tref", Tref.maker());
- builder.addMapping(uri, "image", Image.maker());
- builder.addMapping(uri, "style", Style.maker());
+ builder.addMapping(uri, "desc", Desc.maker());
+ builder.addMapping(uri, "title", Title.maker());
+ builder.addMapping(uri, "circle", Circle.maker());
+ builder.addMapping(uri, "ellipse", Ellipse.maker());
+ builder.addMapping(uri, "g", G.maker());
+ builder.addMapping(uri, "polyline", Polyline.maker());
+ builder.addMapping(uri, "polygon", Polygon.maker());
+ builder.addMapping(uri, "defs", Defs.maker());
+ builder.addMapping(uri, "path", Path.maker());
+ builder.addMapping(uri, "use", Use.maker());
+ builder.addMapping(uri, "tspan", Tspan.maker());
+ builder.addMapping(uri, "tref", Tref.maker());
+ builder.addMapping(uri, "image", Image.maker());
+ builder.addMapping(uri, "style", Style.maker());
-// elements in progress
- builder.addMapping(uri, "textPath", TextPath.maker());
- builder.addMapping(uri, "clipPath", ClipPath.maker());
- builder.addMapping(uri, "mask", Mask.maker());
- builder.addMapping(uri, "linearGradient", LinearGradient.maker());
- builder.addMapping(uri, "radialGradient", RadialGradient.maker());
- builder.addMapping(uri, "stop", Stop.maker());
- builder.addMapping(uri, "a", A.maker());
- builder.addMapping(uri, "switch", Switch.maker());
- builder.addMapping(uri, "symbol", Symbol.maker());
+ builder.addMapping(uri, "textPath", TextPath.maker());
+ builder.addMapping(uri, "clipPath", ClipPath.maker());
+ builder.addMapping(uri, "mask", Mask.maker());
+ builder.addMapping(uri, "linearGradient", LinearGradient.maker());
+ builder.addMapping(uri, "radialGradient", RadialGradient.maker());
+ builder.addMapping(uri, "stop", Stop.maker());
+ builder.addMapping(uri, "a", A.maker());
+ builder.addMapping(uri, "switch", Switch.maker());
+ builder.addMapping(uri, "symbol", Symbol.maker());
-// elements below will not work
- builder.addMapping(uri, "pattern", Pattern.maker());
+ builder.addMapping(uri, "pattern", Pattern.maker());
- builder.addMapping(uri, "marker", Marker.maker());
- builder.addMapping(uri, "animate", Animate.maker());
- builder.addMapping(uri, "altGlyph", AltGlyph.maker());
- builder.addMapping(uri, "font", Font.maker());
- builder.addMapping(uri, "glyph", Glyph.maker());
- builder.addMapping(uri, "missing-glyph", MissingGlyph.maker());
- builder.addMapping(uri, "hkern", Hkern.maker());
- builder.addMapping(uri, "vkern", Vkern.maker());
- builder.addMapping(uri, "set", Set.maker());
- builder.addMapping(uri, "animateMotion", AnimateMotion.maker());
- builder.addMapping(uri, "animateColor", AnimateColor.maker());
- builder.addMapping(uri, "animateTransform", AnimateTransform.maker());
- builder.addMapping(uri, "cursor", Cursor.maker());
- builder.addMapping(uri, "filter", Filter.maker());
+ builder.addMapping(uri, "marker", Marker.maker());
+ builder.addMapping(uri, "animate", Animate.maker());
+ builder.addMapping(uri, "altGlyph", AltGlyph.maker());
+ builder.addMapping(uri, "font", Font.maker());
+ builder.addMapping(uri, "glyph", Glyph.maker());
+ builder.addMapping(uri, "missing-glyph", MissingGlyph.maker());
+ builder.addMapping(uri, "hkern", Hkern.maker());
+ builder.addMapping(uri, "vkern", Vkern.maker());
+ builder.addMapping(uri, "set", Set.maker());
+ builder.addMapping(uri, "animateMotion", AnimateMotion.maker());
+ builder.addMapping(uri, "animateColor", AnimateColor.maker());
+ builder.addMapping(uri, "animateTransform",
+ AnimateTransform.maker());
+ builder.addMapping(uri, "cursor", Cursor.maker());
+ builder.addMapping(uri, "filter", Filter.maker());
- builder.addMapping(uri, "feFlood", FeFlood.maker());
- builder.addMapping(uri, "feGaussianBlur", FeGaussianBlur.maker());
- builder.addMapping(uri, "feOffset", FeOffset.maker());
- builder.addMapping(uri, "feMerge", FeMerge.maker());
- builder.addMapping(uri, "feMergeNode", FeMergeNode.maker());
- }
+ builder.addMapping(uri, "feFlood", FeFlood.maker());
+ builder.addMapping(uri, "feGaussianBlur", FeGaussianBlur.maker());
+ builder.addMapping(uri, "feOffset", FeOffset.maker());
+ builder.addMapping(uri, "feMerge", FeMerge.maker());
+ builder.addMapping(uri, "feMergeNode", FeMergeNode.maker());
+ }
}
-/*-- $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/>.
-
+/* $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.svg;
* that this element is not being layed out inside some incorrect
* element.
*/
-public abstract class SVGObj extends FObj implements GraphicsCreator {
+public abstract class SVGObj extends FObj {
- String tagName = "";
- String[] props = {};
- /**
- *
- * @param parent the parent formatting object
- * @param propertyList the explicit properties of this object
- */
- public SVGObj(FObj parent, PropertyList propertyList) {
- super(parent, propertyList);
- }
+ String tagName = "";
+ String[] props = {};
+ /**
+ *
+ * @param parent the parent formatting object
+ * @param propertyList the explicit properties of this object
+ */
+ public SVGObj(FObj parent, PropertyList propertyList) {
+ super(parent, propertyList);
+ }
protected static Hashtable ns = new Hashtable();
public void addGraphic(Document doc, Element parent) {
- Element element = doc.createElementNS("http://www.w3.org/2000/svg", tagName);
-// Element element = doc.createElement(tagName);
- for(int count = 0; count < props.length; count++) {
- if(this.properties.get(props[count]) != null) {
+ Element element = doc.createElementNS("http://www.w3.org/2000/svg",
+ tagName);
+ // Element element = doc.createElement(tagName);
+ 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) {
- if(props[count].indexOf(":") == -1) {
+ if (rf != null) {
+ if (props[count].indexOf(":") == -1) {
element.setAttribute(props[count], rf);
} else {
- String pref = props[count].substring(0, props[count].indexOf(":"));
-System.out.println(pref);
- if(pref.equals("xmlns")) {
- ns.put(props[count].substring(props[count].indexOf(":") + 1), rf);
-System.out.println(ns);
+ String pref = props[count].substring(0,
+ props[count].indexOf(":"));
+ System.out.println(pref);
+ if (pref.equals("xmlns")) {
+ ns.put(props[count].substring(
+ props[count].indexOf(":") + 1), rf);
+ System.out.println(ns);
}
ns.put("xlink", "http://www.w3.org/1999/xlink");
- element.setAttributeNS((String)ns.get(pref), props[count], rf);
+ element.setAttributeNS((String) ns.get(pref),
+ props[count], rf);
}
}
}
int numChildren = this.children.size();
for (int i = 0; i < numChildren; i++) {
Object child = children.elementAt(i);
- if (child instanceof GraphicsCreator) {
- ((GraphicsCreator)child).addGraphic(doc, element);
+ if (child instanceof SVGObj) {
+ ((SVGObj) child).addGraphic(doc, element);
} else if (child instanceof String) {
- org.w3c.dom.Text text = doc.createTextNode((String)child);
+ org.w3c.dom.Text text = doc.createTextNode((String) child);
element.appendChild(text);
}
}
}
- /**
- * layout this formatting object.
- *
- * @param area the area to layout the object into
- * @return the status of the layout
- */
- public Status layout(Area area) throws FOPException
- {
-// if (area instanceof SVGArea) {
-// } else {
- /* otherwise generate a warning */
- System.err.println("WARNING: " + this.name + " outside svg:svg");
-// }
+ /**
+ * layout this formatting object.
+ *
+ * @param area the area to layout the object into
+ * @return the status of the layout
+ */
+ public Status layout(Area area) throws FOPException {
+ /* generate a warning */
+ System.err.println("WARNING: " + this.name + " outside svg:svg");
- /* return status */
- return new Status(Status.OK);
- }
+ /* return status */
+ return new Status(Status.OK);
+ }
}
+
+++ /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;
-
-// FOP
-import org.apache.fop.fo.*;
-import org.apache.fop.datatypes.*;
-import org.apache.fop.apps.FOPException;
-
-import java.util.*;
-
-/**
- *
- */
-public class SVGPoints extends Property {
-
- /**
- * inner class for making SVG Length objects.
- */
- public static class Maker extends Property.Maker {
-
- /**
- * whether this property is inherited or not.
- *
- * @return is this inherited?
- */
- public boolean isInherited() {
- return false;
- }
-
- /**
- * make an SVG Length property with the given value.
- *
- * @param propertyList the property list this is a member of
- * @param value the explicit string value of the property
- */
- public Property make(PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- return new SVGPoints(propertyList, new PointsData(value));
- }
-
- /**
- * make an SVG Length property with the default value.
- *
- * @param propertyList the property list the property is a member of
- */
- public Property make(PropertyList propertyList)
- throws FOPException {
- return make(propertyList, "", null);
- }
- }
-
- /**
- * returns the maker for this object.
- *
- * @return the maker for SVG Length objects
- */
- public static Property.Maker maker(String propName) {
- return new SVGPoints.Maker();
- }
-
- protected PointsData style;
-
- /**
- * construct an SVG length (called by the Maker).
- *
- * @param propertyList the property list this is a member of
- * @param explicitValue the explicit value as a Length object
- */
- protected SVGPoints(PropertyList propertyList,
- PointsData explicitValue) {
- this.style = explicitValue;
- }
-
- /**
- * get the length
- *
- * @return the length as a Length object
- */
- public Vector getPoints() {
- return this.style.getPoints();
- }
-}
-/*-- $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/>.
-
+/* $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.svg;
public void addToBuilder(TreeBuilder builder) {
- String uri = "http://www.w3.org/2000/svg";
- builder.addPropertyList(uri, SVGPropertyMapping.getGenericMappings());
- /* Add any element mappings */
- for (Enumeration e = SVGPropertyMapping.getElementMappings();
- e.hasMoreElements();) {
- String elem = (String)e.nextElement();
- builder.addElementPropertyList(uri, elem,
- SVGPropertyMapping.getElementMapping(elem));
- }
+ String uri = "http://www.w3.org/2000/svg";
+ builder.addPropertyList(uri,
+ SVGPropertyMapping.getGenericMappings());
+ /* Add any element mappings */
+ for (Enumeration e = SVGPropertyMapping.getElementMappings();
+ e.hasMoreElements();) {
+ String elem = (String) e.nextElement();
+ builder.addElementPropertyList(uri, elem,
+ SVGPropertyMapping.getElementMapping(elem));
+ }
}
}
-/*-- $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/>.
-
+/* $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.svg;
import java.util.*;
import org.apache.fop.apps.FOPException;
/**
- * a class representing all the length properties in SVG
+ * a class representing all properties in SVG
*/
public class SVGStringProperty extends Property {
/**
- * inner class for making SVG Length objects.
+ * inner class for making SVG String objects.
*/
public static class Maker extends Property.Maker {
}
/**
- * make an SVG Length property with the given value.
+ * make an SVG String property with the given value.
*
* @param propertyList the property list this is a member of
* @param value the explicit string value of the property
}
/**
- * make an SVG Length property with the default value.
+ * make an SVG String property with the default value.
*
* @param propertyList the property list the property is a member of
*/
return new SVGStringProperty.Maker();
}
- /** the length as a Length object */
+ /** the value */
protected String value;
/**
- * construct an SVG length (called by the Maker).
+ * construct an SVG String (called by the Maker).
*
* @param propertyList the property list this is a member of
* @param explicitValue the explicit value as a Length object
}
/**
- * get the length
+ * get the value
*
* @return the length as a Length object
*/
+++ /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;
-
-/**
- *
- */
-public interface TextElement {
- public SVGElement createTextElement();
-}
+++ /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;
-
-// FOP
-import org.apache.fop.fo.*;
-import org.apache.fop.datatypes.*;
-import org.apache.fop.apps.FOPException;
-
-import java.util.*;
-
-/**
- *
- */
-public class TextProperty extends Property {
-
- /**
- * inner class for making SVG Length objects.
- */
- public static class Maker extends Property.Maker {
-
- /**
- * whether this property is inherited or not.
- *
- * @return is this inherited?
- */
- public boolean isInherited() {
- return false;
- }
-
- /**
- * make an SVG Length property with the given value.
- *
- * @param propertyList the property list this is a member of
- * @param value the explicit string value of the property
- */
- public Property make(PropertyList propertyList, String value,
- FObj fo) throws FOPException {
- return new TextProperty(propertyList, value);
- }
-
- /**
- * make an SVG Length property with the default value.
- *
- * @param propertyList the property list the property is a member of
- */
- public Property make(PropertyList propertyList)
- throws FOPException {
- return make(propertyList, "", null);
- }
- }
-
- /**
- * returns the maker for this object.
- *
- * @return the maker for SVG Length objects
- */
- public static Property.Maker maker() {
- return new TextProperty.Maker();
- }
-
- /** the length as a Length object */
- protected String str;
-
- /**
- * construct an SVG length (called by the Maker).
- *
- * @param propertyList the property list this is a member of
- * @param explicitValue the explicit value as a Length object
- */
- protected TextProperty(PropertyList propertyList, String s) {
- this.str = s;
- }
-
- /**
- * get the length
- *
- * @return the length as a Length object
- */
- public String getString() {
- return this.str;
- }
-}