Author: alg
Date: Tue Jul 2 16:36:07 2013
New Revision: 1499006
URL: http://svn.apache.org/r1499006
Log:
i122594 Added same handling for outer SVG element
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=1499006&r1=1499005&r2=1499006&view=diff
==============================================================================
--- openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx (original)
+++ openoffice/trunk/main/svgio/source/svgreader/svgsvgnode.cxx Tue Jul 2
16:36:07 2013
@@ -173,6 +173,64 @@ namespace svgio
{
if(getParent())
{
+ 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);
+ }
+
if(getViewBox())
{
// Svg defines that with no width or no height the
viewBox content is empty,
@@ -182,64 +240,6 @@ 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 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()))
@@ -300,10 +300,6 @@ namespace svgio
}
else
{
- // check if we have a size
- const double fW(getWidth().isSet() ?
getWidth().solve(*this, xcoordinate) : 0.0);
- const double fH(getHeight().isSet() ?
getHeight().solve(*this, ycoordinate) : 0.0);
-
// Svg defines that a negative value is an error and
that 0.0 disables rendering
if(basegfx::fTools::more(fW, 0.0) &&
basegfx::fTools::more(fH, 0.0))
{