• 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/dynamic_file_font_provider.h>
17 #include <texgine/system_font_provider.h>
18 #include <texgine/typography_builder.h>
19 
20 #include "feature_test_framework.h"
21 
22 using namespace OHOS::Rosen::TextEngine;
23 
24 namespace {
25 constexpr auto EXAMPLE_TEXT = "Hello World 1234";
26 
27 struct FontsInfo {
28     std::string path = "";
29     std::string fontFamily;
30     std::string title = "";
31 } g_infos[] = {
32     {
33         .title = "default",
34     },
35     {
36         .path = RESOURCE_PATH_PREFIX "Roboto-Black.ttf",
37         .fontFamily = "Roboto",
38         .title = "Roboto",
39     },
40     {
41         .path = RESOURCE_PATH_PREFIX "NotExists.ttf",
42         .fontFamily = "NotExists",
43         .title = "NotExists",
44     },
45 };
46 
47 class DynamicFontTest : public TestFeature {
48 public:
DynamicFontTest()49     DynamicFontTest() : TestFeature("DynamicFontTest")
50     {
51     }
52 
Layout()53     void Layout()
54     {
55         for (auto &info : g_infos) {
56             TypographyStyle tystyle;
57             auto dfProvider = DynamicFileFontProvider::Create();
58             dfProvider->LoadFont(info.fontFamily, info.path);
59             auto fps = FontProviders::Create();
60             fps->AppendFontProvider(dfProvider);
61             fps->AppendFontProvider(SystemFontProvider::GetInstance());
62             auto builder = TypographyBuilder::Create(tystyle, std::move(fps));
63 
64             TextStyle style;
65             style.fontFamilies = {info.fontFamily};
66             builder->PushStyle(style);
67             builder->AppendSpan(EXAMPLE_TEXT);
68             builder->PopStyle();
69 
70             auto typography = builder->Build();
71             double widthLimit = 300.0;
72             typography->Layout(widthLimit);
73             typographies_.push_back({
74                 .typography = typography,
75                 .comment = info.title,
76             });
77         }
78     }
79 } g_test;
80 } // namespace
81