• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     style.fontWeight = fontWeight;
24     style.fontStyle = fontStyle;
25     style.fontFamilies = { fontFamily };
26     style.heightScale = heightScale;
27     style.halfLeading = halfLeading;
28     style.heightOnly = heightOnly;
29     style.locale = locale;
30     style.textStyleUid = defaultTextStyleUid;
31 
32     if (fontSize >= 0) {
33         style.fontSize = fontSize;
34     }
35 
36     return style;
37 }
38 
GetEffectiveAlign() const39 TextAlign TypographyStyle::GetEffectiveAlign() const
40 {
41     if (textAlign == TextAlign::START) {
42         return (textDirection == TextDirection::LTR) ? TextAlign::LEFT : TextAlign::RIGHT;
43     } else if (textAlign == TextAlign::END) {
44         return (textDirection == TextDirection::RTL) ? TextAlign::LEFT : TextAlign::RIGHT;
45     } else {
46         return textAlign;
47     }
48 }
49 
IsUnlimitedLines() const50 bool TypographyStyle::IsUnlimitedLines() const
51 {
52     return maxLines == 1e9; // maximum number of lines
53 }
54 
SetTextStyle(TextStyle & textstyle)55 void TypographyStyle::SetTextStyle(TextStyle& textstyle)
56 {
57     customTextStyle = true;
58     insideTextStyle = textstyle;
59 }
60 
IsEllipsized() const61 bool TypographyStyle::IsEllipsized() const
62 {
63     return !ellipsis.empty();
64 }
65 } // namespace Rosen
66 } // namespace OHOS
67