diff options
author | Dirk-Willem van Gulik <dirkx@apache.org> | 1999-11-08 19:12:49 +0000 |
---|---|---|
committer | Dirk-Willem van Gulik <dirkx@apache.org> | 1999-11-08 19:12:49 +0000 |
commit | 10070e8383ff94f3f256e346b8c4a2a493533cfb (patch) | |
tree | 59080d7faae7c0bd9ff4e5a48f4df4394d468a02 /src/org/apache/fop/svg | |
parent | b510e7f15a798e944bb138993f2b586413adecbe (diff) | |
download | xmlgraphics-fop-10070e8383ff94f3f256e346b8c4a2a493533cfb.tar.gz xmlgraphics-fop-10070e8383ff94f3f256e346b8c4a2a493533cfb.zip |
Initial revision
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193213 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/svg')
-rw-r--r-- | src/org/apache/fop/svg/Graphic.java | 8 | ||||
-rw-r--r-- | src/org/apache/fop/svg/Line.java | 81 | ||||
-rw-r--r-- | src/org/apache/fop/svg/LineGraphic.java | 34 | ||||
-rw-r--r-- | src/org/apache/fop/svg/Makefile | 33 | ||||
-rw-r--r-- | src/org/apache/fop/svg/Rect.java | 81 | ||||
-rw-r--r-- | src/org/apache/fop/svg/RectGraphic.java | 34 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVG.java | 176 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGArea.java | 45 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElementMapping.java | 15 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGLength.java | 77 | ||||
-rw-r--r-- | src/org/apache/fop/svg/Text.java | 95 | ||||
-rw-r--r-- | src/org/apache/fop/svg/TextGraphic.java | 29 | ||||
-rw-r--r-- | src/org/apache/fop/svg/package.html | 7 |
13 files changed, 715 insertions, 0 deletions
diff --git a/src/org/apache/fop/svg/Graphic.java b/src/org/apache/fop/svg/Graphic.java new file mode 100644 index 000000000..48b0c31e9 --- /dev/null +++ b/src/org/apache/fop/svg/Graphic.java @@ -0,0 +1,8 @@ +package org.apache.xml.fop.svg; + +/** + * base class for SVG graphic objects. + * + * Graphic objects include rectangles, lines and text + */ +public abstract class Graphic {} diff --git a/src/org/apache/fop/svg/Line.java b/src/org/apache/fop/svg/Line.java new file mode 100644 index 000000000..93ed5cb51 --- /dev/null +++ b/src/org/apache/fop/svg/Line.java @@ -0,0 +1,81 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.fo.*; +import org.apache.xml.fop.fo.properties.*; +import org.apache.xml.fop.layout.Area; +import org.apache.xml.fop.layout.FontState; +import org.apache.xml.fop.apps.FOPException; + +/** + * class representing svg:line pseudo flow object. + */ +public class Line extends FObj { + + /** + * inner class for making Line objects. + */ + public static class Maker extends FObj.Maker { + + /** + * make a Line object. + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + * + * @return the Line object + */ + public FObj make(FObj parent, PropertyList propertyList) + throws FOPException { + return new Line(parent, propertyList); + } + } + + /** + * returns the maker for this object. + * + * @return the maker for Line objects + */ + public static FObj.Maker maker() { + return new Line.Maker(); + } + + /** + * constructs a Line object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + protected Line(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + this.name = "svg:line"; + } + + /** + * layout this formatting object. + * + * @param area the area to layout the object into + * + * @return the status of the layout + */ + public int layout(Area area) throws FOPException { + + /* retrieve properties */ + int x1 = this.properties.get("x1").getLength().mvalue(); + int x2 = this.properties.get("x2").getLength().mvalue(); + int y1 = this.properties.get("y1").getLength().mvalue(); + int y2 = this.properties.get("y2").getLength().mvalue(); + + /* 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 LineGraphic(x1, y1, x2, y2)); + } else { + /* otherwise generate a warning */ + System.err.println("WARNING: svg:line outside svg:svg"); + } + + /* return status */ + return OK; + } +} diff --git a/src/org/apache/fop/svg/LineGraphic.java b/src/org/apache/fop/svg/LineGraphic.java new file mode 100644 index 000000000..f4d103e22 --- /dev/null +++ b/src/org/apache/fop/svg/LineGraphic.java @@ -0,0 +1,34 @@ +package org.apache.xml.fop.svg; + +/** + * class representing a line in an SVG Area + */ +public class LineGraphic extends Graphic { + + /** x-coordinate of start */ + public int x1; + + /** y-coordinate of start */ + public int y1; + + /** x-coordinate of end */ + public int x2; + + /** y-coordinate of end */ + public int y2; + + /** + * construct a line graphic + * + * @param x1 x-coordinate of start + * @param y1 y-coordinate of start + * @param x2 x-coordinate of end + * @param y2 y-coordinate of end + */ + public LineGraphic(int x1, int y1, int x2, int y2) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } +} diff --git a/src/org/apache/fop/svg/Makefile b/src/org/apache/fop/svg/Makefile new file mode 100644 index 000000000..f2f9f5b73 --- /dev/null +++ b/src/org/apache/fop/svg/Makefile @@ -0,0 +1,33 @@ + + +BASEDIR:=../../../../.. +include $(BASEDIR)/Makefile.rules + +SUBDIRS= + +SOURCES=Graphic.java \ + Line.java \ + LineGraphic.java \ + Rect.java \ + RectGraphic.java \ + SVG.java \ + SVGArea.java \ + SVGElementMapping.java \ + SVGLength.java \ + Text.java \ + TextGraphic.java + +CLASSES=$(SOURCES:.java=.class) + +all: $(CLASSES) allsubs + +clean: cleanme cleansubs + +cleanme: + rm -f *.class + +$(TARGETS:%=%subs): %subs : + for dir in $(SUBDIRS) ; do \ + (cd $$dir && pwd && $(MAKE) $(MFLAGS) $*) || exit 1 ; \ + done + diff --git a/src/org/apache/fop/svg/Rect.java b/src/org/apache/fop/svg/Rect.java new file mode 100644 index 000000000..e86657744 --- /dev/null +++ b/src/org/apache/fop/svg/Rect.java @@ -0,0 +1,81 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.fo.*; +import org.apache.xml.fop.fo.properties.*; +import org.apache.xml.fop.layout.Area; +import org.apache.xml.fop.layout.FontState; +import org.apache.xml.fop.apps.FOPException; + +/** + * class representing svg:rect pseudo flow object. + */ +public class Rect extends FObj { + + /** + * inner class for making Rect objects. + */ + public static class Maker extends FObj.Maker { + + /** + * make a Rect object. + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + * + * @return the Rect object + */ + public FObj make(FObj parent, PropertyList propertyList) + throws FOPException { + return new Rect(parent, propertyList); + } + } + + /** + * returns the maker for this object. + * + * @return the maker for Rect objects + */ + public static FObj.Maker maker() { + return new Rect.Maker(); + } + + /** + * constructs a Rect object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + protected Rect(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + this.name = "svg:rect"; + } + + /** + * layout this formatting object. + * + * @param area the area to layout the object into + * + * @return the status of the layout + */ + public int layout(Area area) throws FOPException { + + /* retrieve properties */ + int width = this.properties.get("width").getLength().mvalue(); + int height = this.properties.get("height").getLength().mvalue(); + int x = this.properties.get("x").getLength().mvalue(); + int y = this.properties.get("y").getLength().mvalue(); + + /* if the area this is being put into is an SVGArea */ + if (area instanceof SVGArea) { + /* add a rectangle to the SVGArea */ + ((SVGArea) area).addGraphic(new RectGraphic(x, y, width, height)); + } else { + /* otherwise generate a warning */ + System.err.println("WARNING: svg:rect outside svg:svg"); + } + + /* return status */ + return OK; + } +} diff --git a/src/org/apache/fop/svg/RectGraphic.java b/src/org/apache/fop/svg/RectGraphic.java new file mode 100644 index 000000000..e27bd488b --- /dev/null +++ b/src/org/apache/fop/svg/RectGraphic.java @@ -0,0 +1,34 @@ +package org.apache.xml.fop.svg; + +/** + * class representing a rectangle in an SVG Area + */ +public class RectGraphic extends Graphic { + + /** x-coordinate of corner */ + public int x; + + /** y-coordinate of corner */ + public int y; + + /** width of rectangle */ + public int width; + + /** height of rectangle */ + public int height; + + /** + * construct a rectangle graphic. + * + * @param x x-coordinate of corner + * @param y y-coordinate of corner + * @param width width of rectangle + * @param height height of rectangle + */ + public RectGraphic(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java new file mode 100644 index 000000000..2e229e738 --- /dev/null +++ b/src/org/apache/fop/svg/SVG.java @@ -0,0 +1,176 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.fo.*; +import org.apache.xml.fop.fo.properties.*; +import org.apache.xml.fop.layout.Area; +import org.apache.xml.fop.layout.BlockArea; +import org.apache.xml.fop.layout.FontState; +import org.apache.xml.fop.apps.FOPException; + +/** + * class representing svg:svg pseudo flow object. + */ +public class SVG extends FObj { + + /** + * inner class for making SVG objects. + */ + public static class Maker extends FObj.Maker { + + /** + * make an SVG object. + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + * + * @return the SVG object + */ + public FObj make(FObj parent, PropertyList propertyList) + throws FOPException { + return new SVG(parent, propertyList); + } + } + + /** + * returns the maker for this object. + * + * @return the maker for SVG objects + */ + public static FObj.Maker maker() { + return new SVG.Maker(); + } + + FontState fs; + int breakBefore; + int breakAfter; + int width; + int height; + int spaceBefore; + int spaceAfter; + + /** + * constructs an SVG object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + public SVG(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + this.name = "svg:svg"; + } + + /** + * layout this formatting object. + * + * @param area the area to layout the object into + * + * @return the status of the layout + */ + public int layout(Area area) throws FOPException { + + if (this.marker == BREAK_AFTER) { + return OK; + } + + if (this.marker == START) { + /* retrieve properties */ + String fontFamily = this.properties.get("font-family").getString(); + String fontStyle = this.properties.get("font-style").getString(); + String fontWeight = this.properties.get("font-weight").getString(); + int fontSize = this.properties.get("font-size").getLength().mvalue(); + + this.fs = new FontState(area.getFontInfo(), fontFamily, + fontStyle, fontWeight, fontSize); + + this.breakBefore = this.properties.get("break-before").getEnum(); + this.breakAfter = this.properties.get("break-after").getEnum(); + this.width = this.properties.get("width").getLength().mvalue(); + this.height = this.properties.get("height").getLength().mvalue(); + + this.spaceBefore = + this.properties.get("space-before.optimum").getLength().mvalue(); + this.spaceAfter = + this.properties.get("space-after.optimum").getLength().mvalue(); + /* if the SVG is embedded in a block area */ + if (area instanceof BlockArea) { + /* temporarily end the block area */ + area.end(); + } + + this.marker = 0; + + if (breakBefore == BreakBefore.PAGE) { + return FORCE_PAGE_BREAK; + } + + if (breakBefore == BreakBefore.ODD_PAGE) { + return FORCE_PAGE_BREAK_ODD; + } + + if (breakBefore == BreakBefore.EVEN_PAGE) { + return FORCE_PAGE_BREAK_EVEN; + } + } + + /* if there is a space-before */ + if (spaceBefore != 0) { + /* add a display space */ + area.addDisplaySpace(spaceBefore); + } + + /* create an SVG area */ + SVGArea svgArea = new SVGArea(fs, width, height); + svgArea.start(); + + /* add the SVG area to the containing area */ + area.addChild(svgArea); + + /* 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); + int status; + if ((status = fo.layout(svgArea)) != OK) { + return status; + } + } + + /* finish off the SVG area */ + svgArea.end(); + + /* increase the height of the containing area accordingly */ + area.increaseHeight(svgArea.getHeight()); + + /* if there is a space-after */ + if (spaceAfter != 0) { + /* add a display space */ + area.addDisplaySpace(spaceAfter); + } + + /* if the SVG is embedded in a block area */ + if (area instanceof BlockArea) { + /* re-start the block area */ + area.start(); + } + + if (breakAfter == BreakAfter.PAGE) { + this.marker = BREAK_AFTER; + return FORCE_PAGE_BREAK; + } + + if (breakAfter == BreakAfter.ODD_PAGE) { + this.marker = BREAK_AFTER; + return FORCE_PAGE_BREAK_ODD; + } + + if (breakAfter == BreakAfter.EVEN_PAGE) { + this.marker = BREAK_AFTER; + return FORCE_PAGE_BREAK_EVEN; + } + + /* return status */ + return OK; + } +} diff --git a/src/org/apache/fop/svg/SVGArea.java b/src/org/apache/fop/svg/SVGArea.java new file mode 100644 index 000000000..7a6ac2815 --- /dev/null +++ b/src/org/apache/fop/svg/SVGArea.java @@ -0,0 +1,45 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.render.Renderer; +import org.apache.xml.fop.layout.FontState; +import org.apache.xml.fop.layout.Area; + +/** + * class representing an SVG area in which the SVG graphics sit + */ +public class SVGArea extends Area { + + /** + * construct an SVG area + * + * @param fontState the font state + * @param width the width of the area + * @param height the height of the area + */ + public SVGArea(FontState fontState, int width, int height) { + super(fontState, width, height); + currentHeight = height; + contentRectangleWidth = width; + } + + /** + * add a graphic. + * + * Graphics include SVG Rectangles, Lines and Text + * + * @param graphic the Graphic to add + */ + public void addGraphic(Graphic graphic) { + this.children.addElement(graphic); + } + + /** + * render the SVG. + * + * @param renderer the Renderer to use + */ + public void render(Renderer renderer) { + renderer.renderSVGArea(this); + } +} diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java new file mode 100644 index 000000000..c01041c6b --- /dev/null +++ b/src/org/apache/fop/svg/SVGElementMapping.java @@ -0,0 +1,15 @@ +package org.apache.xml.fop.svg; + +import org.apache.xml.fop.fo.FOTreeBuilder; +import org.apache.xml.fop.fo.ElementMapping; + +public class SVGElementMapping implements ElementMapping { + + public void addToBuilder(FOTreeBuilder builder) { + String uri = "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"; + builder.addMapping(uri, "svg", SVG.maker()); + builder.addMapping(uri, "rect", Rect.maker()); + builder.addMapping(uri, "line", Line.maker()); + builder.addMapping(uri, "text", Text.maker()); + } +} diff --git a/src/org/apache/fop/svg/SVGLength.java b/src/org/apache/fop/svg/SVGLength.java new file mode 100644 index 000000000..252946046 --- /dev/null +++ b/src/org/apache/fop/svg/SVGLength.java @@ -0,0 +1,77 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.fo.*; +import org.apache.xml.fop.datatypes.*; +import org.apache.xml.fop.apps.FOPException; + +/** + * a class representing all the length properties in SVG + */ +public class SVGLength extends Property { + + /** + * inner class for making SVG Length objects. + */ + public static class Maker extends Property.Maker { + + /** + * whether this property is inherited or not. + * + * @return is this inherited? + */ + public boolean isInherited() { return false; } + + /** + * make an SVG Length property with the given value. + * + * @param propertyList the property list this is a member of + * @param value the explicit string value of the property + */ + public Property make(PropertyList propertyList, String value) + throws FOPException { + return new SVGLength(propertyList, new Length(value)); + } + + /** + * make an SVG Length property with the default value. + * + * @param propertyList the property list the property is a member of + */ + public Property make(PropertyList propertyList) throws FOPException { + return make(propertyList, "0pt"); + } + } + + /** + * returns the maker for this object. + * + * @return the maker for SVG Length objects + */ + public static Property.Maker maker() { + return new SVGLength.Maker(); + } + + /** the length as a Length object */ + protected Length value; + + /** + * construct an SVG length (called by the Maker). + * + * @param propertyList the property list this is a member of + * @param explicitValue the explicit value as a Length object + */ + protected SVGLength(PropertyList propertyList, Length explicitValue) { + this.propertyList = propertyList; + this.value = explicitValue; + } + + /** + * get the length + * + * @return the length as a Length object + */ + public Length getLength() { + return this.value; + } +} diff --git a/src/org/apache/fop/svg/Text.java b/src/org/apache/fop/svg/Text.java new file mode 100644 index 000000000..d24a10d94 --- /dev/null +++ b/src/org/apache/fop/svg/Text.java @@ -0,0 +1,95 @@ +package org.apache.xml.fop.svg; + +// FOP +import org.apache.xml.fop.fo.*; +import org.apache.xml.fop.fo.properties.*; +import org.apache.xml.fop.layout.Area; +import org.apache.xml.fop.layout.FontState; +import org.apache.xml.fop.apps.FOPException; + +/** + * class representing svg:text pseudo flow object. + */ +public class Text extends FObjMixed { + + /** + * inner class for making SVG Text objects. + */ + public static class Maker extends FObj.Maker { + + /** + * make an SVG Text object. + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + * + * @return the SVG Text object + */ + public FObj make(FObj parent, PropertyList propertyList) + throws FOPException { + return new Text(parent, propertyList); + } + } + + /** + * returns the maker for this object. + * + * @return the maker for SVG Text objects + */ + public static FObj.Maker maker() { + return new Text.Maker(); + } + + /** + * the string of text to display + */ + protected String text = ""; + + /** + * constructs an SVG Text object (called by Maker). + * + * @param parent the parent formatting object + * @param propertyList the explicit properties of this object + */ + protected Text(FObj parent, PropertyList propertyList) { + super(parent, propertyList); + this.name = "svg:text"; + } + + /** + * add characters to the string to display. + * + * @param data array of characters + * @param start start offset in character array + * @param length number of characters to add + */ + protected void addCharacters(char data[], int start, int length) { + this.text += new String(data, start, length); + } + + /** + * layout this formatting object. + * + * @param area the area to layout the object into + * + * @return the status of the layout + */ + public int layout(Area area) throws FOPException { + + /* retrieve properties */ + int x = this.properties.get("x").getLength().mvalue(); + int y = this.properties.get("y").getLength().mvalue(); + + /* if the area this is being put into is an SVGArea */ + if (area instanceof SVGArea) { + /* add the text to the SVGArea */ + ((SVGArea) area).addGraphic(new TextGraphic(x, y, text)); + } else { + /* otherwise generate a warning */ + System.err.println("WARNING: svg:text outside svg:svg"); + } + + /* return status */ + return OK; + } +} diff --git a/src/org/apache/fop/svg/TextGraphic.java b/src/org/apache/fop/svg/TextGraphic.java new file mode 100644 index 000000000..e0510f2f1 --- /dev/null +++ b/src/org/apache/fop/svg/TextGraphic.java @@ -0,0 +1,29 @@ +package org.apache.xml.fop.svg; + +/** + * class representing text in an SVG Area + */ +public class TextGraphic extends Graphic { + + /** x-coordinate of text */ + public int x; + + /** y-coordinate of text */ + public int y; + + /** the text string itself */ + public String s; + + /** + * construct a text graphic + * + * @param x x-coordinate of text + * @param y y-coordinate of text + * @param s the text string + */ + public TextGraphic(int x, int y, String s) { + this.x = x; + this.y = y; + this.s = s; + } +} diff --git a/src/org/apache/fop/svg/package.html b/src/org/apache/fop/svg/package.html new file mode 100644 index 000000000..695f0699c --- /dev/null +++ b/src/org/apache/fop/svg/package.html @@ -0,0 +1,7 @@ +<HTML> +<TITLE>org.apache.xml.fop.svg Package</TITLE> +<BODY> +<P>Classes that add basic SVG support to FOP</P> +<P>This includes flow objects, areas and properties.</P> +</BODY> +</HTML>
\ No newline at end of file |