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