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 MyPaint {
25 uint32_t color = 0xFF000000;
26 bool isAntiAlias = false;
27 float blurRadius = 0;
28 TexginePaint::Style style = TexginePaint::FILL;
29 float strokeWidth = 0;
30 };
31
ConvertMyPaintToTexginePaint(const MyPaint & data)32 TexginePaint ConvertMyPaintToTexginePaint(const MyPaint& data)
33 {
34 TexginePaint paint;
35 paint.SetAntiAlias(data.isAntiAlias);
36 paint.SetColor(data.color);
37 paint.SetMaskFilter(TexgineMaskFilter::MakeBlur(TexgineMaskFilter::TexgineBlurStyle::K_NORMAL_SK_BLUR_STYLE,
38 data.blurRadius));
39 paint.SetStrokeWidth(data.strokeWidth);
40 paint.SetStyle(data.style);
41 return paint;
42 }
43
44 struct FontStyleTestData {
45 std::string text;
46 TextStyle style;
47 } g_datas[] = {
48 {
49 .text = "无样式",
50 .style = {
51 .fontSize = 32,
52 }
53 },
54 {
55 .text = "前景样式:颜色",
56 .style = {
57 .fontSize = 32,
58 .foreground = ConvertMyPaintToTexginePaint({
59 .color = 0xFF00FF00,
60 }),
61 }
62 },
63 {
64 .text = "前景样式:模糊",
65 .style = {
66 .fontSize = 32,
67 .foreground = ConvertMyPaintToTexginePaint({
68 .blurRadius = 2.0f,
69 }),
70 }
71 },
72 {
73 .text = "背景样式:颜色",
74 .style = {
75 .fontSize = 32,
76 .background = ConvertMyPaintToTexginePaint({
77 .color = 0x5500FF00,
78 }),
79 }
80 },
81 {
82 .text = "背景样式:边框",
83 .style = {
84 .fontSize = 32,
85 .background = ConvertMyPaintToTexginePaint({
86 .color = 0x5500FF00,
87 .style = TexginePaint::STROKE,
88 .strokeWidth = 2.0f,
89 }),
90 }
91 },
92 };
93
94 class FontStyleTest : public TestFeature {
95 public:
FontStyleTest()96 FontStyleTest() : TestFeature("FontStyleTest")
97 {
98 }
99
Layout()100 void Layout()
101 {
102 for (auto& [text, style] : g_datas) {
103 auto builder = TypographyBuilder::Create();
104 builder->PushStyle(style);
105 builder->AppendSpan(text);
106 auto typography = builder->Build();
107 double widthLimit = 300.0;
108 typography->Layout(widthLimit);
109 typographies_.push_back({
110 .typography = typography,
111 });
112 }
113 }
114 } g_test;
115 } // namespace
116