update emoji autocorrect entries from po-files
[LibreOffice.git] / include / drawinglayer / primitive2d / svggradientprimitive2d.hxx
blob2bc6e54aab056319cd33f03ee70475581b8f9b75
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include <vector>
32 // SvgGradientEntry class
34 namespace drawinglayer
36 namespace primitive2d
38 /// a single GradientStop defining a color and opacity at a distance
39 class SvgGradientEntry
41 private:
42 double mfOffset;
43 basegfx::BColor maColor;
44 double mfOpacity;
46 public:
47 SvgGradientEntry(double fOffset, const basegfx::BColor& rColor = basegfx::BColor(0.0, 0.0, 0.0), double fOpacity = 1.0)
48 : mfOffset(fOffset),
49 maColor(rColor),
50 mfOpacity(fOpacity)
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
81 namespace primitive2d
83 enum SpreadMethod
85 Spread_pad = 0,
86 Spread_reflect,
87 Spread_repeat
90 /* helper for linear and radial gradient, both get derived from this
91 to share common definitions and functionality
92 **/
93 class SvgGradientHelper
95 private:
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;
108 /// how to spread
109 SpreadMethod maSpreadMethod;
111 /// bitfield
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;
122 protected:
123 /// local helpers
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;
131 double createRun(
132 Primitive2DVector& rTargetColor,
133 Primitive2DVector& rTargetOpacity,
134 double fPos,
135 double fMax,
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; }
150 public:
151 /// constructor
152 SvgGradientHelper(
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();
161 /// data read access
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; }
169 /// compare operator
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
185 private:
186 /// the end point for linear gradient
187 basegfx::B2DPoint maEnd;
189 protected:
190 /// local helpers
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;
202 public:
203 /// constructor
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();
214 /// data read access
215 const basegfx::B2DPoint& getEnd() const { return maEnd; }
217 /// compare operator
218 virtual bool operator==(const BasePrimitive2D& rPrimitive) const SAL_OVERRIDE;
220 /// get range
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
239 private:
240 /// the geometric definition
241 double mfRadius;
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;
251 /// bitfield
252 bool mbFocalSet : 1;
254 /// local helpers
255 const SvgGradientEntryVector& getMirroredGradientEntries() const;
256 void createMirroredGradientEntries();
258 protected:
259 /// local helpers
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;
271 public:
272 /// constructor
273 SvgRadialGradientPrimitive2D(
274 const basegfx::B2DHomMatrix& rGradientTransform,
275 const basegfx::B2DPolyPolygon& rPolyPolygon,
276 const SvgGradientEntryVector& rGradientEntries,
277 const basegfx::B2DPoint& rStart,
278 double fRadius,
279 bool bUseUnitCoordinates,
280 SpreadMethod aSpreadMethod = Spread_pad,
281 const basegfx::B2DPoint* pFocal = 0);
282 virtual ~SvgRadialGradientPrimitive2D();
284 /// data read access
285 double getRadius() const { return mfRadius; }
286 const basegfx::B2DPoint& getFocal() const { return maFocal; }
287 bool isFocalSet() const { return mbFocalSet; }
289 /// compare operator
290 virtual bool operator==(const BasePrimitive2D& rPrimitive) const SAL_OVERRIDE;
292 /// get range
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
314 private:
315 /// the geometric definition in unit coordiantes
316 basegfx::BColor maColorA;
317 basegfx::BColor maColorB;
318 double mfOffsetA;
319 double mfOffsetB;
321 protected:
323 /// local decomposition.
324 virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE;
326 public:
327 /// constructor
328 SvgLinearAtomPrimitive2D(
329 const basegfx::BColor& aColorA, double fOffsetA,
330 const basegfx::BColor& aColorB, double fOffsetB);
332 /// data read access
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; }
338 /// compare operator
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
360 private:
361 /// the geometric definition in unit coordiantes
362 basegfx::BColor maColorA;
363 basegfx::BColor maColorB;
364 double mfScaleA;
365 double mfScaleB;
367 // helper to hold translation vectors when given (for focal)
368 struct VectorPair
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;
383 protected:
385 /// local decomposition.
386 virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE;
388 public:
389 /// constructor
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();
398 /// data read access
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(); }
407 /// compare operator
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: */