• 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/typography_builder.h>
17 
18 #include "feature_test_framework.h"
19 
20 using namespace OHOS::Rosen::TextEngine;
21 
22 namespace {
23 struct TextHeightTestData {
24     std::string text;
25     TextStyle style;
26 } g_datas[] = {
27     {
28         .text = "Default text height.",
29         .style = {
30             .heightOnly = true,
31         },
32     },
33     {
34         .text = "Text height test1.",
35         .style = {
36             .heightOnly = true,
37             .fontSize = 10.0, // 10.0 means font size
38             .heightScale = 1.0, // 1.0 means height scale value
39         },
40     },
41     {
42         .text = "Text height test2.",
43         .style = {
44             .heightOnly = true,
45             .fontSize = 10.0, // 10.0 means font size
46             .heightScale = 1.5, // 1.5 means height scale value
47         },
48     },
49     {
50         .text = "Text height test3.",
51         .style = {
52             .heightOnly = true,
53             .fontSize = 10.0, // 10.0 means font size
54             .heightScale = 2.0, // 2.0 means height scale value
55         },
56     },
57     {
58         .text = "Text height test4.",
59         .style = {
60             .heightOnly = true,
61             .fontSize = 15.0, // 15.0 means font size
62             .heightScale = 2.0, // 2.0 means height scale value
63         },
64     },
65     {
66         .text = "Text height test5.",
67         .style = {
68             .heightOnly = true,
69             .fontSize = 20.0, // 20.0 means font size
70             .heightScale = 2.0, // 2.0 means height scale value
71         },
72     },
73     {
74         .text = "Text height test6.",
75         .style = {
76             .heightOnly = true,
77             .fontSize = 20.0, // 20.0 means font size
78             .heightScale = 2.5, // 2.5 means height scale value
79         },
80     },
81 };
82 
83 class TextHeightTest : public TestFeature {
84 public:
TextHeightTest()85     TextHeightTest() : TestFeature("TextHeightTest")
86     {
87     }
88 
Layout()89     void Layout() override
90     {
91         for (auto &[text, style] : g_datas) {
92             auto builder = TypographyBuilder::Create();
93             builder->PushStyle(style);
94             builder->AppendSpan(text);
95             auto typography = builder->Build();
96             typography->Layout(300); // 300 means width limit
97             typographies_.push_back({
98                 .typography = typography,
99             });
100         }
101     }
102 } g_test;
103 } // namespace
104