mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 12:05:29 -04:00
#518 Parsing SVG width/height attributes
This commit is contained in:
parent
fb304d6c27
commit
6d2947b080
@ -33,9 +33,11 @@ package com.twelvemonkeys.imageio.plugins.svg;
|
|||||||
import com.twelvemonkeys.image.ImageUtil;
|
import com.twelvemonkeys.image.ImageUtil;
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
import com.twelvemonkeys.imageio.ImageReaderBase;
|
||||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||||
|
import com.twelvemonkeys.lang.StringUtil;
|
||||||
import org.apache.batik.anim.dom.SVGDOMImplementation;
|
import org.apache.batik.anim.dom.SVGDOMImplementation;
|
||||||
import org.apache.batik.anim.dom.SVGOMDocument;
|
import org.apache.batik.anim.dom.SVGOMDocument;
|
||||||
import org.apache.batik.bridge.*;
|
import org.apache.batik.bridge.*;
|
||||||
|
import org.apache.batik.css.parser.CSSLexicalUnit;
|
||||||
import org.apache.batik.dom.util.DOMUtilities;
|
import org.apache.batik.dom.util.DOMUtilities;
|
||||||
import org.apache.batik.ext.awt.image.GraphicsUtil;
|
import org.apache.batik.ext.awt.image.GraphicsUtil;
|
||||||
import org.apache.batik.gvt.CanvasGraphicsNode;
|
import org.apache.batik.gvt.CanvasGraphicsNode;
|
||||||
@ -47,6 +49,7 @@ import org.apache.batik.transcoder.*;
|
|||||||
import org.apache.batik.transcoder.image.ImageTranscoder;
|
import org.apache.batik.transcoder.image.ImageTranscoder;
|
||||||
import org.apache.batik.util.ParsedURL;
|
import org.apache.batik.util.ParsedURL;
|
||||||
import org.apache.batik.util.SVGConstants;
|
import org.apache.batik.util.SVGConstants;
|
||||||
|
import org.apache.batik.xml.LexicalUnits;
|
||||||
import org.w3c.dom.DOMImplementation;
|
import org.w3c.dom.DOMImplementation;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.svg.SVGSVGElement;
|
import org.w3c.dom.svg.SVGSVGElement;
|
||||||
@ -324,18 +327,18 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
|
SVGSVGElement rootElement = svgDoc.getRootElement();
|
||||||
|
|
||||||
// get the 'width' and 'height' attributes of the SVG document
|
// get the 'width' and 'height' attributes of the SVG document
|
||||||
Dimension2D docSize = ctx.getDocumentSize();
|
String widthStr = rootElement.getAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE);
|
||||||
if (docSize != null) {
|
String heightStr = rootElement.getAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE);
|
||||||
defaultWidth = (float) docSize.getWidth();
|
if (!StringUtil.isEmpty(widthStr) && !StringUtil.isEmpty(heightStr)) {
|
||||||
defaultHeight = (float) docSize.getHeight();
|
UnitProcessor.Context uctx
|
||||||
|
= UnitProcessor.createContext(ctx, rootElement);
|
||||||
|
defaultWidth = UnitProcessor.svgToUserSpace(widthStr, SVGConstants.SVG_WIDTH_ATTRIBUTE, UnitProcessor.HORIZONTAL_LENGTH, uctx);
|
||||||
|
defaultHeight = UnitProcessor.svgToUserSpace(heightStr, SVGConstants.SVG_HEIGHT_ATTRIBUTE, UnitProcessor.VERTICAL_LENGTH, uctx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
defaultWidth = 200;
|
|
||||||
defaultHeight = 200;
|
|
||||||
}
|
|
||||||
SVGSVGElement rootElement = svgDoc.getRootElement();
|
|
||||||
String viewBoxStr = rootElement.getAttributeNS
|
String viewBoxStr = rootElement.getAttributeNS
|
||||||
(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
|
(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
|
||||||
if (viewBoxStr.length() != 0) {
|
if (viewBoxStr.length() != 0) {
|
||||||
@ -343,6 +346,11 @@ public class SVGImageReader extends ImageReaderBase {
|
|||||||
defaultWidth = rect[2];
|
defaultWidth = rect[2];
|
||||||
defaultHeight = rect[3];
|
defaultHeight = rect[3];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
defaultWidth = 200;
|
||||||
|
defaultHeight = 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hack to work around exception above
|
// Hack to work around exception above
|
||||||
if (root != null) {
|
if (root != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user