• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "txt/text_style.h"
17 
18 #include "rosen_text/properties/rosen_converter_txt.h"
19 #include "rosen_text/properties/text_style.h"
20 #include "txt/platform.h"
21 
22 namespace rosen {
SetFeature(std::string tag,int value)23 void FontFeatures::SetFeature(std::string tag, int value)
24 {
25     featureMap_[tag] = value;
26 }
27 
GetFeatureSettings() const28 std::string FontFeatures::GetFeatureSettings() const
29 {
30     // set font variant (its map, need set one by one)
31     txt::FontFeatures features;
32     if (!featureMap_.empty()) {
33         for (auto iter = featureMap_.begin(); iter != featureMap_.end(); ++iter) {
34             features.SetFeature(iter->first, iter->second);
35         }
36     }
37     return features.GetFeatureSettings();
38 }
39 
TextShadow(OHOS::Rosen::Drawing::Color color,OHOS::Rosen::Drawing::Point offset,double blurRadius)40 TextShadow::TextShadow(OHOS::Rosen::Drawing::Color color, OHOS::Rosen::Drawing::Point offset, double blurRadius)
41     : color_(color),
42     offset_(offset),
43     blurRadius_(blurRadius)
44 {
45 }
46 
operator ==(const TextShadow & rhs) const47 bool TextShadow::operator==(const TextShadow& rhs) const
48 {
49     if (color_ != rhs.color_ || offset_ != rhs.offset_ || blurRadius_ != rhs.blurRadius_) {
50         return false;
51     }
52     return true;
53 }
54 
operator !=(const TextShadow & rhs) const55 bool TextShadow::operator != (const TextShadow& rhs) const
56 {
57     return !(*this == rhs);
58 }
59 
hasShadow() const60 bool TextShadow::hasShadow() const
61 {
62     if (offset_.GetX()  != 0.0 || offset_.GetY() != 0.0 || blurRadius_ != 0.0) {
63         return true;
64     }
65     return false;
66 }
67 
TextStyle()68 TextStyle::TextStyle()
69 {
70 #ifdef USE_CANVASKIT0310_SKIA
71     // use new flutter libtxt interface
72     fontFamilies_ = txt::GetDefaultFontFamilies();
73 #else
74     fontFamilies_ = std::vector<std::string>(1, txt::GetDefaultFontFamily());
75 #endif
76 }
77 
equals(const TextStyle & rhs) const78 bool TextStyle::equals(const TextStyle& rhs) const
79 {
80     txt::TextStyle curTextStyle;
81     txt::TextStyle rhsTextStyle;
82     RosenConvertTxtStyle(*this, curTextStyle);
83     RosenConvertTxtStyle(rhs, rhsTextStyle);
84     return curTextStyle.equals(rhsTextStyle);
85 }
86 } // namespace rosen
87