From 53ff53db6bf1f50b648e5df2a8d256957d2fcbbd Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Mon, 4 Sep 2000 00:51:52 +0000 Subject: [PATCH] changes for the text elements, character data, tspan etc. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193684 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/dom/CharacterDataImpl.java | 114 ++++++ .../apache/fop/dom/{svg => }/ElementImpl.java | 35 +- src/org/apache/fop/dom/NodeImpl.java | 325 ++++++++++++++++++ .../dom/svg/SVGAnimatedLengthListImpl.java | 79 +++++ .../apache/fop/dom/svg/SVGDocumentImpl.java | 29 ++ .../apache/fop/dom/svg/SVGElementImpl.java | 9 + .../apache/fop/dom/svg/SVGLengthListImpl.java | 21 +- .../fop/dom/svg/SVGTSpanElementImpl.java | 18 +- 8 files changed, 592 insertions(+), 38 deletions(-) create mode 100644 src/org/apache/fop/dom/CharacterDataImpl.java rename src/org/apache/fop/dom/{svg => }/ElementImpl.java (91%) create mode 100644 src/org/apache/fop/dom/NodeImpl.java create mode 100644 src/org/apache/fop/dom/svg/SVGAnimatedLengthListImpl.java diff --git a/src/org/apache/fop/dom/CharacterDataImpl.java b/src/org/apache/fop/dom/CharacterDataImpl.java new file mode 100644 index 000000000..ed7d39e68 --- /dev/null +++ b/src/org/apache/fop/dom/CharacterDataImpl.java @@ -0,0 +1,114 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ + +package org.apache.fop.dom; + +import org.apache.fop.datatypes.*; +import org.apache.fop.messaging.*; +import org.apache.fop.dom.svg.*; + +import org.w3c.dom.*; + +import java.util.*; + +/** + * + * + */ +public class CharacterDataImpl extends NodeImpl implements CharacterData { + String str; + + public CharacterDataImpl() + { + } + + public String getData() + { + return str; + } + + public void setData(String s) + { + str = s; + } + + public void insertData(int i, String s) + { + } + + public void deleteData(int i, int j) + { + } + + public int getLength() + { + return str.length(); + } + + public void appendData(String s) + { + str = str + s; + } + + public void replaceData(int i, int j, String s) + { + } + + public String substringData(int i, int j) + { + return str.substring(i, j); + } + + public String toString() + { + return "Character Data: " + str; + } +} diff --git a/src/org/apache/fop/dom/svg/ElementImpl.java b/src/org/apache/fop/dom/ElementImpl.java similarity index 91% rename from src/org/apache/fop/dom/svg/ElementImpl.java rename to src/org/apache/fop/dom/ElementImpl.java index 2b07216a1..72f912c1a 100644 --- a/src/org/apache/fop/dom/svg/ElementImpl.java +++ b/src/org/apache/fop/dom/ElementImpl.java @@ -48,7 +48,7 @@ Software Foundation, please see . */ -package org.apache.fop.dom.svg; +package org.apache.fop.dom; import org.apache.fop.datatypes.*; @@ -60,16 +60,17 @@ import java.util.*; * * */ -public class ElementImpl implements Element { - Vector childs = new Vector(); - Node parent = null; +public class ElementImpl extends NodeImpl implements Element { +// Vector childs = new Vector(); +// Node parent = null; +// Document ownerDoc; public Node replaceChild(Node n, Node no) { return null; } - public String getNodeName() +/* public String getNodeName() { return null; } @@ -116,9 +117,21 @@ public class ElementImpl implements Element { public Document getOwnerDocument() { - return null; + return ownerDoc; } + void setOwnerDocument(Document doc) + { + ownerDoc = doc; + NodeList nl = getChildNodes(); + for(int count = 0; count < nl.getLength(); count++) { + Node n = nl.item(count); + if(n instanceof ElementImpl) { + ((ElementImpl)n).setOwnerDocument(ownerDoc); + } + } + } + public Node insertBefore(Node newChild, Node refChild) throws DOMException @@ -137,7 +150,9 @@ public class ElementImpl implements Element { { childs.addElement(newChild); if(newChild instanceof ElementImpl) { - ((ElementImpl)newChild).parent = this; + ElementImpl ele = (ElementImpl)newChild; + ele.parent = this; + ele.setOwnerDocument(ownerDoc); } return newChild; } @@ -194,7 +209,7 @@ public class ElementImpl implements Element { { return null; } - +*/ public String getAttribute(String name) { return null; @@ -283,7 +298,7 @@ public class ElementImpl implements Element { return false; } } - +/* class NodeListImpl implements NodeList { Vector vect = null; @@ -302,4 +317,4 @@ class NodeListImpl implements NodeList { return (Node)vect.elementAt(i); } -} +}*/ diff --git a/src/org/apache/fop/dom/NodeImpl.java b/src/org/apache/fop/dom/NodeImpl.java new file mode 100644 index 000000000..f8fe16c97 --- /dev/null +++ b/src/org/apache/fop/dom/NodeImpl.java @@ -0,0 +1,325 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.dom; + +import org.apache.fop.datatypes.*; + +import org.w3c.dom.*; + +import java.util.*; + +/** + * + * + */ +public class NodeImpl implements Node { + protected Vector childs = new Vector(); + Node parent = null; + protected Document ownerDoc; + + public Node replaceChild(Node n, Node no) + { + return null; + } + + public String getNodeName() + { + return null; + } + + public short getNodeType() + { + return 0; + } + + public Node getParentNode() + { + return parent; + } + + public NodeList getChildNodes() + { + return new NodeListImpl(childs); + } + + public Node getFirstChild() + { + return null; + } + + public Node getLastChild() + { + return null; + } + + public Node getPreviousSibling() + { + return null; + } + + public Node getNextSibling() + { + return null; + } + + public NamedNodeMap getAttributes() + { + return null; + } + + public Document getOwnerDocument() + { + return ownerDoc; + } + + void setOwnerDocument(Document doc) + { + ownerDoc = doc; + NodeList nl = getChildNodes(); + for(int count = 0; count < nl.getLength(); count++) { + Node n = nl.item(count); + if(n instanceof ElementImpl) { + ((ElementImpl)n).setOwnerDocument(ownerDoc); + } + } + } + + public Node insertBefore(Node newChild, + Node refChild) + throws DOMException + { + return null; + } + + public Node removeChild(Node oldChild) + throws DOMException + { + return null; + } + + public Node appendChild(Node newChild) + throws DOMException + { + childs.addElement(newChild); + if(newChild instanceof ElementImpl) { + ElementImpl ele = (ElementImpl)newChild; + ele.parent = this; + ele.setOwnerDocument(ownerDoc); + } + return newChild; + } + + public boolean hasChildNodes() + { + return childs.size() > 0; + } + + public Node cloneNode(boolean deep) + { + return null; + } + + public void normalize() + { + } + + public boolean supports(String feature, + String version) + { + return false; + } + + public String getNamespaceURI() + { + return ""; + } + + public String getPrefix() + { + return "svg"; + } + + public void setPrefix(String prefix) throws DOMException + { + } + + public String getLocalName() + { + return null; + } + + public String getNodeValue() throws DOMException + { + return null; + } + + public void setNodeValue(String nodeValue) throws DOMException + { + } + + public String getTagName() + { + return null; + } + +/* public String getAttribute(String name) + { + return null; + } + + public void setAttribute(String name, String value) throws DOMException + { + } + + public void removeAttribute(String name) throws DOMException + { + } + + public Attr getAttributeNode(String name) + { + return null; + } + + public Attr setAttributeNode(Attr newAttr) + throws DOMException + { + return null; + } + + public Attr removeAttributeNode(Attr oldAttr) + throws DOMException + { + return null; + } + + public NodeList getElementsByTagName(String name) + { + return null; + } + + public String getAttributeNS(String namespaceURI, + String localName) + { + return null; + } + + public void setAttributeNS(String namespaceURI, + String qualifiedName, + String value) + throws DOMException + { + } + + public void removeAttributeNS(String namespaceURI, + String localName) + throws DOMException + { + } + + public Attr getAttributeNodeNS(String namespaceURI, + String localName) + { + return null; + } + + public Attr setAttributeNodeNS(Attr newAttr) + throws DOMException + { + return null; + } + + public NodeList getElementsByTagNameNS(String namespaceURI, + String localName) + { + return null; + } + + public boolean hasAttributeNS (String namespaceURI, + String localName) + { + return false; + } + + public boolean hasAttribute (String name) + { + return false; + } +*/ + public boolean hasAttributes() + { + return false; + } +} + +class NodeListImpl implements NodeList +{ + Vector vect = null; + + NodeListImpl(Vector v) + { + vect = v; + } + + public int getLength() + { + return vect.size(); + } + + public Node item(int i) + { + return (Node)vect.elementAt(i); + } + + public String toString() + { + return vect.toString(); + } +} diff --git a/src/org/apache/fop/dom/svg/SVGAnimatedLengthListImpl.java b/src/org/apache/fop/dom/svg/SVGAnimatedLengthListImpl.java new file mode 100644 index 000000000..0c1feb8fa --- /dev/null +++ b/src/org/apache/fop/dom/svg/SVGAnimatedLengthListImpl.java @@ -0,0 +1,79 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Fop" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ +package org.apache.fop.dom.svg; + +import org.w3c.dom.svg.*; + +/** + * a length quantity in XSL + */ +public class SVGAnimatedLengthListImpl extends SVGListImpl implements SVGAnimatedLengthList { + SVGLengthList baseVal; + + public SVGAnimatedLengthListImpl() + { + } + + public SVGLengthList getBaseVal( ) + { + return baseVal; + } + + public void setBaseVal(SVGLengthList baseVal) + { + this.baseVal = baseVal; + } + + public SVGLengthList getAnimVal( ) + { + return baseVal; + } +} diff --git a/src/org/apache/fop/dom/svg/SVGDocumentImpl.java b/src/org/apache/fop/dom/svg/SVGDocumentImpl.java index 4f0f77671..15b5589b1 100644 --- a/src/org/apache/fop/dom/svg/SVGDocumentImpl.java +++ b/src/org/apache/fop/dom/svg/SVGDocumentImpl.java @@ -52,6 +52,8 @@ package org.apache.fop.dom.svg; import java.util.*; +import org.apache.fop.dom.ElementImpl; + import org.w3c.dom.svg.*; import org.w3c.dom.*; import org.w3c.dom.events.*; @@ -65,6 +67,7 @@ public class SVGDocumentImpl extends ElementImpl implements SVGDocument { public SVGDocumentImpl() { + ownerDoc = this; } public String getTitle() @@ -77,6 +80,11 @@ public class SVGDocumentImpl extends ElementImpl implements SVGDocument { this.title = title; } + public String getNamespaceURI() + { + return namespaceURI; + } + public String getReferrer() { return null; @@ -99,6 +107,27 @@ public class SVGDocumentImpl extends ElementImpl implements SVGDocument { public Element getElementById(String elementId) { + SVGSVGElement svg = getRootElement(); + return findChild(svg, elementId); + } + + protected Element findChild(Node ele, String id) + { + NodeList nl = ele.getChildNodes(); + for(int count = 0; count < nl.getLength(); count++) { + Node n = nl.item(count); + if(n instanceof SVGElement) { + if(id.equals(((SVGElement)n).getId())) { + return (Element)n; + } + } + if(n != null) { + Element el = findChild(n, id); + if(el != null) { + return el; + } + } + } return null; } diff --git a/src/org/apache/fop/dom/svg/SVGElementImpl.java b/src/org/apache/fop/dom/svg/SVGElementImpl.java index e8b157b2b..a1c697b19 100644 --- a/src/org/apache/fop/dom/svg/SVGElementImpl.java +++ b/src/org/apache/fop/dom/svg/SVGElementImpl.java @@ -51,6 +51,7 @@ package org.apache.fop.dom.svg; import org.apache.fop.datatypes.*; +import org.apache.fop.dom.ElementImpl; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSValue; @@ -68,6 +69,11 @@ public abstract class SVGElementImpl extends ElementImpl implements SVGElement { return idString; } + public String getNamespaceURI() + { + return SVGDocumentImpl.namespaceURI; + } + public void setId(String id) { idString = id; @@ -96,6 +102,9 @@ public abstract class SVGElementImpl extends ElementImpl implements SVGElement { { CSSStyleDeclaration style; style = getStyle(); + if(style == null) { + return null; + } CSSValue val; val = style.getPropertyCSSValue(name); if(val == null) { diff --git a/src/org/apache/fop/dom/svg/SVGLengthListImpl.java b/src/org/apache/fop/dom/svg/SVGLengthListImpl.java index 60e7ddd6f..6b33c3218 100644 --- a/src/org/apache/fop/dom/svg/SVGLengthListImpl.java +++ b/src/org/apache/fop/dom/svg/SVGLengthListImpl.java @@ -61,10 +61,6 @@ import org.w3c.dom.svg.*; * a length quantity in XSL */ public class SVGLengthListImpl extends SVGListImpl implements SVGLengthList { - - protected float millipoints = 0; - protected Vector valueList = new Vector(); - protected float fontsize = 12; public void setValueAsString( String valueAsString ) @@ -97,25 +93,22 @@ public class SVGLengthListImpl extends SVGListImpl implements SVGLengthList { int l = len.length(); if (l == 0) { - MessageHandler.errorln("WARNING: empty length"); - this.millipoints = 0; +// MessageHandler.errorln("WARNING: empty length"); } else { // could be an array of points, as in for svg:text int pos; pos = len.trim().indexOf(" "); if(pos != -1) { - this.millipoints = 0; StringTokenizer st = new StringTokenizer(len.trim()); while(st.hasMoreTokens()) { String val = st.nextToken(); float dvalue = getFloatValue(val, val.length()); float intValue = dvalue; - this.valueList.addElement(new Float(intValue)); + appendItem(new Float(intValue)); } } else { float dvalue = getFloatValue(len, l); - this.millipoints = dvalue; - this.valueList.addElement(new Float(millipoints)); + appendItem(new Float(dvalue)); } } } @@ -158,12 +151,4 @@ public class SVGLengthListImpl extends SVGListImpl implements SVGLengthList { } return dvalue; } - - /** - * return the length in 1/1000ths of a point - */ - public Vector valueList() - { - return this.valueList; - } } diff --git a/src/org/apache/fop/dom/svg/SVGTSpanElementImpl.java b/src/org/apache/fop/dom/svg/SVGTSpanElementImpl.java index fbda8d9e5..8e281c13a 100644 --- a/src/org/apache/fop/dom/svg/SVGTSpanElementImpl.java +++ b/src/org/apache/fop/dom/svg/SVGTSpanElementImpl.java @@ -62,12 +62,10 @@ public class SVGTSpanElementImpl extends SVGTextContentElementImpl implements SV public String str; public int dx = 0; public int dy = 0; -// public int x = 0; -// public int y = 0; - public Vector xlist = null; - public Vector ylist = null; - public Vector dxlist = null; - public Vector dylist = null; + public SVGAnimatedLengthList xlist = null; + public SVGAnimatedLengthList ylist = null; + public SVGAnimatedLengthList dxlist = null; + public SVGAnimatedLengthList dylist = null; /** * @@ -78,22 +76,22 @@ public class SVGTSpanElementImpl extends SVGTextContentElementImpl implements SV public SVGAnimatedLengthList getX( ) { - return null; + return xlist; } public SVGAnimatedLengthList getY( ) { - return null; + return ylist; } public SVGAnimatedLengthList getDx( ) { - return null; + return dxlist; } public SVGAnimatedLengthList getDy( ) { - return null; + return dylist; } public SVGAnimatedTextRotate getRotate( ) -- 2.39.5