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