• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved.
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 #include "text_style.h"
17 
18 #include <sstream>
19 
20 #include "txt/platform.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace SPText {
SetFeature(std::string tag,int value)25 void FontFeatures::SetFeature(std::string tag, int value)
26 {
27     features_.emplace_back(std::make_pair(tag, value));
28 }
29 
GetFeatureSettings() const30 std::string FontFeatures::GetFeatureSettings() const
31 {
32     if (features_.empty()) {
33         return "";
34     }
35 
36     std::ostringstream stream;
37 
38     for (const auto& kv : features_) {
39         if (stream.tellp()) {
40             stream << ',';
41         }
42         stream << kv.first << '=' << kv.second;
43     }
44 
45     return stream.str();
46 }
47 
GetFontFeatures() const48 const std::vector<std::pair<std::string, int>>& FontFeatures::GetFontFeatures() const
49 {
50     return features_;
51 }
52 
SetAxisValue(std::string tag,float value)53 void FontVariations::SetAxisValue(std::string tag, float value)
54 {
55     axis_[tag] = value;
56 }
57 
GetAxisValues() const58 const std::map<std::string, float>& FontVariations::GetAxisValues() const
59 {
60     return axis_;
61 }
62 
TextShadow()63 TextShadow::TextShadow() {}
64 
TextShadow(SkColor color,SkPoint offset,double blurSigma)65 TextShadow::TextShadow(SkColor color, SkPoint offset, double blurSigma)
66     : color(color), offset(offset), blurSigma(blurSigma)
67 {}
68 
operator ==(const TextShadow & other) const69 bool TextShadow::operator==(const TextShadow& other) const
70 {
71     return color == other.color &&
72         offset == other.offset &&
73         blurSigma == other.blurSigma;
74 }
75 
operator !=(const TextShadow & other) const76 bool TextShadow::operator!=(const TextShadow& other) const
77 {
78     return !(*this == other);
79 }
80 
HasShadow() const81 bool TextShadow::HasShadow() const
82 {
83     constexpr double blurThreshold = 0.5;
84     return !offset.isZero() || blurSigma > blurThreshold;
85 }
86 
TextStyle()87 TextStyle::TextStyle() : fontFamilies(SPText::DefaultFamilyNameMgr::GetInstance().GetDefaultFontFamilies()) {}
88 
operator ==(TextStyle const & other) const89 bool TextStyle::operator==(TextStyle const& other) const
90 {
91     return color == other.color &&
92         decoration == other.decoration &&
93         decorationColor == other.decorationColor &&
94         decorationStyle == other.decorationStyle &&
95         decorationThicknessMultiplier == other.decorationThicknessMultiplier &&
96         fontWeight == other.fontWeight &&
97         fontStyle == other.fontStyle &&
98         letterSpacing == other.letterSpacing &&
99         wordSpacing == other.wordSpacing &&
100         height == other.height &&
101         heightOverride == other.heightOverride &&
102         halfLeading == other.halfLeading &&
103         locale == other.locale &&
104         styleId == other.styleId &&
105         backgroundRect == other.backgroundRect &&
106         foreground == other.foreground &&
107         fontFamilies == other.fontFamilies &&
108         textShadows == other.textShadows &&
109         badgeType == other.badgeType;
110 }
111 } // namespace SPText
112 } // namespace Rosen
113 } // namespace OHOS
114