summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2013-07-02 12:00:29 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-07-02 14:24:30 +0100
commit6bd99f8d0b510a45d5f1ade2bf00373bce7765b7 (patch)
tree1ddc4c140ebba55b64105ab2f4f8a2132fec9306 /svgio
parenta733e8e91aecbcbde7cc2127a3c45d8dd3ebe4ee (diff)
Resolves: #i122594# correctly handle inner svg node...
when no width/height or percent is given (cherry picked from commit 5fa6275694d0990018b13266b37c359b37251c1c) Change-Id: I2981d7ad174faf0914b4fcd545257674ad5e8cb9
Diffstat (limited to 'svgio')
-rw-r--r--svgio/source/svgreader/svgsvgnode.cxx60
1 files changed, 58 insertions, 2 deletions
diff --git a/svgio/source/svgreader/svgsvgnode.cxx b/svgio/source/svgreader/svgsvgnode.cxx
index dc4d619290f6..4aff559db79d 100644
--- a/svgio/source/svgreader/svgsvgnode.cxx
+++ b/svgio/source/svgreader/svgsvgnode.cxx
@@ -177,8 +177,64 @@ namespace svgio
// create target range homing x,y, width and height as given
const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
- const double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) : getViewBox()->getWidth());
- const double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate) : getViewBox()->getHeight());
+ const bool bWidthIsRelative(!getWidth().isSet() || Unit_percent == getWidth().getUnit());
+ const bool bHeightIsRelative(!getWidth().isSet() || Unit_percent == getWidth().getUnit());
+ const SvgSvgNode* pParentSvgSvgNode = 0;
+ double fW(0.0);
+ double fH(0.0);
+
+ // #i122594# if width/height is not given, it's 100% (see 5.1.2 The ‘svg’ element in SVG1.1 spec).
+ // If it is relative, the question is to what. The previous implementatin assumed relative to the
+ // local ViewBox which is implied by (4.2 Basic data types):
+ //
+ // "Note that the non-property <length> definition also allows a percentage unit identifier.
+ // The meaning of a percentage length value depends on the attribute for which the percentage
+ // length value has been specified. Two common cases are: (a) when a percentage length value
+ // represents a percentage of the viewport width or height (refer to the section that discusses
+ // units in general), and (b) when a percentage length value represents a percentage of the
+ // bounding box width or height on a given object (refer to the section that describes object
+ // bounding box units)."
+ //
+ // This is not closer specified for the SVG element itself as non-outmost element, but comparisons
+ // with common browsers shows that it's mostly interpreted relative to the viewBox of the parent.
+ // Adding code to search the parent SVG element and calculating width/height relative to it's
+ // viewBox width/height (and no longer to the local viewBox).
+ if(bWidthIsRelative || bHeightIsRelative)
+ {
+ for(const SvgNode* pParent = getParent(); pParent && !pParentSvgSvgNode; pParent = pParent->getParent())
+ {
+ pParentSvgSvgNode = dynamic_cast< const SvgSvgNode* >(pParent);
+ }
+ }
+
+ if(bWidthIsRelative)
+ {
+ fW = getWidth().isSet() ? getWidth().getNumber() * 0.01 : 1.0;
+
+ if(pParentSvgSvgNode)
+ {
+ fW *= pParentSvgSvgNode->getViewBox()->getWidth();
+ }
+ }
+ else
+ {
+ fW = getWidth().solve(*this, xcoordinate);
+ }
+
+ if(bHeightIsRelative)
+ {
+ fH = getHeight().isSet() ? getHeight().getNumber() * 0.01 : 1.0;
+
+ if(pParentSvgSvgNode)
+ {
+ fH *= pParentSvgSvgNode->getViewBox()->getHeight();
+ }
+ }
+ else
+ {
+ fH = getHeight().solve(*this, ycoordinate);
+ }
+
const basegfx::B2DRange aTarget(fX, fY, fX + fW, fY + fH);
if(aTarget.equal(*getViewBox()))