summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2013-02-21 17:51:40 +0100
committerThorsten Behrens <tbehrens@suse.com>2013-02-25 16:02:31 +0000
commitf9b5fb1ecd5c6ef1d2b90ad192c956e7d134959a (patch)
tree17fd1fe33aac4e660c3988d5d6114b9cd306b2e9
parent3728944078e53e8dfef08eb445e741a59979b23e (diff)
Corrected SVG gradient primitive and it's decomposition (i#120616)
Conflicts: drawinglayer/source/primitive2d/svggradientprimitive2d.cxx Change-Id: I04c148303e7153a5376eae79803c540f6eba0b00 Signed-off-by: Petr Mladek <pmladek@suse.cz> Reviewed-on: https://gerrit.libreoffice.org/2387 Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Reviewed-by: Thorsten Behrens <tbehrens@suse.com> Tested-by: Thorsten Behrens <tbehrens@suse.com>
-rw-r--r--drawinglayer/inc/drawinglayer/primitive2d/svggradientprimitive2d.hxx9
-rw-r--r--drawinglayer/source/primitive2d/svggradientprimitive2d.cxx81
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx2
3 files changed, 69 insertions, 23 deletions
diff --git a/drawinglayer/inc/drawinglayer/primitive2d/svggradientprimitive2d.hxx b/drawinglayer/inc/drawinglayer/primitive2d/svggradientprimitive2d.hxx
index 39115a76d938..2c9e34fe96e1 100644
--- a/drawinglayer/inc/drawinglayer/primitive2d/svggradientprimitive2d.hxx
+++ b/drawinglayer/inc/drawinglayer/primitive2d/svggradientprimitive2d.hxx
@@ -111,6 +111,11 @@ namespace drawinglayer
bool mbSingleEntry : 1;
bool mbFullyOpaque : 1;
+ // true = interpret in unit coordinate system -> object aspect ratio will scale result
+ // false = interpret in object coordinate system -> object aspect ratio will not scale result
+ // (related to SVG's gradientUnits (userSpaceOnUse|objectBoundingBox)
+ bool mbUseUnitCoordinates : 1;
+
protected:
/// local helpers
Primitive2DSequence createSingleGradientEntryFill() const;
@@ -145,6 +150,7 @@ namespace drawinglayer
const basegfx::B2DPolyPolygon& rPolyPolygon,
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod = Spread_pad);
virtual ~SvgGradientHelper() {}
@@ -152,6 +158,7 @@ namespace drawinglayer
const basegfx::B2DPolyPolygon& getPolyPolygon() const { return maPolyPolygon; }
const SvgGradientEntryVector& getGradientEntries() const { return maGradientEntries; }
const basegfx::B2DPoint& getStart() const { return maStart; }
+ bool getUseUnitCoordinates() const { return mbUseUnitCoordinates; }
SpreadMethod getSpreadMethod() const { return maSpreadMethod; }
/// compare operator
@@ -194,6 +201,7 @@ namespace drawinglayer
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
const basegfx::B2DPoint& rEnd,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod = Spread_pad);
virtual ~SvgLinearGradientPrimitive2D() {}
@@ -261,6 +269,7 @@ namespace drawinglayer
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
double fRadius,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod = Spread_pad,
const basegfx::B2DPoint* pFocal = 0);
diff --git a/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx b/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx
index a8c60da51299..ef1c7ba7b3da 100644
--- a/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx
@@ -283,6 +283,7 @@ namespace drawinglayer
const basegfx::B2DPolyPolygon& rPolyPolygon,
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod)
: maPolyPolygon(rPolyPolygon),
maGradientEntries(rGradientEntries),
@@ -291,7 +292,8 @@ namespace drawinglayer
mbPreconditionsChecked(false),
mbCreatesContent(false),
mbSingleEntry(false),
- mbFullyOpaque(true)
+ mbFullyOpaque(true),
+ mbUseUnitCoordinates(bUseUnitCoordinates)
{
}
@@ -302,6 +304,7 @@ namespace drawinglayer
return (getPolyPolygon() == rCompare.getPolyPolygon()
&& getGradientEntries() == rCompare.getGradientEntries()
&& getStart() == rCompare.getStart()
+ && getUseUnitCoordinates() == rCompare.getUseUnitCoordinates()
&& getSpreadMethod() == rCompare.getSpreadMethod());
}
@@ -388,20 +391,36 @@ namespace drawinglayer
basegfx::tools::createScaleTranslateB2DHomMatrix(
fPolyWidth, fPolyHeight,
aPolyRange.getMinX(), aPolyRange.getMinY()));
+ basegfx::B2DHomMatrix aUnitGradientToObject;
- // create unit transform from unit vector [0.0 .. 1.0] along the X-Axis to given
- // gradient vector defined by Start,End
- const basegfx::B2DVector aVector(getEnd() - getStart());
- const double fVectorLength(aVector.getLength());
- basegfx::B2DHomMatrix aUnitGradientToGradient;
-
- aUnitGradientToGradient.scale(fVectorLength, 1.0);
- aUnitGradientToGradient.rotate(atan2(aVector.getY(), aVector.getX()));
- aUnitGradientToGradient.translate(getStart().getX(), getStart().getY());
-
- // create full transform from unit gradient coordinates to object coordinates
- // including the SvgGradient transformation
- basegfx::B2DHomMatrix aUnitGradientToObject(aObjectTransform * aUnitGradientToGradient);
+ if(getUseUnitCoordinates())
+ {
+ // interpret in unit coordinate system -> object aspect ratio will scale result
+ // create unit transform from unit vector [0.0 .. 1.0] along the X-Axis to given
+ // gradient vector defined by Start,End
+ const basegfx::B2DVector aVector(getEnd() - getStart());
+ const double fVectorLength(aVector.getLength());
+ basegfx::B2DHomMatrix aUnitGradientToGradient;
+
+ aUnitGradientToGradient.scale(fVectorLength, 1.0);
+ aUnitGradientToGradient.rotate(atan2(aVector.getY(), aVector.getX()));
+ aUnitGradientToGradient.translate(getStart().getX(), getStart().getY());
+
+ // create full transform from unit gradient coordinates to object coordinates
+ // including the SvgGradient transformation
+ aUnitGradientToObject = aObjectTransform * aUnitGradientToGradient;
+ }
+ else
+ {
+ // interpret in object coordinate system -> object aspect ratio will not scale result
+ const basegfx::B2DPoint aStart(aObjectTransform * getStart());
+ const basegfx::B2DPoint aEnd(aObjectTransform * getEnd());
+ const basegfx::B2DVector aVector(aEnd - aStart);
+
+ aUnitGradientToObject.scale(aVector.getLength(), 1.0);
+ aUnitGradientToObject.rotate(atan2(aVector.getY(), aVector.getX()));
+ aUnitGradientToObject.translate(aStart.getX(), aStart.getY());
+ }
// create inverse from it
basegfx::B2DHomMatrix aObjectToUnitGradient(aUnitGradientToObject);
@@ -525,9 +544,10 @@ namespace drawinglayer
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
const basegfx::B2DPoint& rEnd,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod)
: BufferedDecompositionPrimitive2D(),
- SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
+ SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, bUseUnitCoordinates, aSpreadMethod),
maEnd(rEnd)
{
}
@@ -698,16 +718,30 @@ namespace drawinglayer
basegfx::tools::createScaleTranslateB2DHomMatrix(
fPolyWidth, fPolyHeight,
aPolyRange.getMinX(), aPolyRange.getMinY()));
+ basegfx::B2DHomMatrix aUnitGradientToObject;
- // create unit transform from unit vector to given linear gradient vector
- basegfx::B2DHomMatrix aUnitGradientToGradient;
+ if(getUseUnitCoordinates())
+ {
+ // interpret in unit coordinate system -> object aspect ratio will scale result
+ // create unit transform from unit vector to given linear gradient vector
+ basegfx::B2DHomMatrix aUnitGradientToGradient;
- aUnitGradientToGradient.scale(getRadius(), getRadius());
- aUnitGradientToGradient.translate(getStart().getX(), getStart().getY());
+ aUnitGradientToGradient.scale(getRadius(), getRadius());
+ aUnitGradientToGradient.translate(getStart().getX(), getStart().getY());
- // create full transform from unit gradient coordinates to object coordinates
- // including the SvgGradient transformation
- basegfx::B2DHomMatrix aUnitGradientToObject(aObjectTransform * aUnitGradientToGradient);
+ // create full transform from unit gradient coordinates to object coordinates
+ // including the SvgGradient transformation
+ aUnitGradientToObject = aObjectTransform * aUnitGradientToGradient;
+ }
+ else
+ {
+ // interpret in object coordinate system -> object aspect ratio will not scale result
+ const double fRadius((aObjectTransform * basegfx::B2DVector(getRadius(), 0.0)).getLength());
+ const basegfx::B2DPoint aStart(aObjectTransform * getStart());
+
+ aUnitGradientToObject.scale(fRadius, fRadius);
+ aUnitGradientToObject.translate(aStart.getX(), aStart.getY());
+ }
// create inverse from it
basegfx::B2DHomMatrix aObjectToUnitGradient(aUnitGradientToObject);
@@ -780,10 +814,11 @@ namespace drawinglayer
const SvgGradientEntryVector& rGradientEntries,
const basegfx::B2DPoint& rStart,
double fRadius,
+ bool bUseUnitCoordinates,
SpreadMethod aSpreadMethod,
const basegfx::B2DPoint* pFocal)
: BufferedDecompositionPrimitive2D(),
- SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
+ SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, bUseUnitCoordinates, aSpreadMethod),
mfRadius(fRadius),
maFocal(rStart),
maFocalVector(0.0, 0.0),
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 07845df8c931..025f9d5612fd 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -407,6 +407,7 @@ namespace svgio
aSvgGradientEntryVector,
aStart,
aEnd,
+ userSpaceOnUse != rFillGradient.getGradientUnits(),
rFillGradient.getSpreadMethod()));
}
else
@@ -467,6 +468,7 @@ namespace svgio
aSvgGradientEntryVector,
aStart,
fRadius,
+ userSpaceOnUse != rFillGradient.getGradientUnits(),
rFillGradient.getSpreadMethod(),
bFocal ? &aFocal : 0));
}