1 /*
2  * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_TEXT_LAYOUT_INFO_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_TEXT_LAYOUT_INFO_H
18 
19 #include "core/components/common/properties/text_style.h"
20 
21 namespace OHOS::Ace {
22 struct FontMetrics {
23     enum FontMetricsFlags {
24         UNDERLINE_THICKNESS_IS_VALID_FLAG = 1 << 0,
25         UNDERLINE_POSITION_IS_VALID_FLAG  = 1 << 1,
26         STRIKEOUT_THICKNESS_IS_VALID_FLAG = 1 << 2,
27         STRIKEOUT_POSITION_IS_VALID_FLAG  = 1 << 3,
28         BOUNDS_INVALID_FLAG               = 1 << 4,
29     };
30 
31     uint32_t fFlags;
32     float fTop;
33     float fAscent;
34     float fDescent;
35     float fBottom;
36     float fLeading;
37     float fAvgCharWidth;
38     float fMaxCharWidth;
39     float fXMin;
40     float fXMax;
41     float fXHeight;
42     float fCapHeight;
43     float fUnderlineThickness;
44     float fUnderlinePosition;
45     float fStrikeoutThickness;
46     float fStrikeoutPosition;
47 };
48 
49 class RunMetrics {
50 public:
51     TextStyle textStyle;
52     FontMetrics fontMetrics;
53 };
54 
55 struct TextLineMetrics {
56     /** Text ascender height */
57     double ascender;
58     /** Tex descender height */
59     double descender;
60     /** The height of a capital letter */
61     double capHeight;
62     /** The height of a lowercase letter */
63     double xHeight;
64     /** Text width */
65     double width;
66     /** Line height */
67     double height;
68     /**
69      * The distance from the left end of the text to the left end of the container,
70      * aligned to 0, is the width of the container minus the width of the line of text
71      */
72     double x;
73     /**
74      * The height from the top of the text to the top of the container, the first line is 0,
75      *  and the second line is the height of the first line
76      */
77     double y;
78     /** Start Index */
79     size_t startIndex;
80     /** End Index */
81     size_t endIndex;
82 
83     FontMetrics firstCharMetrics;
84 
85     /** The y position of the baseline for this line from the top of the paragraph */
86     double baseline;
87     /** Zero indexed line number */
88     size_t lineNumber;
89 
90     std::map<size_t, RunMetrics> runMetrics;
91 };
92 } // namespace OHOS::Ace
93 
94 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_TEXT_LAYOUT_INFO_H