• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
18 
19 #include <memory>
20 #include <optional>
21 #include <regex>
22 #include <vector>
23 
24 #include "base/geometry/dimension.h"
25 #include "base/geometry/rect.h"
26 #include "base/json/json_util.h"
27 #include "base/memory/ace_type.h"
28 #include "base/utils/macros.h"
29 #include "base/utils/utils.h"
30 #include "core/components/common/properties/alignment.h"
31 #include "core/components/common/properties/animatable_color.h"
32 #include "core/components/common/properties/blend_mode.h"
33 #include "core/components/common/properties/border.h"
34 #include "core/components/common/properties/border_image.h"
35 #include "core/components/common/properties/color.h"
36 #include "core/components/common/properties/common_decoration.h"
37 #include "core/components/common/properties/edge.h"
38 #include "core/components/common/properties/invert.h"
39 #include "core/components/common/properties/outline_style.h"
40 #include "core/components/common/properties/shadow.h"
41 #include "core/components/theme/theme_utils.h"
42 #include "core/components_ng/base/inspector_filter.h"
43 #include "core/pipeline/pipeline_context.h"
44 
45 namespace OHOS::Ace {
46 
47 constexpr double CENTER_OFFSET = 50.0;
48 constexpr double FULL_IMG_SIZE = 100.0;
49 constexpr double BOX_BEGIN_SIZE = 0.0;
50 constexpr double BOX_END_SIZE = 100.0;
51 constexpr double PERCENT_TRANSLATE = 100.0;
52 
53 enum class GradientDirection {
54     LEFT = 0,
55     TOP,
56     RIGHT,
57     BOTTOM,
58     LEFT_TOP,
59     LEFT_BOTTOM,
60     RIGHT_TOP,
61     RIGHT_BOTTOM,
62     NONE,
63     START_TO_END,
64     END_TO_START,
65 };
66 
67 enum class GradientType {
68     LINEAR,
69     RADIAL,
70     SWEEP,
71     CONIC,
72 };
73 
74 enum class RadialSizeType {
75     CLOSEST_SIDE,
76     CLOSEST_CORNER,
77     FARTHEST_SIDE,
78     FARTHEST_CORNER,
79     NONE,
80 };
81 
82 enum class RadialShapeType {
83     CIRCLE,
84     ELLIPSE,
85     NONE,
86 };
87 
88 enum class SpreadMethod {
89     PAD,
90     REFLECT,
91     REPEAT,
92 };
93 
94 
95 enum class ThemeColorMode {
96     SYSTEM = 0,
97     LIGHT,
98     DARK,
99 };
100 
101 struct MotionBlurAnchor {
102     float x = 0.0f;
103     float y = 0.0f;
104     bool operator==(const MotionBlurAnchor& other) const
105     {
106         return NearEqual(x, other.x) && NearEqual(y, other.y);
107     }
108     bool operator!=(const MotionBlurAnchor& other) const
109     {
110         return !operator==(other);
111     }
112 };
113 
114 struct MotionBlurOption {
115     float radius = 0.0f;
116     MotionBlurAnchor anchor;
117     bool operator==(const MotionBlurOption& other) const
118     {
119         return NearEqual(radius, other.radius) && anchor == other.anchor;
120     }
121     bool operator!=(const MotionBlurOption& other) const
122     {
123         return !operator==(other);
124     }
125 };
126 
127 struct BlurStyleOption {
128     BlurStyle blurStyle = BlurStyle::NO_MATERIAL;
129     ThemeColorMode colorMode = ThemeColorMode::SYSTEM;
130     AdaptiveColor adaptiveColor = AdaptiveColor::DEFAULT;
131     double scale = 1.0;
132     BlurOption blurOption;
133     bool operator==(const BlurStyleOption& other) const
134     {
135         return blurStyle == other.blurStyle && colorMode == other.colorMode && adaptiveColor == other.adaptiveColor &&
136                NearEqual(scale, other.scale);
137     }
ToJsonValueBlurStyleOption138     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
139     {
140         /* no fixed attr below, just return */
141         if (filter.IsFastFilter()) {
142             return;
143         }
144         static const char* STYLE[] = { "BlurStyle.NONE", "BlurStyle.Thin", "BlurStyle.Regular", "BlurStyle.Thick",
145             "BlurStyle.BACKGROUND_THIN", "BlurStyle.BACKGROUND_REGULAR", "BlurStyle.BACKGROUND_THICK",
146             "BlurStyle.BACKGROUND_ULTRA_THICK", "BlurStyle.COMPONENT_ULTRA_THIN", "BlurStyle.COMPONENT_THIN",
147             "BlurStyle.COMPONENT_REGULAR", "BlurStyle.COMPONENT_THICK", "BlurStyle.COMPONENT_ULTRA_THICK" };
148         static const char* COLOR_MODE[] = { "ThemeColorMode.System", "ThemeColorMode.Light", "ThemeColorMode.Dark" };
149         static const char* ADAPTIVE_COLOR[] = { "AdaptiveColor.Default", "AdaptiveColor.Average" };
150         auto jsonBlurStyle = JsonUtil::Create(true);
151         jsonBlurStyle->Put("value", STYLE[static_cast<int>(blurStyle)]);
152         auto jsonBlurStyleOption = JsonUtil::Create(true);
153         jsonBlurStyleOption->Put("colorMode", COLOR_MODE[static_cast<int>(colorMode)]);
154         jsonBlurStyleOption->Put("adaptiveColor", ADAPTIVE_COLOR[static_cast<int>(adaptiveColor)]);
155         jsonBlurStyleOption->Put("scale", scale);
156         jsonBlurStyle->Put("options", jsonBlurStyleOption);
157 
158         json->PutExtAttr("backgroundBlurStyle", jsonBlurStyle, filter);
159     }
160 };
161 
162 struct MenuPreviewAnimationOptions {
163     float scaleFrom { -1.0f };
164     float scaleTo { -1.0f };
165 };
166 
167 
168 
169 struct BrightnessOption {
170     double rate { 1.0f };
171     double lightUpDegree { 0.0f };
172     double cubicCoeff { 0.0f };
173     double quadCoeff { 0.0f };
174     double saturation { 1.0f };
175     std::vector<float> posRGB = { 0.0f, 0.0f, 0.0f };
176     std::vector<float> negRGB = { 0.0f, 0.0f, 0.0f };
177     double fraction { 1.0f };
178     bool operator==(const BrightnessOption& other) const
179     {
180         return NearEqual(rate, other.rate) && NearEqual(lightUpDegree, other.lightUpDegree) &&
181                NearEqual(cubicCoeff, other.cubicCoeff) && NearEqual(quadCoeff, other.quadCoeff) &&
182                NearEqual(saturation, other.saturation) && posRGB == other.posRGB && negRGB == other.negRGB &&
183                NearEqual(fraction, other.fraction);
184     }
ToJsonValueBrightnessOption185     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
186     {
187         /* no fixed attr below, just return */
188         if (filter.IsFastFilter()) {
189             return;
190         }
191         auto jsonBrightnessOption = JsonUtil::Create(true);
192         jsonBrightnessOption->Put("rate", rate);
193         jsonBrightnessOption->Put("lightUpDegree", lightUpDegree);
194         jsonBrightnessOption->Put("cubicCoeff", cubicCoeff);
195         jsonBrightnessOption->Put("quadCoeff", quadCoeff);
196         auto posRGBstr = "[0.0,0.0,0.0]";
197         if (posRGB.size() > 1) {
198             posRGBstr =
199                 ("[" + std::to_string(posRGB[0]) + "," + std::to_string(posRGB[1]) + "," +
200                 std::to_string(posRGB[2]) + "]").c_str();
201         }
202         jsonBrightnessOption->Put("posRGB", posRGBstr);
203         auto negRGBstr = "[0.0,0.0,0.0]";
204         if (negRGB.size() > 1) {
205             negRGBstr =
206                 ("[" + std::to_string(negRGB[0]) + "," + std::to_string(negRGB[1]) + "," +
207                 std::to_string(negRGB[2]) + "]").c_str();
208         }
209         jsonBrightnessOption->Put("negRGB", negRGBstr);
210         jsonBrightnessOption->Put("fraction", fraction);
211         json->PutExtAttr("brightnessEffect", jsonBrightnessOption, filter);
212     }
213 };
214 
215 struct PixStretchEffectOption {
216     Dimension left;
217     Dimension top;
218     Dimension right;
219     Dimension bottom;
220     bool operator==(const PixStretchEffectOption& other) const
221     {
222         return left == other.left && top == other.top && right == other.right && bottom == other.bottom;
223     }
224 
IsPercentOptionPixStretchEffectOption225     bool IsPercentOption() const
226     {
227         return (left.Unit() == DimensionUnit::PERCENT && top.Unit() == DimensionUnit::PERCENT &&
228                 right.Unit() == DimensionUnit::PERCENT && bottom.Unit() == DimensionUnit::PERCENT);
229     }
230 
ResetValuePixStretchEffectOption231     void ResetValue()
232     {
233         left = Dimension(0.0f);
234         top = Dimension(0.0f);
235         right = Dimension(0.0f);
236         bottom = Dimension(0.0f);
237     }
238 
ToStringPixStretchEffectOption239     std::string ToString() const
240     {
241         return std::string("PixStretchEffectOption (")
242             .append(left.ToString())
243             .append(",")
244             .append(top.ToString())
245             .append(",")
246             .append(right.ToString())
247             .append(",")
248             .append(bottom.ToString())
249             .append(")");
250     }
251 };
252 
253 struct LinearGradientInfo {
254     double x1 = 0.0;
255     double x2 = 0.0;
256     double y1 = 0.0;
257     double y2 = 0.0;
258 };
259 
260 struct RadialGradientInfo {
261     double r = 0.0;
262     double cx = 0.0;
263     double cy = 0.0;
264     double fx = 0.0;
265     double fy = 0.0;
266 };
267 
268 class GradientColor final {
269 public:
270     GradientColor() = default;
271     ~GradientColor() = default;
272 
GradientColor(const Color & color)273     explicit GradientColor(const Color& color)
274     {
275         color_ = color;
276     }
277 
278     void SetDimension(double value, DimensionUnit unit = DimensionUnit::PERCENT)
279     {
280         if (value < 0.0) {
281             return;
282         }
283         if (unit == DimensionUnit::PERCENT && value > BOX_END_SIZE) {
284             return;
285         }
286         dimension_ = Dimension(value, unit);
287     }
288 
SetDimension(const Dimension & dimension)289     void SetDimension(const Dimension& dimension)
290     {
291         if (dimension.Value() < 0.0) {
292             return;
293         }
294         if (dimension.Unit() == DimensionUnit::PERCENT && dimension.Value() > BOX_END_SIZE) {
295             return;
296         }
297         dimension_ = dimension;
298     }
299 
SetHasValue(bool hasValue)300     void SetHasValue(bool hasValue)
301     {
302         hasValue_ = hasValue;
303     }
304 
SetColor(const Color & color)305     void SetColor(const Color& color)
306     {
307         color_ = color;
308     }
309 
GetColor()310     const Color& GetColor() const
311     {
312         return color_;
313     }
314 
GetDimension()315     const Dimension& GetDimension() const
316     {
317         return dimension_;
318     }
319 
GetHasValue()320     bool GetHasValue() const
321     {
322         return hasValue_;
323     }
324 
SetOpacity(double opacity)325     void SetOpacity(double opacity)
326     {
327         opacity_ = opacity;
328     }
329 
GetOpacity()330     double GetOpacity() const
331     {
332         return opacity_;
333     }
334 
335 private:
336     bool hasValue_ = true;
337     Color color_ { Color::TRANSPARENT };
338     Dimension dimension_ { BOX_END_SIZE, DimensionUnit::PERCENT };
339     double opacity_ = 1.0;
340 };
341 
342 struct ACE_EXPORT RadialGradient {
343     // size type
344     std::optional<RadialSizeType> radialSizeType;
345     // shape circle or ellipse
346     std::optional<RadialShapeType> radialShape;
347     // size in x-axis
348     std::optional<AnimatableDimension> radialHorizontalSize;
349     // size in y-axis
350     std::optional<AnimatableDimension> radialVerticalSize;
351     // center of shape
352     std::optional<AnimatableDimension> radialCenterX;
353     std::optional<AnimatableDimension> radialCenterY;
354 
355     std::optional<Dimension> fRadialCenterX;
356     std::optional<Dimension> fRadialCenterY;
357 };
358 
359 struct ACE_EXPORT LinearGradient {
360     // direction in x-axis
361     std::optional<GradientDirection> linearX;
362     // direction in y-axis
363     std::optional<GradientDirection> linearY;
364     // angle of gradient line in bearing angle
365     std::optional<AnimatableDimension> angle;
366 
367     std::optional<Dimension> x1;
368     std::optional<Dimension> y1;
369     std::optional<Dimension> x2;
370     std::optional<Dimension> y2;
371 
372     // is direction in x-axis
IsXAxisLinearGradient373     static bool IsXAxis(GradientDirection direction)
374     {
375         return (direction == GradientDirection::LEFT || direction == GradientDirection::RIGHT ||
376                 direction == GradientDirection::START_TO_END || direction == GradientDirection::END_TO_START);
377     }
378 };
379 
380 struct ACE_EXPORT SweepGradient {
381     // center of x-axis
382     std::optional<AnimatableDimension> centerX;
383     // center of y-axis
384     std::optional<AnimatableDimension> centerY;
385     // startAngle in degree
386     std::optional<AnimatableDimension> startAngle;
387     // endAngle in degree
388     std::optional<AnimatableDimension> endAngle;
389     // rotation in degree
390     std::optional<AnimatableDimension> rotation;
391 };
392 
393 struct ACE_EXPORT ConicGradient {
394     // center of x-axis
395     std::optional<AnimatableDimension> centerX;
396     // center of y-axis
397     std::optional<AnimatableDimension> centerY;
398     // startAngle in radian
399     std::optional<AnimatableDimension> startAngle;
400 };
401 
402 class ACE_FORCE_EXPORT Gradient final {
403 public:
404     void AddColor(const GradientColor& color);
405 
406     void ClearColors();
407 
IsSweepGradientValid()408     bool IsSweepGradientValid() const
409     {
410         if (sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) {
411             return LessOrEqual(sweepGradient_.startAngle.value().Value(), sweepGradient_.endAngle.value().Value());
412         }
413         if (sweepGradient_.startAngle.has_value() && !sweepGradient_.endAngle.has_value()) {
414             return LessOrEqual(sweepGradient_.startAngle.value().Value(), 0.0);
415         }
416         if (!sweepGradient_.startAngle.has_value() && sweepGradient_.endAngle.has_value()) {
417             return LessOrEqual(0.0, sweepGradient_.endAngle.value().Value());
418         }
419         return true;
420     }
421 
IsValid()422     bool IsValid() const
423     {
424         if (GetType() == GradientType::SWEEP) {
425             return IsSweepGradientValid() && colors_.size() > 1;
426         }
427         return colors_.size() > 1;
428     }
429 
SetRepeat(bool repeat)430     void SetRepeat(bool repeat)
431     {
432         repeat_ = repeat;
433     }
434 
GetRepeat()435     bool GetRepeat() const
436     {
437         return repeat_;
438     }
439 
GetColors()440     const std::vector<GradientColor>& GetColors() const
441     {
442         return colors_;
443     }
444 
GetBeginOffset()445     const Offset& GetBeginOffset() const
446     {
447         return beginOffset_;
448     }
449 
SetBeginOffset(const Offset & beginOffset)450     void SetBeginOffset(const Offset& beginOffset)
451     {
452         beginOffset_ = beginOffset;
453     }
454 
GetEndOffset()455     const Offset& GetEndOffset() const
456     {
457         return endOffset_;
458     }
459 
SetEndOffset(const Offset & endOffset)460     void SetEndOffset(const Offset& endOffset)
461     {
462         endOffset_ = endOffset;
463     }
464 
GetInnerRadius()465     double GetInnerRadius() const
466     {
467         return innerRadius_;
468     }
469 
SetInnerRadius(double innerRadius)470     void SetInnerRadius(double innerRadius)
471     {
472         innerRadius_ = innerRadius;
473     }
474 
GetOuterRadius()475     double GetOuterRadius() const
476     {
477         return outerRadius_;
478     }
479 
SetOuterRadius(double outerRadius)480     void SetOuterRadius(double outerRadius)
481     {
482         outerRadius_ = outerRadius;
483     }
484 
GetType()485     GradientType GetType() const
486     {
487         return type_;
488     }
489 
SetType(GradientType type)490     void SetType(GradientType type)
491     {
492         type_ = type;
493     }
494 
ToString()495     std::string ToString() const
496     {
497         return std::string("Gradient (")
498             .append(beginOffset_.ToString())
499             .append(",")
500             .append(std::to_string(innerRadius_))
501             .append(" --- ")
502             .append(endOffset_.ToString())
503             .append(",")
504             .append(std::to_string(outerRadius_))
505             .append(")");
506     }
507 
GetSweepGradient()508     SweepGradient& GetSweepGradient()
509     {
510         return sweepGradient_;
511     }
512 
GetSweepGradient()513     const SweepGradient& GetSweepGradient() const
514     {
515         return sweepGradient_;
516     }
517 
SetSweepGradient(const SweepGradient & sweepGradient)518     void SetSweepGradient(const SweepGradient& sweepGradient)
519     {
520         sweepGradient_ = sweepGradient;
521     }
522 
GetConicGradient()523     ConicGradient& GetConicGradient()
524     {
525         return conicGradient_;
526     }
527 
GetConicGradient()528     const ConicGradient& GetConicGradient() const
529     {
530         return conicGradient_;
531     }
532 
SetConicGradient(const ConicGradient & conicGradient)533     void SetConicGradient(const ConicGradient& conicGradient)
534     {
535         conicGradient_ = conicGradient;
536     }
537 
GetRadialGradient()538     RadialGradient& GetRadialGradient()
539     {
540         return radialGradient_;
541     }
542 
GetRadialGradient()543     const RadialGradient& GetRadialGradient() const
544     {
545         return radialGradient_;
546     }
547 
SetRadialGradient(const RadialGradient & radialGradient)548     void SetRadialGradient(const RadialGradient& radialGradient)
549     {
550         radialGradient_ = radialGradient;
551     }
552 
GetLinearGradient()553     LinearGradient& GetLinearGradient()
554     {
555         return linearGradient_;
556     }
557 
GetLinearGradient()558     const LinearGradient& GetLinearGradient() const
559     {
560         return linearGradient_;
561     }
562 
SetLinearGradient(const LinearGradient & linearGradient)563     void SetLinearGradient(const LinearGradient& linearGradient)
564     {
565         linearGradient_ = linearGradient;
566     }
567 
SetDirection(const GradientDirection & direction)568     void SetDirection(const GradientDirection& direction)
569     {
570         if (LinearGradient::IsXAxis(direction)) {
571             linearGradient_.linearX = direction;
572         } else {
573             linearGradient_.linearY = direction;
574         }
575     }
576 
SetSpreadMethod(SpreadMethod spreadMethod)577     void SetSpreadMethod(SpreadMethod spreadMethod)
578     {
579         spreadMethod_ = spreadMethod;
580     }
581 
SetGradientTransform(const std::string & gradientTransform)582     void SetGradientTransform(const std::string& gradientTransform)
583     {
584         gradientTransform_ = gradientTransform;
585     }
586 
GetSpreadMethod()587     SpreadMethod GetSpreadMethod() const
588     {
589         return spreadMethod_;
590     }
591 
GetGradientTransform()592     const std::string& GetGradientTransform() const
593     {
594         return gradientTransform_;
595     }
596 
GetRadialGradientInfo()597     const RadialGradientInfo& GetRadialGradientInfo() const
598     {
599         return radialGradientInfo_;
600     }
601 
SetRadialGradientInfo(const RadialGradientInfo & radialGradientInfo)602     void SetRadialGradientInfo(const RadialGradientInfo& radialGradientInfo)
603     {
604         radialGradientInfo_ = radialGradientInfo;
605     }
606 
GetLinearGradientInfo()607     const LinearGradientInfo& GetLinearGradientInfo() const
608     {
609         return linearGradientInfo_;
610     }
611 
SetLinearGradientInfo(const LinearGradientInfo & linearGradientInfo)612     void SetLinearGradientInfo(const LinearGradientInfo& linearGradientInfo)
613     {
614         linearGradientInfo_ = linearGradientInfo;
615     }
616 
617 private:
618     GradientType type_ = GradientType::LINEAR;
619     bool repeat_ = false;
620     std::vector<GradientColor> colors_;
621     // for RadialGradient
622     RadialGradient radialGradient_;
623     // for LinearGradient
624     LinearGradient linearGradient_;
625     // for SweepGradient
626     SweepGradient sweepGradient_;
627     // for ConicGradient
628     ConicGradient conicGradient_;
629     // used for CanvasLinearGradient
630     Offset beginOffset_;
631     Offset endOffset_;
632     // used for CanvasRadialGradient
633     double innerRadius_ = 0.0;
634     double outerRadius_ = 0.0;
635     SpreadMethod spreadMethod_ = SpreadMethod::PAD;
636     std::string gradientTransform_;
637     LinearGradientInfo linearGradientInfo_;
638     RadialGradientInfo radialGradientInfo_;
639 };
640 
641 enum class ACE_EXPORT BackgroundImageSizeType {
642     CONTAIN = 0,
643     COVER,
644     AUTO,
645     FILL,
646     LENGTH,
647     PERCENT,
648 };
649 
650 enum class ACE_EXPORT ClickEffectLevel {
651     UNDEFINED = -1,
652     LIGHT = 0,
653     MIDDLE,
654     HEAVY,
655 };
656 
657 struct ClickEffectInfo {
658     ClickEffectLevel level = ClickEffectLevel::LIGHT;
659     float scaleNumber = 0.0f;
660     bool operator==(const ClickEffectInfo& other) const
661     {
662         return level == other.level && NearEqual(scaleNumber, other.scaleNumber);
663     }
664 };
665 
666 class ACE_FORCE_EXPORT BackgroundImageSize final {
667 public:
668     BackgroundImageSize() = default;
BackgroundImageSize(BackgroundImageSizeType type,double value)669     BackgroundImageSize(BackgroundImageSizeType type, double value) : typeX_(type), valueX_(value) {}
BackgroundImageSize(BackgroundImageSizeType typeX,double valueX,BackgroundImageSizeType typeY,double valueY)670     BackgroundImageSize(BackgroundImageSizeType typeX, double valueX, BackgroundImageSizeType typeY, double valueY)
671         : typeX_(typeX), valueX_(valueX), typeY_(typeY), valueY_(valueY)
672     {}
673     ~BackgroundImageSize() = default;
674 
675     void SetSizeTypeX(BackgroundImageSizeType type);
676     void SetSizeTypeY(BackgroundImageSizeType type);
677     void SetSizeValueX(double value);
678     void SetSizeValueY(double value);
679     bool IsValid() const;
680     BackgroundImageSizeType GetSizeTypeX() const;
681     BackgroundImageSizeType GetSizeTypeY() const;
682     double GetSizeValueX() const;
683     double GetSizeValueY() const;
684 
685     BackgroundImageSize operator+(const BackgroundImageSize& size) const;
686     BackgroundImageSize operator-(const BackgroundImageSize& size) const;
687     BackgroundImageSize operator*(double value) const;
688 
689     bool operator==(const BackgroundImageSize& size) const;
690     bool operator!=(const BackgroundImageSize& size) const;
691 
692     std::string ToString() const;
693 
694 private:
695     BackgroundImageSizeType typeX_ { BackgroundImageSizeType::AUTO };
696     double valueX_ = 0.0;
697     BackgroundImageSizeType typeY_ { BackgroundImageSizeType::AUTO };
698     double valueY_ = 0.0;
699 };
700 
701 enum class ACE_EXPORT BackgroundImagePositionType {
702     PERCENT = 0,
703     PX,
704 };
705 
706 class ACE_EXPORT BackgroundImagePosition {
707 public:
708     BackgroundImagePosition() = default;
709     ~BackgroundImagePosition() = default;
BackgroundImagePosition(BackgroundImagePositionType typeX,double valueX,BackgroundImagePositionType typeY,double valueY)710     BackgroundImagePosition(
711         BackgroundImagePositionType typeX, double valueX, BackgroundImagePositionType typeY, double valueY)
712         : typeX_(typeX), typeY_(typeY), valueX_(AnimatableDimension(valueX)), valueY_(AnimatableDimension(valueY))
713     {}
714 
SetContextAndCallback(const WeakPtr<PipelineContext> & context,const RenderNodeAnimationCallback & callback)715     void SetContextAndCallback(const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback)
716     {
717         valueX_.SetContextAndCallback(context, callback);
718         valueY_.SetContextAndCallback(context, callback);
719     }
720 
SetSizeTypeX(BackgroundImagePositionType type)721     void SetSizeTypeX(BackgroundImagePositionType type)
722     {
723         typeX_ = type;
724     }
725 
SetSizeX(const AnimatableDimension & sizeX)726     void SetSizeX(const AnimatableDimension& sizeX)
727     {
728         if (sizeX.Unit() == DimensionUnit::PERCENT) {
729             typeX_ = BackgroundImagePositionType::PERCENT;
730         } else {
731             typeX_ = BackgroundImagePositionType::PX;
732         }
733         valueX_ = sizeX;
734     }
735 
SetSizeTypeY(BackgroundImagePositionType type)736     void SetSizeTypeY(BackgroundImagePositionType type)
737     {
738         typeY_ = type;
739     }
740 
SetSizeY(const AnimatableDimension & sizeY)741     void SetSizeY(const AnimatableDimension& sizeY)
742     {
743         if (sizeY.Unit() == DimensionUnit::PERCENT) {
744             typeY_ = BackgroundImagePositionType::PERCENT;
745         } else {
746             typeY_ = BackgroundImagePositionType::PX;
747         }
748         valueY_ = sizeY;
749     }
750 
SetSizeValueX(double value)751     void SetSizeValueX(double value)
752     {
753         valueX_ = AnimatableDimension(value);
754     }
755 
SetSizeValueY(double value)756     void SetSizeValueY(double value)
757     {
758         valueY_ = AnimatableDimension(value);
759     }
760 
SetIsAlign(bool isAlign)761     void SetIsAlign(bool isAlign)
762     {
763         isAlign_ = isAlign;
764     }
765 
GetSizeTypeX()766     BackgroundImagePositionType GetSizeTypeX() const
767     {
768         return typeX_;
769     }
770 
GetSizeTypeY()771     BackgroundImagePositionType GetSizeTypeY() const
772     {
773         return typeY_;
774     }
775 
GetSizeX()776     const AnimatableDimension& GetSizeX() const
777     {
778         return valueX_;
779     }
780 
GetSizeY()781     const AnimatableDimension& GetSizeY() const
782     {
783         return valueY_;
784     }
785 
GetSizeValueX()786     double GetSizeValueX() const
787     {
788         return valueX_.Value();
789     }
790 
GetSizeValueY()791     double GetSizeValueY() const
792     {
793         return valueY_.Value();
794     }
795 
IsAlign()796     bool IsAlign() const
797     {
798         return isAlign_;
799     }
800 
801     BackgroundImagePosition operator+(const BackgroundImagePosition& position) const;
802 
803     BackgroundImagePosition operator-(const BackgroundImagePosition& position) const;
804 
805     BackgroundImagePosition operator*(double value) const;
806 
807     bool operator==(const BackgroundImagePosition& backgroundImagePosition) const;
808 
809     bool operator!=(const BackgroundImagePosition& backgroundImagePosition) const;
810 
811     std::string ToString() const;
812 
813 private:
814     BackgroundImagePositionType typeX_ { BackgroundImagePositionType::PX };
815     BackgroundImagePositionType typeY_ { BackgroundImagePositionType::PX };
816     AnimatableDimension valueX_ = AnimatableDimension(-1.0);
817     AnimatableDimension valueY_ = AnimatableDimension(0.0);
818     bool isAlign_ = false;
819 };
820 
821 class ImageObjectPosition final : public BackgroundImagePosition {};
822 
823 class BackgroundImage final : public AceType {
824     DECLARE_ACE_TYPE(BackgroundImage, AceType);
825 
826 public:
827     BackgroundImage() = default;
828     ~BackgroundImage() override = default;
829 
GetImageSize()830     const BackgroundImageSize& GetImageSize() const
831     {
832         return imageSize_;
833     }
834 
GetImagePosition()835     const BackgroundImagePosition& GetImagePosition() const
836     {
837         return imagePosition_;
838     }
839 
GetImageRepeat()840     ImageRepeat GetImageRepeat() const
841     {
842         return imageRepeat_;
843     }
844 
GetSrc()845     const std::string& GetSrc() const
846     {
847         return src_;
848     }
849 
SetImageSize(BackgroundImageSize imageSize)850     void SetImageSize(BackgroundImageSize imageSize)
851     {
852         imageSize_ = imageSize;
853     }
854 
855     void SetImageSize(BackgroundImageSizeType type, double value = FULL_IMG_SIZE)
856     {
857         imageSize_ = BackgroundImageSize(type, value);
858     }
859 
SetImageSize(BackgroundImageSizeType typeX,double valueX,BackgroundImageSizeType typeY,double valueY)860     void SetImageSize(BackgroundImageSizeType typeX, double valueX, BackgroundImageSizeType typeY, double valueY)
861     {
862         imageSize_ = BackgroundImageSize(typeX, valueX, typeY, valueY);
863     }
864 
SetImagePosition(const BackgroundImagePosition & imagePosition)865     void SetImagePosition(const BackgroundImagePosition& imagePosition)
866     {
867         imagePosition_ = imagePosition;
868     }
869 
SetImagePosition(BackgroundImagePositionType typeX,double valueX,BackgroundImagePositionType typeY,double valueY)870     void SetImagePosition(
871         BackgroundImagePositionType typeX, double valueX, BackgroundImagePositionType typeY, double valueY)
872     {
873         imagePosition_ = BackgroundImagePosition(typeX, valueX, typeY, valueY);
874     }
875 
SetImageRepeat(const ImageRepeat & imageRepeat)876     void SetImageRepeat(const ImageRepeat& imageRepeat)
877     {
878         imageRepeat_ = imageRepeat;
879     }
880 
SetSrc(const std::string & src,const RefPtr<ThemeConstants> & themeConstants)881     void SetSrc(const std::string& src, const RefPtr<ThemeConstants>& themeConstants)
882     {
883         // If match the regex, src with the outer "url()" removed is returned.
884         // Otherwise return a copy of src directly.
885         auto imgSrc = std::regex_replace(src, std::regex(R"(^url\(\s*['"]?\s*([^()]+?)\s*['"]?\s*\)$)"), "$1");
886         src_ = ThemeUtils::ProcessImageSource(imgSrc, themeConstants);
887     }
888 
889     void SetParsedSrc(const std::string& src)
890     {
891         // src is processed by ParseJsMedia function
892         src_ = src;
893     }
894 
895     bool operator==(const BackgroundImage& image) const
896     {
897         bool fileName = src_ == image.GetSrc();
898         bool size = imageSize_ == image.GetImageSize();
899         bool position = imagePosition_ == image.GetImagePosition();
900         bool repeat = imageRepeat_ == image.GetImageRepeat();
901         return fileName && size && position && repeat;
902     }
903 
904     bool operator!=(const BackgroundImage& image) const
905     {
906         return !operator==(image);
907     }
908 
909 private:
910     std::string src_;
911     BackgroundImageSize imageSize_;
912     BackgroundImagePosition imagePosition_;
913     ImageRepeat imageRepeat_ { ImageRepeat::REPEAT };
914 };
915 
916 class ArcBackground final : public AceType {
917     DECLARE_ACE_TYPE(ArcBackground, AceType);
918 
919 public:
920     ~ArcBackground() override = default;
921     ArcBackground(Point center, double radius)
922     {
923         SetCenter(center);
924         SetRadius(radius);
925     }
926 
927     const Point& GetCenter() const
928     {
929         return center_;
930     }
931 
932     double GetRadius() const
933     {
934         return radius_;
935     }
936 
937     void SetCenter(const Point& center)
938     {
939         center_ = center;
940     }
941 
942     void SetRadius(double radius)
943     {
944         radius_ = radius;
945     }
946 
947     void SetColor(const Color& color)
948     {
949         color_ = color;
950     }
951 
952     const Color& GetColor() const
953     {
954         return color_;
955     }
956 
957 private:
958     Point center_;
959     double radius_ = 0.0;
960     Color color_;
961 };
962 
963 class Decoration final : public AceType {
964     DECLARE_ACE_TYPE(Decoration, AceType);
965 
966 public:
967     Decoration() = default;
968     ~Decoration() override = default;
969 
970     void SetContextAndCallback(const WeakPtr<PipelineContext>& context, const RenderNodeAnimationCallback& callback);
971 
972     void AddShadow(const Shadow& shadow);
973 
974     void ClearAllShadow();
975 
976     void SetBackgroundColor(const Color& backgroundColor, const AnimationOption& option = AnimationOption())
977     {
978         backgroundColor_ = AnimatableColor(backgroundColor, option);
979     }
980 
981     void SetBackgroundColor(const AnimatableColor& backgroundColor)
982     {
983         backgroundColor_ = backgroundColor;
984     }
985 
986     void SetAnimationColor(const Color& animationColor)
987     {
988         animationColor_ = animationColor;
989     }
990 
991     void SetGradient(const Gradient& gradient, const WeakPtr<PipelineContext>& context = nullptr,
992         const RenderNodeAnimationCallback& callback = nullptr)
993     {
994         gradient_ = gradient;
995         if (callback) {
996             switch (gradient_.GetType()) {
997                 case GradientType::LINEAR:
998                     if (gradient_.GetLinearGradient().angle) {
999                         gradient_.GetLinearGradient().angle->SetContextAndCallbackAfterFirstAssign(context, callback);
1000                     }
1001                     break;
1002                 case GradientType::SWEEP:
1003                     if (gradient_.GetSweepGradient().centerX) {
1004                         gradient_.GetSweepGradient().centerX->SetContextAndCallbackAfterFirstAssign(context, callback);
1005                     }
1006                     if (gradient_.GetSweepGradient().centerY) {
1007                         gradient_.GetSweepGradient().centerY->SetContextAndCallbackAfterFirstAssign(context, callback);
1008                     }
1009                     if (gradient_.GetSweepGradient().startAngle) {
1010                         gradient_.GetSweepGradient().startAngle->SetContextAndCallbackAfterFirstAssign(
1011                             context, callback);
1012                     }
1013                     if (gradient_.GetSweepGradient().endAngle) {
1014                         gradient_.GetSweepGradient().endAngle->SetContextAndCallbackAfterFirstAssign(context, callback);
1015                     }
1016                     if (gradient_.GetSweepGradient().rotation) {
1017                         gradient_.GetSweepGradient().rotation->SetContextAndCallbackAfterFirstAssign(context, callback);
1018                     }
1019                     break;
1020                 case GradientType::RADIAL:
1021                     if (gradient_.GetRadialGradient().radialHorizontalSize) {
1022                         gradient_.GetRadialGradient().radialHorizontalSize->SetContextAndCallbackAfterFirstAssign(
1023                             context, callback);
1024                     }
1025                     if (gradient_.GetRadialGradient().radialVerticalSize) {
1026                         gradient_.GetRadialGradient().radialVerticalSize->SetContextAndCallbackAfterFirstAssign(
1027                             context, callback);
1028                     }
1029                     if (gradient_.GetRadialGradient().radialCenterX) {
1030                         gradient_.GetRadialGradient().radialCenterX->SetContextAndCallbackAfterFirstAssign(
1031                             context, callback);
1032                     }
1033                     if (gradient_.GetRadialGradient().radialCenterY) {
1034                         gradient_.GetRadialGradient().radialCenterY->SetContextAndCallbackAfterFirstAssign(
1035                             context, callback);
1036                     }
1037                     break;
1038                 default:
1039                     break;
1040             }
1041         }
1042     }
1043 
1044     void SetBorderImageGradient(const Gradient& gradient)
1045     {
1046         gradientBorderImage_ = gradient;
1047     }
1048     void SetImage(const RefPtr<BackgroundImage>& image)
1049     {
1050         image_ = image;
1051     }
1052 
1053     void SetBorderImage(const RefPtr<BorderImage>& borderImage)
1054     {
1055         borderImage_ = borderImage;
1056     }
1057 
1058     void SetHasBorderImageSource(const bool tag)
1059     {
1060         hasBorderImageSource_ = tag;
1061     }
1062 
1063     void SetHasBorderImageSlice(const bool tag)
1064     {
1065         hasBorderImageSlice_ = tag;
1066     }
1067 
1068     void SetHasBorderImageWidth(const bool tag)
1069     {
1070         hasBorderImageWidth_ = tag;
1071     }
1072 
1073     void SetHasBorderImageOutset(const bool tag)
1074     {
1075         hasBorderImageOutset_ = tag;
1076     }
1077 
1078     void SetHasBorderImageRepeat(const bool tag)
1079     {
1080         hasBorderImageRepeat_ = tag;
1081     }
1082 
1083     void SetHasBorderImageGradient(const bool tag)
1084     {
1085         hasBorderImageGradient_ = tag;
1086     }
1087 
1088     void SetPadding(const Edge& padding)
1089     {
1090         padding_ = padding;
1091     }
1092 
1093     void SetBorderRadius(const Radius& radius)
1094     {
1095         border_.SetBorderRadius(radius);
1096     }
1097 
1098     void SetBorder(const Border& border)
1099     {
1100         border_ = border;
1101     }
1102 
1103     void SetArcBackground(const RefPtr<ArcBackground>& arcBG)
1104     {
1105         arcBG_ = arcBG;
1106     }
1107 
1108     void SetBlurRadius(const Dimension& radius)
1109     {
1110         blurRadius_ = radius;
1111     }
1112 
1113     void SetBlurRadius(const AnimatableDimension& radius)
1114     {
1115         blurRadius_ = radius;
1116     }
1117 
1118     const Color& GetColorBlend(void) const
1119     {
1120         return colorBlend;
1121     }
1122 
1123     void SetColorBlend(const Color& color)
1124     {
1125         colorBlend = color;
1126     }
1127 
1128     void SetWindowBlurProgress(float progress)
1129     {
1130         windowBlurProgress_ = progress;
1131     }
1132 
1133     void SetWindowBlurStyle(WindowBlurStyle style)
1134     {
1135         windowBlurStyle_ = style;
1136     }
1137 
1138     void SetBlurStyle(const BlurStyleOption& style)
1139     {
1140         blurStyle_ = style;
1141     }
1142 
1143     const Border& GetBorder() const
1144     {
1145         return border_;
1146     }
1147 
1148     const Edge& GetPadding() const
1149     {
1150         return padding_;
1151     }
1152 
1153     const RefPtr<BackgroundImage>& GetImage() const
1154     {
1155         return image_;
1156     }
1157 
1158     const RefPtr<BorderImage>& GetBorderImage() const
1159     {
1160         return borderImage_;
1161     }
1162 
1163     const Gradient& GetGradient() const
1164     {
1165         return gradient_;
1166     }
1167 
1168     const Gradient& GetBorderImageGradient() const
1169     {
1170         return gradientBorderImage_;
1171     }
1172 
1173     bool GetHasBorderImageSource()
1174     {
1175         return hasBorderImageSource_;
1176     }
1177 
1178     bool GetHasBorderImageSlice()
1179     {
1180         return hasBorderImageSlice_;
1181     }
1182 
1183     bool GetHasBorderImageWidth()
1184     {
1185         return hasBorderImageWidth_;
1186     }
1187 
1188     bool GetHasBorderImageOutset()
1189     {
1190         return hasBorderImageOutset_;
1191     }
1192 
1193     bool GetHasBorderImageRepeat()
1194     {
1195         return hasBorderImageRepeat_;
1196     }
1197 
1198     bool GetHasBorderImageGradient()
1199     {
1200         return hasBorderImageGradient_;
1201     }
1202 
1203     const AnimatableColor& GetBackgroundColor() const
1204     {
1205         return backgroundColor_;
1206     }
1207 
1208     const Color& GetAnimationColor() const
1209     {
1210         return animationColor_;
1211     }
1212 
1213     const std::vector<Shadow>& GetShadows() const
1214     {
1215         return shadows_;
1216     }
1217 
1218     void SetShadows(const std::vector<Shadow>& shadows)
1219     {
1220         shadows_.assign(shadows.begin(), shadows.end());
1221     }
1222 
1223     BlendMode GetBlendMode() const
1224     {
1225         return blendMode_;
1226     }
1227 
1228     void SetBlendMode(BlendMode blendMode)
1229     {
1230         blendMode_ = blendMode;
1231     }
1232 
1233     BlendApplyType GetBlendApplyType() const
1234     {
1235         return blendApplyType_;
1236     }
1237 
1238     void SetBlendApplyType(BlendApplyType blendApplyType)
1239     {
1240         blendApplyType_ = blendApplyType;
1241     }
1242 
1243     const Dimension& GetGrayScale(void) const
1244     {
1245         return grayScale_;
1246     }
1247 
1248     void SetGrayScale(const Dimension& grayScale)
1249     {
1250         grayScale_ = grayScale;
1251     }
1252 
1253     void SetBrightness(const Dimension& brightness)
1254     {
1255         brightness_ = brightness;
1256     }
1257 
1258     const Dimension& GetBrightness() const
1259     {
1260         return brightness_;
1261     }
1262 
1263     const Dimension& GetContrast(void) const
1264     {
1265         return contrast_;
1266     }
1267 
1268     void SetContrast(const Dimension& contrast)
1269     {
1270         contrast_ = contrast;
1271     }
1272 
1273     const Dimension& GetSaturate(void) const
1274     {
1275         return saturate_;
1276     }
1277 
1278     void SetSaturate(const Dimension& saturate)
1279     {
1280         saturate_ = saturate;
1281     }
1282 
1283     const Dimension& GetSepia(void) const
1284     {
1285         return sepia_;
1286     }
1287 
1288     void SetSepia(const Dimension& sepia)
1289     {
1290         sepia_ = sepia;
1291     }
1292 
1293     void SetInvert(const Dimension& invert)
1294     {
1295         invert_ = invert;
1296     }
1297 
1298     const Dimension& GetInvert(void) const
1299     {
1300         return invert_;
1301     }
1302 
1303     float GetHueRotate(void) const
1304     {
1305         return hueRotate_;
1306     }
1307 
1308     void SetHueRotate(const float& hueRotate)
1309     {
1310         hueRotate_ = hueRotate;
1311     }
1312 
1313     const RefPtr<ArcBackground>& GetArcBackground() const
1314     {
1315         return arcBG_;
1316     }
1317 
1318     bool NeedReloadImage(const RefPtr<Decoration>& lastDecoration) const
1319     {
1320         if (!image_) {
1321             return false;
1322         }
1323 
1324         if (!lastDecoration || !(lastDecoration->GetImage())) {
1325             return true;
1326         }
1327 
1328         return (*image_) != (*(lastDecoration->GetImage()));
1329     }
1330 
1331     const AnimatableDimension& GetBlurRadius() const
1332     {
1333         return blurRadius_;
1334     }
1335 
1336     float GetWindowBlurProgress() const
1337     {
1338         return windowBlurProgress_;
1339     }
1340 
1341     WindowBlurStyle GetWindowBlurStyle() const
1342     {
1343         return windowBlurStyle_;
1344     }
1345 
1346     const BlurStyleOption& GetBlurStyle() const
1347     {
1348         return blurStyle_;
1349     }
1350 
1351     // Indicate how much size the decoration taken, excluding the content size.
1352     Size GetOccupiedSize(double dipScale) const;
1353     double HorizontalSpaceOccupied(double dipScale) const;
1354     double VerticalSpaceOccupied(double dipScale) const;
1355 
1356     Offset GetOffset(double dipScale) const;
1357 
1358 private:
1359     bool hasBorderImageSource_ = false;
1360     bool hasBorderImageSlice_ = false;
1361     bool hasBorderImageWidth_ = false;
1362     bool hasBorderImageOutset_ = false;
1363     bool hasBorderImageRepeat_ = false;
1364     bool hasBorderImageGradient_ = false;
1365 
1366     // padding is zero
1367     Edge padding_;
1368     // border contains black color and 1.0f thickness as default
1369     Border border_;
1370     // shadow vector is empty
1371     std::vector<Shadow> shadows_;
1372     // blendMode
1373     BlendMode blendMode_ = BlendMode::NONE;
1374     BlendApplyType blendApplyType_ = BlendApplyType::FAST;
1375     Dimension grayScale_;
1376     // Brightness (1.0 as default), range = (0, 2)
1377     Dimension brightness_ = 1.0_px;
1378     // hueRotate
1379     float hueRotate_ = 0.0f;
1380     // Contrast (1.0 as default), complete gray at 0
1381     Dimension contrast_ = 1.0_px;
1382     // Saturate
1383     Dimension saturate_ = 1.0_px;
1384     // Sepia
1385     Dimension sepia_;
1386     // invert
1387     Dimension invert_;
1388     // color is transparent
1389     AnimatableColor backgroundColor_ { Color::TRANSPARENT };
1390     Color animationColor_ = Color::TRANSPARENT;
1391     // Gradient is not implemented
1392     Gradient gradient_ = Gradient();
1393     Gradient gradientBorderImage_ = Gradient();
1394     RefPtr<BackgroundImage> image_;
1395     RefPtr<BorderImage> borderImage_;
1396     RefPtr<ArcBackground> arcBG_;
1397     // Blur radius
1398     AnimatableDimension blurRadius_;
1399     // window blur progress
1400     float windowBlurProgress_ = 0.0f;
1401     // window blur style;
1402     WindowBlurStyle windowBlurStyle_ = WindowBlurStyle::STYLE_BACKGROUND_SMALL_LIGHT;
1403     Color colorBlend;
1404     // blur from rosen
1405     BlurStyleOption blurStyle_;
1406 };
1407 
1408 class Pattern final : std::enable_shared_from_this<Pattern> {
1409 public:
1410     bool IsValid() const
1411     {
1412         return (!imgSrc_.empty() || pixelMap_);
1413     }
1414 
1415     const std::string& GetImgSrc() const
1416     {
1417         return imgSrc_;
1418     }
1419 
1420     void SetImgSrc(const std::string& imgSrc)
1421     {
1422         imgSrc_ = imgSrc;
1423     }
1424 
1425     const std::string& GetRepetition() const
1426     {
1427         return repetition_;
1428     }
1429 
1430     void SetRepetition(const std::string& repetition)
1431     {
1432         repetition_ = repetition;
1433     }
1434 
1435     double GetImageWidth() const
1436     {
1437         return imageWidth_;
1438     }
1439 
1440     void SetImageWidth(double imageWidth)
1441     {
1442         imageWidth_ = imageWidth;
1443     }
1444 
1445     double GetImageHeight() const
1446     {
1447         return imageHeight_;
1448     }
1449 
1450     void SetImageHeight(double imageHeight)
1451     {
1452         imageHeight_ = imageHeight;
1453     }
1454 
1455     double GetScaleX() const
1456     {
1457         return scaleX_;
1458     }
1459 
1460     void SetScaleX(double scaleX)
1461     {
1462         transformable_ = true;
1463         scaleX_ = scaleX;
1464     }
1465 
1466     double GetScaleY() const
1467     {
1468         return scaleY_;
1469     }
1470 
1471     void SetScaleY(double scaleY)
1472     {
1473         transformable_ = true;
1474         scaleY_ = scaleY;
1475     }
1476 
1477     double GetSkewX() const
1478     {
1479         return skewX_;
1480     }
1481 
1482     void SetSkewX(double skewX)
1483     {
1484         transformable_ = true;
1485         skewX_ = skewX;
1486     }
1487 
1488     double GetSkewY() const
1489     {
1490         return skewY_;
1491     }
1492 
1493     void SetSkewY(double skewY)
1494     {
1495         transformable_ = true;
1496         skewY_ = skewY;
1497     }
1498 
1499     double GetTranslateX() const
1500     {
1501         return translateX_;
1502     }
1503 
1504     void SetTranslateX(double translateX)
1505     {
1506         transformable_ = true;
1507         translateX_ = translateX;
1508     }
1509 
1510     double GetTranslateY() const
1511     {
1512         return translateY_;
1513     }
1514 
1515     void SetTranslateY(double translateY)
1516     {
1517         transformable_ = true;
1518         translateY_ = translateY;
1519     }
1520 
1521     bool IsTransformable() const
1522     {
1523         return transformable_;
1524     }
1525 
1526     void SetPixelMap(const RefPtr<PixelMap>& pixelMap)
1527     {
1528         pixelMap_ = pixelMap;
1529     }
1530 
1531     RefPtr<PixelMap> GetPixelMap() const
1532     {
1533         return pixelMap_;
1534     }
1535 
1536 private:
1537     double imageWidth_ = 0.0;
1538     double imageHeight_ = 0.0;
1539     double scaleX_ = 0.0;
1540     double skewX_ = 0.0;
1541     double skewY_ = 0.0;
1542     double scaleY_ = 0.0;
1543     double translateX_ = 0.0;
1544     double translateY_ = 0.0;
1545     bool transformable_ = false;
1546     std::string imgSrc_;
1547     std::string repetition_;
1548     RefPtr<PixelMap> pixelMap_;
1549 };
1550 
1551 enum class PathCmd {
1552     CMDS,
1553     TRANSFORM,
1554     MOVE_TO,
1555     LINE_TO,
1556     ARC,
1557     ARC_TO,
1558     QUADRATIC_CURVE_TO,
1559     BEZIER_CURVE_TO,
1560     ELLIPSE,
1561     RECT,
1562     CLOSE_PATH,
1563 };
1564 
1565 struct PathArgs {
1566     std::string cmds;
1567     double para1 = 0.0;
1568     double para2 = 0.0;
1569     double para3 = 0.0;
1570     double para4 = 0.0;
1571     double para5 = 0.0;
1572     double para6 = 0.0;
1573     double para7 = 0.0;
1574     double para8 = 0.0;
1575 };
1576 
1577 class ACE_FORCE_EXPORT CanvasPath2D : virtual public AceType {
1578     DECLARE_ACE_TYPE(CanvasPath2D, AceType)
1579 public:
1580     CanvasPath2D() = default;
1581     ~CanvasPath2D() = default;
1582     explicit CanvasPath2D(const std::string& cmds);
1583     explicit CanvasPath2D(const RefPtr<CanvasPath2D>& path);
1584     void AddPath(const RefPtr<CanvasPath2D>& path);
1585     void SetTransform(double a, double b, double c, double d, double e, double f);
1586     void MoveTo(double x, double y);
1587     void LineTo(double x, double y);
1588     void Arc(double x, double y, double radius, double startAngle, double endAngle, double ccw);
1589     void ArcTo(double x1, double y1, double x2, double y2, double radius);
1590     void QuadraticCurveTo(double cpx, double cpy, double x, double y);
1591     void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
1592     void Ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle,
1593         double endAngle, double ccw);
1594     void Rect(double x, double y, double width, double height);
1595     void ClosePath();
1596     const std::vector<std::pair<PathCmd, PathArgs>>& GetCaches() const;
1597     std::string ToString() const;
1598 
1599 private:
1600     std::vector<std::pair<PathCmd, PathArgs>> caches_;
1601 };
1602 
1603 } // namespace OHOS::Ace
1604 
1605 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_DECORATION_H
1606