• 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 <sstream>
20 
21 #include "feature_test_framework.h"
22 
23 using namespace OHOS::Rosen::TextEngine;
24 
25 namespace {
26 constexpr auto EXAMPLE_TEXT = "你好世界 Landscape engineering. Landscape engineering. Landscape engineering. ";
27 struct TestInfo {
28     TextStyle xs_;
29     TypographyStyle ys_;
30 } g_datas[] = {
31     { },
32     { .xs_ = { .letterSpacing = -1, }, },
33     { .xs_ = { .letterSpacing = 5, }, },
34     { .xs_ = { .letterSpacing = 20, }, },
35     { .xs_ = { .wordSpacing = -5, }, },
36     { .xs_ = { .wordSpacing = 5, }, },
37     { .xs_ = { .wordSpacing = 20, }, },
38     {
39         .xs_ = { .letterSpacing = 20, .wordSpacing = 20, },
40         .ys_ = { .wordBreakType = WordBreakType::BREAK_ALL, },
41     },
42 };
43 
44 class SpacingTest : public TestFeature {
45 public:
SpacingTest()46     SpacingTest() : TestFeature("SpacingTest")
47     {
48     }
49 
Layout()50     void Layout()
51     {
52         option_.needRainbowChar = true;
53 
54         for (auto &[xs, ys] : g_datas) {
55             auto builder = TypographyBuilder::Create(ys);
56             builder->PushStyle(xs);
57             builder->AppendSpan(EXAMPLE_TEXT);
58             builder->PopStyle();
59             auto typography = builder->Build();
60             typography->Layout(250);    // 250 means layout width
61 
62             std::stringstream ss;
63             if (xs.letterSpacing) {
64                 ss << "LetterSpacing: " << xs.letterSpacing << " ";
65             }
66             if (xs.wordSpacing) {
67                 ss << "WordSpacing: " << xs.wordSpacing << " ";
68             }
69             if (ys.wordBreakType == WordBreakType::BREAK_ALL) {
70                 ss << "BreakAll";
71             }
72 
73             typographies_.push_back({
74                 .typography = typography,
75                 .comment = ss.str(),
76             });
77         }
78     }
79 } g_test;
80 } // namespace
81