• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef GRAPHIC_LITE_PAINT_H
16 #define GRAPHIC_LITE_PAINT_H
17 
18 #include "gfx_utils/diagram/imagefilter/filter_blur.h"
19 #include "gfx_utils/diagram/spancolorfill/fill_pattern_rgba.h"
20 #include "gfx_utils/diagram/vertexprimitive/geometry_math_stroke.h"
21 #include "gfx_utils/diagram/vertexprimitive/geometry_path_storage.h"
22 #include "gfx_utils/list.h"
23 
24 namespace OHOS {
25 
26 /**
27  * @brief Defines the basic styles of graphs drawn on canvases.
28  *
29  * @since 1.0
30  * @version 1.0
31  */
32 class Paint : public HeapBase {
33     const uint16_t DEFAULT_STROKE_WIDTH = 2;
34 public:
35     /**
36      * @brief A constructor used to create a <b>Paint</b> instance.
37      *
38      * @since 1.0
39      * @version 1.0
40      */
Paint()41     Paint()
42         : style_(PaintStyle::STROKE_FILL_STYLE),
43           fillColor_(Color::Black()),
44           strokeColor_(Color::White()),
45           opacity_(OPA_OPAQUE),
46           strokeWidth_(DEFAULT_STROKE_WIDTH),
47           changeFlag_(false),
48 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
49           lineJoin_(LineJoin::ROUND_JOIN),
50 #endif
51 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
52           lineCap_(LineCap::BUTT_CAP),
53 #endif
54 #if defined(GRAPHIC_ENABLE_DASH_GENERATE_FLAG) && GRAPHIC_ENABLE_DASH_GENERATE_FLAG
55           isDashMode_(false),
56           dashOffset_(0),
57           dashArray_(nullptr),
58           ndashes_(0),
59 #endif
60 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
61           miterLimit_(0),
62 #endif
63 #if defined(GRAPHIC_ENABLE_GRADIENT_FILL_FLAG) && GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
64           linearGradientPoint_({0, 0, 0, 0}),
65           radialGradientPoint_({0, 0, 0, 0, 0, 0}),
66           stopAndColors_({}),
67           gradientflag_(Linear),
68 #endif
69 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
70           patternRepeat_(REPEAT),
71 #endif
72 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
73           image_(nullptr),
74 #endif
75 #if defined(GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG) && GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
76           shadowBlurRadius_(0),
77           shadowOffsetX_(0.0f),
78           shadowOffsetY_(0.0f),
79           shadowColor_(Color::Black()),
80           haveShadow_(false),
81 #endif
82           globalAlpha_(1.0),
83           globalCompositeOperation_(SOURCE_OVER),
84           rotateAngle_(0),
85           scaleRadioX_(1.0f),
86           scaleRadioY_(1.0f),
87           translationX_(0),
88           translationY_(0),
89           haveComposite_(false)
90     {
91     }
92 
Paint(const Paint & paint)93     Paint(const Paint& paint)
94     {
95         Init(paint);
96     }
InitDash(const Paint & paint)97     void InitDash(const Paint& paint)
98     {
99 #if defined(GRAPHIC_ENABLE_DASH_GENERATE_FLAG) && GRAPHIC_ENABLE_DASH_GENERATE_FLAG
100         if (isDashMode_ && ndashes_ > 0) {
101             dashArray_ = new float[ndashes_];
102             if (dashArray_) {
103                 if (memset_s(dashArray_, ndashes_ * sizeof(float), 0, ndashes_ * sizeof(float)) != EOF) {
104                 }
105                 for (uint32_t i = 0; i < ndashes_; i++) {
106                     dashArray_[i] = paint.dashArray_[i];
107                 }
108             } else {
109                 ndashes_ = 0;
110                 dashOffset_ = 0;
111                 isDashMode_ = false;
112             }
113         } else {
114             dashArray_ = nullptr;
115         }
116 #endif
117     }
118     /*
119      * Initialize data members.
120      * style_:       paint style.
121      * fillColor_:   Sets the fill color of the pen.
122      * strokeColor_: Sets the line color of the pen.
123      * opacity_:     Set transparency.
124      * strokeWidth_: Set lineweight.
125      * lineCap_:     Set pen cap.
126      * lineJoin_:    Sets the style at the path connection of the pen.
127      * miterLimit_:  Sets the spacing limit for sharp corners at path connections.
128      * dashOffset:   dash Point offset.
129      * isDrawDash:   Whether to draw dotted line.
130      * dashArray:    dash Point group.
131      * ndashes:      Number of dotted lines.
132      * globalAlpha:  Set element Global alpha.
133      * shadowBlurRadius:  Sets the shadow blur radius.
134      * shadowOffsetX:     Sets the abscissa offset of the shadow.
135      * shadowOffsetY:     Sets the shadow ordinate offset.
136      * shadowColor:       Set shadow color.
137      */
Init(const Paint & paint)138     void Init(const Paint& paint)
139     {
140         style_ = paint.style_;
141         fillColor_ = paint.fillColor_;
142         strokeColor_ = paint.strokeColor_;
143         strokeWidth_ = paint.strokeWidth_;
144         opacity_ = paint.opacity_;
145 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
146         lineCap_ = paint.lineCap_;
147 #endif
148 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
149         lineJoin_ = paint.lineJoin_;
150 #endif
151 #if defined(GRAPHIC_ENABLE_DASH_GENERATE_FLAG) && GRAPHIC_ENABLE_DASH_GENERATE_FLAG
152         isDashMode_ = paint.isDashMode_;
153         dashOffset_ = paint.dashOffset_;
154         dashArray_ = paint.dashArray_;
155         ndashes_ = paint.ndashes_;
156 #endif
157         changeFlag_ = paint.changeFlag_;
158         scaleRadioX_ = paint.scaleRadioX_;
159         scaleRadioY_ = paint.scaleRadioY_;
160         translationX_ = paint.translationX_;
161         translationY_ = paint.translationY_;
162         InitDash(paint);
163 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
164         miterLimit_ = paint.miterLimit_;
165 #endif
166 #if defined(GRAPHIC_ENABLE_GRADIENT_FILL_FLAG) && GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
167         linearGradientPoint_ = paint.linearGradientPoint_;
168         radialGradientPoint_ = paint.radialGradientPoint_;
169         stopAndColors_ = paint.stopAndColors_;
170         gradientflag_ = paint.gradientflag_;
171 #endif
172 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
173         patternRepeat_ = paint.patternRepeat_;
174 #endif
175 #if defined(GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG) && GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
176         shadowBlurRadius_ = paint.shadowBlurRadius_;
177         shadowOffsetX_ = paint.shadowOffsetX_;
178         shadowOffsetY_ = paint.shadowOffsetY_;
179         shadowColor_ = paint.shadowColor_;
180         haveShadow_ = paint.haveShadow_;
181 #endif
182         globalAlpha_ = paint.globalAlpha_;
183         globalCompositeOperation_ = paint.globalCompositeOperation_;
184         rotateAngle_ = paint.rotateAngle_;
185         transfrom_ = paint.transfrom_;
186         haveComposite_ = paint.haveComposite_;
187     }
188 
189     /**
190      * @brief A destructor used to delete the <b>Paint</b> instance.
191      *
192      * @since 1.0
193      * @version 1.0
194      */
~Paint()195     virtual ~Paint() {}
196 
197     const Paint& operator=(const Paint& paint)
198     {
199         Init(paint);
200         return *this;
201     }
202     /**
203      * @brief Enumerates paint styles of a closed graph. The styles are invalid for non-closed graphs.
204      */
205     enum PaintStyle {
206         /** Stroke only */
207         STROKE_STYLE = 1,
208         /** Fill only */
209         FILL_STYLE,
210         /** Stroke and fill */
211         STROKE_FILL_STYLE,
212         /** Gradual change */
213         GRADIENT,
214         /** Image mode */
215         PATTERN
216     };
217 
218     struct LinearGradientPoint {
219         /**  Start point coordinate x  */
220         float x0;
221         /**  Start point coordinate y  */
222         float y0;
223         /**  End point coordinate x  */
224         float x1;
225         /**  End point coordinate y  */
226         float y1;
227     };
228 
229     struct RadialGradientPoint {
230         /**  Start dot coordinate x  */
231         float x0;
232         /** Start dot coordinate y  */
233         float y0;
234         /**  Start circle radius r0  */
235         float r0;
236         /**  End dot coordinates x  */
237         float x1;
238         /**  End dot coordinates y  */
239         float y1;
240         /**  Start circle radius r0  */
241         float r1;
242     };
243 
244     struct StopAndColor {
245         /** Values between 0.0 and 1.0 represent the position between the beginning and end of the ramp.  */
246         float stop;
247         /** The color value displayed at the end */
248         ColorType color;
249     };
250 
251     enum Gradient { Linear, Radial };
252 
253     /**
254      * @brief Sets the paint style of a closed graph.
255      *
256      * @param style Indicates the paint style. Stroke and fill are set by default.
257      * For details, see {@link PaintStyle}.
258      * @see GetStyle
259      * @since 1.0
260      * @version 1.0
261      */
SetStyle(PaintStyle style)262     void SetStyle(PaintStyle style)
263     {
264         style_ = style;
265     }
266 
267     /**
268      * @brief Sets the paint style.
269      *
270      * @param color value.
271      * @since 1.0
272      * @version 1.0
273      */
SetStrokeStyle(ColorType color)274     void SetStrokeStyle(ColorType color)
275     {
276         SetStyle(Paint::STROKE_STYLE);
277         SetStrokeColor(color);
278     }
279 
280     /**
281      * @brief Sets fill style.
282      *
283      * @param color value.
284      * @since 1.0
285      * @version 1.0
286      */
SetFillStyle(ColorType color)287     void SetFillStyle(ColorType color)
288     {
289         SetStyle(Paint::FILL_STYLE);
290         SetFillColor(color);
291     }
292 
293     /**
294      * @brief Sets the paint stroke style of a closed graph.
295      *
296      * @param style Indicates the paint style. Stroke and fill are set by default.
297      * @since 1.0
298      * @version 1.0
299      */
SetStrokeStyle(PaintStyle style)300     void SetStrokeStyle(PaintStyle style)
301     {
302         SetStyle(style);
303     }
304 
305     /**
306      * @brief Sets the paint fill style of a closed graph.
307      *
308      * @param style Indicates the paint style. Stroke and fill are set by default.
309      * @since 1.0
310      * @version 1.0
311      */
SetFillStyle(PaintStyle style)312     void SetFillStyle(PaintStyle style)
313     {
314         SetStyle(style);
315     }
316 
317     /**
318      * @brief Obtains the paint style of a closed graph.
319      *
320      * @return Returns the paint style. For details, see {@link PaintStyle}.
321      * @see SetStyle
322      * @since 1.0
323      * @version 1.0
324      */
GetStyle()325     PaintStyle GetStyle() const
326     {
327         return style_;
328     }
329 
330     /**
331      * @brief Sets the width of a line or border.
332      *
333      * @param width Indicates the line width when a line is drawn or the border width when a closed graph is drawn.
334      *        The width is extended to both sides.
335      * @see GetStrokeWidth
336      * @since 1.0
337      * @version 1.0
338      */
SetStrokeWidth(uint16_t width)339     void SetStrokeWidth(uint16_t width)
340     {
341         strokeWidth_ = width;
342     }
343 
344     /**
345      * @brief Obtains the width of a line or border.
346      *
347      * @return Returns the line width if a line is drawn or the border width if a closed graph is drawn.
348      * @see SetStrokeWidth
349      * @since 1.0
350      * @version 1.0
351      */
GetStrokeWidth()352     uint16_t GetStrokeWidth() const
353     {
354         return strokeWidth_;
355     }
356 
357     /**
358      * @brief Sets the color of a line or border.
359      *
360      * @param color Indicates the line color when a line is drawn or the border color when a closed graph is drawn.
361      * @see GetStrokeColor
362      * @since 1.0
363      * @version 1.0
364      */
SetStrokeColor(ColorType color)365     void SetStrokeColor(ColorType color)
366     {
367         strokeColor_ = color;
368         changeFlag_ = true;
369     }
370 
371     /**
372      * @brief Obtains the color of a line or border.
373      *
374      * @return Returns the line color if a line is drawn or the border color if a closed graph is drawn.
375      * @see SetStrokeWidth
376      * @since 1.0
377      * @version 1.0
378      */
GetStrokeColor()379     ColorType GetStrokeColor() const
380     {
381         return strokeColor_;
382     }
383 
384     /**
385      * @brief Sets fill color.
386      *
387      * This function is valid only for closed graphs.
388      *
389      * @param color Indicates the fill color to set.
390      * @see GetFillColor
391      * @since 1.0
392      * @version 1.0
393      */
SetFillColor(ColorType color)394     void SetFillColor(ColorType color)
395     {
396         fillColor_ = color;
397         changeFlag_ = true;
398     }
399 
400     /**
401      * @brief Obtains the fill color.
402      *
403      * @return Returns the fill color.
404      * @see SetFillColor
405      * @since 1.0
406      * @version 1.0
407      */
GetFillColor()408     ColorType GetFillColor() const
409     {
410         return fillColor_;
411     }
412 
413     /**
414      * @brief Sets the opacity.
415      *
416      * The setting takes effect for the entire graph, including the border, line color, and fill color.
417      *
418      * @param opacity Indicates the opacity. The value range is [0, 255].
419      * @see GetOpacity
420      * @since 1.0
421      * @version 1.0
422      */
SetOpacity(uint8_t opacity)423     void SetOpacity(uint8_t opacity)
424     {
425         opacity_ = opacity;
426     }
427 
428     /**
429      * @brief Obtains the opacity.
430      *
431      * @return Returns the opacity.
432      * @see SetOpacity
433      * @since 1.0
434      * @version 1.0
435      */
GetOpacity()436     uint8_t GetOpacity() const
437     {
438         return opacity_;
439     }
440 
GetChangeFlag()441     bool GetChangeFlag() const
442     {
443         return changeFlag_;
444     }
445 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
446     /**
447      * @brief Sets the cap type.
448      * @see GetLineCap
449      * @since 1.0
450      * @version 1.0
451      */
SetLineCap(LineCap lineCap)452     void SetLineCap(LineCap lineCap)
453     {
454         lineCap_ = lineCap;
455         changeFlag_ = true;
456     }
457 #endif
458 
459 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
460     /**
461      * @brief Gets the cap type.
462      * @see SetLineCap
463      * @since 1.0
464      * @version 1.0
465      */
GetLineCap()466     LineCap GetLineCap() const
467     {
468         return lineCap_;
469     }
470 #endif
471 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
472     /**
473      * @brief Sets the style at the path connection of the pen.
474      * @see GetLineJoin
475      * @since 1.0
476      * @version 1.0
477      */
SetLineJoin(LineJoin lineJoin)478     void SetLineJoin(LineJoin lineJoin)
479     {
480         lineJoin_ = lineJoin;
481         changeFlag_ = true;
482     }
483 #endif
484 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
485     /**
486      * @brief Sets the spacing limit for sharp corners at path connections.
487      * @see GetMiterLimit
488      * @since 1.0
489      * @version 1.0
490      */
SetMiterLimit(float miterLimit)491     void SetMiterLimit(float miterLimit)
492     {
493         miterLimit_ = miterLimit;
494         changeFlag_ = true;
495     }
496 #endif
497 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
GetMiterLimit()498     float GetMiterLimit() const
499     {
500         return miterLimit_;
501     }
502 #endif
503 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
504     /**
505      * @brief Gets the style at the path connection of the pen.
506      * @see SetLineJoin
507      * @since 1.0
508      * @version 1.0
509      */
GetLineJoin()510     LineJoin GetLineJoin() const
511     {
512         return lineJoin_;
513     }
514 #endif
515 #if defined(GRAPHIC_ENABLE_DASH_GENERATE_FLAG) && GRAPHIC_ENABLE_DASH_GENERATE_FLAG
IsLineDash()516     bool IsLineDash() const
517     {
518         return isDashMode_;
519     }
520 
521     /**
522      * @brief Sets the array and number of dashes.
523      * @param lineDashs Represents an array of dotted lines,ndash Indicates the number of dotted lines
524      * @since 1.0
525      * @version 1.0
526      */
SetLineDash(float * lineDashs,const uint32_t ndash)527     void SetLineDash(float* lineDashs, const uint32_t ndash)
528     {
529         ClearLineDash();
530         if (lineDashs == nullptr || ndash == 0) {
531             return;
532         }
533         ndashes_ = ndash;
534         isDashMode_ = true;
535         dashArray_ = new float[ndashes_];
536         if (dashArray_) {
537             if (memset_s(dashArray_, ndashes_ * sizeof(float), 0, ndashes_ * sizeof(float)) != EOF) {
538             }
539             for (uint32_t iIndex = 0; iIndex < ndashes_; iIndex++) {
540                 dashArray_[iIndex] = lineDashs[iIndex];
541             }
542         } else {
543             ndashes_ = 0;
544             dashOffset_ = 0;
545             isDashMode_ = false;
546         }
547         changeFlag_ = true;
548     }
549 
550     /**
551      * @brief Get dash array
552      * @return
553      */
GetLineDash()554     float* GetLineDash() const
555     {
556         return dashArray_;
557     }
558 
GetLineDashOffset()559     float GetLineDashOffset() const
560     {
561         return dashOffset_;
562     }
563 
564     /**
565      * @brief Sets the offset of the dash mode start point
566      * @see GetLineDashOffset
567      * @since 1.0
568      * @version 1.0
569      */
SetLineDashOffset(float offset)570     void SetLineDashOffset(float offset)
571     {
572         dashOffset_ = offset;
573         changeFlag_ = true;
574         isDashMode_ = true;
575     }
576 
577     /**
578      * @brief Get dash array length
579      * @return
580      */
GetLineDashCount()581     uint32_t GetLineDashCount() const
582     {
583         return ndashes_;
584     }
585 
586     /**
587      * @brief Empty the dotted line and draw it instead.
588      * @since 1.0
589      * @version 1.0
590      */
ClearLineDash(void)591     void ClearLineDash(void)
592     {
593         dashOffset_ = 0;
594         ndashes_ = 0;
595         isDashMode_ = false;
596         if (dashArray_ != nullptr) {
597             delete[] dashArray_;
598             dashArray_ = nullptr;
599         }
600     }
601 #endif
602 #if defined(GRAPHIC_ENABLE_GRADIENT_FILL_FLAG) && GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
createLinearGradient(float startx,float starty,float endx,float endy)603     void createLinearGradient(float startx, float starty, float endx, float endy)
604     {
605         gradientflag_ = Linear;
606         linearGradientPoint_.x0 = startx;
607         linearGradientPoint_.y0 = starty;
608         linearGradientPoint_.x1 = endx;
609         linearGradientPoint_.y1 = endy;
610         changeFlag_ = true;
611     }
612 
addColorStop(float stop,ColorType color)613     void addColorStop(float stop, ColorType color)
614     {
615         StopAndColor stopAndColor;
616         stopAndColor.stop = stop;
617         stopAndColor.color = color;
618         stopAndColors_.PushBack(stopAndColor);
619     }
620 
createRadialGradient(float start_x,float start_y,float start_r,float end_x,float end_y,float end_r)621     void createRadialGradient(float start_x, float start_y, float start_r, float end_x, float end_y, float end_r)
622     {
623         gradientflag_ = Radial;
624         radialGradientPoint_.x0 = start_x;
625         radialGradientPoint_.y0 = start_y;
626         radialGradientPoint_.r0 = start_r;
627         radialGradientPoint_.x1 = end_x;
628         radialGradientPoint_.y1 = end_y;
629         radialGradientPoint_.r1 = end_r;
630         changeFlag_ = true;
631     }
632 
getStopAndColor()633     List<StopAndColor> getStopAndColor() const
634     {
635         return stopAndColors_;
636     }
637 
GetLinearGradientPoint()638     LinearGradientPoint GetLinearGradientPoint() const
639     {
640         return linearGradientPoint_;
641     }
642 
GetRadialGradientPoint()643     RadialGradientPoint GetRadialGradientPoint() const
644     {
645         return radialGradientPoint_;
646     }
647 
GetGradient()648     Gradient GetGradient() const
649     {
650         return gradientflag_;
651     }
652 #endif
653 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
654     /*
655      * Set hatch patterns for elements
656      * @param img Represents the pattern of the hatch,text Represents a fill pattern
657      */
CreatePattern(const char * img,PatternRepeatMode patternRepeat)658     void CreatePattern(const char* img, PatternRepeatMode patternRepeat)
659     {
660         image_ = img;
661         patternRepeat_ = patternRepeat;
662         changeFlag_ = true;
663     }
664 
GetPatternImage()665     const char* GetPatternImage() const
666     {
667         return image_;
668     }
669 
GetPatternRepeatMode()670     PatternRepeatMode GetPatternRepeatMode() const
671     {
672         return patternRepeat_;
673     }
674 #endif
675 
676 #if defined(GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG) && GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
677     /**
678      * @brief Sets the shadow blur level.
679      * @since 1.0
680      * @version 1.0
681      */
SetShadowBlur(uint16_t radius)682     void SetShadowBlur(uint16_t radius)
683     {
684         shadowBlurRadius_ = radius;
685         changeFlag_ = true;
686     }
687 
688     /**
689      * @brief Gets the shadow blur level.
690      * @since 1.0
691      * @version 1.0
692      */
GetShadowBlur()693     uint16_t GetShadowBlur() const
694     {
695         return shadowBlurRadius_;
696     }
697 
698     /**
699      * @brief Gets the abscissa offset of the shadow.
700      * @since 1.0
701      * @version 1.0
702      */
GetShadowOffsetX()703     float GetShadowOffsetX() const
704     {
705         return shadowOffsetX_;
706     }
707     /**
708      * @brief Sets the abscissa offset of the shadow.
709      * @since 1.0
710      * @version 1.0
711      */
SetShadowOffsetX(float offset)712     void SetShadowOffsetX(float offset)
713     {
714         shadowOffsetX_ = offset;
715         changeFlag_ = true;
716     }
717     /**
718      * @brief Gets the shadow ordinate offset.
719      * @since 1.0
720      * @version 1.0
721      */
GetShadowOffsetY()722     float GetShadowOffsetY() const
723     {
724         return shadowOffsetY_;
725     }
726     /**
727      * @brief Sets the shadow ordinate offset.
728      * @since 1.0
729      * @version 1.0
730      */
SetShadowOffsetY(float offset)731     void SetShadowOffsetY(float offset)
732     {
733         shadowOffsetY_ = offset;
734         changeFlag_ = true;
735     }
736     /**
737      * @brief Gets the color value of the shadow.
738      * @since 1.0
739      * @version 1.0
740      */
GetShadowColor()741     ColorType GetShadowColor() const
742     {
743         return shadowColor_;
744     }
745     /**
746      * @brief Sets the color value of the shadow.
747      * @since 1.0
748      * @version 1.0
749      */
SetShadowColor(ColorType color)750     void SetShadowColor(ColorType color)
751     {
752         shadowColor_ = color;
753         changeFlag_ = true;
754         haveShadow_ = true;
755     }
HaveShadow()756     bool HaveShadow() const
757     {
758         return haveShadow_;
759     }
760 #endif
761     /**
762      * @brief Sets the alpha of the current drawing.
763      */
SetGlobalAlpha(float alphaPercentage)764     void SetGlobalAlpha(float alphaPercentage)
765     {
766         if (alphaPercentage > 1) {
767             globalAlpha_ = 1.0;
768             return;
769         }
770         if (alphaPercentage < 0) {
771             globalAlpha_ = 0.0;
772             return;
773         }
774         globalAlpha_ = alphaPercentage;
775         changeFlag_ = true;
776     }
777 
778     /**
779      * @brief get the alpha of the current drawing
780      * @return Returns the alpha of the current drawing
781      * @since 1.0
782      * @version 1.0
783      */
GetGlobalAlpha()784     float GetGlobalAlpha() const
785     {
786         return globalAlpha_;
787     }
788 
789     /**
790      * @brief Set blend mode
791      */
SetGlobalCompositeOperation(GlobalCompositeOperation globalCompositeOperation)792     void SetGlobalCompositeOperation(GlobalCompositeOperation globalCompositeOperation)
793     {
794         globalCompositeOperation_ = globalCompositeOperation;
795         changeFlag_ = true;
796         if (globalCompositeOperation != SOURCE_OVER) {
797             haveComposite_ = true;
798         }
799     }
800 
801     /**
802      * @brief Get blend mode
803      */
GetGlobalCompositeOperation()804     GlobalCompositeOperation GetGlobalCompositeOperation() const
805     {
806         return globalCompositeOperation_;
807     }
808 
809     /* Zooms the current drawing to a larger or smaller size */
Scale(float scaleX,float scaleY)810     void Scale(float scaleX, float scaleY)
811     {
812         this->scaleRadioX_ *= scaleX;
813         this->scaleRadioY_ *= scaleX;
814         if (rotateAngle_ > 0.0f || rotateAngle_ < 0) {
815             transfrom_.Rotate(-rotateAngle_ * PI / BOXER);
816             transfrom_.Scale(scaleX, scaleY);
817             transfrom_.Rotate(rotateAngle_ * PI / BOXER);
818         } else {
819             transfrom_.Scale(scaleX, scaleY);
820         }
821         changeFlag_ = true;
822     }
823 
824     /**
825      * @brief get the x coordinate scale value
826      * @since 1.0
827      * @version 1.0
828      */
GetScaleX()829     float GetScaleX() const
830     {
831         return this->scaleRadioX_;
832     }
833 
834     /**
835      * @brief get the y coordinate scale value
836      * @since 1.0
837      * @version 1.0
838      */
GetScaleY()839     float GetScaleY() const
840     {
841         return this->scaleRadioY_;
842     }
843 
844     /**
845      * @brief Rotate current drawing
846      * @param angle rotate angle value.
847      * @since 1.0
848      * @version 1.0
849      */
Rotate(float angle)850     void Rotate(float angle)
851     {
852         changeFlag_ = true;
853         transfrom_.Rotate(angle * PI / BOXER);
854         rotateAngle_ += angle;
855     }
856 
857     /**
858      * @brief Rotate current drawing
859      * @param angle rotate angle value.
860      * @param x translate x coordinate.
861      * @param y translate y coordinate.
862      * @since 1.0
863      * @version 1.0
864      */
Rotate(float angle,int16_t x,int16_t y)865     void Rotate(float angle, int16_t x, int16_t y)
866     {
867         transfrom_.Translate(-x, -y);
868         transfrom_.Rotate(angle * PI / BOXER);
869         rotateAngle_ += angle;
870         transfrom_.Translate(x, y);
871         changeFlag_ = true;
872     }
873 
874     /**
875      * @brief Remap the (x, y) position on the canvas
876      * @param x translate x coordinate.
877      * @param y translate y coordinate.
878      * @since 1.0
879      * @version 1.0
880      */
Translate(int16_t x,int16_t y)881     void Translate(int16_t x, int16_t y)
882     {
883         changeFlag_ = true;
884         transfrom_.Translate(x, y);
885         this->translationX_ += x;
886         this->translationY_ += y;
887     }
888 
889     /**
890      * @brief Gets the x position on the remapping canvas
891      * @since 1.0
892      * @version 1.0
893      */
GetTranslateX()894     int16_t GetTranslateX() const
895     {
896         return this->translationX_;
897     }
898 
899     /**
900      * @brief Gets the Y position on the remapping canvas
901      * @since 1.0
902      * @version 1.0
903      */
GetTranslateY()904     int16_t GetTranslateY() const
905     {
906         return this->translationY_;
907     }
908 
909     /**
910      * @brief Resets the current conversion to the identity matrix. Then run transform ()
911      * @param scaleX scale x value.
912      * @param shearX shear x value.
913      * @param shearY shear y value.
914      * @param scaleY scale y value
915      * @param transLateX translate x coordinate.
916      * @param transLateY translate y coordinate.
917      * @since 1.0
918      * @version 1.0
919      */
SetTransform(float scaleX,float shearX,float shearY,float scaleY,int16_t transLateX,int16_t transLateY)920     void SetTransform(float scaleX, float shearX, float shearY, float scaleY, int16_t transLateX, int16_t transLateY)
921     {
922         transfrom_.Reset();
923         rotateAngle_ = 0;
924         Transform(scaleX, shearX, shearY, scaleY, transLateX, transLateY);
925         changeFlag_ = true;
926     }
927 
928     /**
929      * @brief Resets the current conversion to the identity matrix. Then run transform ()
930      * @param scaleX scale x value.
931      * @param shearX shear x value.
932      * @param shearY shear y value.
933      * @param scaleY scale y value
934      * @param transLateX translate x coordinate.
935      * @param transLateY translate y coordinate.
936      * @since 1.0
937      * @version 1.0
938      */
Transform(float scaleX,float shearX,float shearY,float scaleY,int16_t transLateX,int16_t transLateY)939     void Transform(float scaleX, float shearX, float shearY, float scaleY, int16_t transLateX, int16_t transLateY)
940     {
941         changeFlag_ = true;
942         this->translationX_ += transLateX;
943         this->translationY_ += transLateY;
944         transLateX += transfrom_.GetData()[2];
945         transLateY += transfrom_.GetData()[5];
946         transfrom_.Translate(-transfrom_.GetData()[2], -transfrom_.GetData()[5]);
947         Scale(scaleX, scaleY);
948         transfrom_.Translate(transLateX, transLateY);
949         transfrom_.SetData(1, transfrom_.GetData()[1] + shearX);
950         transfrom_.SetData(3, transfrom_.GetData()[3] + shearY);
951     }
952 
953     /**
954      * @brief Gets the Trans Affine
955      * @since 1.0
956      * @version 1.0
957      */
GetTransAffine()958     TransAffine GetTransAffine() const
959     {
960         return transfrom_;
961     }
962 
963     /**
964      * @brief Gets the Rotate Angle
965      * @since 1.0
966      * @version 1.0
967      */
GetRotateAngle()968     float GetRotateAngle() const
969     {
970         return rotateAngle_;
971     }
972 
HaveComposite()973     bool HaveComposite() const
974     {
975         return haveComposite_;
976     }
977 
978 #if defined(GRAPHIC_ENABLE_BLUR_EFFECT_FLAG) && GRAPHIC_ENABLE_BLUR_EFFECT_FLAG
979     Filterblur drawBlur;
GetDrawBoxBlur()980     Filterblur GetDrawBoxBlur() const
981     {
982         return drawBlur;
983     }
984 #endif
985 
986 private:
987     PaintStyle style_;
988     ColorType fillColor_;
989     ColorType strokeColor_;
990     uint8_t opacity_;
991     uint16_t strokeWidth_;
992     bool changeFlag_;
993 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
994     LineJoin lineJoin_;
995 #endif
996 
997 #if defined(GRAPHIC_ENABLE_LINECAP_FLAG) && GRAPHIC_ENABLE_LINECAP_FLAG
998     LineCap lineCap_;
999 #endif
1000 #if defined(GRAPHIC_ENABLE_DASH_GENERATE_FLAG) && GRAPHIC_ENABLE_DASH_GENERATE_FLAG
1001     bool isDashMode_;  // Is it a dash mode segment.
1002     float dashOffset_; // dash Point offset.
1003     float* dashArray_; // dash Point array.
1004     uint32_t ndashes_; // Length of dasharray
1005 #endif
1006 #if defined(GRAPHIC_ENABLE_LINEJOIN_FLAG) && GRAPHIC_ENABLE_LINEJOIN_FLAG
1007     float miterLimit_; // Sets the spacing limit for sharp corners at path connections
1008 #endif
1009 #if defined(GRAPHIC_ENABLE_GRADIENT_FILL_FLAG) && GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
1010     LinearGradientPoint linearGradientPoint_;
1011     RadialGradientPoint radialGradientPoint_;
1012     List<StopAndColor> stopAndColors_;
1013     Gradient gradientflag_;
1014 #endif
1015 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
1016     PatternRepeatMode patternRepeat_;
1017 #endif
1018 #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG
1019     const char* image_;
1020 #endif
1021 #if defined(GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG) && GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
1022     uint16_t shadowBlurRadius_; // Sets the shadow blur radius.
1023     float shadowOffsetX_;       // Sets the abscissa offset of the shadow.
1024     float shadowOffsetY_;       // Sets the shadow ordinate offset.
1025     ColorType shadowColor_;     // Set shadow color.
1026     bool haveShadow_;           // Is there a shadow currently.
1027 #endif
1028     float globalAlpha_;                                 // The transparency of the current drawing is 0-1 percent
1029     GlobalCompositeOperation globalCompositeOperation_; // Mixed image mode
1030     float rotateAngle_;                                 // Rotation angle in degrees
1031     float scaleRadioX_;
1032     float scaleRadioY_;
1033     int32_t translationX_;
1034     int32_t translationY_;
1035     TransAffine transfrom_; // matrix.
1036     bool haveComposite_;
1037 };
1038 } // namespace OHOS
1039 
1040 #endif // GRAPHIC_LITE_PAINT_H
1041