• 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 #include <texgine/system_font_provider.h>
17 #include <texgine/typography_builder.h>
18 
19 #include "feature_test_framework.h"
20 
21 using namespace OHOS::Rosen::TextEngine;
22 
23 namespace {
24 #define EXAMPLE 5
25 
26 #if EXAMPLE == 0
27 #elif EXAMPLE == 1
28 constexpr auto EXAMPLE_TEXT = "Typography is the art and technique of arranging type to make written "
29     "language legible, readable and appealing when displayed. The "
30     "arrangement of type involves selecting typefaces, point sizes, "
31     "line lengths, line-spacing (leading), and letter-spacing "
32     "(tracking), as well as adjusting the space between pairs of "
33     "letters (kerning).";
34 constexpr auto EXAMPLE_TEXT_HALF = "Typography is the art and technique of arranging type to make written "
35     "language legible, readable and appealing when displayed.";
36 #elif EXAMPLE == 2
37 constexpr auto EXAMPLE_TEXT = "مرحباً،";
38 constexpr auto EXAMPLE_TEXT_HALF = "";
39 #elif EXAMPLE == 3
40 constexpr auto EXAMPLE_TEXT = "مرحباً، العالم";
41 constexpr auto EXAMPLE_TEXT_HALF = "";
42 #elif EXAMPLE == 4
43 constexpr auto EXAMPLE_TEXT = "مرحباً، العالم جاهز";
44 constexpr auto EXAMPLE_TEXT_HALF = "";
45 #elif EXAMPLE == 5
46 constexpr auto EXAMPLE_TEXT = "12345678 مرحباً، العالم جاهز "
47     "22345678 مرحباً، العالم جاهز "
48     "32345678 مرحباً، العالم جاهز "
49     "42345678 مرحباً، العالم جاهز "
50     "52345678 مرحباً، العالم جاهز "
51     "62345678 مرحباً، العالم جاهز "
52     "72345678 مرحباً، العالم جاهز ";
53 constexpr auto EXAMPLE_TEXT_HALF = "12345678 مرحباً، العالم جاهز "
54     "22345678 مرحباً، العالم جاهز "
55     "32345678 مرحباً، العالم جاهز ";
56 #elif EXAMPLE == 6
57 constexpr auto EXAMPLE_TEXT = "مرحباً، العالم جاهز 1234567890";
58 constexpr auto EXAMPLE_TEXT_HALF = "مرحباً،";
59 #endif
60 
61 class LayoutTest : public TestFeature {
62 public:
LayoutTest()63     LayoutTest() : TestFeature("LayoutTest")
64     {
65     }
66 
Layout()67     void Layout() override
68     {
69         option_.needRainbowChar = true;
70 
71         TypographyStyle ys = {
72             .ellipsis = u"",
73             .breakStrategy = BreakStrategy::GREEDY,
74             .wordBreakType = WordBreakType::BREAK_ALL,
75         };
76         auto builder = TypographyBuilder::Create(ys);
77 
78         TextStyle style = {
79             .fontSize = 16,
80         };
81 
82         builder->PushStyle(style);
83         builder->AppendSpan(EXAMPLE_TEXT_HALF);
84         builder->PopStyle();
85 
86         TextStyle style2 = {
87             .fontSize = 24,
88         };
89 
90         builder->PushStyle(style2);
91         builder->AppendSpan((EXAMPLE_TEXT + strlen(EXAMPLE_TEXT_HALF)));
92         builder->PopStyle();
93 
94         auto typography = builder->Build();
95         double widthLimit = 300.0;
96         typography->Layout(widthLimit);
97         typographies_.push_back({
98             .typography = typography
99         });
100     }
101 } g_test;
102 } // namespace
103