aboutsummaryrefslogtreecommitdiffstats
path: root/examples/plan/src
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-08-05 15:20:54 +0000
committerJeremias Maerki <jeremias@apache.org>2008-08-05 15:20:54 +0000
commit46631569e9ccd7e2a179b0c6d1349fa7451ccc70 (patch)
tree6f5e1d86e4792c108a730e34a6801788ab2d0026 /examples/plan/src
parent8f6baaa89272c01fb960bffa2c5840bcd4f9aeab (diff)
downloadxmlgraphics-fop-46631569e9ccd7e2a179b0c6d1349fa7451ccc70.tar.gz
xmlgraphics-fop-46631569e9ccd7e2a179b0c6d1349fa7451ccc70.zip
Fix for plan reloader when the namespace doesn't match.
Added a viewBox attribute to the generated SVG so scaling is done properly when embedded in another SVG file. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@682748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples/plan/src')
-rw-r--r--examples/plan/src/org/apache/fop/plan/PreloaderPlan.java11
-rw-r--r--examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java15
2 files changed, 18 insertions, 8 deletions
diff --git a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
index b8a7a612c..902560e96 100644
--- a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
+++ b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
@@ -66,7 +66,7 @@ public class PreloaderPlan extends AbstractImagePreloader {
return info;
}
- private ImageInfo getImage(String uri, Source src, ImageContext context) {
+ private ImageInfo getImage(String uri, Source src, ImageContext context) throws IOException {
InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
try {
@@ -76,9 +76,16 @@ public class PreloaderPlan extends AbstractImagePreloader {
DOMResult res = new DOMResult();
transformer.transform(source, res);
+ Document planDoc = (Document)res.getNode();
+ if (!PlanElementMapping.NAMESPACE.equals(
+ planDoc.getDocumentElement().getNamespaceURI())) {
+ in.reset();
+ return null;
+ }
+
//Have to render the plan to know its size
PlanRenderer pr = new PlanRenderer();
- Document svgDoc = pr.createSVGDocument((Document)res.getNode());
+ Document svgDoc = pr.createSVGDocument(planDoc);
float width = pr.getWidth();
float height = pr.getHeight();
diff --git a/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java b/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java
index b49256a31..46b07601a 100644
--- a/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java
+++ b/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java
@@ -29,6 +29,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.batik.dom.svg.SVGDOMImplementation;
+
import org.apache.fop.svg.SVGUtilities;
/**
@@ -83,13 +84,15 @@ public class SimplePlanDrawer implements PlanDrawer {
String title = "";
- DOMImplementation impl =
- SVGDOMImplementation.getDOMImplementation();
+ DOMImplementation impl
+ = SVGDOMImplementation.getDOMImplementation();
Document doc = impl.createDocument(SVG_NAMESPACE, "svg", null);
Element svgRoot = doc.getDocumentElement();
- svgRoot.setAttributeNS(null, "width", "" + width);
- svgRoot.setAttributeNS(null, "height", "" + height);
+ svgRoot.setAttributeNS(null, "width", Float.toString(width));
+ svgRoot.setAttributeNS(null, "height", Float.toString(height));
+ svgRoot.setAttributeNS(null, "viewBox",
+ "0 0 " + Float.toString(width) + " " + Float.toString(height));
svgRoot.setAttributeNS(null, "style",
"font-size:" + 8
+ ";font-family:"
@@ -99,8 +102,8 @@ public class SimplePlanDrawer implements PlanDrawer {
java.awt.Font.PLAIN, (int)fontSize);
if (bord) {
- Element border =
- SVGUtilities.createRect(doc, 0, 0, width, height);
+ Element border
+ = SVGUtilities.createRect(doc, 0, 0, width, height);
border.setAttributeNS(null, "style", "stroke:black;fill:none");
svgRoot.appendChild(border);
}