• 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 struct Rect {
25     TextRectHeightStyle heightStyle;
26     TextRectWidthStyle widthStyle;
27     std::string title = "";
28 } g_rectInfos[] = {
29     {
30         .heightStyle = TextRectHeightStyle::TIGHT,
31         .widthStyle = TextRectWidthStyle::TIGHT,
32         .title = "height:Tight, width:Tight",
33     },
34     {
35         .heightStyle = TextRectHeightStyle::TIGHT,
36         .widthStyle = TextRectWidthStyle::MAX_WIDTH,
37         .title = "height:Tight, width:Max",
38     },
39     {
40         .heightStyle = TextRectHeightStyle::COVER_TOP_AND_BOTTOM,
41         .widthStyle = TextRectWidthStyle::TIGHT,
42         .title = "height:Max, width:Tight",
43     },
44     {
45         .heightStyle = TextRectHeightStyle::COVER_TOP_AND_BOTTOM,
46         .widthStyle = TextRectWidthStyle::TIGHT,
47         .title = "height:IncludeSpacingMiddle, width:Tight",
48     },
49     {
50         .heightStyle = TextRectHeightStyle::COVER_TOP,
51         .widthStyle = TextRectWidthStyle::TIGHT,
52         .title = "height:IncludeSpacingTop, width:Tight",
53     },
54     {
55         .heightStyle = TextRectHeightStyle::COVER_BOTTOM,
56         .widthStyle = TextRectWidthStyle::TIGHT,
57         .title = "height:IncludeSpacingBottom, width:Tight",
58     },
59     {
60         .heightStyle = TextRectHeightStyle::FOLLOW_BY_LINE_STYLE,
61         .widthStyle = TextRectWidthStyle::TIGHT,
62         .title = "height:StructForce, width:Tight",
63     },
64 };
65 
66 class StrutTest : public TestFeature {
67 public:
StrutTest()68     StrutTest() : TestFeature("StrutTest")
69     {
70     }
71 
Layout()72     void Layout()
73     {
74         option_.needRainbowChar = true;
75 
76         TextStyle style = {
77             .fontSize = 64,
78         };
79 
80         TypographyStyle tpStyle = {
81             .lineStyle = {
82                 .only = true,
83                 .fontSize = 64,
84             },
85         };
86 
87         for (auto &[heightStyle, widthStyle, title] : g_rectInfos) {
88             auto builder = TypographyBuilder::Create(tpStyle);
89             builder->PushStyle(style);
90             builder->AppendSpan("jhello hello hello JHELLO");
91             auto typography = builder->Build();
92             typography->Layout(300);
93             typographies_.push_back({
94                 .typography = typography,
95                 .comment = title,
96                 .ws = widthStyle,
97                 .hs = heightStyle,
98             });
99         }
100     }
101 };
102 } // namespace
103