summaryrefslogtreecommitdiff
path: root/svgio/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-05-13 20:21:17 +0900
committerTomaž Vajngerl <quikee@gmail.com>2018-05-13 15:28:27 +0200
commit7e6dac4edce063a766497ecb498e293bf4e16e66 (patch)
treeffbe7d1dd9f689877e3668c4015838bde8446e4a /svgio/source
parent32cad25f949eabea52e1cf7962ba18a3edd1c647 (diff)
svgio: fix rendering when the width/height isn't present in SVG
The general size of the image should be the same when width/height attributes are present. It is very wrong to assume the size of the image is the area covered by all the primitives in the image. Change-Id: I56f241e84dee37796f9804ce2569c4eb416e83a0 Reviewed-on: https://gerrit.libreoffice.org/54191 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svgio/source')
-rw-r--r--svgio/source/svgreader/svgsvgnode.cxx51
1 files changed, 33 insertions, 18 deletions
diff --git a/svgio/source/svgreader/svgsvgnode.cxx b/svgio/source/svgreader/svgsvgnode.cxx
index 5803c877331b..40dfaca1a402 100644
--- a/svgio/source/svgreader/svgsvgnode.cxx
+++ b/svgio/source/svgreader/svgsvgnode.cxx
@@ -350,13 +350,20 @@ namespace svgio
seekReferenceWidth(fWReference, bHasFoundWidth);
if (!bHasFoundWidth)
{
- // Even outermost svg has not all information to resolve relative values,
- // I use content itself as fallback to set missing values for viewport
- // Any better idea for such ill structured svg documents?
- const basegfx::B2DRange aChildRange(
- aSequence.getB2DRange(
- drawinglayer::geometry::ViewInformation2D()));
- fWReference = aChildRange.getWidth();
+ if (getViewBox())
+ {
+ fWReference = getViewBox()->getWidth();
+ }
+ else
+ {
+ // Even outermost svg has not all information to resolve relative values,
+ // I use content itself as fallback to set missing values for viewport
+ // Any better idea for such ill structured svg documents?
+ const basegfx::B2DRange aChildRange(
+ aSequence.getB2DRange(
+ drawinglayer::geometry::ViewInformation2D()));
+ fWReference = aChildRange.getWidth();
+ }
}
// referenced values are already in 'user unit'
if (!bXIsAbsolute)
@@ -377,13 +384,20 @@ namespace svgio
seekReferenceHeight(fHReference, bHasFoundHeight);
if (!bHasFoundHeight)
{
+ if (getViewBox())
+ {
+ fHReference = getViewBox()->getHeight();
+ }
+ else
+ {
// Even outermost svg has not all information to resolve relative values,
- // I use content itself as fallback to set missing values for viewport
- // Any better idea for such ill structured svg documents?
- const basegfx::B2DRange aChildRange(
- aSequence.getB2DRange(
- drawinglayer::geometry::ViewInformation2D()));
- fHReference = aChildRange.getHeight();
+ // I use content itself as fallback to set missing values for viewport
+ // Any better idea for such ill structured svg documents?
+ const basegfx::B2DRange aChildRange(
+ aSequence.getB2DRange(
+ drawinglayer::geometry::ViewInformation2D()));
+ fHReference = aChildRange.getHeight();
+ }
}
// referenced values are already in 'user unit'
@@ -527,13 +541,15 @@ namespace svgio
// by the viewBox. No mapping.
// We get viewport >= content, therefore no clipping.
bNeedsMapping = false;
+
const basegfx::B2DRange aChildRange(
aSequence.getB2DRange(
drawinglayer::geometry::ViewInformation2D()));
- const double fChildWidth(aChildRange.getWidth());
- const double fChildHeight(aChildRange.getHeight());
- const double fLeft(aChildRange.getMinX());
- const double fTop(aChildRange.getMinY());
+
+ const double fChildWidth(getViewBox() ? getViewBox()->getWidth() : aChildRange.getWidth());
+ const double fChildHeight(getViewBox() ? getViewBox()->getHeight() : aChildRange.getHeight());
+ const double fLeft(getViewBox() ? getViewBox()->getMinX() : aChildRange.getMinX());
+ const double fTop (getViewBox() ? getViewBox()->getMinY() : aChildRange.getMinY());
if ( fChildWidth / fViewBoxWidth > fChildHeight / fViewBoxHeight )
{ // expand y
fW = fChildWidth;
@@ -547,7 +563,6 @@ namespace svgio
aSvgCanvasRange = basegfx::B2DRange(fLeft, fTop, fLeft + fW, fTop + fH);
}
-
if (bNeedsMapping)
{
// create mapping