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