1 /*
2  * Copyright (c) 2024 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 #ifndef ROSEN_MODULES_SPTEXT_LINE_METRICS_H
16 #define ROSEN_MODULES_SPTEXT_LINE_METRICS_H
17 
18 #include <map>
19 #include <vector>
20 
21 #include "include/core/SkFontMetrics.h"
22 #include "text/font_metrics.h"
23 #include "text_style.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace SPText {
28 class RunMetrics {
29 public:
RunMetrics(const TextStyle * style)30     explicit RunMetrics(const TextStyle* style) : textStyle(style) {}
31 
RunMetrics(const TextStyle * style,const Drawing::FontMetrics & metrics)32     RunMetrics(const TextStyle* style, const Drawing::FontMetrics& metrics)
33         : textStyle(style), fontMetrics(metrics) {}
34 
35     const TextStyle* textStyle;
36     Drawing::FontMetrics fontMetrics;
37 };
38 
39 class LineMetrics {
40 public:
41     size_t startIndex = 0;
42     size_t endIndex = 0;
43     size_t endExcludingWhitespace = 0;
44     size_t endIncludingNewline = 0;
45     bool hardBreak = false;
46 
47     double ascent = 0.0;
48     double descent = 0.0;
49     double unscaledAscent = 0.0;
50 
51     double height = 0.0;
52     double width = 0.0;
53     double left = 0.0;
54     double baseline = 0.0;
55 
56     size_t lineNumber = 0;
57    // Width include spaces
58     double widthWithSpaces = 0.0;
59     // Height from the top
60     double topHeight = 0.0;
61 
62     std::map<size_t, RunMetrics> runMetrics;
63 };
64 } // namespace SPText
65 } // namespace Rosen
66 } // namespace OHOS
67 
68 #endif // ROSEN_MODULES_SPTEXT_LINE_METRICS_H
69