• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_ADVANCED_TEXT_STYLE_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_ADVANCED_TEXT_STYLE_H
17 #include "ui/base/ace_type.h"
18 
19 #include "core/components/common/properties/decoration.h"
20 #include "frameworks/base/geometry/ng/point_t.h"
21 #include "frameworks/core/components_ng/pattern/symbol/symbol_effect_options.h"
22 
23 namespace OHOS::Ace {
24 struct FontForegroudGradiantColor {
25     std::vector<NG::PointF> points;
26     std::vector<float> scalars;
27     std::vector<Color> colors;
28 
IsValidFontForegroudGradiantColor29     bool IsValid() const
30     {
31         // 2 points including begin and end
32         return points.size() == 2 && scalars.size() == colors.size();
33     }
34 
35     bool operator==(const FontForegroudGradiantColor& fontForegroudGradiantColor) const
36     {
37         auto isScalarEq = true;
38         if (scalars.size() != fontForegroudGradiantColor.scalars.size()) {
39             isScalarEq = false;
40         }
41         for (size_t i = 0; i < scalars.size() && isScalarEq; i++) {
42             isScalarEq = NearEqual(scalars[i], fontForegroudGradiantColor.scalars[i]);
43         }
44         return isScalarEq && (points == fontForegroudGradiantColor.points) &&
45                (colors == fontForegroudGradiantColor.colors);
46     }
47 };
48 
49 class AdvancedTextStyle : public AceType {
50     DECLARE_ACE_TYPE(AdvancedTextStyle, AceType);
51 
52 public:
SetGradient(const std::optional<Gradient> & gradient)53     void SetGradient(const std::optional<Gradient>& gradient)
54     {
55         gradient_ = gradient;
56     }
57 
GetGradient()58     const std::optional<Gradient>& GetGradient() const
59     {
60         return gradient_;
61     }
62 
SetFontForegroudGradiantColor(const std::optional<FontForegroudGradiantColor> & gradiantColor)63     void SetFontForegroudGradiantColor(const std::optional<FontForegroudGradiantColor>& gradiantColor)
64     {
65         fontForegroudGradiantColor_ = gradiantColor;
66     }
67 
GetFontForegroudGradiantColor()68     const std::optional<FontForegroudGradiantColor>& GetFontForegroudGradiantColor() const
69     {
70         return fontForegroudGradiantColor_;
71     }
72 
73 private:
74     std::optional<Gradient> gradient_;
75     // for ai option's gradient color
76     std::optional<FontForegroudGradiantColor> fontForegroudGradiantColor_;
77 };
78 
79 class SymbolTextStyle : public AceType {
80     DECLARE_ACE_TYPE(SymbolTextStyle, AceType);
81 
82 public:
83 
SetInnerSymbolEffectOptions(const std::optional<NG::SymbolEffectOptions> & symbolEffectOptions)84     void SetInnerSymbolEffectOptions(const std::optional<NG::SymbolEffectOptions>& symbolEffectOptions)
85     {
86         symbolEffectOptions_ = symbolEffectOptions;
87     }
88 
GetInnerSymbolEffectOptions()89     const std::optional<NG::SymbolEffectOptions>& GetInnerSymbolEffectOptions() const
90     {
91         return symbolEffectOptions_;
92     }
93 
SetInnerSymbolShadowProp(const std::optional<SymbolShadow> & symbolShadow)94     void SetInnerSymbolShadowProp(const std::optional<SymbolShadow>& symbolShadow)
95     {
96         symbolShadowProp_ = symbolShadow;
97     }
98 
GetInnerSymbolShadowProp()99     const std::optional<SymbolShadow>& GetInnerSymbolShadowProp() const
100     {
101         return symbolShadowProp_;
102     }
103 private:
104     // for symbol
105     std::optional<NG::SymbolEffectOptions> symbolEffectOptions_;
106     std::optional<SymbolShadow> symbolShadowProp_;
107 };
108 } // namespace OHOS::Ace
109 
110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_ADVANCED_TEXT_STYLE_H