Related: #i122600# access memory problem in SvgSvgNode::getCurrentViewPort

(cherry picked from commit d41dc0bbe76922fee4ce177ecac0d84b9efc4206)

Conflicts:
	svgio/inc/svgio/svgreader/svgnode.hxx
	svgio/inc/svgio/svgreader/svgtools.hxx

Change-Id: Ie4d5cd29461845edb5b8a57fe639302947d80ebd
This commit is contained in:
Oliver-Rainer Wittmann
2013-08-21 09:39:21 +00:00
committed by Caolán McNamara
parent 172c37522b
commit 199eb7607c
10 changed files with 24 additions and 25 deletions

View File

@@ -71,7 +71,7 @@ namespace svgio
const drawinglayer::primitive2d::Primitive2DSequence& getMarkerPrimitives() const;
/// InfoProvider support for % values
virtual const basegfx::B2DRange* getCurrentViewPort() const;
virtual const basegfx::B2DRange getCurrentViewPort() const;
/// viewBox content
const basegfx::B2DRange* getViewBox() const { return mpViewBox; }

View File

@@ -134,7 +134,7 @@ namespace svgio
const SvgNodeVector& getChildren() const { return maChildren; }
/// InfoProvider support for %, em and ex values
virtual const basegfx::B2DRange* getCurrentViewPort() const SAL_OVERRIDE;
virtual const basegfx::B2DRange getCurrentViewPort() const SAL_OVERRIDE;
virtual double getCurrentFontSizeInherited() const SAL_OVERRIDE;
virtual double getCurrentXHeightInherited() const SAL_OVERRIDE;

View File

@@ -74,7 +74,7 @@ namespace svgio
const drawinglayer::primitive2d::Primitive2DSequence& getPatternPrimitives() const;
/// InfoProvider support for % values
virtual const basegfx::B2DRange* getCurrentViewPort() const;
virtual const basegfx::B2DRange getCurrentViewPort() const;
/// viewBox content
const basegfx::B2DRange* getViewBox() const;

View File

@@ -62,7 +62,7 @@ namespace svgio
// The returned 'CurrentViewPort' is the viewport as it is set by this svg element
// and as it is needed to resolve relative values in childs
// The method does not check for invalid width and height
virtual const basegfx::B2DRange* getCurrentViewPort() const;
virtual const basegfx::B2DRange getCurrentViewPort() const;
/// viewBox content
const basegfx::B2DRange* getViewBox() const { return mpViewBox; }

View File

@@ -66,7 +66,7 @@ namespace svgio
{
public:
virtual ~InfoProvider() {}
virtual const basegfx::B2DRange* getCurrentViewPort() const = 0;
virtual const basegfx::B2DRange getCurrentViewPort() const = 0;
/// return font size of node inherited from parents
virtual double getCurrentFontSizeInherited() const = 0;
/// return xheight of node inherited from parents

View File

@@ -190,11 +190,11 @@ namespace svgio
return aPrimitives;
}
const basegfx::B2DRange* SvgMarkerNode::getCurrentViewPort() const
const basegfx::B2DRange SvgMarkerNode::getCurrentViewPort() const
{
if(getViewBox())
{
return getViewBox();
return *(getViewBox());
}
else
{

View File

@@ -479,7 +479,7 @@ namespace svgio
}
}
const basegfx::B2DRange* SvgNode::getCurrentViewPort() const
const basegfx::B2DRange SvgNode::getCurrentViewPort() const
{
if(getParent())
{
@@ -487,7 +487,7 @@ namespace svgio
}
else
{
return 0;
return basegfx::B2DRange(); // return empty B2DRange
}
}

View File

@@ -287,11 +287,11 @@ namespace svgio
return aPrimitives;
}
const basegfx::B2DRange* SvgPatternNode::getCurrentViewPort() const
const basegfx::B2DRange SvgPatternNode::getCurrentViewPort() const
{
if(getViewBox())
{
return getViewBox();
return *(getViewBox());
}
else
{

View File

@@ -600,11 +600,11 @@ namespace svgio
}
}
const basegfx::B2DRange* SvgSvgNode::getCurrentViewPort() const
const basegfx::B2DRange SvgSvgNode::getCurrentViewPort() const
{
if(getViewBox())
{
return getViewBox();
return *(getViewBox());
}
else // viewport should be given by x, y, width, and height
{
@@ -628,7 +628,7 @@ namespace svgio
if (bXIsAbsolute && bYIsAbsolute && bWidthIsAbsolute && bHeightIsAbsolute)
{
return &basegfx::B2DRange(fX, fY, fX+fW, fY+fH);
return basegfx::B2DRange(fX, fY, fX+fW, fY+fH);
}
else // try to resolve relative values
{
@@ -671,7 +671,7 @@ namespace svgio
if (bXIsAbsolute && bYIsAbsolute && bWidthIsAbsolute && bHeightIsAbsolute)
{
return &basegfx::B2DRange(fX, fY, fX+fW, fY+fH);
return basegfx::B2DRange(fX, fY, fX+fW, fY+fH);
}
else // relative values could not be resolved, there exists no fallback
{
@@ -690,7 +690,7 @@ namespace svgio
double fH( bHeightIsAbsolute ? getHeight().solveNonPercentage(*this) : 0.0);
if (bWidthIsAbsolute && bHeightIsAbsolute)
{
return &basegfx::B2DRange(0.0, 0.0, fW, fH);
return basegfx::B2DRange(0.0, 0.0, fW, fH);
}
else // no fallback exists
{

View File

@@ -226,40 +226,39 @@ namespace svgio
case Unit_percent:
{
double fRetval(mfNumber * 0.01);
const basegfx::B2DRange* pViewPort = rInfoProvider.getCurrentViewPort();
basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
if(!pViewPort)
if ( aViewPort.isEmpty() )
{
#ifdef DBG_UTIL
myAssert(rtl::OUString::createFromAscii("Design error, this case should have been handled in the caller"));
#endif
// no viewPort, assume a normal page size (A4)
static basegfx::B2DRange aDinA4Range(
aViewPort = basegfx::B2DRange(
0.0,
0.0,
210.0 * F_SVG_PIXEL_PER_INCH / 2.54,
297.0 * F_SVG_PIXEL_PER_INCH / 2.54);
pViewPort = &aDinA4Range;
}
if(pViewPort)
if ( !aViewPort.isEmpty() )
{
if(xcoordinate == aNumberType)
{
// it's a x-coordinate, relative to current width (w)
fRetval *= pViewPort->getWidth();
fRetval *= aViewPort.getWidth();
}
else if(ycoordinate == aNumberType)
{
// it's a y-coordinate, relative to current height (h)
fRetval *= pViewPort->getHeight();
fRetval *= aViewPort.getHeight();
}
else // length
{
// it's a length, relative to sqrt(w*w + h*h)/sqrt(2)
const double fCurrentWidth(pViewPort->getWidth());
const double fCurrentHeight(pViewPort->getHeight());
const double fCurrentWidth(aViewPort.getWidth());
const double fCurrentHeight(aViewPort.getHeight());
const double fCurrentLength(
sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0));