1 /*
2  * Copyright (c) 2023 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 #ifndef ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H
17 #define ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "text_style.h"
23 #include "typography_types.h"
24 #include "modules/skparagraph/include/TextStyle.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 struct TypographyStyle {
29     const static inline std::u16string ELLIPSIS = u"\u2026";
30 
31     FontWeight fontWeight = FontWeight::W400;
32     FontWidth fontWidth = FontWidth::NORMAL;
33     FontStyle fontStyle = FontStyle::NORMAL;
34     std::string fontFamily = "";
35     double fontSize = 14.0; // default is libtxt text style fonst size
36     double heightScale = 1.0;
37     bool halfLeading = false;
38     bool heightOnly = false;
39     bool useLineStyle = false;
40 
41     FontWeight lineStyleFontWeight = FontWeight::W400;
42     FontWidth lineStyleFontWidth = FontWidth::NORMAL;
43     FontStyle lineStyleFontStyle = FontStyle::NORMAL;
44     std::vector<std::string> lineStyleFontFamilies;
45     double lineStyleFontSize = 14.0; // default is libtxt text style font size
46     double lineStyleHeightScale = 1.0;
47     bool lineStyleHeightOnlyInit = false;
48     bool lineStyleHeightOnly = false;
49     bool lineStyleHalfLeading = false;
50     double lineStyleSpacingScale = -1.0;
51     bool lineStyleOnly = false;
52 
53     TextAlign textAlign = TextAlign::START;
54     TextDirection textDirection = TextDirection::LTR;
55     size_t maxLines = 1e9;
56     std::u16string ellipsis;
57     std::string locale;
58 
59     BreakStrategy breakStrategy = BreakStrategy::GREEDY;
60     WordBreakType wordBreakType = WordBreakType::BREAK_WORD;
61     EllipsisModal ellipsisModal = EllipsisModal::TAIL;
62     float textSplitRatio = 0.5f;
63 
64     bool operator==(const TypographyStyle &rhs) const
65     {
66         return
67             this->ELLIPSIS == rhs.ELLIPSIS &&
68             this->fontWeight == rhs.fontWeight &&
69             this->fontStyle == rhs.fontStyle &&
70             this->fontFamily == rhs.fontFamily &&
71             skia::textlayout::nearlyEqual(this->fontSize, rhs.fontSize) &&
72             skia::textlayout::nearlyEqual(this->heightScale, rhs.heightScale) &&
73             this->halfLeading == rhs.halfLeading &&
74             this->heightOnly == rhs.heightOnly &&
75             this->useLineStyle == rhs.useLineStyle &&
76             this->lineStyleFontWidth == rhs.lineStyleFontWidth &&
77             this->lineStyleFontWeight == rhs.lineStyleFontWeight &&
78             this->lineStyleFontStyle == rhs.lineStyleFontStyle &&
79             this->lineStyleFontFamilies == rhs.lineStyleFontFamilies &&
80             skia::textlayout::nearlyEqual(this->lineStyleFontSize, rhs.lineStyleFontSize) &&
81             skia::textlayout::nearlyEqual(this->lineStyleHeightScale, rhs.lineStyleHeightScale) &&
82             this->lineStyleHeightOnlyInit == rhs.lineStyleHeightOnlyInit &&
83             this->lineStyleHeightOnly == rhs.lineStyleHeightOnly &&
84             this->lineStyleHalfLeading == rhs.lineStyleHalfLeading &&
85             skia::textlayout::nearlyEqual(this->lineStyleSpacingScale, rhs.lineStyleSpacingScale) &&
86             this->lineStyleOnly == rhs.lineStyleOnly &&
87             this->textAlign == rhs.textAlign &&
88             this->textDirection == rhs.textDirection &&
89             this->maxLines == rhs.maxLines &&
90             this->ellipsis == rhs.ellipsis &&
91             this->locale == rhs.locale &&
92             this->breakStrategy == rhs.breakStrategy &&
93             this->wordBreakType == rhs.wordBreakType &&
94             this->ellipsisModal == rhs.ellipsisModal &&
95             skia::textlayout::nearlyEqual(this->textSplitRatio, rhs.textSplitRatio);
96     }
97     TextStyle GetTextStyle() const;
98     void SetTextStyle(TextStyle& textstyle);
99     TextAlign GetEffectiveAlign() const;
100     bool IsUnlimitedLines() const;
101     bool IsEllipsized() const;
EllipsizedTypographyStyle102     bool Ellipsized() const
103     {
104         return !ellipsis.empty();
105     }
106     TextStyle insideTextStyle;
107     bool customTextStyle = false;
108     TextHeightBehavior textHeightBehavior = TextHeightBehavior::ALL;
109     bool hintingIsOn = false;
110 };
111 } // namespace Rosen
112 } // namespace OHOS
113 #endif // ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H
114