1 /*
2  * Copyright (c) 2022 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_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_H
18 
19 #include <vector>
20 
21 #include "testing_canvas.h"
22 #include "testing_typography_properties.h"
23 
24 namespace OHOS::Ace::Testing {
25 enum class WordBreakType { WordBreakTypeNormal = 0, WordBreakTypeBreakAll, WordBreakTypeBreakWord };
26 
27 enum class TextAlign {
28     LEFT = 0,
29     RIGHT,
30     CENTER,
31     JUSTIFY,
32     START,
33     END,
34 };
35 
36 enum class EllipsisMode {
37     HEAD,
38     MIDDLE,
39     TAIL,
40 };
41 
42 class TestingTypography {
43 public:
44     TestingTypography() = default;
45     virtual ~TestingTypography() = default;
46 
GetHeight()47     virtual double GetHeight()
48     {
49         return 1.0;
50     }
51 
Layout(double width)52     virtual void Layout(double width) {}
53 
GetMaxIntrinsicWidth()54     virtual double GetMaxIntrinsicWidth()
55     {
56         return 1.0;
57     }
58 
GetMaxWidth()59     virtual double GetMaxWidth()
60     {
61         return 1.0;
62     }
63 
64 #ifndef USE_GRAPHIC_TEXT_GINE
GetLongestLine()65     virtual double GetLongestLine()
66 #else
67     virtual double GetActualWidth()
68 #endif
69     {
70         return 1.0;
71     }
72 
GetMinIntrinsicWidth()73     virtual double GetMinIntrinsicWidth()
74     {
75         return 1.0;
76     }
77 
GetLineCount()78     virtual size_t GetLineCount()
79     {
80         return 1;
81     }
82 
Paint(TestingCanvas * canvas,double x,double y)83     virtual void Paint(TestingCanvas* canvas, double x, double y) {}
84 
85 #ifndef USE_GRAPHIC_TEXT_GINE
GetRectsForRange(size_t,size_t,TestingTypographyProperties::RectHeightStyle,TestingTypographyProperties::RectWidthStyle)86     virtual std::vector<TestingTypographyProperties::TextBox> GetRectsForRange(size_t /* start */, size_t /* end */,
87         TestingTypographyProperties::RectHeightStyle /* height */,
88         TestingTypographyProperties::RectWidthStyle /* width */)
89 #else
90     virtual std::vector<TestingTypographyProperties::TextRect> GetTextRectsByBoundary(size_t /* start */,
91         size_t /* end */, TestingTypographyProperties::TextRectHeightStyle /* height */,
92         TestingTypographyProperties::TextRectWidthStyle /* width */)
93 #endif
94     {
95         return {};
96     }
97 
98 #ifndef USE_GRAPHIC_TEXT_GINE
GetGlyphPositionAtCoordinateWithCluster(double x,double y)99     virtual TestingTypographyProperties::PositionAndAffinity GetGlyphPositionAtCoordinateWithCluster(double x, double y)
100     {
101         TestingTypographyProperties::PositionAndAffinity res(1, TestingTypographyProperties::Affinity::UPSTREAM);
102         return res;
103     }
104 #else
GetGlyphIndexByCoordinate(double x,double y)105     virtual TestingTypographyProperties::IndexAndAffinity GetGlyphIndexByCoordinate(double x, double y)
106     {
107         TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV);
108         return res;
109     }
110 #endif
111 
112 #ifndef USE_GRAPHIC_TEXT_GINE
GetGlyphPositionAtCoordinate(double x,double y)113     virtual TestingTypographyProperties::PositionAndAffinity GetGlyphPositionAtCoordinate(double x, double y)
114     {
115         TestingTypographyProperties::PositionAndAffinity res(1, TestingTypographyProperties::Affinity::UPSTREAM);
116         return res;
117     }
118 
GetWordBoundary(size_t offset)119     virtual TestingTypographyProperties::Range<size_t> GetWordBoundary(size_t offset)
120     {
121         TestingTypographyProperties::Range<size_t> range =
122             TestingTypographyProperties::Range<size_t>(offset, offset + 1);
123         return range;
124     }
125 #else
GetGlyphPositionAtCoordinate(double x,double y)126     virtual TestingTypographyProperties::IndexAndAffinity GetGlyphPositionAtCoordinate(double x, double y)
127     {
128         TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV);
129         return res;
130     }
131 
GetWordBoundaryByIndex(size_t offset)132     virtual TestingTypographyProperties::Boundary<size_t> GetWordBoundaryByIndex(size_t offset)
133     {
134         TestingTypographyProperties::Boundary<size_t> range =
135             TestingTypographyProperties::Boundary<size_t>(offset, offset + 1);
136         return range;
137     }
138 #endif
GetAlphabeticBaseline()139     double GetAlphabeticBaseline()
140     {
141         return 0.0;
142     }
GetIdeographicBaseline()143     double GetIdeographicBaseline()
144     {
145         return 0.0;
146     }
147 };
148 } // namespace OHOS::Ace::Testing
149 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_H
150