• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
26     WordBreakTypeNormal = 0,
27     WordBreakTypeBreakAll,
28     WordBreakTypeBreakWord,
29     WordBreakTypeHyphenation,
30 };
31 
32 enum class TextAlign {
33     LEFT = 0,
34     RIGHT,
35     CENTER,
36     JUSTIFY,
37     START,
38     END,
39 };
40 
41 enum class EllipsisMode {
42     HEAD,
43     MIDDLE,
44     TAIL,
45 };
46 
47 class TestingTypography {
48 public:
49     TestingTypography() = default;
50     virtual ~TestingTypography() = default;
51 
GetHeight()52     virtual double GetHeight()
53     {
54         return 1.0;
55     }
56 
Layout(double width)57     virtual void Layout(double width) {}
58 
GetMaxIntrinsicWidth()59     virtual double GetMaxIntrinsicWidth()
60     {
61         return 1.0;
62     }
63 
GetMaxWidth()64     virtual double GetMaxWidth()
65     {
66         return 1.0;
67     }
68 
GetActualWidth()69     virtual double GetActualWidth()
70     {
71         return 1.0;
72     }
73 
GetMinIntrinsicWidth()74     virtual double GetMinIntrinsicWidth()
75     {
76         return 1.0;
77     }
78 
GetLineCount()79     virtual size_t GetLineCount()
80     {
81         return 1;
82     }
83 
Paint(TestingCanvas * canvas,double x,double y)84     virtual void Paint(TestingCanvas* canvas, double x, double y) {}
85 
GetTextRectsByBoundary(size_t,size_t,TestingTypographyProperties::TextRectHeightStyle,TestingTypographyProperties::TextRectWidthStyle)86     virtual std::vector<TestingTypographyProperties::TextRect> GetTextRectsByBoundary(size_t /* start */,
87         size_t /* end */, TestingTypographyProperties::TextRectHeightStyle /* height */,
88         TestingTypographyProperties::TextRectWidthStyle /* width */)
89     {
90         return {};
91     }
92 
GetGlyphIndexByCoordinate(double x,double y)93     virtual TestingTypographyProperties::IndexAndAffinity GetGlyphIndexByCoordinate(double x, double y)
94     {
95         TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV);
96         return res;
97     }
98 
GetGlyphPositionAtCoordinate(double x,double y)99     virtual TestingTypographyProperties::IndexAndAffinity GetGlyphPositionAtCoordinate(double x, double y)
100     {
101         TestingTypographyProperties::IndexAndAffinity res(1, TestingTypographyProperties::Affinity::PREV);
102         return res;
103     }
104 
GetWordBoundaryByIndex(size_t offset)105     virtual TestingTypographyProperties::Boundary<size_t> GetWordBoundaryByIndex(size_t offset)
106     {
107         TestingTypographyProperties::Boundary<size_t> range =
108             TestingTypographyProperties::Boundary<size_t>(offset, offset + 1);
109         return range;
110     }
GetAlphabeticBaseline()111     double GetAlphabeticBaseline()
112     {
113         return 0.0;
114     }
GetIdeographicBaseline()115     double GetIdeographicBaseline()
116     {
117         return 0.0;
118     }
119 };
120 } // namespace OHOS::Ace::Testing
121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_TYPOGRAPHY_H
122