• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "../../dtk_test_ext.h"
16 #include "text/font.h"
17 #include "recording/mem_allocator.h"
18 #include "text/font_mgr.h"
19 #include "text/font_style_set.h"
20 #include "text/rs_xform.h"
21 #include "utils/point.h"
22 #include "utils/rect.h"
23 #include "text/typeface.h"
24 
25 /*
26 测试类:FontMgr
27 测试接口:MatchFamilyStyle
28 测试内容:对接口入参familyName和fontStyle取组合,构造typeface字体格式,并指定在font上,最终通过drawtextblob接口将text内容绘制在画布上
29 */
30 namespace OHOS {
31 namespace Rosen {
32 
CommonMatchfamilystyle(TestPlaybackCanvas * playbackCanvas,std::shared_ptr<Drawing::FontMgr> fontMgr,bool bSlant,std::string familyName)33 void CommonMatchfamilystyle(TestPlaybackCanvas* playbackCanvas,
34                             std::shared_ptr<Drawing::FontMgr> fontMgr,
35                             bool bSlant,
36                             std::string familyName)
37 {
38     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
39     std::string styleName = "";
40     Drawing::FontStyle fontStyle;
41     fontStyleSet->GetStyle(0, &fontStyle, &styleName);
42     if (bSlant) {
43         fontStyle = Drawing::FontStyle{fontStyle.GetWeight(), fontStyle.GetWidth(), Drawing::FontStyle::OBLIQUE_SLANT};
44     }
45     if (familyName == "get") {
46         fontMgr->GetFamilyName(0, familyName);
47     }
48     auto typeface = std::shared_ptr<Drawing::Typeface>(fontMgr->MatchFamilyStyle(familyName.c_str(), fontStyle));
49 
50     auto font = Drawing::Font(typeface, 50.f, 1.0f, 0.f);
51     std::string text1 = "DDGR ddgr 鸿蒙 !@#%¥^&*;:,。";
52     std::string text2 = "-_=+()123`.---~|{}【】,./?、?<>《》";
53     std::string text3 = "\xE2\x99\x88\xE2\x99\x8A\xE2\x99\x88\xE2\x99\x8C\xE2\x99\x8D\xE2\x99\x8D";
54     std::string texts[] = {text1, text2, text3};
55     int line = 200;
56     int interval2 = 200;
57     for (auto text :texts) {
58         std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(text.c_str(), text.size(), font);
59         Drawing::Brush brush;
60         playbackCanvas->AttachBrush(brush);
61         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
62         line += interval2;
63         playbackCanvas->DetachBrush();
64         Drawing::Pen pen;
65         playbackCanvas->AttachPen(pen);
66         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
67         line += interval2;
68         playbackCanvas->DetachPen();
69     }
70 }
71 
72 //对应用例 FontMgr_MatchFamilyStyle_3001
73 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 1)
74 {
75     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
76     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "abcd");
77 }
78 
79 //对应用例 FontMgr_MatchFamilyStyle_3002
80 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 2)
81 {
82     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
83     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "HMOS Color Emoji");
84 }
85 
86 //对应用例 FontMgr_MatchFamilyStyle_3003
87 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 3)
88 {
89     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
90     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "get");
91 }
92 
93 //对应用例 FontMgr_MatchFamilyStyle_3004
94 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 4)
95 {
96     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
97     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "get");
98 }
99 
100 //对应用例 FontMgr_MatchFamilyStyle_3005
101 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 5)
102 {
103     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
104     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "abcd");
105 }
106 
107 //对应用例 FontMgr_MatchFamilyStyle_3006
108 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 6)
109 {
110     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
111     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "abcd");
112 }
113 
114 //对应用例 FontMgr_MatchFamilyStyle_3007
115 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 7)
116 {
117     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
118     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "get");
119 }
120 
121 //对应用例 FontMgr_MatchFamilyStyle_3008
122 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 8)
123 {
124     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
125     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "HMOS Color Emoji");
126 }
127 
128 //对应用例 FontMgr_MatchFamilyStyle_3009
129 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 9)
130 {
131     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
132     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "");
133 }
134 
135 //对应用例 FontMgr_MatchFamilyStyle_3010
136 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 10)
137 {
138     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
139     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "HMOS Color Emoji");
140 }
141 
142 //对应用例 FontMgr_MatchFamilyStyle_3011
143 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 11)
144 {
145     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
146     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "");
147 }
148 
149 //对应用例 FontMgr_MatchFamilyStyle_3012
150 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 12)
151 {
152     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
153     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "get");
154 }
155 
156 //对应用例 FontMgr_MatchFamilyStyle_3013
157 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 13)
158 {
159     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
160     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "");
161 }
162 
163 //对应用例 FontMgr_MatchFamilyStyle_3014
164 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 14)
165 {
166     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
167     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "abcd");
168 }
169 
170 //对应用例 FontMgr_MatchFamilyStyle_3015
171 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 15)
172 {
173     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
174     CommonMatchfamilystyle(playbackCanvas_, fontMgr, true, "HMOS Color Emoji");
175 }
176 
177 //对应用例 FontMgr_MatchFamilyStyle_3016
178 DEF_DTK(fontmgr_matchfamilystyle, TestLevel::L1, 16)
179 {
180     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
181     CommonMatchfamilystyle(playbackCanvas_, fontMgr, false, "");
182 }
183 
184 }
185 }
186