1 /*
2  * Copyright (c) 2023 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 #include "rosen_text/typography_style.h"
17 
18 namespace OHOS {
19 namespace Rosen {
GetTextStyle() const20 TextStyle TypographyStyle::GetTextStyle() const
21 {
22     TextStyle style = {
23 #ifndef USE_GRAPHIC_TEXT_GINE
24         .fontWeight_ = fontWeight_,
25         .fontStyle_ = fontStyle_,
26         .fontFamilies_ = { fontFamily_ },
27         .fontSize_ = fontSize_,
28         .heightScale_ = heightScale_,
29         .halfLeading_ = halfLeading_,
30         .heightOnly_ = heightOnly_,
31         .locale_ = locale_,
32 #else
33         .fontWeight = fontWeight,
34         .fontStyle = fontStyle,
35         .fontFamilies = { fontFamily },
36         .fontSize = fontSize,
37         .heightScale = heightScale,
38         .halfLeading = halfLeading,
39         .heightOnly = heightOnly,
40         .locale = locale,
41 #endif
42     };
43 #ifndef USE_GRAPHIC_TEXT_GINE
44     if (fontSize_ >= 0) {
45         style.fontSize_ = fontSize_;
46 #else
47     if (fontSize >= 0) {
48         style.fontSize = fontSize;
49 #endif
50     }
51 
52     return style;
53 }
54 
55 TextAlign TypographyStyle::GetEffectiveAlign() const
56 {
57 #ifndef USE_GRAPHIC_TEXT_GINE
58     if (textAlign_ == TextAlign::START) {
59         return (textDirection_ == TextDirection::LTR) ? TextAlign::LEFT : TextAlign::RIGHT;
60     } else if (textAlign_ == TextAlign::END) {
61         return (textDirection_ == TextDirection::RTL) ? TextAlign::LEFT : TextAlign::RIGHT;
62 #else
63     if (textAlign == TextAlign::START) {
64         return (textDirection == TextDirection::LTR) ? TextAlign::LEFT : TextAlign::RIGHT;
65     } else if (textAlign == TextAlign::END) {
66         return (textDirection == TextDirection::RTL) ? TextAlign::LEFT : TextAlign::RIGHT;
67 #endif
68     } else {
69 #ifndef USE_GRAPHIC_TEXT_GINE
70         return textAlign_;
71 #else
72         return textAlign;
73 #endif
74     }
75 }
76 
77 bool TypographyStyle::IsUnlimitedLines() const
78 {
79 #ifndef USE_GRAPHIC_TEXT_GINE
80     return maxLines_ == 1e9;
81 #else
82     return maxLines == 1e9;     // maximum number of lines
83 #endif
84 }
85 
86 void TypographyStyle::SetTextStyle(TextStyle& textstyle)
87 {
88     customTextStyle = true;
89     insideTextStyle = textstyle;
90 }
91 
92 bool TypographyStyle::IsEllipsized() const
93 {
94 #ifndef USE_GRAPHIC_TEXT_GINE
95     return !ellipsis_.empty();
96 #else
97     return !ellipsis.empty();
98 #endif
99 }
100 } // namespace Rosen
101 } // namespace OHOS
102