From 439f2e573db6508b7a42c70bbdb1e69c5c118bf3 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Mon, 28 Aug 2000 23:54:26 +0000 Subject: [PATCH] remove layout and makes all elements return an SVGElement git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193674 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/svg/A.java | 30 +- src/org/apache/fop/svg/AltGlyph.java | 24 +- src/org/apache/fop/svg/Animate.java | 24 +- src/org/apache/fop/svg/AnimateColor.java | 24 +- src/org/apache/fop/svg/AnimateMotion.java | 24 +- src/org/apache/fop/svg/AnimateTransform.java | 24 +- src/org/apache/fop/svg/Circle.java | 30 +- src/org/apache/fop/svg/ClipPath.java | 33 +- src/org/apache/fop/svg/Cursor.java | 25 +- src/org/apache/fop/svg/Defs.java | 36 +- src/org/apache/fop/svg/Desc.java | 2 +- src/org/apache/fop/svg/Ellipse.java | 31 +- src/org/apache/fop/svg/Filter.java | 25 +- src/org/apache/fop/svg/Font.java | 25 +- src/org/apache/fop/svg/G.java | 38 +- src/org/apache/fop/svg/Glyph.java | 25 +- src/org/apache/fop/svg/GraphicsCreator.java | 4 +- src/org/apache/fop/svg/HKern.java | 25 +- src/org/apache/fop/svg/Image.java | 28 +- src/org/apache/fop/svg/Line.java | 32 +- src/org/apache/fop/svg/LinearGradient.java | 6 +- src/org/apache/fop/svg/Marker.java | 25 +- src/org/apache/fop/svg/Mask.java | 35 +- src/org/apache/fop/svg/MissingGlyph.java | 26 +- src/org/apache/fop/svg/Path.java | 31 +- src/org/apache/fop/svg/Pattern.java | 26 +- src/org/apache/fop/svg/Polygon.java | 32 +- src/org/apache/fop/svg/Polyline.java | 31 +- src/org/apache/fop/svg/RadialGradient.java | 30 +- src/org/apache/fop/svg/Rect.java | 29 +- src/org/apache/fop/svg/SVG.java | 70 ++-- src/org/apache/fop/svg/SVGDriver.java | 336 ++++++++++++++++++ src/org/apache/fop/svg/SVGElementMapping.java | 6 +- .../apache/fop/svg/SVGLengthListProperty.java | 2 +- src/org/apache/fop/svg/SVGObj.java | 102 ++++++ .../fop/svg/SVGPropertyListMapping.java | 6 +- src/org/apache/fop/svg/SVGStyle.java | 4 +- src/org/apache/fop/svg/SVGTransform.java | 6 +- src/org/apache/fop/svg/Set.java | 26 +- src/org/apache/fop/svg/Stop.java | 2 +- src/org/apache/fop/svg/Style.java | 25 +- src/org/apache/fop/svg/Switch.java | 29 +- src/org/apache/fop/svg/Symbol.java | 25 +- src/org/apache/fop/svg/TRef.java | 36 +- src/org/apache/fop/svg/TSpan.java | 38 +- src/org/apache/fop/svg/Text.java | 60 ++-- src/org/apache/fop/svg/TextElement.java | 5 +- src/org/apache/fop/svg/TextPath.java | 28 +- src/org/apache/fop/svg/Title.java | 2 +- src/org/apache/fop/svg/Use.java | 31 +- src/org/apache/fop/svg/VKern.java | 26 +- 51 files changed, 657 insertions(+), 988 deletions(-) create mode 100644 src/org/apache/fop/svg/SVGDriver.java create mode 100644 src/org/apache/fop/svg/SVGObj.java diff --git a/src/org/apache/fop/svg/A.java b/src/org/apache/fop/svg/A.java index 5dc0371a1..8ab3ad016 100644 --- a/src/org/apache/fop/svg/A.java +++ b/src/org/apache/fop/svg/A.java @@ -59,11 +59,13 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:a pseudo flow object. * */ -public class A extends FObj implements GraphicsCreator { +public class A extends SVGObj { /** * inner class for making A objects. @@ -104,7 +106,7 @@ public class A extends FObj implements GraphicsCreator { this.name = "svg:a"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { String rf = this.properties.get("xlink:href").getString(); SVGAElementImpl graphic; @@ -115,7 +117,7 @@ public class A extends FObj implements GraphicsCreator { for (int i = 0; i < numChildren; i++) { FONode child = (FONode) children.elementAt(i); if(child instanceof GraphicsCreator) { - GraphicImpl impl = ((GraphicsCreator)child).createGraphic(); + SVGElement impl = ((GraphicsCreator)child).createGraphic(); graphic.appendChild((GraphicElement)impl); } else if(child instanceof Defs) { } @@ -123,26 +125,4 @@ public class A extends FObj implements GraphicsCreator { return graphic; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:a outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/AltGlyph.java b/src/org/apache/fop/svg/AltGlyph.java index 08a34eefe..86739386e 100644 --- a/src/org/apache/fop/svg/AltGlyph.java +++ b/src/org/apache/fop/svg/AltGlyph.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.*; * class representing svg:altGlyph pseudo flow object. * */ -public class AltGlyph extends FObj { +public class AltGlyph extends SVGObj { /** * inner class for making AltGlyph objects. @@ -103,26 +103,4 @@ public class AltGlyph extends FObj { super(parent, propertyList); this.name = "svg:altGlyph"; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ -// ((SVGArea) area).addGraphic(new AltGlyphGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:altGlyph outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Animate.java b/src/org/apache/fop/svg/Animate.java index d0e9ecbfa..b1f79b7ca 100644 --- a/src/org/apache/fop/svg/Animate.java +++ b/src/org/apache/fop/svg/Animate.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.*; * class representing svg:Animate pseudo flow object. * */ -public class Animate extends FObj { +public class Animate extends SVGObj { /** * inner class for making Animate objects. @@ -103,26 +103,4 @@ public class Animate extends FObj { super(parent, propertyList); this.name = "svg:animate"; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ -// ((SVGArea) area).addGraphic(new AnimateGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:animate outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/AnimateColor.java b/src/org/apache/fop/svg/AnimateColor.java index 1e99f907c..b25f20198 100644 --- a/src/org/apache/fop/svg/AnimateColor.java +++ b/src/org/apache/fop/svg/AnimateColor.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.*; * class representing svg:AnimateColor pseudo flow object. * */ -public class AnimateColor extends FObj { +public class AnimateColor extends SVGObj { /** * inner class for making AnimateColor objects. @@ -103,26 +103,4 @@ public class AnimateColor extends FObj { super(parent, propertyList); this.name = "svg:animateColor"; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a AnimateColor to the SVGArea */ -// ((SVGArea) area).addGraphic(new AnimateColorGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:animateColor outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/AnimateMotion.java b/src/org/apache/fop/svg/AnimateMotion.java index 865e59347..facb011d5 100644 --- a/src/org/apache/fop/svg/AnimateMotion.java +++ b/src/org/apache/fop/svg/AnimateMotion.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.*; * class representing svg:AnimateMotion pseudo flow object. * */ -public class AnimateMotion extends FObj { +public class AnimateMotion extends SVGObj { /** * inner class for making AnimateMotion objects. @@ -103,26 +103,4 @@ public class AnimateMotion extends FObj { super(parent, propertyList); this.name = "svg:animateMotion"; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a AnimateMotion to the SVGArea */ -// ((SVGArea) area).addGraphic(new AnimateMotionGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:animateMotion outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/AnimateTransform.java b/src/org/apache/fop/svg/AnimateTransform.java index 01a8f77f7..a569c535a 100644 --- a/src/org/apache/fop/svg/AnimateTransform.java +++ b/src/org/apache/fop/svg/AnimateTransform.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.*; * class representing svg:AnimateTransform pseudo flow object. * */ -public class AnimateTransform extends FObj { +public class AnimateTransform extends SVGObj { /** * inner class for making AnimateTransform objects. @@ -103,26 +103,4 @@ public class AnimateTransform extends FObj { super(parent, propertyList); this.name = "svg:animateTransform"; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ -// ((SVGArea) area).addGraphic(new AnimateTransformGraphic(x1, y1, x2, y2)); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:animateTransform outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Circle.java b/src/org/apache/fop/svg/Circle.java index 8e3690eb3..678fd4ba7 100644 --- a/src/org/apache/fop/svg/Circle.java +++ b/src/org/apache/fop/svg/Circle.java @@ -63,11 +63,13 @@ import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; import org.w3c.dom.svg.SVGLength; +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Circle pseudo flow object. * */ -public class Circle extends FObj implements GraphicsCreator { +public class Circle extends SVGObj { /** * inner class for making Circle objects. @@ -108,7 +110,7 @@ public class Circle extends FObj implements GraphicsCreator { this.name = "svg:circle"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { /* retrieve properties */ SVGLength cx = ((SVGLengthProperty)this.properties.get("cx")).getSVGLength(); @@ -119,30 +121,8 @@ public class Circle extends FObj implements GraphicsCreator { graph.setCy(new SVGAnimatedLengthImpl(cy)); graph.setR(new SVGAnimatedLengthImpl(r)); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:circle outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/ClipPath.java b/src/org/apache/fop/svg/ClipPath.java index 3eee2d757..42a6f9e4a 100644 --- a/src/org/apache/fop/svg/ClipPath.java +++ b/src/org/apache/fop/svg/ClipPath.java @@ -59,11 +59,14 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:ClipPath pseudo flow object. * */ -public class ClipPath extends FObj implements GraphicsCreator { +public class ClipPath extends SVGObj { /** * inner class for making ClipPath objects. @@ -110,40 +113,18 @@ public class ClipPath extends FObj implements GraphicsCreator { super.addChild(child); if(child instanceof GraphicsCreator) { GraphicsCreator gc = (GraphicsCreator)child; - GraphicImpl graph = gc.createGraphic(); + SVGElement graph = gc.createGraphic(); clippath.addElement(graph); - graph.setParent(clippath); +// graph.setParent(clippath); } else { // error } } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { clippath.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); clippath.setId(this.properties.get("id").getString()); return clippath; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:clipPath outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Cursor.java b/src/org/apache/fop/svg/Cursor.java index 220fcc012..1507ce04b 100644 --- a/src/org/apache/fop/svg/Cursor.java +++ b/src/org/apache/fop/svg/Cursor.java @@ -62,7 +62,7 @@ import org.apache.fop.dom.svg.SVGArea; /** * */ -public class Cursor extends FObj { +public class Cursor extends SVGObj { /** * inner class for making Cursor objects. @@ -102,27 +102,4 @@ public class Cursor extends FObj { super(parent, propertyList); this.name = "svg:cursor"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGCursorElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:cursor outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Defs.java b/src/org/apache/fop/svg/Defs.java index 4b0100bc1..362bf8c9f 100644 --- a/src/org/apache/fop/svg/Defs.java +++ b/src/org/apache/fop/svg/Defs.java @@ -59,7 +59,7 @@ import org.apache.fop.apps.FOPException; import java.util.*; -import org.w3c.dom.svg.SVGElement; +import org.w3c.dom.svg.*; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; @@ -67,7 +67,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Defs pseudo flow object. * */ -public class Defs extends FObj { +public class Defs extends SVGObj { /** * inner class for making Defs objects. @@ -108,19 +108,21 @@ public class Defs extends FObj { this.name = "svg:defs"; } - Hashtable defs = new Hashtable(); +// Hashtable defs = new Hashtable(); - public Hashtable createDefs() + public SVGElement createGraphic() { + SVGDefsElement defs = new SVGDefsElementImpl(); int numChildren = this.children.size(); for (int i = 0; i < numChildren; i++) { FONode child = (FONode) children.elementAt(i); if(child instanceof GraphicsCreator) { - GraphicImpl gi = ((GraphicsCreator)child).createGraphic(); + SVGElement gi = ((GraphicsCreator)child).createGraphic(); if(gi instanceof SVGElement) { + defs.appendChild((SVGElement)gi); String id = ((SVGElement)gi).getId(); if(!id.equals("")) { - defs.put(id, gi); +// defs.put(id, gi); } else { // no id System.err.println("WARNING No ID for defs element : " + gi); @@ -130,26 +132,4 @@ public class Defs extends FObj { } return defs; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addDefs(createDefs()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:defs outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Desc.java b/src/org/apache/fop/svg/Desc.java index 7f8280282..8bf382ccf 100644 --- a/src/org/apache/fop/svg/Desc.java +++ b/src/org/apache/fop/svg/Desc.java @@ -61,7 +61,7 @@ import org.apache.fop.apps.FOPException; * class representing svg:Desc pseudo flow object. * */ -public class Desc extends FObj { +public class Desc extends SVGObj { /** * inner class for making Desc objects. diff --git a/src/org/apache/fop/svg/Ellipse.java b/src/org/apache/fop/svg/Ellipse.java index 781871097..d1c4e5e3b 100644 --- a/src/org/apache/fop/svg/Ellipse.java +++ b/src/org/apache/fop/svg/Ellipse.java @@ -61,11 +61,13 @@ import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; import org.w3c.dom.svg.SVGLength; +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Ellipse pseudo flow object. * */ -public class Ellipse extends FObj implements GraphicsCreator { +public class Ellipse extends SVGObj { /** * inner class for making Ellipse objects. @@ -106,7 +108,7 @@ public class Ellipse extends FObj implements GraphicsCreator { this.name = "svg:ellipse"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { /* retrieve properties */ SVGLength cx = ((SVGLengthProperty)this.properties.get("cx")).getSVGLength(); @@ -119,31 +121,8 @@ public class Ellipse extends FObj implements GraphicsCreator { graph.setRx(new SVGAnimatedLengthImpl(rx)); graph.setRy(new SVGAnimatedLengthImpl(ry)); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:ellipse outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Filter.java b/src/org/apache/fop/svg/Filter.java index 65dd0de02..a2dc40f08 100644 --- a/src/org/apache/fop/svg/Filter.java +++ b/src/org/apache/fop/svg/Filter.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Filter pseudo flow object. * */ -public class Filter extends FObj { +public class Filter extends SVGObj { /** * inner class for making Filter objects. @@ -103,27 +103,4 @@ public class Filter extends FObj { super(parent, propertyList); this.name = "svg:filter"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGFilterElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:filter outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Font.java b/src/org/apache/fop/svg/Font.java index 072f10194..bffe59043 100644 --- a/src/org/apache/fop/svg/Font.java +++ b/src/org/apache/fop/svg/Font.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Font pseudo flow object. * */ -public class Font extends FObj { +public class Font extends SVGObj { /** * inner class for making Font objects. @@ -103,27 +103,4 @@ public class Font extends FObj { super(parent, propertyList); this.name = "svg:font"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGFontElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:font outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/G.java b/src/org/apache/fop/svg/G.java index 8adcdb32b..f857a91f1 100644 --- a/src/org/apache/fop/svg/G.java +++ b/src/org/apache/fop/svg/G.java @@ -59,11 +59,14 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:G pseudo flow object. * */ -public class G extends FObj implements GraphicsCreator { +public class G extends SVGObj { /** * inner class for making G objects. @@ -106,44 +109,23 @@ public class G extends FObj implements GraphicsCreator { SVGGElementImpl ggraphic = new SVGGElementImpl(); - public GraphicImpl createGraphic() + public SVGElement createGraphic() { - ggraphic.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + ggraphic.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); ggraphic.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); ggraphic.setId(this.properties.get("id").getString()); int numChildren = this.children.size(); for (int i = 0; i < numChildren; i++) { FONode child = (FONode) children.elementAt(i); if(child instanceof GraphicsCreator) { - GraphicImpl impl = ((GraphicsCreator)child).createGraphic(); - ggraphic.addGraphic(impl); + SVGElement impl = ((GraphicsCreator)child).createGraphic(); + if(impl != null) + ggraphic.appendChild(impl); } else if(child instanceof Defs) { // System.out.println(child); - ggraphic.addDefs(((Defs)child).createDefs()); +// ggraphic.addDefs(((Defs)child).createDefs()); } } return ggraphic; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a G to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:g outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Glyph.java b/src/org/apache/fop/svg/Glyph.java index 29b90b261..8fb8b59a6 100644 --- a/src/org/apache/fop/svg/Glyph.java +++ b/src/org/apache/fop/svg/Glyph.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Glyph pseudo flow object. * */ -public class Glyph extends FObj { +public class Glyph extends SVGObj { /** * inner class for making Glyph objects. @@ -103,27 +103,4 @@ public class Glyph extends FObj { super(parent, propertyList); this.name = "svg:glyph"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGGlyphElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:glyph outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/GraphicsCreator.java b/src/org/apache/fop/svg/GraphicsCreator.java index 7ccc5dffb..139bf7b8a 100644 --- a/src/org/apache/fop/svg/GraphicsCreator.java +++ b/src/org/apache/fop/svg/GraphicsCreator.java @@ -53,9 +53,11 @@ package org.apache.fop.svg; import org.apache.fop.dom.svg.*; +import org.w3c.dom.svg.SVGElement; + /** * */ public interface GraphicsCreator { - public GraphicImpl createGraphic(); + public SVGElement createGraphic(); } diff --git a/src/org/apache/fop/svg/HKern.java b/src/org/apache/fop/svg/HKern.java index a50db1d53..7632c9930 100644 --- a/src/org/apache/fop/svg/HKern.java +++ b/src/org/apache/fop/svg/HKern.java @@ -62,7 +62,7 @@ import org.apache.fop.dom.svg.SVGArea; /** * */ -public class HKern extends FObj { +public class HKern extends SVGObj { /** * inner class for making HKern objects. @@ -102,27 +102,4 @@ public class HKern extends FObj { super(parent, propertyList); this.name = "svg:hkern"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGHKernElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:hkern outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Image.java b/src/org/apache/fop/svg/Image.java index cbf50f66e..1a02982e9 100644 --- a/src/org/apache/fop/svg/Image.java +++ b/src/org/apache/fop/svg/Image.java @@ -59,11 +59,14 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Image pseudo flow object. * */ -public class Image extends FObj implements GraphicsCreator { +public class Image extends SVGObj { /** * inner class for making Image objects. @@ -104,7 +107,7 @@ public class Image extends FObj implements GraphicsCreator { this.name = "svg:image"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { String link = this.properties.get("xlink:href").getString(); float x = ((SVGLengthProperty)this.properties.get("x")).getSVGLength().getValue(); @@ -116,25 +119,4 @@ public class Image extends FObj implements GraphicsCreator { graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Image to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:image outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Line.java b/src/org/apache/fop/svg/Line.java index 8118f6641..7891f0e3b 100644 --- a/src/org/apache/fop/svg/Line.java +++ b/src/org/apache/fop/svg/Line.java @@ -61,13 +61,15 @@ import org.apache.fop.apps.FOPException; import org.w3c.dom.svg.SVGLength; import org.apache.fop.dom.svg.*; -//import org.apache.fop.dom.svg.Graphic; import org.apache.fop.dom.svg.SVGLineElementImpl; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:line pseudo flow object. */ -public class Line extends FObj implements GraphicsCreator { +public class Line extends SVGObj { /** * inner class for making Line objects. @@ -108,7 +110,7 @@ public class Line extends FObj implements GraphicsCreator { this.name = "svg:line"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { /* retrieve properties */ SVGLength x1 = ((SVGLengthProperty)this.properties.get("x1")).getSVGLength(); @@ -121,30 +123,8 @@ public class Line extends FObj implements GraphicsCreator { graph.setX2(new SVGAnimatedLengthImpl(x2)); graph.setY2(new SVGAnimatedLengthImpl(y2)); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - MessageHandler.errorln("WARNING: svg:line outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/LinearGradient.java b/src/org/apache/fop/svg/LinearGradient.java index 28bf256f5..b175a81e3 100644 --- a/src/org/apache/fop/svg/LinearGradient.java +++ b/src/org/apache/fop/svg/LinearGradient.java @@ -66,7 +66,7 @@ import org.w3c.dom.svg.*; * class representing svg:LinearGradient pseudo flow object. * */ -public class LinearGradient extends FObj implements GraphicsCreator { +public class LinearGradient extends SVGObj { /** * inner class for making LinearGradient objects. @@ -117,10 +117,10 @@ public class LinearGradient extends FObj implements GraphicsCreator { } } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { linear.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - linear.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + linear.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); linear.setId(this.properties.get("id").getString()); linear.setX1(new SVGAnimatedLengthImpl(((SVGLengthProperty)this.properties.get("x1")).getSVGLength())); diff --git a/src/org/apache/fop/svg/Marker.java b/src/org/apache/fop/svg/Marker.java index 34c840485..7fd2887d6 100644 --- a/src/org/apache/fop/svg/Marker.java +++ b/src/org/apache/fop/svg/Marker.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Marker pseudo flow object. * */ -public class Marker extends FObj { +public class Marker extends SVGObj { /** * inner class for making Marker objects. @@ -103,27 +103,4 @@ public class Marker extends FObj { super(parent, propertyList); this.name = "svg:marker"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGMarkerElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:marker outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Mask.java b/src/org/apache/fop/svg/Mask.java index 4e613a216..451de833a 100644 --- a/src/org/apache/fop/svg/Mask.java +++ b/src/org/apache/fop/svg/Mask.java @@ -58,11 +58,14 @@ import org.apache.fop.layout.FontState; import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Mask pseudo flow object. * */ -public class Mask extends FObj { +public class Mask extends SVGObj { /** * inner class for making Mask objects. @@ -109,38 +112,20 @@ public class Mask extends FObj { super.addChild(child); if(child instanceof GraphicsCreator) { GraphicsCreator gc = (GraphicsCreator)child; - GraphicImpl graph = gc.createGraphic(); - mask.addElement(graph); - graph.setParent(mask); + SVGElement graph = gc.createGraphic(); + if(graph != null) { + mask.addElement(graph); +// graph.setParent(mask); + } } else { // error } } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { mask.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); mask.setId(this.properties.get("id").getString()); return mask; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:mask outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/MissingGlyph.java b/src/org/apache/fop/svg/MissingGlyph.java index fc3193f8e..5065e2b16 100644 --- a/src/org/apache/fop/svg/MissingGlyph.java +++ b/src/org/apache/fop/svg/MissingGlyph.java @@ -62,7 +62,7 @@ import org.apache.fop.dom.svg.SVGArea; /** * */ -public class MissingGlyph extends FObj { +public class MissingGlyph extends SVGObj { /** * inner class for making MissingGlyph objects. @@ -102,28 +102,4 @@ public class MissingGlyph extends FObj { super(parent, propertyList); this.name = "svg:missing-glyph"; } - - /** - * 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 { - - /* retrieve properties */ - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGMissingGlyphElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:missing-glyph outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Path.java b/src/org/apache/fop/svg/Path.java index 1091117b3..64a5b0a8c 100644 --- a/src/org/apache/fop/svg/Path.java +++ b/src/org/apache/fop/svg/Path.java @@ -61,11 +61,14 @@ import java.util.*; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Path pseudo flow object. * */ -public class Path extends FObj implements GraphicsCreator { +public class Path extends SVGObj { /** * inner class for making Path objects. @@ -106,35 +109,13 @@ public class Path extends FObj implements GraphicsCreator { this.name = "svg:path"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { Vector pd = ((SVGD)this.properties.get("d")).getPath(); SVGPathElementImpl graph = new SVGPathElementImpl(pd); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Path to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:path outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Pattern.java b/src/org/apache/fop/svg/Pattern.java index e76c3ad0b..73ae9ae4d 100644 --- a/src/org/apache/fop/svg/Pattern.java +++ b/src/org/apache/fop/svg/Pattern.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Pattern pseudo flow object. * */ -public class Pattern extends FObj { +public class Pattern extends SVGObj { /** * inner class for making Pattern objects. @@ -103,28 +103,4 @@ public class Pattern extends FObj { super(parent, propertyList); this.name = "svg:pattern"; } - - /** - * 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 { - - /* retrieve properties */ - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Pattern to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGPatternElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:pattern outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Polygon.java b/src/org/apache/fop/svg/Polygon.java index 8b9725b07..bd53fe4de 100644 --- a/src/org/apache/fop/svg/Polygon.java +++ b/src/org/apache/fop/svg/Polygon.java @@ -61,10 +61,13 @@ import java.util.*; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * */ -public class Polygon extends FObj implements GraphicsCreator { +public class Polygon extends SVGObj { /** * inner class for making Polygon objects. @@ -105,36 +108,13 @@ public class Polygon extends FObj implements GraphicsCreator { this.name = "svg:polygon"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { Vector points = ((SVGPoints)this.properties.get("points")).getPoints(); SVGPolygonElementImpl graph = new SVGPolygonElementImpl(points); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:polygon outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Polyline.java b/src/org/apache/fop/svg/Polyline.java index b0846b87c..05187eef1 100644 --- a/src/org/apache/fop/svg/Polyline.java +++ b/src/org/apache/fop/svg/Polyline.java @@ -61,11 +61,14 @@ import java.util.*; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:Polyline pseudo flow object. * */ -public class Polyline extends FObj implements GraphicsCreator { +public class Polyline extends SVGObj { /** * inner class for making Polyline objects. @@ -106,35 +109,13 @@ public class Polyline extends FObj implements GraphicsCreator { this.name = "svg:polyline"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { Vector points = ((SVGPoints)this.properties.get("points")).getPoints(); SVGPolylineElementImpl graph = new SVGPolylineElementImpl(points); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Polyline to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:polyline outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/RadialGradient.java b/src/org/apache/fop/svg/RadialGradient.java index c53526086..ec941801d 100644 --- a/src/org/apache/fop/svg/RadialGradient.java +++ b/src/org/apache/fop/svg/RadialGradient.java @@ -66,7 +66,7 @@ import org.w3c.dom.svg.*; * class representing svg:RadialGradient pseudo flow object. * */ -public class RadialGradient extends FObj implements GraphicsCreator { +public class RadialGradient extends SVGObj { /** * inner class for making RadialGradient objects. @@ -117,10 +117,10 @@ public class RadialGradient extends FObj implements GraphicsCreator { } } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { radial.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - radial.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + radial.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); radial.setId(this.properties.get("id").getString()); radial.setCx(new SVGAnimatedLengthImpl(((SVGLengthProperty)this.properties.get("cx")).getSVGLength())); @@ -130,28 +130,4 @@ public class RadialGradient extends FObj implements GraphicsCreator { radial.setFy(new SVGAnimatedLengthImpl(((SVGLengthProperty)this.properties.get("fy")).getSVGLength())); return radial; } - - /** - * 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 { - - /* retrieve properties */ - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a RadialGradient to the SVGArea */ - ((SVGArea) area).addGraphic(radial); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:radialGradient outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Rect.java b/src/org/apache/fop/svg/Rect.java index ba2d09bcf..19579470b 100644 --- a/src/org/apache/fop/svg/Rect.java +++ b/src/org/apache/fop/svg/Rect.java @@ -65,11 +65,12 @@ import org.apache.fop.dom.svg.SVGRectElementImpl; import org.apache.fop.dom.svg.SVGArea; import org.w3c.dom.svg.SVGLength; +import org.w3c.dom.svg.SVGElement; /** * class representing svg:rect pseudo flow object. */ -public class Rect extends FObj implements GraphicsCreator { +public class Rect extends SVGObj { /** * inner class for making Rect objects. @@ -110,7 +111,7 @@ public class Rect extends FObj implements GraphicsCreator { this.name = "svg:rect"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { /* retrieve properties */ SVGLength width = ((SVGLengthProperty)this.properties.get("width")).getSVGLength(); @@ -127,30 +128,8 @@ public class Rect extends FObj implements GraphicsCreator { graph.setWidth(new SVGAnimatedLengthImpl(width)); graph.setHeight(new SVGAnimatedLengthImpl(height)); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a rectangle to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - MessageHandler.errorln("WARNING: svg:rect outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java index 660af2647..6ddd4d2d3 100644 --- a/src/org/apache/fop/svg/SVG.java +++ b/src/org/apache/fop/svg/SVG.java @@ -60,6 +60,7 @@ import org.apache.fop.layout.FontState; import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; +import org.w3c.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; /** @@ -110,45 +111,32 @@ public class SVG extends FObj implements GraphicsCreator { this.name = "svg:svg"; } -/* protected void addChild(FONode child) { - super.addChild(child); - if(svgArea != null) { - Status status; - try { - if ((status = child.layout(svgArea)).isIncomplete()) { - } - } catch(FOPException fope) { - fope.printStackTrace(); - } - } - }*/ - - SVGArea svgArea = null; - public GraphicImpl createGraphic() + public SVGElement createGraphic() { - this.width = ((SVGLengthProperty)this.properties.get("width")).getSVGLength().getValue(); - this.height = ((SVGLengthProperty)this.properties.get("height")).getSVGLength().getValue(); - svgArea = new SVGArea(null, width, height); + SVGSVGElementImpl svgArea = null; + SVGLength w = ((SVGLengthProperty)this.properties.get("width")).getSVGLength(); + SVGLength h = ((SVGLengthProperty)this.properties.get("height")).getSVGLength(); + svgArea = new SVGSVGElementImpl(); + SVGAnimatedLength sal; + sal = new SVGAnimatedLengthImpl(w); + sal.setBaseVal(w); + svgArea.setWidth(sal); + sal = new SVGAnimatedLengthImpl(h); + sal.setBaseVal(h); + svgArea.setHeight(sal); svgArea.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - svgArea.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); -// svgArea.setId(this.properties.get("id").getString()); + 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) { - GraphicImpl impl = ((GraphicsCreator)fo).createGraphic(); - svgArea.addGraphic(impl); - } else if(fo instanceof Defs) { - svgArea.addDefs(((Defs)fo).createDefs()); + SVGElement impl = ((GraphicsCreator)fo).createGraphic(); + svgArea.appendChild((org.w3c.dom.Node)impl); +// } else if(fo instanceof Defs) { +// svgArea.addDefs(((Defs)fo).createDefs()); } Status status; -/* try { - if ((status = fo.layout(svgArea)).isIncomplete()) { -// return null; - } - } catch(FOPException fope) { - fope.printStackTrace(); - }*/ } return svgArea; } @@ -162,11 +150,6 @@ public class SVG extends FObj implements GraphicsCreator { */ public Status layout(Area area) throws FOPException { - if (area instanceof SVGArea) { - ((SVGArea) area).addGraphic(createGraphic()); - return new Status(Status.OK); - } - if (!(area instanceof ForeignObjectArea)) { // this is an error throw new FOPException("SVG not in fo:instream-foreign-object"); @@ -196,8 +179,8 @@ public class SVG extends FObj implements GraphicsCreator { /* create an SVG area */ /* if width and height are zero, may want to get the bounds of the content. */ SVGArea svg = new SVGArea(fs, width, height); - svg.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - svg.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + SVGDocument doc = new SVGDocumentImpl(); + svg.setSVGDocument(doc); svg.start(); /* add the SVG area to the containing area */ @@ -206,16 +189,7 @@ public class SVG extends FObj implements GraphicsCreator { foa.setIntrinsicWidth(svg.getWidth()); foa.setIntrinsicHeight(svg.getHeight()); - /* iterate over the child formatting objects and lay them out - into the SVG area */ - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - FONode fo = (FONode) children.elementAt(i); - Status status; - if ((status = fo.layout(svg)).isIncomplete()) { - return status; - } - } + doc.appendChild((SVGSVGElement)createGraphic()); /* finish off the SVG area */ svg.end(); diff --git a/src/org/apache/fop/svg/SVGDriver.java b/src/org/apache/fop/svg/SVGDriver.java new file mode 100644 index 000000000..caa56640d --- /dev/null +++ b/src/org/apache/fop/svg/SVGDriver.java @@ -0,0 +1,336 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ + +package org.apache.fop.svg; + +// FOP +import org.apache.fop.fo.*; +import org.apache.fop.apps.*; +import org.apache.fop.dom.svg.*; +import org.apache.fop.fo.FOTreeBuilder; +import org.apache.fop.fo.ElementMapping; +import org.apache.fop.fo.PropertyListMapping; +import org.apache.fop.layout.AreaTree; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.render.Renderer; +import org.apache.fop.messaging.MessageHandler; + +// DOM +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Attr; + +// SAX +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import org.w3c.dom.svg.*; + +// Java +import java.io.PrintWriter; +import java.io.IOException; + +/** + *

Primary class that drives overall FOP process. + * + *

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). + * + *

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. + * + *

A third possibility may be used to build the FO Tree, namely + * calling getDocumentHandler() and firing the SAX events yourself. + * + *

Once the FO Tree is built, the format() and render() methods may be + * called in that order. + * + *

Here is an example use of Driver from CommandLine.java: + * + *

+ *   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();
+ * 
+ */ +public class SVGDriver { + + /** the FO tree builder */ + protected SVGTreeBuilder treeBuilder; + + /** the PrintWriter to use to output the results of the renderer */ + protected PrintWriter writer; + + /** create a new Driver */ + public SVGDriver() { + 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); + } + + /** + * add the element mapping with the given class name + */ + public void addElementMapping(String mappingClassName) { + 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; + } + + /** + * add the element mapping with the given class name + */ + public void addPropertyList(String listClassName) { + 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; + } + + /** + * return the tree builder (a SAX DocumentHandler). + * + * used in situations where SAX is used but not via a FOP-invoked + * SAX parser. A good example is an XSLT engine that fires SAX + * events but isn't a SAX Parser itself. + */ + public ContentHandler getContentHandler() { + 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()); + } + } + + /** + * 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 SVGDocument getSVGDocument() + { + return this.treeBuilder.getSVGDocument(); + } + + /** + * format the formatting object tree into an area tree + */ + public void format() + throws FOPException { + FontInfo fontInfo = new FontInfo(); + } +} diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java index a045a3fec..43e5ce005 100644 --- a/src/org/apache/fop/svg/SVGElementMapping.java +++ b/src/org/apache/fop/svg/SVGElementMapping.java @@ -50,13 +50,15 @@ */ package org.apache.fop.svg; +import org.apache.fop.fo.TreeBuilder; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.ElementMapping; +import org.apache.fop.dom.svg.SVGDocumentImpl; public class SVGElementMapping implements ElementMapping { - public void addToBuilder(FOTreeBuilder builder) { - String uri = "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd"; + public void addToBuilder(TreeBuilder builder) { + String uri = SVGDocumentImpl.namespaceURI; builder.addMapping(uri, "svg", SVG.maker()); builder.addMapping(uri, "rect", Rect.maker()); builder.addMapping(uri, "line", Line.maker()); diff --git a/src/org/apache/fop/svg/SVGLengthListProperty.java b/src/org/apache/fop/svg/SVGLengthListProperty.java index da2dfed5a..7ebe0bd44 100644 --- a/src/org/apache/fop/svg/SVGLengthListProperty.java +++ b/src/org/apache/fop/svg/SVGLengthListProperty.java @@ -94,7 +94,7 @@ public class SVGLengthListProperty extends Property { * @param propertyList the property list the property is a member of */ public Property make(PropertyList propertyList) throws FOPException { - return make(propertyList, "0pt"); + return make(propertyList, ""); } } diff --git a/src/org/apache/fop/svg/SVGObj.java b/src/org/apache/fop/svg/SVGObj.java new file mode 100644 index 000000000..c41b58cef --- /dev/null +++ b/src/org/apache/fop/svg/SVGObj.java @@ -0,0 +1,102 @@ +/*-- $Id$ -- + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "FOP" and "Apache Software Foundation" must not be used to + endorse or promote products derived from this software without prior + written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + James Tauber . For more information on the Apache + Software Foundation, please see . + + */ + +package org.apache.fop.svg; + +// FOP +import org.apache.fop.fo.*; +import org.apache.fop.layout.Area; +import org.apache.fop.layout.FontState; +import org.apache.fop.apps.FOPException; + +import org.apache.fop.dom.svg.*; + +import org.w3c.dom.svg.SVGElement; + +/** + * Since SVG objects are not layed out then this class checks + * that this element is not being layed out inside some incorrect + * element. + */ +public abstract class SVGObj extends FObj implements GraphicsCreator { + + /** + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + public SVGObj(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + } + + public SVGElement createGraphic() + { + return null; + } + + /** + * 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"); + } + + /* return status */ + return new Status(Status.OK); + } +} diff --git a/src/org/apache/fop/svg/SVGPropertyListMapping.java b/src/org/apache/fop/svg/SVGPropertyListMapping.java index 78a096a1f..10d838410 100644 --- a/src/org/apache/fop/svg/SVGPropertyListMapping.java +++ b/src/org/apache/fop/svg/SVGPropertyListMapping.java @@ -53,14 +53,15 @@ package org.apache.fop.svg; import org.apache.fop.fo.*; import org.apache.fop.fo.properties.*; +import org.apache.fop.dom.svg.SVGDocumentImpl; import java.util.Hashtable; public class SVGPropertyListMapping implements PropertyListMapping { - public void addToBuilder(FOTreeBuilder builder) { + public void addToBuilder(TreeBuilder builder) { - String uri = "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd"; + String uri = SVGDocumentImpl.namespaceURI; Hashtable propertyTable = new Hashtable(); propertyTable.put("height",SVGLengthProperty.maker()); propertyTable.put("width",SVGLengthProperty.maker()); @@ -93,6 +94,7 @@ public class SVGPropertyListMapping implements PropertyListMapping { propertyTable.put("d",SVGD.maker()); propertyTable.put("points",SVGPoints.maker()); // propertyTable.put("viewBox",SVGBox.maker()); + propertyTable.put("xml:space",XMLSpace.maker()); propertyTable.put("font-family",FontFamily.maker()); propertyTable.put("font-style",FontStyle.maker()); diff --git a/src/org/apache/fop/svg/SVGStyle.java b/src/org/apache/fop/svg/SVGStyle.java index cad70c499..8bd7da0be 100644 --- a/src/org/apache/fop/svg/SVGStyle.java +++ b/src/org/apache/fop/svg/SVGStyle.java @@ -57,6 +57,8 @@ import org.apache.fop.apps.FOPException; import java.util.*; +import org.w3c.dom.css.CSSStyleDeclaration; + /** * */ @@ -122,7 +124,7 @@ public class SVGStyle extends Property { * * @return the length as a Length object */ - public Hashtable getStyle() + public CSSStyleDeclaration getStyle() { return this.style.getStyle(); } diff --git a/src/org/apache/fop/svg/SVGTransform.java b/src/org/apache/fop/svg/SVGTransform.java index 36e2bb134..3c90f82d3 100644 --- a/src/org/apache/fop/svg/SVGTransform.java +++ b/src/org/apache/fop/svg/SVGTransform.java @@ -55,6 +55,8 @@ import org.apache.fop.fo.*; import org.apache.fop.datatypes.*; import org.apache.fop.apps.FOPException; +import org.w3c.dom.svg.SVGAnimatedTransformList; + import java.util.*; /** @@ -120,7 +122,7 @@ public class SVGTransform extends Property { * * @return the length as a Length object */ - public Vector oldgetTransform() { - return this.trans.oldgetTransform(); + public SVGAnimatedTransformList getTransform() { + return this.trans.getTransform(); } } diff --git a/src/org/apache/fop/svg/Set.java b/src/org/apache/fop/svg/Set.java index 39ecc4c95..d35dd254f 100644 --- a/src/org/apache/fop/svg/Set.java +++ b/src/org/apache/fop/svg/Set.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Set pseudo flow object. * */ -public class Set extends FObj { +public class Set extends SVGObj { /** * inner class for making Set objects. @@ -103,28 +103,4 @@ public class Set extends FObj { super(parent, propertyList); this.name = "svg:set"; } - - /** - * 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 { - - /* retrieve properties */ - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Set to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGSetElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:set outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Stop.java b/src/org/apache/fop/svg/Stop.java index 7a5fafb55..76f0e1af5 100644 --- a/src/org/apache/fop/svg/Stop.java +++ b/src/org/apache/fop/svg/Stop.java @@ -67,7 +67,7 @@ import org.w3c.dom.svg.SVGLength; * class representing svg:Stop pseudo flow object. * */ -public class Stop extends FObj { +public class Stop extends SVGObj { /** * inner class for making Stop objects. diff --git a/src/org/apache/fop/svg/Style.java b/src/org/apache/fop/svg/Style.java index 8d7312729..0efe1e8a0 100644 --- a/src/org/apache/fop/svg/Style.java +++ b/src/org/apache/fop/svg/Style.java @@ -63,7 +63,7 @@ import org.apache.fop.dom.svg.SVGArea; * class representing svg:Style pseudo flow object. * */ -public class Style extends FObj { +public class Style extends SVGObj { /** * inner class for making Style objects. @@ -103,27 +103,4 @@ public class Style extends FObj { super(parent, propertyList); this.name = "svg:style"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a Style to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGStyleElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:style outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Switch.java b/src/org/apache/fop/svg/Switch.java index 06051a4ce..486752f02 100644 --- a/src/org/apache/fop/svg/Switch.java +++ b/src/org/apache/fop/svg/Switch.java @@ -65,7 +65,7 @@ import org.w3c.dom.svg.*; /** * */ -public class Switch extends FObj implements GraphicsCreator { +public class Switch extends SVGObj { /** * inner class for making Line objects. @@ -106,7 +106,7 @@ public class Switch extends FObj implements GraphicsCreator { this.name = "svg:switch"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { /* * There are two options @@ -138,7 +138,7 @@ public class Switch extends FObj implements GraphicsCreator { for (int i = 0; i < numChildren; i++) { FONode child = (FONode) children.elementAt(i); if(child instanceof GraphicsCreator) { - GraphicImpl impl = ((GraphicsCreator)child).createGraphic(); + SVGElement impl = ((GraphicsCreator)child).createGraphic(); if(impl instanceof SVGTests) { SVGTests testable = (SVGTests)impl; rf = child.getProperty("requiredFeatures").getString(); @@ -164,27 +164,4 @@ public class Switch extends FObj implements GraphicsCreator { return graphic; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:switch outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Symbol.java b/src/org/apache/fop/svg/Symbol.java index 1a269f450..8a859dadd 100644 --- a/src/org/apache/fop/svg/Symbol.java +++ b/src/org/apache/fop/svg/Symbol.java @@ -62,7 +62,7 @@ import org.apache.fop.dom.svg.SVGArea; /** * */ -public class Symbol extends FObj { +public class Symbol extends SVGObj { /** * inner class for making Symbol objects. @@ -102,27 +102,4 @@ public class Symbol extends FObj { super(parent, propertyList); this.name = "svg:symbol"; } - - /** - * 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 { - - /* retrieve properties */ - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGSymbolElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:symbol outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/TRef.java b/src/org/apache/fop/svg/TRef.java index 7bf16dec9..4fe43ca2c 100644 --- a/src/org/apache/fop/svg/TRef.java +++ b/src/org/apache/fop/svg/TRef.java @@ -59,10 +59,13 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * */ -public class TRef extends FObj implements TextElement { +public class TRef extends SVGObj implements TextElement { /** * inner class for making Line objects. @@ -103,7 +106,7 @@ public class TRef extends FObj implements TextElement { this.name = "svg:tref"; } - public GraphicImpl createTextElement() + public SVGElement createTextElement() { SVGTRefElementImpl tref = new SVGTRefElementImpl(); tref.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); @@ -115,41 +118,20 @@ public class TRef extends FObj implements TextElement { prop = this.properties.get("x"); // bit of a hack, but otherwise the svg:text x element could be // returned which is not a list - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tref.xlist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("y"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tref.ylist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("dx"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tref.dxlist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("dy"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tref.dylist = ((SVGLengthListProperty)prop).getSVGLengthList(); // tref.dxlist = ((SVGLengthProperty)this.properties.get("dx")).getSVGLength().valueList(); tref.ref = this.properties.get("xlink:href").getString(); tref.setId(this.properties.get("id").getString()); return tref; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:tref outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/TSpan.java b/src/org/apache/fop/svg/TSpan.java index a9527193e..02f565df9 100644 --- a/src/org/apache/fop/svg/TSpan.java +++ b/src/org/apache/fop/svg/TSpan.java @@ -59,11 +59,14 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:tspan pseudo flow object. * */ -public class TSpan extends FObj implements TextElement { +public class TSpan extends SVGObj implements TextElement { /** * inner class for making tspan objects. @@ -105,7 +108,7 @@ public class TSpan extends FObj implements TextElement { protected void addCharacters(char data[], int start, int length) { this.text += new String(data, start, length - start); - tspan.str = this.text.trim(); + tspan.str = this.text; } /** @@ -119,7 +122,7 @@ public class TSpan extends FObj implements TextElement { this.name = "svg:tspan"; } - public GraphicImpl createTextElement() + public SVGElement createTextElement() { tspan.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); // tspan.dx = ((SVGLengthProperty)this.properties.get("dx")).getSVGLength().mvalue(); @@ -130,41 +133,20 @@ public class TSpan extends FObj implements TextElement { prop = this.properties.get("x"); // bit of a hack, but otherwise the svg:text x element coud be // returned which is not a list - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tspan.xlist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("y"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tspan.ylist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("dx"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tspan.dxlist = ((SVGLengthListProperty)prop).getSVGLengthList(); prop = this.properties.get("dy"); - if(prop instanceof SVGLengthListProperty) +// if(prop instanceof SVGLengthListProperty) tspan.dylist = ((SVGLengthListProperty)prop).getSVGLengthList(); // tspan.xlist = ((SVGLengthListProperty)this.properties.get("x")).getSVGLengthList(); // tspan.dxlist = ((SVGLengthProperty)this.properties.get("dx")).getSVGLength().valueList(); tspan.setId(this.properties.get("id").getString()); return tspan; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:tspan outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Text.java b/src/org/apache/fop/svg/Text.java index 5facce490..ebb0027bf 100644 --- a/src/org/apache/fop/svg/Text.java +++ b/src/org/apache/fop/svg/Text.java @@ -57,6 +57,7 @@ import org.apache.fop.messaging.MessageHandler; import org.apache.fop.layout.Area; import org.apache.fop.layout.FontState; import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.properties.XMLSpace; import java.util.*; @@ -64,11 +65,13 @@ import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGTextElementImpl; import org.apache.fop.dom.svg.SVGArea; +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:text pseudo flow object. * */ -public class Text extends FObjMixed implements GraphicsCreator { +public class Text extends SVGObj { /** * inner class for making SVG Text objects. @@ -125,52 +128,53 @@ public class Text extends FObjMixed implements GraphicsCreator { */ protected void addCharacters(char data[], int start, int length) { - textList.addElement(new String(data, start, length - start).trim()); + textList.addElement(new String(data, start, length - start)); } + /** + * The children need to be added in order so that the text data + * is also added in order. + */ protected void addChild(FONode child) { super.addChild(child); if(child instanceof TextElement) { TextElement te = (TextElement)child; - GraphicImpl graph = te.createTextElement(); + SVGElement graph = te.createTextElement(); textList.addElement(graph); - graph.setParent(textGraph); } else { // error } } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { + int numChildren = this.textList.size(); + for (int i = 0; i < numChildren; i++) { + Object obj = textList.elementAt(i); + if(obj instanceof SVGElement) { + SVGElement child = (SVGElement)obj; + textGraph.appendChild(child); + } else if(obj instanceof String) { + String str = (String)obj; + // new CDATANode(str); ?? + } +// System.out.println(child); + } /* retrieve properties */ textGraph.x = ((SVGLengthProperty)this.properties.get("x")).getSVGLength().getValue(); textGraph.y = ((SVGLengthProperty)this.properties.get("y")).getSVGLength().getValue(); textGraph.textList = textList; textGraph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - textGraph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + textGraph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); textGraph.setId(this.properties.get("id").getString()); + switch((this.properties.get("xml:space")).getEnum()) { + case XMLSpace.DEFAULT: + textGraph.setXMLspace("default"); + break; + case XMLSpace.PRESERVE: + textGraph.setXMLspace("preserve"); + break; + } return textGraph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add the text to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - MessageHandler.errorln("WARNING: svg:text outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/TextElement.java b/src/org/apache/fop/svg/TextElement.java index 34b4fcd0d..92486066b 100644 --- a/src/org/apache/fop/svg/TextElement.java +++ b/src/org/apache/fop/svg/TextElement.java @@ -52,9 +52,12 @@ package org.apache.fop.svg; import org.apache.fop.dom.svg.*; + +import org.w3c.dom.svg.SVGElement; + /** * */ public interface TextElement { - public GraphicImpl createTextElement(); + public SVGElement createTextElement(); } diff --git a/src/org/apache/fop/svg/TextPath.java b/src/org/apache/fop/svg/TextPath.java index 9841e3dd3..0e1c96799 100644 --- a/src/org/apache/fop/svg/TextPath.java +++ b/src/org/apache/fop/svg/TextPath.java @@ -59,11 +59,14 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * class representing svg:TextPath pseudo flow object. * */ -public class TextPath extends FObj implements TextElement { +public class TextPath extends SVGObj implements TextElement { /** * inner class for making TextPath objects. @@ -110,7 +113,7 @@ public class TextPath extends FObj implements TextElement { text += new String(data, start, length - start); } - public GraphicImpl createTextElement() + public SVGElement createTextElement() { SVGTextPathElementImpl graph = null; String link = this.properties.get("xlink:href").getString(); @@ -118,25 +121,4 @@ public class TextPath extends FObj implements TextElement { graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a TextPath to the SVGArea */ - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:textPath outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/Title.java b/src/org/apache/fop/svg/Title.java index 15f0288c1..a8f8cd89a 100644 --- a/src/org/apache/fop/svg/Title.java +++ b/src/org/apache/fop/svg/Title.java @@ -60,7 +60,7 @@ import org.apache.fop.apps.FOPException; /** * */ -public class Title extends FObj { +public class Title extends SVGObj { /** * inner class for making Title objects. diff --git a/src/org/apache/fop/svg/Use.java b/src/org/apache/fop/svg/Use.java index 60a286f30..415512684 100644 --- a/src/org/apache/fop/svg/Use.java +++ b/src/org/apache/fop/svg/Use.java @@ -59,10 +59,13 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.dom.svg.*; import org.apache.fop.dom.svg.SVGArea; + +import org.w3c.dom.svg.SVGElement; + /** * */ -public class Use extends FObj implements GraphicsCreator { +public class Use extends SVGObj { /** * inner class for making Use objects. @@ -103,35 +106,13 @@ public class Use extends FObj implements GraphicsCreator { this.name = "svg:use"; } - public GraphicImpl createGraphic() + public SVGElement createGraphic() { String str = this.properties.get("xlink:href").getString(); SVGUseElementImpl graph = new SVGUseElementImpl(str); graph.setStyle(((SVGStyle)this.properties.get("style")).getStyle()); - graph.setTransform(((SVGTransform)this.properties.get("transform")).oldgetTransform()); + graph.setTransform(((SVGTransform)this.properties.get("transform")).getTransform()); graph.setId(this.properties.get("id").getString()); return graph; } - - /** - * 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 the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a line to the SVGArea */ - ((SVGArea) area).addGraphic(createGraphic()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:use outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } diff --git a/src/org/apache/fop/svg/VKern.java b/src/org/apache/fop/svg/VKern.java index 2707d49a5..78c2f67c8 100644 --- a/src/org/apache/fop/svg/VKern.java +++ b/src/org/apache/fop/svg/VKern.java @@ -62,7 +62,7 @@ import org.apache.fop.dom.svg.SVGArea; /** * */ -public class VKern extends FObj { +public class VKern extends SVGObj { /** * inner class for making VKern objects. @@ -102,28 +102,4 @@ public class VKern extends FObj { super(parent, propertyList); this.name = "svg:vkern"; } - - /** - * 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 { - - /* retrieve properties */ - - /* if the area this is being put into is an SVGArea */ - if (area instanceof SVGArea) { - /* add a VKern to the SVGArea */ - ((SVGArea) area).addGraphic(new SVGVKernElementImpl()); - } else { - /* otherwise generate a warning */ - System.err.println("WARNING: svg:vkern outside svg:svg"); - } - - /* return status */ - return new Status(Status.OK); - } } -- 2.39.5