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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_PROPERTIES_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_PROPERTIES_H
18 
19 #include <cstddef>
20 
21 #include "testing_rect.h"
22 
23 namespace OHOS::Ace::Testing {
24 enum class TextDirection {
25     RTL,
26     LTR,
27 };
28 
29 class TestingTypographyProperties {
30 public:
31 #ifndef USE_GRAPHIC_TEXT_GINE
32     enum class RectWidthStyle {
33 #else
34     enum class TextRectWidthStyle {
35 #endif
36         TIGHT,
37         MAX,
38     };
39 
40     enum class Affinity {
41 #ifndef USE_GRAPHIC_TEXT_GINE
42         UPSTREAM,
43         DOWNSTREAM,
44 #else
45         PREV,
46         NEXT,
47 #endif
48     };
49 
50 #ifndef USE_GRAPHIC_TEXT_GINE
51     enum class RectHeightStyle {
52 #else
53     enum class TextRectHeightStyle {
54 #endif
55         TIGHT,
56 #ifndef USE_GRAPHIC_TEXT_GINE
57         MAX,
58         INCLUDELINESPACEMIDDLE,
59         INCLUDELINESPACETOP,
60         INCLUDELINESPACEBOTTOM,
61         STRUCT,
62 #else
63         COVER_TOP_AND_BOTTOM,
64         COVER_HALF_TOP_AND_BOTTOM,
65         COVER_TOP,
66         COVER_BOTTOM,
67         FOLLOW_BY_STRUT,
68 #endif
69     };
70 
71 #ifndef USE_GRAPHIC_TEXT_GINE
72     struct TextBox {
73         TextDirection direction_;
74         TestingRect rect_;
75         TextBox() = default;
TextBoxTextBox76         TextBox(TestingRect rect, TextDirection direction) : direction_(direction), rect_(rect) {}
77     };
78 #else
79     struct TextRect {
80         TextDirection direction;
81         TestingRect rect;
82         TextRect() = default;
TextRectTextRect83         TextRect(TestingRect testRect, TextDirection testDirection) : direction(testDirection), rect(testRect) {}
84     };
85 #endif
86 
87 #ifndef USE_GRAPHIC_TEXT_GINE
88     struct PositionAndAffinity {
89         const size_t pos_;
90         const Affinity affinity_;
PositionAndAffinityPositionAndAffinity91         PositionAndAffinity(size_t pos, Affinity affinity) : pos_(pos), affinity_(affinity) {}
92     };
93 #else
94     struct IndexAndAffinity {
95         const size_t index;
96         const Affinity affinity;
IndexAndAffinityIndexAndAffinity97         IndexAndAffinity(size_t pos, Affinity affinity) : index(pos), affinity(affinity) {}
98     };
99 #endif
100 
101     template<typename T>
102 #ifndef USE_GRAPHIC_TEXT_GINE
103     struct Range {
104         T start_, end_;
RangeRange105         Range() : start_(), end_() {}
RangeRange106         Range(T a, T b) : start_(a), end_(b) {}
107         bool operator==(const Range<T>& rhs) const
108         {
109             return start_ == rhs.start_ && end_ == rhs.end_;
110         }
111 #else
112     struct Boundary {
113         T leftIndex, rightIndex;
114         Boundary() : leftIndex(), rightIndex() {}
115         Boundary(T a, T b) : leftIndex(a), rightIndex(b) {}
116         bool operator==(const Boundary<T>& rhs) const
117         {
118             return leftIndex == rhs.leftIndex && rightIndex == rhs.rightIndex;
119         }
120 #endif
121 
WidthRange122         T Width() const
123         {
124 #ifndef USE_GRAPHIC_TEXT_GINE
125             return end_ - start_;
126 #else
127             return rightIndex - leftIndex;
128 #endif
129         }
130 
ShiftRange131         void Shift(T offset)
132         {
133 #ifndef USE_GRAPHIC_TEXT_GINE
134             start_ += offset;
135             end_ += offset;
136 #else
137             leftIndex += offset;
138             rightIndex += offset;
139 #endif
140         }
141     };
142 };
143 } // namespace OHOS::Ace::Testing
144 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_PROPERTIES_H
145