• 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 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     enum class TextRectWidthStyle {
32         TIGHT,
33         MAX,
34     };
35 
36     enum class Affinity {
37         PREV,
38         NEXT,
39     };
40 
41     enum class TextRectHeightStyle {
42         TIGHT,
43         COVER_TOP_AND_BOTTOM,
44         COVER_HALF_TOP_AND_BOTTOM,
45         COVER_TOP,
46         COVER_BOTTOM,
47         FOLLOW_BY_STRUT,
48     };
49 
50     struct TextRect {
51         TextDirection direction;
52         TestingRect rect;
53         TextRect() = default;
TextRectTextRect54         TextRect(TestingRect testRect, TextDirection testDirection) : direction(testDirection), rect(testRect) {}
55     };
56 
57     struct IndexAndAffinity {
58         const size_t index;
59         const Affinity affinity;
IndexAndAffinityIndexAndAffinity60         IndexAndAffinity(size_t pos, Affinity affinity) : index(pos), affinity(affinity) {}
61     };
62 
63     template<typename T>
64     struct Boundary {
65         T leftIndex, rightIndex;
BoundaryBoundary66         Boundary() : leftIndex(), rightIndex() {}
BoundaryBoundary67         Boundary(T a, T b) : leftIndex(a), rightIndex(b) {}
68         bool operator==(const Boundary<T>& rhs) const
69         {
70             return leftIndex == rhs.leftIndex && rightIndex == rhs.rightIndex;
71         }
72 
WidthBoundary73         T Width() const
74         {
75             return rightIndex - leftIndex;
76         }
77 
ShiftBoundary78         void Shift(T offset)
79         {
80             leftIndex += offset;
81             rightIndex += offset;
82         }
83     };
84 };
85 } // namespace OHOS::Ace::Testing
86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_PROPERTIES_H
87