aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache')
-rw-r--r--src/org/apache/fop/svg/PDFImageElementBridge.java94
-rw-r--r--src/org/apache/fop/svg/PDFTextElementBridge.java30
-rw-r--r--src/org/apache/fop/svg/PDFTextPainter.java214
-rw-r--r--src/org/apache/fop/svg/PDFTranscoder.java115
-rw-r--r--src/org/apache/fop/svg/SVGElement.java67
-rw-r--r--src/org/apache/fop/svg/SVGElementMapping.java14
-rw-r--r--src/org/apache/fop/svg/SVGObj.java4
-rw-r--r--src/org/apache/fop/svg/SVGUserAgent.java58
-rw-r--r--src/org/apache/fop/svg/SVGUtilities.java103
9 files changed, 448 insertions, 251 deletions
diff --git a/src/org/apache/fop/svg/PDFImageElementBridge.java b/src/org/apache/fop/svg/PDFImageElementBridge.java
index 3d0e30f38..e661c7767 100644
--- a/src/org/apache/fop/svg/PDFImageElementBridge.java
+++ b/src/org/apache/fop/svg/PDFImageElementBridge.java
@@ -1,63 +1,21 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.svg;
-import java.awt.Cursor;
-import java.awt.geom.AffineTransform;
+import org.apache.batik.bridge.SVGImageElementBridge;
-import org.apache.batik.bridge.*;
+import org.apache.fop.image.JpegImage;
-import org.apache.batik.gvt.CompositeGraphicsNode;
-import org.apache.batik.gvt.GraphicsNode;
-
-import org.apache.fop.pdf.*;
-import org.apache.fop.image.*;
-import org.apache.fop.apps.*;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.events.Event;
-import org.w3c.dom.events.EventListener;
-import org.w3c.dom.events.EventTarget;
-import org.w3c.dom.svg.SVGAElement;
-
-import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Graphics2D;
-import java.awt.color.ICC_Profile;
-import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-
-import org.apache.batik.dom.svg.SVGOMDocument;
-import org.apache.batik.dom.util.XLinkSupport;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
-import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit;
-import org.apache.batik.ext.awt.image.renderable.Filter;
-import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
-import org.apache.batik.gvt.CompositeGraphicsNode;
-import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.gvt.ImageNode;
-import org.apache.batik.gvt.RasterImageNode;
-import org.apache.batik.gvt.AbstractGraphicsNode;
-import org.apache.batik.gvt.filter.GraphicsNodeRable8Bit;
-import org.apache.batik.util.ParsedURL;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.css.CSSPrimitiveValue;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.svg.SVGDocument;
-import org.w3c.dom.svg.SVGSVGElement;
+import org.apache.batik.gvt.AbstractGraphicsNode;
/**
* Bridge class for the <image> element when jpeg images.
@@ -69,8 +27,18 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
/**
* Constructs a new bridge for the <image> element.
*/
- public PDFImageElementBridge() {}
+ public PDFImageElementBridge() { }
+
/*
+ /**
+ * Create the raster image node.
+ * THis checks if it is a jpeg file and creates a jpeg node
+ * so the jpeg can be inserted directly into the pdf document.
+ * @param ctx the bridge context
+ * @param e the svg element for the image
+ * @param purl the parsed url for the image resource
+ * @return a new graphics node
+ *
protected GraphicsNode createRasterImageNode(BridgeContext ctx,
Element e, ParsedURL purl) {
@@ -96,16 +64,38 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
return super.createRasterImageNode(ctx, e, purl);
}
*/
+
+ /**
+ * A PDF jpeg node.
+ * This holds a jpeg image so that it can be drawn into
+ * the PDFGraphics2D.
+ */
public static class PDFJpegNode extends AbstractGraphicsNode {
- JpegImage jpeg;
+ private JpegImage jpeg;
+
+ /**
+ * Create a new pdf jpeg node for drawing jpeg images
+ * into pdf graphics.
+ * @param j the jpeg image
+ */
public PDFJpegNode(JpegImage j) {
jpeg = j;
}
+ /**
+ * Get the outline of this image.
+ * @return the outline shape which is the primitive bounds
+ */
public Shape getOutline() {
return getPrimitiveBounds();
}
+ /**
+ * Paint this jpeg image.
+ * As this is used for inserting jpeg into pdf
+ * it adds the jpeg image to the PDFGraphics2D.
+ * @param g2d the graphics to draw the image on
+ */
public void primitivePaint(Graphics2D g2d) {
if (g2d instanceof PDFGraphics2D) {
PDFGraphics2D pdfg = (PDFGraphics2D) g2d;
@@ -122,10 +112,18 @@ public class PDFImageElementBridge extends SVGImageElementBridge {
}
}
+ /**
+ * Get the geometrix bounds of the image.
+ * @return the primitive bounds
+ */
public Rectangle2D getGeometryBounds() {
return getPrimitiveBounds();
}
+ /**
+ * Get the primitive bounds of this bridge element.
+ * @return the bounds of the jpeg image
+ */
public Rectangle2D getPrimitiveBounds() {
try {
return new Rectangle2D.Double(0, 0, jpeg.getWidth(),
diff --git a/src/org/apache/fop/svg/PDFTextElementBridge.java b/src/org/apache/fop/svg/PDFTextElementBridge.java
index e01026472..c740f63d2 100644
--- a/src/org/apache/fop/svg/PDFTextElementBridge.java
+++ b/src/org/apache/fop/svg/PDFTextElementBridge.java
@@ -1,6 +1,6 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,9 +8,9 @@
package org.apache.fop.svg;
import org.apache.batik.gvt.TextNode;
-import org.apache.batik.bridge.*;
-
-import org.apache.batik.gvt.CompositeGraphicsNode;
+import org.apache.batik.bridge.SVGTextElementBridge;
+import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.TextUtilities;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.fop.layout.FontInfo;
@@ -18,8 +18,6 @@ import org.apache.fop.layout.FontInfo;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.apache.batik.gvt.GraphicsNode;
-
/**
* Bridge class for the <text> element.
* This bridge will use the direct text painter if the text
@@ -32,14 +30,22 @@ public class PDFTextElementBridge extends SVGTextElementBridge {
/**
* Constructs a new bridge for the <text> element.
+ * @param fi the font infomration
*/
public PDFTextElementBridge(FontInfo fi) {
pdfTextPainter = new PDFTextPainter(fi);
}
+ /**
+ * Create a text element bridge.
+ * This set the text painter on the node if the text is simple.
+ * @param ctx the bridge context
+ * @param e the svg element
+ * @return the text graphics node created by the super class
+ */
public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
GraphicsNode node = super.createGraphicsNode(ctx, e);
- if(node != null && isSimple(ctx, e, node)) {
+ if (node != null && isSimple(ctx, e, node)) {
((TextNode)node).setTextPainter(getTextPainter());
}
return node;
@@ -56,12 +62,18 @@ public class PDFTextElementBridge extends SVGTextElementBridge {
* with basic text drawing algorithms. This means there are no
* alternate characters, the font is known and there are no effects
* applied to the text.
+ *
+ * @param ctx the bridge context
+ * @param element the svg text element
+ * @param node the graphics node
+ * @return true if this text is simple of false if it cannot be
+ * easily rendered using normal drawString on the PDFGraphics2D
*/
private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) {
// Font size, in user space units.
float fs = TextUtilities.convertFontSize(element).floatValue();
// PDF cannot display fonts over 36pt
- if(fs > 36) {
+ if (fs > 36) {
return false;
}
@@ -89,7 +101,7 @@ public class PDFTextElementBridge extends SVGTextElementBridge {
}
}
- /*if(CSSUtilities.convertFilter(element, node, ctx) != null) {
+ /*if (CSSUtilities.convertFilter(element, node, ctx) != null) {
return false;
}*/
diff --git a/src/org/apache/fop/svg/PDFTextPainter.java b/src/org/apache/fop/svg/PDFTextPainter.java
index d2be59f68..989c504f1 100644
--- a/src/org/apache/fop/svg/PDFTextPainter.java
+++ b/src/org/apache/fop/svg/PDFTextPainter.java
@@ -1,6 +1,6 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -8,30 +8,30 @@
package org.apache.fop.svg;
import java.awt.Graphics2D;
-import java.awt.*;
-import java.text.AttributedCharacterIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.Font;
import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.text.CharacterIterator;
-import java.awt.font.TextLayout;
import java.awt.font.TextAttribute;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.*;
-import java.util.Set;
+import java.awt.Shape;
+import java.awt.Paint;
+import java.awt.Stroke;
+import java.awt.Color;
+import java.util.Vector;
+import java.util.Enumeration;
import org.apache.batik.gvt.text.Mark;
-import org.apache.batik.gvt.*;
-import org.apache.batik.gvt.text.*;
-import org.apache.batik.gvt.renderer.*;
-import org.apache.batik.gvt.font.*;
+import org.apache.batik.gvt.TextPainter;
+import org.apache.batik.gvt.TextNode;
+import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
+import org.apache.batik.gvt.font.GVTFontFamily;
import org.apache.batik.bridge.SVGFontFamily;
+import org.apache.batik.gvt.renderer.StrokingTextPainter;
-import org.apache.fop.layout.*;
+import org.apache.fop.layout.FontState;
+import org.apache.fop.layout.FontInfo;
+import org.apache.fop.layout.FontMetric;
/**
* Renders the attributed character iterator of a <tt>TextNode</tt>.
@@ -41,22 +41,26 @@ import org.apache.fop.layout.*;
* drawString. If the text is complex or the cannot be translated
* into a simple drawString the StrokingTextPainter is used instead.
*
- * TODO handle underline, overline and strikethrough
- * TODO use drawString(AttributedCharacterIterator iterator...) for some
+ * @todo handle underline, overline and strikethrough
+ * @todo use drawString(AttributedCharacterIterator iterator...) for some
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
* @version $Id$
*/
public class PDFTextPainter implements TextPainter {
- FontInfo fontInfo;
+ private FontInfo fontInfo;
/**
* Use the stroking text painter to get the bounds and shape.
* Also used as a fallback to draw the string with strokes.
*/
- protected final static TextPainter proxyPainter =
+ protected static final TextPainter PROXY_PAINTER =
StrokingTextPainter.getInstance();
+ /**
+ * Create a new PDF text painter with the given font information.
+ * @param fi the fint info
+ */
public PDFTextPainter(FontInfo fi) {
fontInfo = fi;
}
@@ -66,7 +70,6 @@ public class PDFTextPainter implements TextPainter {
* specified Graphics2D and context and font context.
* @param node the TextNode to paint
* @param g2d the Graphics2D to use
- * @param context the rendering context.
*/
public void paint(TextNode node, Graphics2D g2d) {
// System.out.println("PDFText paint");
@@ -83,14 +86,17 @@ public class PDFTextPainter implements TextPainter {
if (ch == AttributedCharacterIterator.DONE) {
return;
}
- TextNode.Anchor anchor = (TextNode.Anchor) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
+ TextNode.Anchor anchor;
+ anchor = (TextNode.Anchor) aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
- Vector gvtFonts = (Vector) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
+ Vector gvtFonts;
+ gvtFonts = (Vector) aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
Paint forg = (Paint) aci.getAttribute(TextAttribute.FOREGROUND);
- Paint strokePaint = (Paint) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.STROKE_PAINT);
+ Paint strokePaint;
+ strokePaint = (Paint) aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.STROKE_PAINT);
Float size = (Float) aci.getAttribute(TextAttribute.SIZE);
if (size == null) {
return;
@@ -122,44 +128,21 @@ public class PDFTextPainter implements TextPainter {
useStrokePainter = true;
}
- Object letSpace = aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.LETTER_SPACING);
- if (letSpace != null) {
- useStrokePainter = true;
- }
-
- Object wordSpace = aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.WORD_SPACING);
- if (wordSpace != null) {
- useStrokePainter = true;
- }
-
- Object writeMod = aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE);
- if (!GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE_LTR.equals(
- writeMod)) {
- useStrokePainter = true;
- }
-
- Object vertOr = aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION);
- if (GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE.equals(
- vertOr)) {
+ if (hasUnsupportedAttributes(aci)) {
useStrokePainter = true;
}
-
-
+ // text contains unsupported information
if (useStrokePainter) {
- proxyPainter.paint(node, g2d);
+ PROXY_PAINTER.paint(node, g2d);
return;
}
- String style = ((posture != null) && (posture.floatValue() > 0.0)) ?
- "italic" : "normal";
- int weight = ((taWeight != null) &&
- (taWeight.floatValue() > 1.0)) ? FontInfo.BOLD :
- FontInfo.NORMAL;
+ String style = ((posture != null) && (posture.floatValue() > 0.0))
+ ? "italic" : "normal";
+ int weight = ((taWeight != null)
+ && (taWeight.floatValue() > 1.0)) ? FontInfo.BOLD
+ : FontInfo.NORMAL;
FontState fontState = null;
FontInfo fi = fontInfo;
@@ -170,7 +153,7 @@ public class PDFTextPainter implements TextPainter {
e.hasMoreElements();) {
GVTFontFamily fam = (GVTFontFamily) e.nextElement();
if (fam instanceof SVGFontFamily) {
- proxyPainter.paint(node, g2d);
+ PROXY_PAINTER.paint(node, g2d);
return;
}
fontFamily = fam.getFamilyName();
@@ -229,7 +212,38 @@ public class PDFTextPainter implements TextPainter {
g2d.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
}
- public float getStringWidth(String str, FontState fontState) {
+ private boolean hasUnsupportedAttributes(AttributedCharacterIterator aci) {
+ boolean hasunsupported = false;
+ Object letSpace = aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.LETTER_SPACING);
+ if (letSpace != null) {
+ hasunsupported = true;
+ }
+
+ Object wordSpace = aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.WORD_SPACING);
+ if (wordSpace != null) {
+ hasunsupported = true;
+ }
+
+ AttributedCharacterIterator.Attribute key;
+ key = GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE;
+ Object writeMod = aci.getAttribute(key);
+ if (!GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE_LTR.equals(
+ writeMod)) {
+ hasunsupported = true;
+ }
+
+ Object vertOr = aci.getAttribute(
+ GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION);
+ if (GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE.equals(
+ vertOr)) {
+ hasunsupported = true;
+ }
+ return hasunsupported;
+ }
+
+ private float getStringWidth(String str, FontState fontState) {
float wordWidth = 0;
float whitespaceWidth = fontState.width(fontState.mapChar(' '));
@@ -238,8 +252,9 @@ public class PDFTextPainter implements TextPainter {
char c = str.charAt(i);
if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
charWidth = fontState.width(fontState.mapChar(c));
- if (charWidth <= 0)
+ if (charWidth <= 0) {
charWidth = whitespaceWidth;
+ }
} else {
charWidth = whitespaceWidth;
}
@@ -248,50 +263,123 @@ public class PDFTextPainter implements TextPainter {
return wordWidth / 1000f;
}
+ /**
+ * Get the outline shape of the text characters.
+ * This uses the StrokingTextPainter to get the outline
+ * shape since in theory it should be the same.
+ *
+ * @param node the text node
+ * @return the outline shape of the text characters
+ */
public Shape getOutline(TextNode node) {
- return proxyPainter.getOutline(node);
+ return PROXY_PAINTER.getOutline(node);
}
+ /**
+ * Get the bounds.
+ * This uses the StrokingTextPainter to get the bounds
+ * since in theory it should be the same.
+ *
+ * @param node the text node
+ * @return the bounds of the text
+ */
public Rectangle2D getBounds2D(TextNode node) {
- return proxyPainter.getBounds2D(node);
+ return PROXY_PAINTER.getBounds2D(node);
}
+ /**
+ * Get the geometry bounds.
+ * This uses the StrokingTextPainter to get the bounds
+ * since in theory it should be the same.
+ * @param node the text node
+ * @return the bounds of the text
+ */
public Rectangle2D getGeometryBounds(TextNode node) {
- return proxyPainter.getGeometryBounds(node);
+ return PROXY_PAINTER.getGeometryBounds(node);
}
// Methods that have no purpose for PDF
+ /**
+ * Get the mark.
+ * This does nothing since the output is pdf and not interactive.
+ * @param node the text node
+ * @param pos the position
+ * @param all select all
+ * @return null
+ */
public Mark getMark(TextNode node, int pos, boolean all) {
System.out.println("PDFText getMark");
return null;
}
+ /**
+ * Select at.
+ * This does nothing since the output is pdf and not interactive.
+ * @param x the x position
+ * @param y the y position
+ * @param node the text node
+ * @return null
+ */
public Mark selectAt(double x, double y, TextNode node) {
System.out.println("PDFText selectAt");
return null;
}
+ /**
+ * Select to.
+ * This does nothing since the output is pdf and not interactive.
+ * @param x the x position
+ * @param y the y position
+ * @param beginMark the start mark
+ * @return null
+ */
public Mark selectTo(double x, double y, Mark beginMark) {
System.out.println("PDFText selectTo");
return null;
}
+ /**
+ * Selec first.
+ * This does nothing since the output is pdf and not interactive.
+ * @param node the text node
+ * @return null
+ */
public Mark selectFirst(TextNode node) {
System.out.println("PDFText selectFirst");
return null;
}
+ /**
+ * Select last.
+ * This does nothing since the output is pdf and not interactive.
+ * @param node the text node
+ * @return null
+ */
public Mark selectLast(TextNode node) {
System.out.println("PDFText selectLast");
return null;
}
+ /**
+ * Get selected.
+ * This does nothing since the output is pdf and not interactive.
+ * @param start the start mark
+ * @param finish the finish mark
+ * @return null
+ */
public int[] getSelected(Mark start, Mark finish) {
System.out.println("PDFText getSelected");
return null;
}
+ /**
+ * Get the highlighted shape.
+ * This does nothing since the output is pdf and not interactive.
+ * @param beginMark the start mark
+ * @param endMark the end mark
+ * @return null
+ */
public Shape getHighlightShape(Mark beginMark, Mark endMark) {
System.out.println("PDFText getHighlightShape");
return null;
diff --git a/src/org/apache/fop/svg/PDFTranscoder.java b/src/org/apache/fop/svg/PDFTranscoder.java
index 9333483fc..a55fbc881 100644
--- a/src/org/apache/fop/svg/PDFTranscoder.java
+++ b/src/org/apache/fop/svg/PDFTranscoder.java
@@ -1,41 +1,25 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.svg;
-import java.awt.AlphaComposite;
-import java.awt.Cursor;
import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.geom.*;
-import java.awt.font.*;
+import java.awt.Color;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-
import java.io.IOException;
-import org.apache.batik.transcoder.*;
-
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.BridgeException;
import org.apache.batik.bridge.GVTBuilder;
@@ -46,55 +30,25 @@ import org.apache.batik.bridge.ViewBox;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.dom.svg.SVGOMDocument;
-import org.apache.batik.dom.svg.SVGContext;
import org.apache.batik.dom.util.DocumentFactory;
-import org.apache.batik.ext.awt.image.GraphicsUtil;
-
import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.gvt.event.EventDispatcher;
-import org.apache.batik.gvt.renderer.ImageRenderer;
-import org.apache.batik.gvt.renderer.ImageRendererFactory;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
-import org.apache.batik.transcoder.TranscodingHints;
import org.apache.batik.transcoder.XMLAbstractTranscoder;
import org.apache.batik.transcoder.image.resources.Messages;
-import org.apache.batik.transcoder.keys.BooleanKey;
-import org.apache.batik.transcoder.keys.FloatKey;
-import org.apache.batik.transcoder.keys.LengthKey;
-import org.apache.batik.transcoder.keys.PaintKey;
-import org.apache.batik.transcoder.keys.PaintKey;
-import org.apache.batik.transcoder.keys.Rectangle2DKey;
-import org.apache.batik.transcoder.keys.StringKey;
-import org.apache.batik.transcoder.*;
-import org.apache.batik.transcoder.image.*;
+import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.util.XMLResourceDescriptor;
-import org.apache.batik.bridge.*;
-import org.apache.batik.swing.svg.*;
-import org.apache.batik.swing.gvt.*;
-import org.apache.batik.gvt.*;
-import org.apache.batik.gvt.renderer.*;
-import org.apache.batik.gvt.filter.*;
-import org.apache.batik.gvt.event.*;
-
-import org.w3c.dom.*;
-import org.w3c.dom.svg.*;
-import org.w3c.dom.css.*;
-import org.w3c.dom.svg.SVGLength;
-
-//import org.apache.fop.layout.FontInfo;
-import org.apache.fop.pdf.*;
+import org.apache.batik.gvt.TextPainter;
+import org.apache.batik.gvt.renderer.StrokingTextPainter;
-import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGAElement;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;
@@ -180,7 +134,8 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
textPainter = new StrokingTextPainter();
ctx.setTextPainter(textPainter);
- PDFTextElementBridge pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontInfo());
+ PDFTextElementBridge pdfTextElementBridge;
+ pdfTextElementBridge = new PDFTextElementBridge(graphics.getFontInfo());
ctx.putBridge(pdfTextElementBridge);
PDFAElementBridge pdfAElementBridge = new PDFAElementBridge();
@@ -226,7 +181,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
height = docHeight;
}
// compute the preserveAspectRatio matrix
- AffineTransform Px;
+ AffineTransform px;
String ref = null;
try {
ref = new URL(uri).getRef();
@@ -235,34 +190,34 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
}
try {
- Px = ViewBox.getViewTransform(ref, root, width, height);
+ px = ViewBox.getViewTransform(ref, root, width, height);
} catch (BridgeException ex) {
throw new TranscoderException(ex);
}
- if (Px.isIdentity() && (width != docWidth || height != docHeight)) {
+ if (px.isIdentity() && (width != docWidth || height != docHeight)) {
// The document has no viewBox, we need to resize it by hand.
// we want to keep the document size ratio
float d = Math.max(docWidth, docHeight);
float dd = Math.max(width, height);
float scale = dd / d;
- Px = AffineTransform.getScaleInstance(scale, scale);
+ px = AffineTransform.getScaleInstance(scale, scale);
}
// take the AOI into account if any
if (hints.containsKey(ImageTranscoder.KEY_AOI)) {
Rectangle2D aoi = (Rectangle2D)hints.get(ImageTranscoder.KEY_AOI);
// transform the AOI into the image's coordinate system
- aoi = Px.createTransformedShape(aoi).getBounds2D();
- AffineTransform Mx = new AffineTransform();
+ aoi = px.createTransformedShape(aoi).getBounds2D();
+ AffineTransform mx = new AffineTransform();
double sx = width / aoi.getWidth();
double sy = height / aoi.getHeight();
- Mx.scale(sx, sy);
+ mx.scale(sx, sy);
double tx = -aoi.getX();
double ty = -aoi.getY();
- Mx.translate(tx, ty);
+ mx.translate(tx, ty);
// take the AOI transformation matrix into account
// we apply first the preserveAspectRatio matrix
- Px.preConcatenate(Mx);
+ px.preConcatenate(mx);
}
// prepare the image to be painted
int w = (int)width;
@@ -284,7 +239,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
graphics.setBackgroundColor((Color)hints.get(ImageTranscoder.KEY_BACKGROUND_COLOR));
}
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
- graphics.setTransform(Px);
+ graphics.setTransform(px);
gvtRoot.paint(graphics);
@@ -302,6 +257,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
*
* @param domImpl the DOM Implementation (not used)
* @param parserClassname the XML parser classname
+ * @return the document factory
*/
protected DocumentFactory createDocumentFactory(DOMImplementation domImpl,
String parserClassname) {
@@ -319,6 +275,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Returns the default size of this user agent (400x400).
+ * @return the default viewport size
*/
public Dimension2D getViewportSize() {
return new Dimension(400, 400);
@@ -326,6 +283,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Displays the specified error message using the <tt>ErrorHandler</tt>.
+ * @param message the message to display
*/
public void displayError(String message) {
try {
@@ -337,6 +295,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Displays the specified error using the <tt>ErrorHandler</tt>.
+ * @param e the exception to display
*/
public void displayError(Exception e) {
try {
@@ -348,6 +307,7 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Displays the specified message using the <tt>ErrorHandler</tt>.
+ * @param message the message to display
*/
public void displayMessage(String message) {
try {
@@ -360,10 +320,12 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Returns the pixel to millimeter conversion factor specified in the
* <tt>TranscodingHints</tt> or 0.3528 if any.
+ * @return the pixel unit to millimeter factor
*/
public float getPixelUnitToMillimeter() {
- if (getTranscodingHints().containsKey(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER)) {
- return ((Float)getTranscodingHints().get(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER)).floatValue();
+ Object key = ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER;
+ if (getTranscodingHints().containsKey(key)) {
+ return ((Float)getTranscodingHints().get(key)).floatValue();
} else {
// return 0.3528f; // 72 dpi
return 0.26458333333333333333333333333333f; // 96dpi
@@ -373,15 +335,21 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Returns the user language specified in the
* <tt>TranscodingHints</tt> or "en" (english) if any.
+ * @return the languages for the transcoder
*/
public String getLanguages() {
- if (getTranscodingHints().containsKey(ImageTranscoder.KEY_LANGUAGE)) {
- return (String)getTranscodingHints().get(ImageTranscoder.KEY_LANGUAGE);
+ Object key = ImageTranscoder.KEY_LANGUAGE;
+ if (getTranscodingHints().containsKey(key)) {
+ return (String)getTranscodingHints().get(key);
} else {
return "en";
}
}
+ /**
+ * Get the media for this transcoder. Which is always print.
+ * @return PDF media is "print"
+ */
public String getMedia() {
return "print";
}
@@ -389,28 +357,37 @@ public class PDFTranscoder extends XMLAbstractTranscoder {
/**
* Returns the user stylesheet specified in the
* <tt>TranscodingHints</tt> or null if any.
+ * @return the user style sheet URI specified in the hints
*/
public String getUserStyleSheetURI() {
- return (String)getTranscodingHints().get(ImageTranscoder.KEY_USER_STYLESHEET_URI);
+ return (String)getTranscodingHints()
+ .get(ImageTranscoder.KEY_USER_STYLESHEET_URI);
}
/**
* Returns the XML parser to use from the TranscodingHints.
+ * @return the XML parser class name
*/
public String getXMLParserClassName() {
- if (getTranscodingHints().containsKey(KEY_XML_PARSER_CLASSNAME)) {
- return (String)getTranscodingHints().get(KEY_XML_PARSER_CLASSNAME);
+ Object key = KEY_XML_PARSER_CLASSNAME;
+ if (getTranscodingHints().containsKey(key)) {
+ return (String)getTranscodingHints().get(key);
} else {
return XMLResourceDescriptor.getXMLParserClassName();
}
}
+ /**
+ * Check if the XML parser is validating.
+ * @return true if the XML parser is validating
+ */
public boolean isXMLParserValidating() {
return false;
}
/**
* Unsupported operation.
+ * @return null since this is unsupported
*/
public AffineTransform getTransform() {
return null;
diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java
index ab7bf7215..fa61e0251 100644
--- a/src/org/apache/fop/svg/SVGElement.java
+++ b/src/org/apache/fop/svg/SVGElement.java
@@ -31,25 +31,35 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/**
- * class representing svg:svg pseudo flow object.
+ * class representing the SVG root element
+ * for constructing an svg document.
*/
public class SVGElement extends SVGObj {
/**
- * constructs an SVG object (called by Maker).
+ * Constructs an SVG object
*
* @param parent the parent formatting object
- * @param propertyList the explicit properties of this object
*/
public SVGElement(FONode parent) {
super(parent);
}
+ /**
+ * Handle the xml attributes from SAX.
+ * @param attlist the attribute list
+ * @throws FOPException not thrown from here
+ */
public void handleAttrs(Attributes attlist) throws FOPException {
super.handleAttrs(attlist);
init();
}
+ /**
+ * Get the dimensions of this XML document.
+ * @param view the viewport dimensions
+ * @return the dimensions of this SVG document
+ */
public Point2D getDimension(final Point2D view) {
// TODO - change so doesn't hold onto fo,area tree
@@ -59,7 +69,7 @@ public class SVGElement extends SVGObj {
try {
String baseDir = userAgent.getBaseURL();
- if(baseDir != null) {
+ if (baseDir != null) {
((SVGOMDocument)doc).setURLObject(new URL(baseDir));
}
} catch (Exception e) {
@@ -68,6 +78,7 @@ public class SVGElement extends SVGObj {
Element e = ((SVGDocument)doc).getRootElement();
final float ptmm = userAgent.getPixelUnitToMillimeter();
+ // temporary svg context
SVGContext dc = new SVGContext() {
public float getPixelToMM() {
return ptmm;
@@ -96,14 +107,15 @@ public class SVGElement extends SVGObj {
return (float)view.getY();
}
- public float getFontSize(){
+ public float getFontSize() {
return 12;
}
};
((SVGOMElement)e).setSVGContext(dc);
- //if(!e.hasAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns")) {
- e.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns", SVGDOMImplementation.SVG_NAMESPACE_URI);
+ //if (!e.hasAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns")) {
+ e.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns",
+ SVGDOMImplementation.SVG_NAMESPACE_URI);
//}
int fontSize = 12;
Point2D p2d = getSize(fontSize, svgRoot, userAgent.getPixelUnitToMillimeter());
@@ -122,17 +134,28 @@ public class SVGElement extends SVGObj {
buildTopLevel(doc, element);
}
+ /**
+ * Get the size of the SVG root element.
+ * @param size the font size
+ * @param svgRoot the svg root element
+ * @param ptmm the pixel to millimeter conversion factor
+ * @return the size of the SVG document
+ */
public static Point2D getSize(int size, Element svgRoot, float ptmm) {
String str;
UnitProcessor.Context ctx;
ctx = new PDFUnitContext(size, svgRoot, ptmm);
str = svgRoot.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE);
- if (str.length() == 0) str = "100%";
+ if (str.length() == 0) {
+ str = "100%";
+ }
float width = UnitProcessor.svgHorizontalLengthToUserSpace
(str, SVGConstants.SVG_WIDTH_ATTRIBUTE, ctx);
str = svgRoot.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE);
- if (str.length() == 0) str = "100%";
+ if (str.length() == 0) {
+ str = "100%";
+ }
float height = UnitProcessor.svgVerticalLengthToUserSpace
(str, SVGConstants.SVG_HEIGHT_ATTRIBUTE, ctx);
return new Point2D.Float(width, height);
@@ -147,10 +170,16 @@ public class SVGElement extends SVGObj {
public static class PDFUnitContext implements UnitProcessor.Context {
/** The element. */
- protected Element e;
- protected int fontSize;
- float pixeltoMM;
+ private Element e;
+ private int fontSize;
+ private float pixeltoMM;
+ /**
+ * Create a PDF unit context.
+ * @param size the font size.
+ * @param e the svg element
+ * @param ptmm the pixel to millimeter factor
+ */
public PDFUnitContext(int size, Element e, float ptmm) {
this.e = e;
this.fontSize = size;
@@ -159,6 +188,7 @@ public class SVGElement extends SVGObj {
/**
* Returns the element.
+ * @return the element
*/
public Element getElement() {
return e;
@@ -168,23 +198,31 @@ public class SVGElement extends SVGObj {
* Returns the context of the parent element of this context.
* Since this is always for the root SVG element there never
* should be one...
+ * @return null
*/
public UnitProcessor.Context getParentElementContext() {
return null;
}
/**
- * Returns the pixel to mm factor.
+ * Returns the pixel to mm factor. (this is deprecated)
+ * @return the pixel to millimeter factor
*/
public float getPixelToMM() {
return pixeltoMM;
}
+
+ /**
+ * Returns the pixel to mm factor.
+ * @return the pixel to millimeter factor
+ */
public float getPixelUnitToMillimeter() {
return pixeltoMM;
}
/**
* Returns the font-size value.
+ * @return the default font size
*/
public float getFontSize() {
return fontSize;
@@ -192,6 +230,7 @@ public class SVGElement extends SVGObj {
/**
* Returns the x-height value.
+ * @return the x-height value
*/
public float getXHeight() {
return 0.5f;
@@ -199,6 +238,7 @@ public class SVGElement extends SVGObj {
/**
* Returns the viewport width used to compute units.
+ * @return the default viewport width of 100
*/
public float getViewportWidth() {
return 100;
@@ -206,6 +246,7 @@ public class SVGElement extends SVGObj {
/**
* Returns the viewport height used to compute units.
+ * @return the default viewport height of 100
*/
public float getViewportHeight() {
return 100;
diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java
index 785f66080..a30b61988 100644
--- a/src/org/apache/fop/svg/SVGElementMapping.java
+++ b/src/org/apache/fop/svg/SVGElementMapping.java
@@ -1,6 +1,6 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -16,8 +16,12 @@ import org.apache.fop.apps.Driver;
import org.apache.batik.util.XMLResourceDescriptor;
import org.apache.batik.dom.svg.SVGDOMImplementation;
-import org.w3c.dom.DOMImplementation;
+/**
+ * Setup the SVG element mapping.
+ * This adds the svg element mappings used to create the objects
+ * that create the SVG Document.
+ */
public class SVGElementMapping implements ElementMapping {
private static HashMap foObjs = null;
private static boolean batik = true;
@@ -36,8 +40,12 @@ public class SVGElementMapping implements ElementMapping {
}
}
+ /**
+ * Add the SVG element mappings to the tree builder.
+ * @param builder the FOTreeBuilder to add the mappings to
+ */
public void addToBuilder(FOTreeBuilder builder) {
- if(batik) {
+ if (batik) {
try {
setupSVG();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
diff --git a/src/org/apache/fop/svg/SVGObj.java b/src/org/apache/fop/svg/SVGObj.java
index f33c0b43c..8daa2a652 100644
--- a/src/org/apache/fop/svg/SVGObj.java
+++ b/src/org/apache/fop/svg/SVGObj.java
@@ -10,6 +10,10 @@ package org.apache.fop.svg;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.XMLObj;
+/**
+ * Class for SVG element objects.
+ * This aids in the construction of the SVG Document.
+ */
public class SVGObj extends XMLObj {
/**
* constructs an svg object (called by Maker).
diff --git a/src/org/apache/fop/svg/SVGUserAgent.java b/src/org/apache/fop/svg/SVGUserAgent.java
index a3b458588..10a584e9c 100644
--- a/src/org/apache/fop/svg/SVGUserAgent.java
+++ b/src/org/apache/fop/svg/SVGUserAgent.java
@@ -1,6 +1,6 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
@@ -9,37 +9,29 @@ package org.apache.fop.svg;
import org.apache.fop.fo.FOUserAgent;
-import org.apache.batik.bridge.*;
-import org.apache.batik.swing.svg.*;
-import org.apache.batik.swing.gvt.*;
-import org.apache.batik.gvt.*;
-import org.apache.batik.gvt.renderer.*;
-import org.apache.batik.gvt.filter.*;
-import org.apache.batik.gvt.event.*;
+import org.apache.batik.bridge.UserAgentAdapter;
import org.apache.avalon.framework.logger.Logger;
-import org.w3c.dom.*;
-import org.w3c.dom.svg.*;
-import org.w3c.dom.css.*;
-import org.w3c.dom.svg.SVGLength;
-
// Java
-import java.io.IOException;
-import java.io.OutputStream;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
-import java.awt.Point;
-import java.awt.RenderingHints;
import java.awt.Dimension;
+/**
+ * The SVG user agent.
+ * This is an implementation of the batik svg user agent
+ * for handling errors and getting user agent values.
+ */
public class SVGUserAgent extends UserAgentAdapter {
- AffineTransform currentTransform = null;
- Logger log;
- FOUserAgent userAgent;
+ private AffineTransform currentTransform = null;
+ private Logger log;
+ private FOUserAgent userAgent;
/**
* Creates a new SVGUserAgent.
+ * @param ua the FO user agent
+ * @param at the current transform
*/
public SVGUserAgent(FOUserAgent ua, AffineTransform at) {
currentTransform = at;
@@ -49,6 +41,7 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Displays an error message.
+ * @param message the message to display
*/
public void displayError(String message) {
log.error(message);
@@ -56,6 +49,7 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Displays an error resulting from the specified Exception.
+ * @param ex the exception to display
*/
public void displayError(Exception ex) {
log.error("SVG Error" + ex.getMessage(), ex);
@@ -64,6 +58,7 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Displays a message in the User Agent interface.
* The given message is typically displayed in a status bar.
+ * @param message the message to display
*/
public void displayMessage(String message) {
log.info(message);
@@ -71,6 +66,7 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Shows an alert dialog box.
+ * @param message the message to display
*/
public void showAlert(String message) {
log.warn(message);
@@ -78,18 +74,24 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Returns a customized the pixel to mm factor.
+ * @return the pixel unit to millimeter conversion factor
*/
- public float getPixelUnitToMillimter() {
+ public float getPixelUnitToMillimeter() {
return userAgent.getPixelUnitToMillimeter();
}
/**
* Returns the language settings.
+ * @return the languages supported
*/
public String getLanguages() {
return "en"; // userLanguages;
}
+ /**
+ * Returns the media type for this rendering.
+ * @return the media for fo documents is "print"
+ */
public String getMedia() {
return "print";
}
@@ -104,19 +106,33 @@ public class SVGUserAgent extends UserAgentAdapter {
/**
* Returns the class name of the XML parser.
+ * @return the XML parser class name
*/
public String getXMLParserClassName() {
return org.apache.fop.apps.Driver.getParserClassName();
}
+ /**
+ * Is the XML parser validating.
+ * @return true if the xml parser is validating
+ */
public boolean isXMLParserValidating() {
return false;
}
+ /**
+ * Get the transform of the svg document.
+ * @return the transform
+ */
public AffineTransform getTransform() {
return currentTransform;
}
+ /**
+ * Get the default viewport size for an svg document.
+ * This returns a default value of 100x100.
+ * @return the default viewport size
+ */
public Dimension2D getViewportSize() {
return new Dimension(100, 100);
}
diff --git a/src/org/apache/fop/svg/SVGUtilities.java b/src/org/apache/fop/svg/SVGUtilities.java
index bbc22cb44..dd8e46951 100644
--- a/src/org/apache/fop/svg/SVGUtilities.java
+++ b/src/org/apache/fop/svg/SVGUtilities.java
@@ -1,28 +1,22 @@
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.svg;
-import java.util.*;
-import java.text.*;
-import java.awt.*;
+import java.util.StringTokenizer;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.font.FontRenderContext;
-import org.apache.fop.fo.*;
-import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.*;
-import org.apache.fop.apps.*;
-import org.apache.fop.datatypes.*;
-import org.apache.fop.svg.*;
-import org.w3c.dom.*;
-import org.w3c.dom.svg.*;
-import org.w3c.dom.css.*;
+//import org.apache.fop.fo.*;
+//import org.apache.fop.datatypes.*;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.DOMImplementation;
import org.apache.batik.dom.svg.SVGDOMImplementation;
@@ -30,13 +24,18 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
* Some utilities for creating svg DOM documents and elements.
*/
public class SVGUtilities {
- final static String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
-
+ private static final String SVG_NS = SVGDOMImplementation.SVG_NAMESPACE_URI;
+ /**
+ * Create a new svg document with batik.
+ * @param width the width of the root svg element
+ * @param height the height of the root svg element
+ * @return a new SVG Document
+ */
public static final Document createSVGDocument(float width,
float height) {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
- Document doc = impl.createDocument(svgNS, "svg", null);
+ Document doc = impl.createDocument(SVG_NS, "svg", null);
Element svgRoot = doc.getDocumentElement();
svgRoot.setAttributeNS(null, "width", "" + width);
@@ -46,6 +45,9 @@ public class SVGUtilities {
/**
* Get the string width for a particular string given the font.
+ * @param str the string
+ * @param font the font
+ * @return the width of the string in the given font
*/
public static final float getStringWidth(String str, java.awt.Font font) {
Rectangle2D rect =
@@ -57,6 +59,9 @@ public class SVGUtilities {
/**
* Get the string height for a particular string given the font.
+ * @param str the string
+ * @param font the font
+ * @return the height of the string in the given font
*/
public static final float getStringHeight(String str,
java.awt.Font font) {
@@ -69,6 +74,9 @@ public class SVGUtilities {
/**
* Get the string bounds for a particular string given the font.
+ * @param str the string
+ * @param font the font
+ * @return the bounds of the string
*/
public static final Rectangle2D getStringBounds(String str,
java.awt.Font font) {
@@ -79,10 +87,16 @@ public class SVGUtilities {
/**
* Create an SVG Line
+ * @param doc the document to create the element
+ * @param x the start x position
+ * @param y the start y position
+ * @param x2 the end x position
+ * @param y2 the end y position
+ * @return the new line element
*/
public static final Element createLine(Document doc, float x, float y,
float x2, float y2) {
- Element ellipse = doc.createElementNS(svgNS, "line");
+ Element ellipse = doc.createElementNS(SVG_NS, "line");
ellipse.setAttributeNS(null, "x1", "" + x);
ellipse.setAttributeNS(null, "x2", "" + x2);
ellipse.setAttributeNS(null, "y1", "" + y);
@@ -92,10 +106,16 @@ public class SVGUtilities {
/**
* Create an SVG Ellipse
+ * @param doc the document to create the element
+ * @param cx the centre x position
+ * @param cy the centre y position
+ * @param rx the x axis radius
+ * @param ry the y axis radius
+ * @return the new ellipse element
*/
public static final Element createEllipse(Document doc, float cx,
float cy, float rx, float ry) {
- Element ellipse = doc.createElementNS(svgNS, "ellipse");
+ Element ellipse = doc.createElementNS(SVG_NS, "ellipse");
ellipse.setAttributeNS(null, "cx", "" + cx);
ellipse.setAttributeNS(null, "rx", "" + rx);
ellipse.setAttributeNS(null, "cy", "" + cy);
@@ -105,19 +125,27 @@ public class SVGUtilities {
/**
* Create an SVG Path.
+ * @param doc the document to create the element
+ * @param str the string for the d attribute on the path
+ * @return the new path element
*/
public static final Element createPath(Document doc, String str) {
- Element path = doc.createElementNS(svgNS, "path");
+ Element path = doc.createElementNS(SVG_NS, "path");
path.setAttributeNS(null, "d", str);
return path;
}
/**
* Create an SVG Text object.
+ * @param doc the document to create the element
+ * @param x the start x position
+ * @param y the start y position
+ * @param str the string
+ * @return the new text element
*/
public static final Element createText(Document doc, float x, float y,
String str) {
- Element textGraph = doc.createElementNS(svgNS, "text");
+ Element textGraph = doc.createElementNS(SVG_NS, "text");
textGraph.setAttributeNS(null, "x", "" + x);
textGraph.setAttributeNS(null, "y", "" + y);
org.w3c.dom.Text text = doc.createTextNode(str);
@@ -127,10 +155,16 @@ public class SVGUtilities {
/**
* Create an SVG Rectangle.
+ * @param doc the document to create the element
+ * @param x the start x position
+ * @param y the start y position
+ * @param width the width of the rectangle
+ * @param height the height of the rectangle
+ * @return the new rectangle element
*/
public static final Element createRect(Document doc, float x, float y,
float width, float height) {
- Element border = doc.createElementNS(svgNS, "rect");
+ Element border = doc.createElementNS(SVG_NS, "rect");
border.setAttributeNS(null, "x", "" + x);
border.setAttributeNS(null, "y", "" + y);
border.setAttributeNS(null, "width", "" + width);
@@ -140,26 +174,40 @@ public class SVGUtilities {
/**
* Create an SVG G.
+ * @param doc the document to create the element
+ * @return the new g element
*/
public static final Element createG(Document doc) {
- Element border = doc.createElementNS(svgNS, "g");
+ Element border = doc.createElementNS(SVG_NS, "g");
return border;
}
/**
* Create an SVG Clip.
+ * @param doc the document to create the element
+ * @param els the child elements that make the clip
+ * @param id the id of the clipping path
+ * @return the new clip element
*/
public static final Element createClip(Document doc, Element els,
String id) {
- Element border = doc.createElementNS(svgNS, "clipPath");
+ Element border = doc.createElementNS(SVG_NS, "clipPath");
border.setAttributeNS(null, "id", id);
border.appendChild(els);
return border;
}
+ /**
+ * Create and svg image element.
+ * @param doc the document to create the element
+ * @param ref the href link to the image
+ * @param width the width to set on the image
+ * @param height the height to set on the image
+ * @return a new image element
+ */
public static final Element createImage(Document doc, String ref,
float width, float height) {
- Element border = doc.createElementNS(svgNS, "image");
+ Element border = doc.createElementNS(SVG_NS, "image");
border.setAttributeNS("http://www.w3.org/1999/xlink", "href",
ref);
border.setAttributeNS(null, "width", "" + width);
@@ -168,7 +216,12 @@ public class SVGUtilities {
}
/**
- * Create some SVG text that is wrapped into a specified width..
+ * Create some SVG text that is wrapped into a specified width.
+ * @param doc the document to create the elements
+ * @param str the string to wrap
+ * @param font the font
+ * @param width the width to wrap
+ * @return the new element containing the wrapped text
*/
public static final Element wrapText(Document doc, String str,
java.awt.Font font, float width) {