diff options
author | Keiron Liddle <keiron@apache.org> | 2001-09-25 12:32:36 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-09-25 12:32:36 +0000 |
commit | d62d9670a2c2c9c839677eb5a6a7cdd223b8f136 (patch) | |
tree | 3f2e173eea93725051b4d484863ba3849b45f9d7 | |
parent | e8ebf0309db50be59038219c1b88d0c50d12621b (diff) | |
download | xmlgraphics-fop-d62d9670a2c2c9c839677eb5a6a7cdd223b8f136.tar.gz xmlgraphics-fop-d62d9670a2c2c9c839677eb5a6a7cdd223b8f136.zip |
gets the width and height in a better way
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194483 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 29 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElement.java | 29 |
2 files changed, 38 insertions, 20 deletions
diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index 1b3801470..57b0c0060 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -72,18 +72,27 @@ public class SVGReader extends AbstractImageReader { new SAXSVGDocumentFactory(SVGImage.getParserName()); SVGDocument doc = factory.createDocument(uri, imageStream); - // this is ugly preprocessing to get the width and height + Element e = ((SVGDocument)doc).getRootElement(); + String s; UserAgent userAgent = new MUserAgent(new AffineTransform()); - GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(userAgent); - GraphicsNode root; - root = builder.build(ctx, doc); - // get the 'width' and 'height' attributes of the SVG document - width = (int) ctx.getDocumentSize().getWidth(); - height = (int) ctx.getDocumentSize().getHeight(); - ctx = null; - builder = null; - /////// + UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); + + // 'width' attribute - default is 100% + s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE); + if (s.length() == 0) { + s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE; + } + width = (int)UnitProcessor.svgHorizontalLengthToUserSpace + (s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx); + + // 'height' attribute - default is 100% + s = e.getAttributeNS(null, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE); + if (s.length() == 0) { + s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE; + } + height = (int)UnitProcessor.svgVerticalLengthToUserSpace + (s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx); return true; } catch (NoClassDefFoundError ncdfe) { diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index 30d7a06f7..730a984e4 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -138,19 +138,28 @@ public class SVGElement extends SVGObj { }; ((SVGOMDocument)doc).setSVGContext(dc); - // this is ugly preprocessing to get the width and height + Element e = ((SVGDocument)doc).getRootElement(); + String s; SVGUserAgent userAgent = new SVGUserAgent(new AffineTransform()); userAgent.setLogger(log); - GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(userAgent); - GraphicsNode root; - root = builder.build(ctx, doc); - // get the 'width' and 'height' attributes of the SVG document - float width = (float)ctx.getDocumentSize().getWidth(); - float height = (float)ctx.getDocumentSize().getHeight(); - ctx = null; - builder = null; - /////// + UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); + + // 'width' attribute - default is 100% + s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE); + if (s.length() == 0) { + s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE; + } + float width = UnitProcessor.svgHorizontalLengthToUserSpace + (s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx); + + // 'height' attribute - default is 100% + s = e.getAttributeNS(null, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE); + if (s.length() == 0) { + s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE; + } + float height = UnitProcessor.svgVerticalLengthToUserSpace + (s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx); SVGArea svg = new SVGArea(fs, width, height); svg.setSVGDocument(doc); |