You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by al...@apache.org on 2013/07/02 14:00:29 UTC

svn commit: r1498895 - /openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx

Author: alg
Date: Tue Jul  2 12:00:29 2013
New Revision: 1498895

URL: http://svn.apache.org/r1498895
Log:
i122594 correctly handle iner svg node when no width/height or percent is given

Modified:
    openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx

Modified: openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx?rev=1498895&r1=1498894&r2=1498895&view=diff
==============================================================================
--- openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx (original)
+++ openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx Tue Jul  2 12:00:29 2013
@@ -182,8 +182,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);
+
+                            // #122594# 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()))