aboutsummaryrefslogtreecommitdiffstats
path: root/src/sandbox/org/apache
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2009-09-18 17:10:42 +0000
committerVincent Hennebert <vhennebert@apache.org>2009-09-18 17:10:42 +0000
commit0e5a789b6b0604bb9c6cc9b782c22f490917e9f9 (patch)
tree70af78b83ebd8d83f4576c8b9329113ee34aae0f /src/sandbox/org/apache
parentc5d9b312e01efc7f96a30043d73945594504c7d0 (diff)
parent9b49126cd645f4377d1bb56d5078a8d4a0cd491e (diff)
downloadxmlgraphics-fop-0e5a789b6b0604bb9c6cc9b782c22f490917e9f9.tar.gz
xmlgraphics-fop-0e5a789b6b0604bb9c6cc9b782c22f490917e9f9.zip
Merged changes from Trunk up to revision 816269
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@816718 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox/org/apache')
-rw-r--r--src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java20
-rw-r--r--src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java88
-rw-r--r--src/sandbox/org/apache/fop/render/svg/SVGPainter.java57
-rw-r--r--src/sandbox/org/apache/fop/render/svg/SVGUtil.java78
4 files changed, 157 insertions, 86 deletions
diff --git a/src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java b/src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java
index b20982d54..fdcac6c35 100644
--- a/src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java
+++ b/src/sandbox/org/apache/fop/render/svg/EmbeddedSVGImageHandler.java
@@ -90,12 +90,11 @@ public class EmbeddedSVGImageHandler implements ImageHandler, SVGConstants {
ImageXMLDOM svg = (ImageXMLDOM)image;
ContentHandler handler = svgContext.getContentHandler();
AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "x", "x", CDATA, Integer.toString(pos.x));
- atts.addAttribute("", "y", "y", CDATA, Integer.toString(pos.y));
- atts.addAttribute("", "width", "width", CDATA, Integer.toString(pos.width));
- atts.addAttribute("", "height", "height", CDATA, Integer.toString(pos.height));
+ atts.addAttribute("", "x", "x", CDATA, SVGUtil.formatMptToPt(pos.x));
+ atts.addAttribute("", "y", "y", CDATA, SVGUtil.formatMptToPt(pos.y));
+ atts.addAttribute("", "width", "width", CDATA, SVGUtil.formatMptToPt(pos.width));
+ atts.addAttribute("", "height", "height", CDATA, SVGUtil.formatMptToPt(pos.height));
try {
- //handler.startElement(NAMESPACE, "svg", "svg", atts);
Document doc = (Document)svg.getDocument();
Element svgEl = (Element)doc.getDocumentElement();
@@ -127,10 +126,10 @@ public class EmbeddedSVGImageHandler implements ImageHandler, SVGConstants {
&& SVG_ELEMENT.getLocalName().equals(localName)) {
topLevelSVGFound = true;
AttributesImpl modAtts = new AttributesImpl(atts);
- setAttribute(modAtts, "x", Integer.toString(pos.x));
- setAttribute(modAtts, "y", Integer.toString(pos.y));
- setAttribute(modAtts, "width", Integer.toString(pos.width));
- setAttribute(modAtts, "height", Integer.toString(pos.height));
+ setAttribute(modAtts, "x", SVGUtil.formatMptToPt(pos.x));
+ setAttribute(modAtts, "y", SVGUtil.formatMptToPt(pos.y));
+ setAttribute(modAtts, "width", SVGUtil.formatMptToPt(pos.width));
+ setAttribute(modAtts, "height", SVGUtil.formatMptToPt(pos.height));
super.startElement(uri, localName, name, modAtts);
} else {
super.startElement(uri, localName, name, atts);
@@ -139,9 +138,6 @@ public class EmbeddedSVGImageHandler implements ImageHandler, SVGConstants {
});
transformer.transform(src, res);
- //handler.endElement(NAMESPACE, "svg", "svg");
- //} catch (SAXException e) {
- //throw new IOException(e.getMessage());
} catch (TransformerException te) {
throw new IOException(te.getMessage());
}
diff --git a/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java b/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
index a8ce2dd2b..42ca17e08 100644
--- a/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
+++ b/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
@@ -22,9 +22,6 @@ package org.apache.fop.render.svg;
import java.awt.Dimension;
import java.io.IOException;
import java.io.OutputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -66,6 +63,9 @@ public class SVGDocumentHandler extends AbstractSVGDocumentHandler {
private StreamResult firstStream;
private StreamResult currentStream;
+ /** Used for single-page documents rendered to a DOM or SAX. */
+ private Result simpleResult;
+
private Document reusedParts;
/**
@@ -92,7 +92,7 @@ public class SVGDocumentHandler extends AbstractSVGDocumentHandler {
getUserAgent().getOutputFile());
this.firstStream = (StreamResult)result;
} else {
- throw new UnsupportedOperationException("Result is not supported: " + result);
+ this.simpleResult = result;
}
}
@@ -152,46 +152,19 @@ public class SVGDocumentHandler extends AbstractSVGDocumentHandler {
/** {@inheritDoc} */
public void startPage(int index, String name, String pageMasterName, Dimension size)
throws IFException {
- OutputStream out;
- try {
- if (index == 0) {
- out = null;
- } else {
- out = this.multiFileUtil.createOutputStream(index);
- if (out == null) {
- //TODO Convert to event
- throw new IFException(
- "No filename information available. Stopping after first page.", null);
- }
- }
- } catch (IOException ioe) {
- throw new IFException("I/O exception while setting up output file", ioe);
- }
- if (out == null) {
- this.handler = decorate(createContentHandler(this.firstStream));
+ if (this.multiFileUtil != null) {
+ prepareHandlerWithOutputStream(index);
} else {
- this.currentStream = new StreamResult(out);
- this.handler = decorate(createContentHandler(this.currentStream));
- }
- if (false) {
- final ContentHandler originalHandler = this.handler;
- this.handler = decorate((ContentHandler)Proxy.newProxyInstance(
- ContentHandler.class.getClassLoader(),
- new Class[] {ContentHandler.class},
- new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- String methodName = method.getName();
- System.out.println(methodName + ":");
- if (args != null) {
- for (int i = 0; i < args.length; i++) {
- System.out.println(" " + args[i]);
- }
- }
- return method.invoke(originalHandler, args);
- }
- }));
+ if (this.simpleResult == null) {
+ //Only one page is supported with this approach at the moment
+ throw new IFException(
+ "Only one page is supported for output with the given Result instance!",
+ null);
+ }
+ super.setResult(this.simpleResult);
+ this.simpleResult = null;
}
+
try {
handler.startDocument();
handler.startPrefixMapping("", NAMESPACE);
@@ -202,10 +175,11 @@ public class SVGDocumentHandler extends AbstractSVGDocumentHandler {
XMLUtil.addAttribute(atts, "index", Integer.toString(index));
XMLUtil.addAttribute(atts, "name", name);
*/
- XMLUtil.addAttribute(atts, "width", Float.toString(size.width / 1000f) + "pt");
- XMLUtil.addAttribute(atts, "height", Float.toString(size.height / 1000f) + "pt");
+ XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(size.width) + "pt");
+ XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(size.height) + "pt");
XMLUtil.addAttribute(atts, "viewBox",
- "0 0 " + Integer.toString(size.width) + " " + Integer.toString(size.height));
+ "0 0 " + SVGUtil.formatMptToPt(size.width)
+ + " " + SVGUtil.formatMptToPt(size.height));
handler.startElement("svg", atts);
try {
@@ -227,6 +201,30 @@ public class SVGDocumentHandler extends AbstractSVGDocumentHandler {
}
}
+ private void prepareHandlerWithOutputStream(int index) throws IFException {
+ OutputStream out;
+ try {
+ if (index == 0) {
+ out = null;
+ } else {
+ out = this.multiFileUtil.createOutputStream(index);
+ if (out == null) {
+ //TODO Convert to event
+ throw new IFException(
+ "No filename information available. Stopping after first page.", null);
+ }
+ }
+ } catch (IOException ioe) {
+ throw new IFException("I/O exception while setting up output file", ioe);
+ }
+ if (out == null) {
+ this.handler = decorate(createContentHandler(this.firstStream));
+ } else {
+ this.currentStream = new StreamResult(out);
+ this.handler = decorate(createContentHandler(this.currentStream));
+ }
+ }
+
private GenerationHelperContentHandler decorate(ContentHandler contentHandler) {
return new GenerationHelperContentHandler(contentHandler, getMainNamespace());
}
diff --git a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
index c31190eba..aa2e325d9 100644
--- a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
+++ b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
@@ -52,7 +52,6 @@ import org.apache.fop.render.intermediate.IFConstants;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
-import org.apache.fop.render.intermediate.IFUtil;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.ColorUtil;
@@ -99,13 +98,13 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
/** {@inheritDoc} */
public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
throws IFException {
- startViewport(IFUtil.toString(transform), size, clipRect);
+ startViewport(SVGUtil.formatAffineTransformMptToPt(transform), size, clipRect);
}
/** {@inheritDoc} */
public void startViewport(AffineTransform[] transforms, Dimension size, Rectangle clipRect)
throws IFException {
- startViewport(IFUtil.toString(transforms), size, clipRect);
+ startViewport(SVGUtil.formatAffineTransformsMptToPt(transforms), size, clipRect);
}
private void startViewport(String transform, Dimension size, Rectangle clipRect)
@@ -119,8 +118,8 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
handler.startElement("g", atts);
atts.clear();
- XMLUtil.addAttribute(atts, "width", Integer.toString(size.width));
- XMLUtil.addAttribute(atts, "height", Integer.toString(size.height));
+ XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(size.width));
+ XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(size.height));
if (clipRect != null) {
int[] v = new int[] {
clipRect.y,
@@ -133,10 +132,10 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
}
if (sum != 0) {
StringBuffer sb = new StringBuffer("rect(");
- sb.append(v[0]).append(',');
- sb.append(v[1]).append(',');
- sb.append(v[2]).append(',');
- sb.append(v[3]).append(')');
+ sb.append(SVGUtil.formatMptToPt(v[0])).append(',');
+ sb.append(SVGUtil.formatMptToPt(v[1])).append(',');
+ sb.append(SVGUtil.formatMptToPt(v[2])).append(',');
+ sb.append(SVGUtil.formatMptToPt(v[3])).append(')');
XMLUtil.addAttribute(atts, "clip", sb.toString());
}
XMLUtil.addAttribute(atts, "overflow", "hidden");
@@ -162,12 +161,12 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
/** {@inheritDoc} */
public void startGroup(AffineTransform[] transforms) throws IFException {
- startGroup(IFUtil.toString(transforms));
+ startGroup(SVGUtil.formatAffineTransformsMptToPt(transforms));
}
/** {@inheritDoc} */
public void startGroup(AffineTransform transform) throws IFException {
- startGroup(IFUtil.toString(transform));
+ startGroup(SVGUtil.formatAffineTransformMptToPt(transform));
}
private void startGroup(String transform) throws IFException {
@@ -216,10 +215,10 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
//TODO Some additional URI rewriting might be necessary
AttributesImpl atts = new AttributesImpl();
XMLUtil.addAttribute(atts, IFConstants.XLINK_HREF, uri);
- XMLUtil.addAttribute(atts, "x", Integer.toString(rect.x));
- XMLUtil.addAttribute(atts, "y", Integer.toString(rect.y));
- XMLUtil.addAttribute(atts, "width", Integer.toString(rect.width));
- XMLUtil.addAttribute(atts, "height", Integer.toString(rect.height));
+ XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(rect.x));
+ XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(rect.y));
+ XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(rect.width));
+ XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(rect.height));
handler.element("image", atts);
} else {
drawImageUsingImageHandler(info, rect);
@@ -282,10 +281,10 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
try {
establish(MODE_NORMAL);
AttributesImpl atts = new AttributesImpl();
- XMLUtil.addAttribute(atts, "x", Integer.toString(rect.x));
- XMLUtil.addAttribute(atts, "y", Integer.toString(rect.y));
- XMLUtil.addAttribute(atts, "width", Integer.toString(rect.width));
- XMLUtil.addAttribute(atts, "height", Integer.toString(rect.height));
+ XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(rect.x));
+ XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(rect.y));
+ XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(rect.width));
+ XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(rect.height));
if (fill != null) {
XMLUtil.addAttribute(atts, "fill", toString(fill));
}
@@ -311,10 +310,10 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
try {
establish(MODE_NORMAL);
AttributesImpl atts = new AttributesImpl();
- XMLUtil.addAttribute(atts, "x1", Integer.toString(start.x));
- XMLUtil.addAttribute(atts, "y1", Integer.toString(start.y));
- XMLUtil.addAttribute(atts, "x2", Integer.toString(end.x));
- XMLUtil.addAttribute(atts, "y2", Integer.toString(end.y));
+ XMLUtil.addAttribute(atts, "x1", SVGUtil.formatMptToPt(start.x));
+ XMLUtil.addAttribute(atts, "y1", SVGUtil.formatMptToPt(start.y));
+ XMLUtil.addAttribute(atts, "x2", SVGUtil.formatMptToPt(end.x));
+ XMLUtil.addAttribute(atts, "y2", SVGUtil.formatMptToPt(end.y));
XMLUtil.addAttribute(atts, "stroke-width", toString(color));
XMLUtil.addAttribute(atts, "fill", toString(color));
//TODO Handle style parameter
@@ -332,16 +331,16 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
establish(MODE_TEXT);
AttributesImpl atts = new AttributesImpl();
XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve");
- XMLUtil.addAttribute(atts, "x", Integer.toString(x));
- XMLUtil.addAttribute(atts, "y", Integer.toString(y));
+ XMLUtil.addAttribute(atts, "x", SVGUtil.formatMptToPt(x));
+ XMLUtil.addAttribute(atts, "y", SVGUtil.formatMptToPt(y));
if (letterSpacing != 0) {
- XMLUtil.addAttribute(atts, "letter-spacing", Integer.toString(letterSpacing));
+ XMLUtil.addAttribute(atts, "letter-spacing", SVGUtil.formatMptToPt(letterSpacing));
}
if (wordSpacing != 0) {
- XMLUtil.addAttribute(atts, "word-spacing", Integer.toString(wordSpacing));
+ XMLUtil.addAttribute(atts, "word-spacing", SVGUtil.formatMptToPt(wordSpacing));
}
if (dx != null) {
- XMLUtil.addAttribute(atts, "dx", IFUtil.toString(dx));
+ XMLUtil.addAttribute(atts, "dx", SVGUtil.formatMptArrayToPt(dx));
}
handler.startElement("text", atts);
char[] chars = text.toCharArray();
@@ -386,7 +385,7 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants {
XMLUtil.addAttribute(atts, "font-style", state.getFontStyle());
XMLUtil.addAttribute(atts, "font-weight", Integer.toString(state.getFontWeight()));
XMLUtil.addAttribute(atts, "font-variant", state.getFontVariant());
- XMLUtil.addAttribute(atts, "font-size", Integer.toString(state.getFontSize()));
+ XMLUtil.addAttribute(atts, "font-size", SVGUtil.formatMptToPt(state.getFontSize()));
XMLUtil.addAttribute(atts, "fill", toString(state.getTextColor()));
handler.startElement("g", atts);
state.resetFontChanged();
diff --git a/src/sandbox/org/apache/fop/render/svg/SVGUtil.java b/src/sandbox/org/apache/fop/render/svg/SVGUtil.java
new file mode 100644
index 000000000..2953b0d5a
--- /dev/null
+++ b/src/sandbox/org/apache/fop/render/svg/SVGUtil.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.svg;
+
+import java.awt.geom.AffineTransform;
+
+import org.apache.fop.render.intermediate.IFUtil;
+
+/**
+ * This class provides utility methods for generating SVG.
+ */
+public class SVGUtil {
+
+ /**
+ * Formats a length in millipoints as a point value.
+ * @param mpt the length in millipoints
+ * @return the formatted value in points
+ */
+ public static String formatMptToPt(int mpt) {
+ return Float.toString(mpt / 1000f);
+ }
+
+ /**
+ * Formats an array of lengths in millipoints as point values.
+ * @param lengths the lengths in millipoints
+ * @return the formatted array in points
+ */
+ public static String formatMptArrayToPt(int[] lengths) {
+ return IFUtil.toString(lengths);
+ }
+
+ /**
+ * Formats a transformation matrix in millipoints with values as points.
+ * @param transform the transformation matrix in millipoints
+ * @return the formatted matrix in points
+ */
+ public static String formatAffineTransformMptToPt(AffineTransform transform) {
+ AffineTransform scaled = new AffineTransform(transform);
+ scaled.setToTranslation(
+ transform.getTranslateX() / 1000,
+ transform.getTranslateY() / 1000);
+ return IFUtil.toString(scaled);
+ }
+
+ /**
+ * Formats an array of transformation matrices in millipoints with values as points.
+ * @param transforms the transformation matrices in millipoints
+ * @return the formatted matrices in points
+ */
+ public static String formatAffineTransformsMptToPt(AffineTransform[] transforms) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0, c = transforms.length; i < c; i++) {
+ if (i > 0) {
+ sb.append(' ');
+ }
+ sb.append(formatAffineTransformMptToPt(transforms[i]));
+ }
+ return sb.toString();
+ }
+
+}