aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/svg/SVG.java
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2001-05-17 07:48:06 +0000
committerKeiron Liddle <keiron@apache.org>2001-05-17 07:48:06 +0000
commitc824ede99cb449252823876b6224f6ed75e799cd (patch)
tree771770e0d8604c5511de0249b4072817fc483736 /src/org/apache/fop/svg/SVG.java
parentf89f05c27124377ec9497b30d4d75874a2bec67b (diff)
downloadxmlgraphics-fop-c824ede99cb449252823876b6224f6ed75e799cd.tar.gz
xmlgraphics-fop-c824ede99cb449252823876b6224f6ed75e799cd.zip
FOP now uses Batik to render svg
This is handled for awt - using batik to render to a graphic and pdf. Pdf still requires better image support. The elements and properties are generated from the svgelements.xml document. The version of batik is 17/05/2001 cvs. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194250 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/svg/SVG.java')
-rw-r--r--src/org/apache/fop/svg/SVG.java232
1 files changed, 171 insertions, 61 deletions
diff --git a/src/org/apache/fop/svg/SVG.java b/src/org/apache/fop/svg/SVG.java
index afa9ab336..3b9b18c02 100644
--- a/src/org/apache/fop/svg/SVG.java
+++ b/src/org/apache/fop/svg/SVG.java
@@ -59,18 +59,17 @@ import org.apache.fop.layout.FontState;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.inline.*;
-import org.apache.fop.dom.svg.*;
+import org.apache.batik.dom.svg.*;
+import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import org.w3c.dom.svg.SVGLength;
-import org.apache.fop.dom.svg.SVGArea;
-
-import java.util.StringTokenizer;
+import java.io.File;
/**
* class representing svg:svg pseudo flow object.
*/
-public class SVG extends FObj implements GraphicsCreator {
+public class SVG extends SVGObj implements GraphicsCreator {
/**
* inner class for making SVG objects.
@@ -101,8 +100,6 @@ public class SVG extends FObj implements GraphicsCreator {
}
FontState fs;
- float width;
- float height;
/**
* constructs an SVG object (called by Maker).
@@ -113,49 +110,128 @@ public class SVG extends FObj implements GraphicsCreator {
public SVG(FObj parent, PropertyList propertyList) {
super(parent, propertyList);
this.name = "svg:svg";
+ tagName = "svg";
+ props = new String[] {"width", "height", "x", "y", "id", "style", "class", "visibility",
+ "id",
+ "class",
+
+
+
+ "enable-background",
+
+
+ "flood-color",
+ "flood-opacity",
+
+
+ "fill",
+ "fill-opacity",
+ "fill-rule",
+ "stroke",
+ "stroke-dasharray",
+ "stroke-dashoffset",
+ "stroke-linecap",
+ "stroke-linejoin",
+ "stroke-miterlimit",
+ "stroke-opacity",
+ "stroke-width",
+
+
+ "font-family",
+ "font-size",
+ "font-size-adjust",
+ "font-stretch",
+ "font-style",
+ "font-variant",
+ "font-weight",
+
+
+ "stop-color",
+ "stop-opacity",
+
+
+ "clip-path",
+ "clip-rule",
+ "color",
+ "color-interpolation",
+ "color-rendering",
+ "cursor",
+ "display",
+ "filter",
+ "image-rendering",
+ "mask",
+ "opacity",
+ "pointer-events",
+ "space-rendering",
+ "text-rendering",
+ "visibility",
+
+
+ "color-profile",
+
+
+ "lighting-color",
+
+
+ "marker-start",
+ "marker-mid",
+ "marker-end",
+
+
+ "alignment-baseline",
+ "baseline-shift",
+ "direction",
+ "glyph-orientation-horizontal",
+ "glyph-orientation-vertical",
+ "kerning",
+ "letter-spacing",
+ "text-decoration",
+ "unicode-bidi",
+ "word-spacing",
+
+
+ "writing-mode",
+ "text-anchor",
+ "dominant-baseline",
+
+
+ "clip",
+ "overflow",
+
+
+ "id",
+ "style",
+ "transform",
+ "class",
+ };
}
- public SVGElement createGraphic() {
+/* public void addGraphic(Document doc, Element parent) {
+ Element element = doc.createElement(tagName);
+ for(int count = 0; count < props.length; count++) {
+ String rf = this.properties.get(props[count]).getString();
+ element.setAttribute(props[count], rf);
+ }
+ parent.appendChild(element);
+ int numChildren = this.children.size();
+ for (int i = 0; i < numChildren; i++) {
+ Object child = children.elementAt(i);
+ if (child instanceof GraphicsCreator) {
+ ((GraphicsCreator)child).addGraphic(doc, element);
+ } else if (child instanceof String) {
+ org.w3c.dom.Text text = doc.createTextNode((String)child);
+ element.appendChild(text);
+ }
+ }
+ }*/
+
+/* public SVGElement createGraphic() {
SVGSVGElementImpl svgArea = null;
SVGLength w = ((SVGLengthProperty) this.properties.get("width")).
getSVGLength();
SVGLength h = ((SVGLengthProperty) this.properties.get("height")).
getSVGLength();
svgArea = new SVGSVGElementImpl();
- {
- String box = this.properties.get("viewBox").getString();
- if (box != "") {
- StringTokenizer st = new StringTokenizer(box, " ");
- float x = 0;
- float y = 0;
- float width = 0;
- float height = 0;
- try {
- if(st.hasMoreTokens()) {
- x = Double.valueOf(st.nextToken()).floatValue();
- }
- if(st.hasMoreTokens()) {
- y = Double.valueOf(st.nextToken()).floatValue();
- }
- if(st.hasMoreTokens()) {
- width = Double.valueOf(st.nextToken()).floatValue();
- }
- if(st.hasMoreTokens()) {
- height = Double.valueOf(st.nextToken()).floatValue();
- }
- } catch(Exception e) {
- }
- SVGRect rect = new SVGRectImpl();
- rect.setX(x);
- rect.setY(y);
- rect.setWidth(width);
- rect.setHeight(height);
- svgArea.setViewBox (new SVGAnimatedRectImpl (rect));
- } else {
- svgArea.setViewBox (null);
- }
- }
-
SVGAnimatedLengthImpl sal;
if (w == null)
w = new SVGLengthImpl();
@@ -206,7 +282,7 @@ public class SVG extends FObj implements GraphicsCreator {
Status status;
}
return svgArea;
- }
+ }*/
/**
* layout this formatting object.
@@ -235,45 +311,79 @@ public class SVG extends FObj implements GraphicsCreator {
this.properties.get("font-style").getString();
String fontWeight =
this.properties.get("font-weight").getString();
- int fontSize =
- this.properties.get("font-size").getLength().mvalue();
+ String fontSz = this.properties.get("font-size").getString();
+ int fontSize = area.getFontState().getFontSize();
+ try {
+ fontSize = Integer.parseInt(fontSz);
+ } catch(Exception e) {
+ }
// FIX-ME: should get the font-variant property
this.fs = new FontState(area.getFontInfo(), fontFamily,
fontStyle, fontWeight, fontSize, FontVariant.NORMAL);
- SVGLength length;
- length = ((SVGLengthProperty) this.properties.get("width")).getSVGLength();
- if (length == null)
- length = new SVGLengthImpl();
- this.width = length.getValue();
- length = ((SVGLengthProperty) this.properties.get("height")).
- getSVGLength();
- if (length == null)
- length = new SVGLengthImpl();
- this.height = length.getValue();
+// this.width = this.properties.get("width").getString();
+// this.height = this.properties.get("height").getString();
this.marker = 0;
}
/* create an SVG area */
/* if width and height are zero, may want to get the bounds of the content. */
+ SVGOMDocument doc = new SVGOMDocument(null, SVGDOMImplementation.getDOMImplementation());
+ try {
+ doc.setURLObject(new File(".").toURL());
+ } catch(Exception e) {
+ }
+
+ DefaultSVGContext dc = new DefaultSVGContext() {
+ public float getPixelToMM() {
+ return 0.264583333333333333333f; // 72 dpi
+ }
+ public float getViewportWidth() {
+ return 100;
+ }
+ public float getViewportHeight() {
+ return 100;
+ }
+ };
+ doc.setSVGContext(dc);
+
+ Element topLevel = doc.createElementNS("http://www.w3.org/2000/svg", tagName);
+ for(int count = 0; count < props.length; count++) {
+ if(this.properties.get(props[count]) != null) {
+ String rf = this.properties.get(props[count]).getString();
+ if(rf != null)
+ topLevel.setAttribute(props[count], rf);
+ }
+ }
+ doc.appendChild(topLevel);
+ int numChildren = this.children.size();
+ for (int i = 0; i < numChildren; i++) {
+ Object child = children.elementAt(i);
+ if (child instanceof GraphicsCreator) {
+ ((GraphicsCreator)child).addGraphic(doc, topLevel);
+ } else if (child instanceof String) {
+ org.w3c.dom.Text text = doc.createTextNode((String)child);
+ topLevel.appendChild(text);
+ }
+ }
+
+ float width = ((SVGSVGElement)topLevel).getWidth().getBaseVal().getValue();
+ float height = ((SVGSVGElement)topLevel).getHeight().getBaseVal().getValue();
SVGArea svg = new SVGArea(fs, width, height);
- SVGDocument doc = new SVGDocumentImpl();
svg.setSVGDocument(doc);
svg.start();
+ /* finish off the SVG area */
+ svg.end();
+
/* add the SVG area to the containing area */
ForeignObjectArea foa = (ForeignObjectArea) area;
foa.setObject(svg);
foa.setIntrinsicWidth(svg.getWidth());
foa.setIntrinsicHeight(svg.getHeight());
- doc.appendChild((SVGSVGElement) createGraphic());
-
- /* finish off the SVG area */
- svg.end();
-
/* return status */
return new Status(Status.OK);
}