• 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 constexpr auto EXAMPLE_TEXT = "    Landscape engineering quality management, the most likely "
25     "problem is not clear responsible person, responsible unit, resulting "
26     "in problems again and again, therefore, should establish a strict quality "
27     "management responsibility system and norms, through the system to ensure the quality "
28     "of     Landscape engineering construction.";
29 
30 struct AlignTestData {
31     std::string title;
32     TypographyStyle tStyle;
33 } g_datas[] = {
34     {
35         .title = "Start对齐布局",
36         .tStyle = {
37             .align = TextAlign::START,
38         },
39     },
40     {
41         .title = "左对齐布局",
42         .tStyle = {
43             .align = TextAlign::LEFT,
44         },
45     },
46     {
47         .title = "右对齐布局",
48         .tStyle = {
49             .align = TextAlign::RIGHT,
50         },
51     },
52     {
53         .title = "居中对齐布局",
54         .tStyle = {
55             .align = TextAlign::CENTER,
56         },
57     },
58     {
59         .title = "End对齐布局",
60         .tStyle = {
61             .align = TextAlign::END,
62         },
63     },
64 };
65 
66 class AlignTest : public TestFeature {
67 public:
AlignTest()68     AlignTest() : TestFeature("AlignTest") {}
69 
Layout()70     void Layout()
71     {
72         TexginePaint background;
73         uint32_t color = 0xff00ff00;
74         double strokeWidth = 2.0;
75         background.SetColor(color);
76         background.SetStrokeWidth(strokeWidth);
77         background.SetStyle(TexginePaint::STROKE);
78         TextStyle style = {
79             .fontSize = 16,
80             .background = background,
81         };
82 
83         for (auto &[title, tstyle] : g_datas) {
84             for (auto dir : {TextDirection::LTR, TextDirection::RTL}) {
85                 tstyle.direction = dir;
86                 auto builder = TypographyBuilder::Create(tstyle);
87                 builder->PushStyle(style);
88                 builder->AppendSpan(EXAMPLE_TEXT);
89                 auto typography = builder->Build();
90                 double widthLimit = 325.0;
91                 typography->Layout(widthLimit);
92                 typographies_.push_back({
93                     .typography = typography,
94                     .comment = (dir == TextDirection::LTR ? "LTR " : "RTL ") + title,
95                 });
96             }
97         }
98     }
99 } g_test;
100 } // namespace
101