• 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 constexpr const char *TEXT = "hello world hello world hello world hello 123";
24 
25 namespace {
26 struct EllipsisInfo {
27     std::string span;
28     TypographyStyle tpStyle;
29     TextStyle style;
30     std::string title = "";
31 } g_infos[] = {
32     {
33         .span = TEXT,
34         .title = "default",
35     },
36     {
37         .span = TEXT,
38         .tpStyle = {
39             .maxLines = 1,
40         },
41         .title = "maxline: 1, ellipse: default",
42     },
43     {
44         .span = TEXT,
45         .tpStyle = {
46             .ellipsis = u"",
47         },
48         .title = "maxline: defult, ellipse: \"\"",
49     },
50     {
51         .span = TEXT,
52         .tpStyle = {
53             .maxLines = 1,
54             .ellipsis = u"",
55         },
56         .title = "maxline: 1, ellipse: \"\"",
57     },
58 };
59 
60 class EllipsisTest : public TestFeature {
61 public:
EllipsisTest()62     EllipsisTest() : TestFeature("EllipsisTest")
63     {
64     }
65 
Layout()66     void Layout()
67     {
68         for (auto &info : g_infos) {
69             auto builder = TypographyBuilder::Create(info.tpStyle);
70             builder->PushStyle(info.style);
71             builder->AppendSpan(info.span);
72             auto typography = builder->Build();
73             double widthLimit = 300.0;
74             typography->Layout(widthLimit);
75             typographies_.push_back({
76                 .typography = typography,
77                 .comment = info.title,
78             });
79         }
80     }
81 } g_test;
82 } // namespace
83