1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SVGGRADIENTPRIMITIVE2D_HXX
21 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SVGGRADIENTPRIMITIVE2D_HXX
23 #include <drawinglayer/drawinglayerdllapi.h>
24 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25 #include <basegfx/color/bcolor.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <drawinglayer/primitive2d/primitivetools2d.hxx>
32 // SvgGradientEntry class
34 namespace drawinglayer
38 /// a single GradientStop defining a color and opacity at a distance
39 class SvgGradientEntry
43 basegfx::BColor maColor
;
47 SvgGradientEntry(double fOffset
, const basegfx::BColor
& rColor
= basegfx::BColor(0.0, 0.0, 0.0), double fOpacity
= 1.0)
54 double getOffset() const { return mfOffset
; }
55 const basegfx::BColor
& getColor() const { return maColor
; }
56 double getOpacity() const { return mfOpacity
; }
58 bool operator==(const SvgGradientEntry
& rCompare
) const
60 return (getOffset() == rCompare
.getOffset()
61 && getColor() == rCompare
.getColor()
62 && getOpacity() == rCompare
.getOpacity());
65 bool operator<(const SvgGradientEntry
& rCompare
) const
67 return getOffset() < rCompare
.getOffset();
71 typedef ::std::vector
< SvgGradientEntry
> SvgGradientEntryVector
;
73 } // end of namespace primitive2d
74 } // end of namespace drawinglayer
77 // SvgGradientHelper class
79 namespace drawinglayer
90 /* helper for linear and radial gradient, both get derived from this
91 to share common definitions and functionality
93 class SvgGradientHelper
96 /// the extra gradient transform
97 basegfx::B2DHomMatrix maGradientTransform
;
99 /// geometric definition, the geometry to be filled
100 basegfx::B2DPolyPolygon maPolyPolygon
;
102 /// the gradient definition
103 SvgGradientEntryVector maGradientEntries
;
105 /// start and/or center point
106 basegfx::B2DPoint maStart
;
109 SpreadMethod maSpreadMethod
;
112 bool mbPreconditionsChecked
: 1;
113 bool mbCreatesContent
: 1;
114 bool mbSingleEntry
: 1;
115 bool mbFullyOpaque
: 1;
117 // true = interpret in unit coordinate system -> object aspect ratio will scale result
118 // false = interpret in object coordinate system -> object aspect ratio will not scale result
119 // (related to SVG's gradientUnits (userSpaceOnUse|objectBoundingBox)
120 bool mbUseUnitCoordinates
: 1;
124 Primitive2DSequence
createSingleGradientEntryFill() const;
125 virtual void createAtom(
126 Primitive2DVector
& rTargetColor
,
127 Primitive2DVector
& rTargetOpacity
,
128 const SvgGradientEntry
& rFrom
,
129 const SvgGradientEntry
& rTo
,
130 sal_Int32 nOffset
) const = 0;
132 Primitive2DVector
& rTargetColor
,
133 Primitive2DVector
& rTargetOpacity
,
136 const SvgGradientEntryVector
& rEntries
,
137 sal_Int32 nOffset
) const;
138 virtual void checkPreconditions();
139 Primitive2DSequence
createResult(
140 const Primitive2DVector
& rTargetColor
,
141 const Primitive2DVector
& rTargetOpacity
,
142 const basegfx::B2DHomMatrix
& rUnitGradientToObject
,
143 bool bInvert
= false) const;
144 bool getCreatesContent() const { return mbCreatesContent
; }
145 bool getSingleEntry() const { return mbSingleEntry
; }
146 void setSingleEntry() { mbSingleEntry
= true; }
147 bool getPreconditionsChecked() const { return mbPreconditionsChecked
; }
148 bool getFullyOpaque() const { return mbFullyOpaque
; }
153 const basegfx::B2DHomMatrix
& rGradientTransform
,
154 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
155 const SvgGradientEntryVector
& rGradientEntries
,
156 const basegfx::B2DPoint
& rStart
,
157 bool bUseUnitCoordinates
,
158 SpreadMethod aSpreadMethod
= Spread_pad
);
159 virtual ~SvgGradientHelper();
162 const basegfx::B2DHomMatrix
& getGradientTransform() const { return maGradientTransform
; }
163 const basegfx::B2DPolyPolygon
& getPolyPolygon() const { return maPolyPolygon
; }
164 const SvgGradientEntryVector
& getGradientEntries() const { return maGradientEntries
; }
165 const basegfx::B2DPoint
& getStart() const { return maStart
; }
166 bool getUseUnitCoordinates() const { return mbUseUnitCoordinates
; }
167 SpreadMethod
getSpreadMethod() const { return maSpreadMethod
; }
170 bool operator==(const SvgGradientHelper
& rSvgGradientHelper
) const;
172 } // end of namespace primitive2d
173 } // end of namespace drawinglayer
176 // SvgLinearGradientPrimitive2D class
178 namespace drawinglayer
180 namespace primitive2d
182 /// the basic linear gradient primitive
183 class DRAWINGLAYER_DLLPUBLIC SvgLinearGradientPrimitive2D
: public BufferedDecompositionPrimitive2D
, public SvgGradientHelper
186 /// the end point for linear gradient
187 basegfx::B2DPoint maEnd
;
191 virtual void createAtom(
192 Primitive2DVector
& rTargetColor
,
193 Primitive2DVector
& rTargetOpacity
,
194 const SvgGradientEntry
& rFrom
,
195 const SvgGradientEntry
& rTo
,
196 sal_Int32 nOffset
) const SAL_OVERRIDE
;
197 virtual void checkPreconditions() SAL_OVERRIDE
;
199 /// local decomposition.
200 virtual Primitive2DSequence
create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
204 SvgLinearGradientPrimitive2D(
205 const basegfx::B2DHomMatrix
& rGradientTransform
,
206 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
207 const SvgGradientEntryVector
& rGradientEntries
,
208 const basegfx::B2DPoint
& rStart
,
209 const basegfx::B2DPoint
& rEnd
,
210 bool bUseUnitCoordinates
,
211 SpreadMethod aSpreadMethod
= Spread_pad
);
212 virtual ~SvgLinearGradientPrimitive2D();
215 const basegfx::B2DPoint
& getEnd() const { return maEnd
; }
218 virtual bool operator==(const BasePrimitive2D
& rPrimitive
) const SAL_OVERRIDE
;
221 virtual basegfx::B2DRange
getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
223 /// provide unique ID
224 DeclPrimitive2DIDBlock()
226 } // end of namespace primitive2d
227 } // end of namespace drawinglayer
230 // SvgRadialGradientPrimitive2D class
232 namespace drawinglayer
234 namespace primitive2d
236 /// the basic radial gradient primitive
237 class DRAWINGLAYER_DLLPUBLIC SvgRadialGradientPrimitive2D
: public BufferedDecompositionPrimitive2D
, public SvgGradientHelper
240 /// the geometric definition
243 /// Focal only used when focal is set at all, see constructors
244 basegfx::B2DPoint maFocal
;
245 basegfx::B2DVector maFocalVector
;
246 double maFocalLength
;
248 // internal helper for case Spread_reflect
249 SvgGradientEntryVector maMirroredGradientEntries
;
255 const SvgGradientEntryVector
& getMirroredGradientEntries() const;
256 void createMirroredGradientEntries();
260 virtual void createAtom(
261 Primitive2DVector
& rTargetColor
,
262 Primitive2DVector
& rTargetOpacity
,
263 const SvgGradientEntry
& rFrom
,
264 const SvgGradientEntry
& rTo
,
265 sal_Int32 nOffset
) const SAL_OVERRIDE
;
266 virtual void checkPreconditions() SAL_OVERRIDE
;
268 /// local decomposition.
269 virtual Primitive2DSequence
create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
273 SvgRadialGradientPrimitive2D(
274 const basegfx::B2DHomMatrix
& rGradientTransform
,
275 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
276 const SvgGradientEntryVector
& rGradientEntries
,
277 const basegfx::B2DPoint
& rStart
,
279 bool bUseUnitCoordinates
,
280 SpreadMethod aSpreadMethod
= Spread_pad
,
281 const basegfx::B2DPoint
* pFocal
= 0);
282 virtual ~SvgRadialGradientPrimitive2D();
285 double getRadius() const { return mfRadius
; }
286 const basegfx::B2DPoint
& getFocal() const { return maFocal
; }
287 bool isFocalSet() const { return mbFocalSet
; }
290 virtual bool operator==(const BasePrimitive2D
& rPrimitive
) const SAL_OVERRIDE
;
293 virtual basegfx::B2DRange
getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
295 /// provide unique ID
296 DeclPrimitive2DIDBlock()
298 } // end of namespace primitive2d
299 } // end of namespace drawinglayer
302 // SvgLinearAtomPrimitive2D class
304 namespace drawinglayer
306 namespace primitive2d
308 /* basic primitive for a single linear GradientRun in unit coordiantes.
309 It's derived from DiscreteMetricDependentPrimitive2D to allow view-dependent
310 decompositions allowing reduced color steps
312 class DRAWINGLAYER_DLLPUBLIC SvgLinearAtomPrimitive2D
: public DiscreteMetricDependentPrimitive2D
315 /// the geometric definition in unit coordiantes
316 basegfx::BColor maColorA
;
317 basegfx::BColor maColorB
;
323 /// local decomposition.
324 virtual Primitive2DSequence
create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
328 SvgLinearAtomPrimitive2D(
329 const basegfx::BColor
& aColorA
, double fOffsetA
,
330 const basegfx::BColor
& aColorB
, double fOffsetB
);
333 const basegfx::BColor
& getColorA() const { return maColorA
; }
334 const basegfx::BColor
& getColorB() const { return maColorB
; }
335 double getOffsetA() const { return mfOffsetA
; }
336 double getOffsetB() const { return mfOffsetB
; }
339 virtual bool operator==(const BasePrimitive2D
& rPrimitive
) const SAL_OVERRIDE
;
341 /// provide unique ID
342 DeclPrimitive2DIDBlock()
344 } // end of namespace primitive2d
345 } // end of namespace drawinglayer
348 // SvgRadialAtomPrimitive2D class
350 namespace drawinglayer
352 namespace primitive2d
354 /* basic primitive for a single radial GradientRun in unit coordiantes.
355 It's derived from DiscreteMetricDependentPrimitive2D to allow view-dependent
356 decompositions allowing reduced color steps
358 class DRAWINGLAYER_DLLPUBLIC SvgRadialAtomPrimitive2D
: public DiscreteMetricDependentPrimitive2D
361 /// the geometric definition in unit coordiantes
362 basegfx::BColor maColorA
;
363 basegfx::BColor maColorB
;
367 // helper to hold translation vectors when given (for focal)
370 basegfx::B2DVector maTranslateA
;
371 basegfx::B2DVector maTranslateB
;
373 VectorPair(const basegfx::B2DVector
& rTranslateA
, const basegfx::B2DVector
& rTranslateB
)
374 : maTranslateA(rTranslateA
),
375 maTranslateB(rTranslateB
)
380 /// Only used when focal is set
381 VectorPair
* mpTranslate
;
385 /// local decomposition.
386 virtual Primitive2DSequence
create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const SAL_OVERRIDE
;
390 SvgRadialAtomPrimitive2D(
391 const basegfx::BColor
& aColorA
, double fScaleA
, const basegfx::B2DVector
& rTranslateA
,
392 const basegfx::BColor
& aColorB
, double fScaleB
, const basegfx::B2DVector
& rTranslateB
);
393 SvgRadialAtomPrimitive2D(
394 const basegfx::BColor
& aColorA
, double fScaleA
,
395 const basegfx::BColor
& aColorB
, double fScaleB
);
396 virtual ~SvgRadialAtomPrimitive2D();
399 const basegfx::BColor
& getColorA() const { return maColorA
; }
400 const basegfx::BColor
& getColorB() const { return maColorB
; }
401 double getScaleA() const { return mfScaleA
; }
402 double getScaleB() const { return mfScaleB
; }
403 bool isTranslateSet() const { return (0 != mpTranslate
); }
404 basegfx::B2DVector
getTranslateA() const { if(mpTranslate
) return mpTranslate
->maTranslateA
; return basegfx::B2DVector(); }
405 basegfx::B2DVector
getTranslateB() const { if(mpTranslate
) return mpTranslate
->maTranslateB
; return basegfx::B2DVector(); }
408 virtual bool operator==(const BasePrimitive2D
& rPrimitive
) const SAL_OVERRIDE
;
410 /// provide unique ID
411 DeclPrimitive2DIDBlock()
413 } // end of namespace primitive2d
414 } // end of namespace drawinglayer
418 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SVGGRADIENTPRIMITIVE2D_HXX
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */