• 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 #ifndef ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TEXT_STYLE_H
17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TEXT_STYLE_H
18 
19 #include <map>
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 #include "texgine_paint.h"
25 #include "texgine/typography_types.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace TextEngine {
30 /*
31  * @brief FontFeatures is the container that stores the
32  *        feature used to control how a font selects glyphs.
33  */
34 class FontFeatures {
35 public:
36     /*
37      * @brief Set a feature by integer value.
38      * @param ftag   The tag of feature.
39      * @param fvalue The integer value of feature.
40      */
41     void SetFeature(const std::string& ftag, int fvalue);
42 
43     /*
44      * @brief Returns the feature map that user set.
45      */
46     const std::map<std::string, int>& GetFeatures() const;
47 
48     /*
49      * @brief Implements the equality operator.
50      */
51     bool operator ==(const FontFeatures& rhs) const;
52 
53 private:
54     friend void ReportMemoryUsage(const std::string& member, const FontFeatures& that, const bool needThis);
55 
56     std::map<std::string, int> features_;
57 };
58 
59 /*
60  * @brief TextShadow contains parameters that control
61  *        how the text shadow is displayed.
62  */
63 struct TextShadow {
64     // The offset between the shaded text and the main text
65     double offsetX = 0.0;
66     double offsetY = 0.0;
67     uint32_t color = 0xffcccccc;
68     uint32_t blurLeave = 0;
69 
70     // Implements the equality operator.
71     bool operator ==(TextShadow const& rhs) const;
72 };
73 
74 /*
75  * @brief TextStyle is a collection of parameters that control how text is displayed,
76  *        including parameters for fonts, decorations, and text.
77  */
78 struct TextStyle {
79     // font style
80     FontWeight fontWeight = FontWeight::W400;
81     FontStyle fontStyle = FontStyle::NORMAL;
82     std::vector<std::string> fontFamilies = {};
83     double fontSize = 16.0;
84     FontFeatures fontFeature;
85 
86     // Decoration style
87     TextDecoration decoration = TextDecoration::NONE;
88     std::optional<uint32_t> decorationColor = std::nullopt;
89     TextDecorationStyle decorationStyle = TextDecorationStyle::SOLID;
90     double decorationThicknessScale = 1.0;
91 
92     // text style
93     uint32_t color = 0xff000000; // black
94     TextBaseline baseline = TextBaseline::ALPHABETIC;
95     std::string locale = "";
96     bool heightOnly = false; // true means text height is heightScale_ * fontSize_
97     double heightScale = 1.0;
98     double letterSpacing = 0.0;
99     double wordSpacing = 0.0;
100     std::optional<TexginePaint> foreground = std::nullopt;
101     std::optional<TexginePaint> background = std::nullopt;
102     std::vector<TextShadow> shadows;
103 
104     // Implements the equality operator.
105     bool operator ==(TextStyle const& rhs) const;
106 };
107 } // namespace TextEngine
108 } // namespace Rosen
109 } // namespace OHOS
110 
111 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TEXT_STYLE_H
112