1 /*
2 * Copyright (c) 2025 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_types.h"
17 #include "text/text_blob_builder.h"
18 #include "text/font_mgr.h"
19 #include "text/font.h"
20 #include "recording/mem_allocator.h"
21 #include "text/font_style_set.h"
22 #include "text/rs_xform.h"
23 #include "utils/point.h"
24 #include "utils/rect.h"
25 #include "text/typeface.h"
26 #include "text/font_style.h"
27 #include <sstream>
28
29 namespace OHOS {
30 namespace Rosen {
31
DrawTextBlob(std::vector<std::string> & texts,std::shared_ptr<Drawing::TextBlob> textBlob,Drawing::Font & font1,TestPlaybackCanvas * playbackCanvas)32 static void DrawTextBlob(std::vector<std::string>& texts, std::shared_ptr<Drawing::TextBlob> textBlob,
33 Drawing::Font& font1, TestPlaybackCanvas* playbackCanvas)
34 {
35 int line = 200;
36 int interval1 = 100;
37 int interval2 = 200;
38 int interval3 = 300;
39 int interval4 = 400;
40
41 for (auto text : texts) {
42 std::shared_ptr<Drawing::TextBlob> textinfo = Drawing::TextBlob::MakeFromText(text.c_str(), text.size(), font1);
43 Drawing::Brush brush;
44 playbackCanvas->AttachBrush(brush);
45 playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
46 playbackCanvas->DrawTextBlob(textinfo.get(), interval2, line + interval1);
47 playbackCanvas->DetachBrush();
48 Drawing::Pen pen;
49 playbackCanvas->AttachPen(pen);
50 playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line + interval2);
51 playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line + interval3);
52 playbackCanvas->DetachPen();
53 line += interval4;
54 }
55 }
56
57 // 用例 Font_Scene_Transform_0270
58 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 270)
59 {
60 // 1.创建typeface
61 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
62 std::string familyName = "HMOS Color Emoji";
63 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
64 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
65 // 2.组合typeface操作接口
66 auto familyNamex = typeface->GetFamilyName();
67 std::string typefacestr = "GetFamilyName = " + familyNamex;
68 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
69 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
70 font1.SetSubpixel(false);
71 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
72 auto scalar = font1.UnicharToGlyph(0x44);
73 std::string text4 = "Glyphs = " + std::to_string(scalar);
74
75 // 4.创建TextBlob
76 Drawing::TextBlobBuilder builder;
77 auto buffer = builder.AllocRunRSXform(font1, 20);
78 for (int i = 0; i < 20; i++) {
79 buffer.glyphs[i] = font1.UnicharToGlyph(0x30);
80 buffer.pos[i * 4] = cos(i * 18);
81 buffer.pos[i * 4 + 1] = sin(18 * i);
82 buffer.pos[i * 4 + 2] = 100;
83 buffer.pos[i * 4 + 3] = 100;
84 }
85 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
86
87 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
88 Drawing::Paint paint;
89 paint.SetColor(0xFFFF0000);
90 float boundsx[] = {1, 2, 3};
91 int intercepts = textBlob->GetIntercepts(boundsx, nullptr, &paint);
92 std::string text2 = "intercepts = " + std::to_string(intercepts);
93
94 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
95 std::vector<std::string> texts = {typefacestr, text2, text4};
96
97 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
98 auto rect1 = Drawing::Rect(0, 0, 600, 600);
99 playbackCanvas_->ClipRect(rect1);
100
101 //8.调用Scale,Rotate,ConcatMatrix
102 playbackCanvas_->Translate(400, 600);
103
104 //9.最终绘制
105 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
106 }
107
108 // 用例 Font_Scene_Transform_0271
109 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 271)
110 {
111 // 1.创建typeface
112 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
113 std::string familyName = "HMOS Color Emoji";
114 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
115 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
116 // 2.组合typeface操作接口
117 auto data = typeface->Serialize();
118 uint32_t size = 10;
119 typeface->SetSize(size);
120 std::shared_ptr<Drawing::Typeface> typeface1 = Drawing::Typeface::Deserialize(data->GetData(), typeface->GetSize());
121 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
122 auto font = Drawing::Font(typeface1, 50.f, 1.0f, 1.0f);
123 font.SetSubpixel(false);
124 font.SetHinting(Drawing::FontHinting::NORMAL);
125 auto font1 = Drawing::Font(typeface1, 50.f, 1.0f, 1.0f);
126 font1.SetSubpixel(font.IsSubpixel());
127 font1.SetHinting(font.GetHinting());
128
129 // 4.创建TextBlob
130 std::string textInfo = "";
131 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(
132 textInfo.c_str(), textInfo.size(), font1, Drawing::TextEncoding::UTF8);
133
134 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
135 std::string textinfo1 = "Deserialize @Hello World";
136 Drawing::TextBlob::Context* Ctx = new (std::nothrow) Drawing::TextBlob::Context(typeface, false);
137 auto data2 = textBlob->Serialize(Ctx);
138 std::shared_ptr<Drawing::TextBlob> infoTextBlob2 =
139 Drawing::TextBlob::Deserialize(data2->GetData(), data2->GetSize(), Ctx);
140
141 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
142 std::vector<std::string> texts = {};
143
144 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
145
146 //8.调用Scale,Rotate,ConcatMatrix
147 Drawing::Matrix matrix;
148 playbackCanvas_->ConcatMatrix(matrix);
149 playbackCanvas_->Rotate(45, 50, 50);
150 playbackCanvas_->Translate(400, 600);
151
152 //9.最终绘制
153 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
154 }
155
156 // 用例 Font_Scene_Transform_0272
157 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 272)
158 {
159 // 1.创建typeface
160 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
161 std::string familyName = "HMOS Color Emoji";
162 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
163 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
164 // 2.组合typeface操作接口
165 std::string typefacestr = "GetItalic = " + std::to_string(typeface->GetItalic());
166 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
167 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
168 font.SetSubpixel(false);
169 font.SetScaleX(1);
170 auto font1 = Drawing::Font(typeface, 50.f, font.GetScaleX(), 1.0f);
171 font1.SetSubpixel(font.IsSubpixel());
172
173 // 4.创建TextBlob
174 std::string textInfo = "";
175 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(
176 textInfo.c_str(), textInfo.size(), font1, Drawing::TextEncoding::UTF8);
177
178 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
179 std::string text = "harmony_os";
180 std::vector<uint16_t> glyphid;
181 Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
182 playbackCanvas_->Translate(200, 200);
183 for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
184 auto path = Drawing::TextBlob::GetDrawingPathforTextBlob(glyphid[row], textBlob.get());
185 playbackCanvas_->DrawPath(path);
186 playbackCanvas_->Translate(0, 100);
187 }
188
189 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
190 std::vector<std::string> texts = {typefacestr};
191
192 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
193 Drawing::Path path;
194 path.AddOval({100, 100, 356, 356});
195 playbackCanvas_->ClipPath(path);
196
197 //8.调用Scale,Rotate,ConcatMatrix
198 playbackCanvas_->Scale(0.5, 0.5);
199 playbackCanvas_->Translate(400, 600);
200
201 //9.最终绘制
202 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
203 }
204
205 // 用例 Font_Scene_Transform_0274
206 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 274)
207 {
208 // 1.创建typeface
209 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
210 std::string familyName = "HMOS Color Emoji";
211 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
212 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
213 // 2.组合typeface操作接口
214 auto familyNamex = typeface->GetFamilyName();
215 std::string typefacestr = "GetFamilyName = " + familyNamex;
216 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
217 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
218 font.SetSubpixel(false);
219 font.SetEmbeddedBitmaps(true);
220 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
221 font1.SetSubpixel(font.IsSubpixel());
222 font1.SetEmbeddedBitmaps(font.IsEmbeddedBitmaps());
223
224 // 4.创建TextBlob
225 std::string textInfo = "harmony_os";
226 int cont = textInfo.size();
227 Drawing::Point p[cont];
228 for (int i = 0; i < cont; i++) {
229 p[i].SetX(-100 + 50 * i);
230 p[i].SetY(1000 - 50 * i);
231 }
232 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
233 textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
234
235 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
236 std::string name1 = "HMOS Color Emoji";
237 std::string textInfo1 = "";
238 std::shared_ptr<Drawing::TextBlob> textBlob1 = Drawing::TextBlob::MakeFromText(textInfo1.c_str(),
239 textInfo1.size(), font1, Drawing::TextEncoding::UTF8);
240 if (textBlob1->IsEmoji()) {
241 playbackCanvas_->DrawBackground(0xFF0000FF);
242 } else {
243 playbackCanvas_->DrawBackground(0xFFFF0000);
244 }
245
246 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
247 std::vector<std::string> texts = {typefacestr};
248
249 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
250 auto rect1 = Drawing::Rect(0, 0, 600, 600);
251 playbackCanvas_->ClipRect(rect1);
252
253 //8.调用Scale,Rotate,ConcatMatrix
254 playbackCanvas_->Scale(0.5, 0.5);
255
256 //9.最终绘制
257 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
258 }
259
260 // 用例 Font_Scene_Transform_0275
261 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 275)
262 {
263 // 1.创建typeface
264 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
265 std::string familyName = "HMOS Color Emoji";
266 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
267 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
268 // 2.组合typeface操作接口
269 std::string typefacestr = "GetUniqueID = " + std::to_string(typeface->GetUniqueID());
270 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
271 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
272 font.SetSubpixel(false);
273 font.SetSkewX(1.0f);
274 auto font1 = Drawing::Font(typeface, 50.f, font.GetSkewX(), 1.0f);
275 font1.SetSubpixel(font.IsSubpixel());
276
277 // 4.创建TextBlob
278 std::string textInfo = "harmony_os";
279 int cont = textInfo.size();
280 Drawing::Point p[cont];
281 for (int i = 0; i < cont; i++) {
282 p[i].SetX(-100 + 50 * i);
283 p[i].SetY(1000 - 50 * i);
284 }
285 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
286 textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
287
288 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
289 std::vector<Drawing::Point> points;
290 Drawing::TextBlob::GetDrawingPointsForTextBlob(textBlob.get(), points);
291 std::string text2 = "";
292 for (int i = 0; i < points.size(); i++) {
293 text2 += std::to_string(i) + "-- X:" + std::to_string(points[i].GetX())
294 + "Y:" + std::to_string(points[i].GetY());
295 }
296
297 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
298 std::vector<std::string> texts = {typefacestr, text2};
299
300 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
301 auto rrect = Drawing::RoundRect(Drawing::Rect(0, 0, 1000, 1000), 52, 52);
302 playbackCanvas_->ClipRoundRect(rrect);
303
304 //8.调用Scale,Rotate,ConcatMatrix
305 Drawing::Matrix matrix;
306 playbackCanvas_->ConcatMatrix(matrix);
307 playbackCanvas_->Rotate(45, 50, 50);
308 playbackCanvas_->Scale(0.5, 0.5);
309
310 //9.最终绘制
311 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
312 }
313
314 // 用例 Font_Scene_Transform_0276
315 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 276)
316 {
317 // 1.创建typeface
318 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
319 std::string familyName = "HMOS Color Emoji";
320 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
321 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
322 // 2.组合typeface操作接口
323 std::string str = "CPAL";
324 reverse(str.begin(), str.end());
325 uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(str.c_str())));
326 std::string typefacestr = "GetTableSize = " + std::to_string(typeface->GetTableSize(tagid));
327 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
328 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
329 font1.SetSubpixel(false);
330 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
331 Drawing::Rect bounds;
332 auto scalar = font1.MeasureText(text0.c_str(), text0.length(), Drawing::TextEncoding::UTF32, &bounds);
333 std::string text4 = "MeasureTextWidths = " + std::to_string(scalar);
334
335 // 4.创建TextBlob
336 std::string textInfo = "harmony_os";
337 int cont = textInfo.size();
338 Drawing::Point p[cont];
339 for (int i = 0; i < cont; i++) {
340 p[i].SetX(-100 + 50 * i);
341 p[i].SetY(1000 - 50 * i);
342 }
343 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
344 textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
345
346 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
347 std::string text = "harmony_os";
348 std::vector<uint16_t> glyphid;
349 Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
350 playbackCanvas_->Translate(200, 200);
351 for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
352 auto path = Drawing::TextBlob::GetDrawingPathforTextBlob(glyphid[row], textBlob.get());
353 playbackCanvas_->DrawPath(path);
354 playbackCanvas_->Translate(0, 100);
355 }
356
357 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
358 std::vector<std::string> texts = {typefacestr, text4};
359
360 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
361 auto rrect = Drawing::RoundRect(Drawing::Rect(0, 0, 1000, 1000), 52, 52);
362 playbackCanvas_->ClipRoundRect(rrect);
363
364 //8.调用Scale,Rotate,ConcatMatrix
365
366 //9.最终绘制
367 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
368 }
369
370 // 用例 Font_Scene_Transform_0277
371 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 277)
372 {
373 // 1.创建typeface
374 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
375 std::string familyName = "HMOS Color Emoji";
376 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
377 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
378 // 2.组合typeface操作接口
379 auto familyNamex = typeface->GetFamilyName();
380 std::string typefacestr = "GetFamilyName = " + familyNamex;
381 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
382 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
383 font.SetSubpixel(false);
384 font.SetTypeface(typeface);
385 auto font1 = Drawing::Font(font.GetTypeface(), 50.f, 1.0f, 1.0f);
386 font1.SetSubpixel(font.IsSubpixel());
387
388 // 4.创建TextBlob
389 std::string textInfo = "harmony_os";
390 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromString(
391 textInfo.c_str(), font1, Drawing::TextEncoding::UTF8);
392
393 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
394 std::string text = "harmony_os";
395 std::vector<uint16_t> glyphid;
396 Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
397 std::string text2 = "";
398 for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
399 text2 += std::string(1, text[row]) + ":" + std::to_string(glyphid[row]);
400 }
401
402 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
403 std::vector<std::string> texts = {typefacestr, text2};
404
405 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
406 auto rrect = Drawing::RoundRect(Drawing::Rect(0, 0, 1000, 1000), 52, 52);
407 playbackCanvas_->ClipRoundRect(rrect);
408
409 //8.调用Scale,Rotate,ConcatMatrix
410 playbackCanvas_->Rotate(45, 50, 50);
411 playbackCanvas_->Scale(0.5, 0.5);
412
413 //9.最终绘制
414 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
415 }
416
417 // 用例 Font_Scene_Transform_0278
418 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 278)
419 {
420 // 1.创建typeface
421 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
422 std::string familyName = "HMOS Color Emoji";
423 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
424 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
425 // 2.组合typeface操作接口
426 std::string typefacestr = "GetUnitsPerEm = " + std::to_string(typeface->GetUnitsPerEm());
427 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
428 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
429 font.SetSubpixel(false);
430 font.SetLinearMetrics(false);
431 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
432 font1.SetSubpixel(font.IsSubpixel());
433 font1.SetLinearMetrics(font.IsLinearMetrics());
434
435 // 4.创建TextBlob
436 std::string textInfo = "harmony_os";
437 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromString(
438 textInfo.c_str(), font1, Drawing::TextEncoding::UTF8);
439
440 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
441 auto rect = textBlob->Bounds();
442 playbackCanvas_->DrawRect(*rect);
443
444 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
445 std::vector<std::string> texts = {typefacestr};
446
447 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
448 Drawing::Region region;
449 region.SetRect(Drawing::RectI(100, 100, 500, 500));
450 playbackCanvas_->ClipRegion(region);
451
452 //8.调用Scale,Rotate,ConcatMatrix
453 Drawing::Matrix matrix;
454 playbackCanvas_->ConcatMatrix(matrix);
455 playbackCanvas_->Rotate(45, 50, 50);
456 playbackCanvas_->Translate(400, 600);
457
458 //9.最终绘制
459 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
460 }
461
462 // 用例 Font_Scene_Transform_0279
463 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 279)
464 {
465 // 1.创建typeface
466 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
467 std::string familyName = "HMOS Color Emoji";
468 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
469 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
470 // 2.组合typeface操作接口
471 std::string s = "011c50";
472 int a;
473 std::stringstream ss;
474 ss<<std::hex<<s;
475 ss>>a;
476 uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(s.c_str())));
477 std::string typefacestr = "GetTableData = "
478 + std::to_string(typeface->GetTableData(tagid, a, typeface->GetTableSize(tagid), nullptr));
479 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
480 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
481 font1.SetSubpixel(false);
482 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
483 auto SpaceLine = font1.MeasureSingleCharacter(0x44);
484 std::string text4 = "Recommended spacing between lines = " + std::to_string(SpaceLine);
485
486 // 4.创建TextBlob
487 std::string textInfo = "harmony_os";
488 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromString(
489 textInfo.c_str(), font1, Drawing::TextEncoding::UTF8);
490
491 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
492 std::vector<Drawing::Point> points;
493 Drawing::TextBlob::GetDrawingPointsForTextBlob(textBlob.get(), points);
494 std::string text2 = "";
495 for (int i = 0; i < points.size(); i++) {
496 text2 += std::to_string(i) + "-- X:" + std::to_string(points[i].GetX())
497 + "Y:" + std::to_string(points[i].GetY());
498 }
499
500 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
501 std::vector<std::string> texts = {typefacestr, text2, text4};
502
503 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
504 Drawing::Region region;
505 region.SetRect(Drawing::RectI(100, 100, 500, 500));
506 playbackCanvas_->ClipRegion(region);
507
508 //8.调用Scale,Rotate,ConcatMatrix
509 playbackCanvas_->Translate(400, 600);
510
511 //9.最终绘制
512 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
513 }
514
515 // 用例 Font_Scene_Transform_0281
516 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 281)
517 {
518 // 1.创建typeface
519 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
520 std::string familyName = "HMOS Color Emoji";
521 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
522 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
523 // 2.组合typeface操作接口
524 typeface->SetHash(100);
525 std::string typefacestr = "GetHash = " + std::to_string(typeface->GetHash());;
526 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
527 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
528 font1.SetSubpixel(false);
529 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
530 Drawing::FontMetrics metrics;
531 auto SpaceLine = font1.GetMetrics(&metrics);
532 std::string text4 = "Recommended spacing between lines = " + std::to_string(SpaceLine);
533
534 // 4.创建TextBlob
535 std::string textInfo = "1111111111111111111111111111111111";
536 int maxGlyphCount = font1.CountText(textInfo.c_str(), textInfo.size(), Drawing::TextEncoding::UTF8);
537 Drawing::RSXform xform[maxGlyphCount];
538 for (int i = 0; i < maxGlyphCount; ++i) {
539 xform[i].cos_ = cos(10 * i) + 0.1 * i;
540 xform[i].sin_ = sin(10 * i);
541 xform[i].tx_ = 40 * i + 100;;
542 xform[i].ty_ = 100;
543 }
544 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromRSXform(
545 textInfo.c_str(), textInfo.size(), &xform[0], font1, Drawing::TextEncoding::UTF8);
546
547 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
548 std::string textinfo1 = "Deserialize @Hello World";
549 Drawing::TextBlob::Context* Ctx = new (std::nothrow) Drawing::TextBlob::Context(typeface, false);
550 auto data2 = textBlob->Serialize(Ctx);
551 std::shared_ptr<Drawing::TextBlob> infoTextBlob2 =
552 Drawing::TextBlob::Deserialize(data2->GetData(), data2->GetSize(), Ctx);
553
554 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
555 std::vector<std::string> texts = {typefacestr, text4};
556
557 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
558
559 //8.调用Scale,Rotate,ConcatMatrix
560 Drawing::Matrix matrix;
561 playbackCanvas_->ConcatMatrix(matrix);
562 playbackCanvas_->Scale(0.5, 0.5);
563
564 //9.最终绘制
565 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
566 }
567
568 // 用例 Font_Scene_Transform_0282
569 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 282)
570 {
571 // 1.创建typeface
572 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
573 std::string familyName = "HMOS Color Emoji";
574 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
575 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
576 // 2.组合typeface操作接口
577 std::string typefacestr = "GetItalic = " + std::to_string(typeface->GetItalic());
578 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
579 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
580 font1.SetSubpixel(false);
581 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
582 auto glyphsCount = font1.CountText(text0.c_str(), text0.length(), Drawing::TextEncoding::GLYPH_ID);
583 std::string text4 = "glyphsCount = " + std::to_string(glyphsCount);
584
585 // 4.创建TextBlob
586 std::string textInfo = "1111111111111111111111111111111111";
587 int maxGlyphCount = font1.CountText(textInfo.c_str(), textInfo.size(), Drawing::TextEncoding::UTF8);
588 Drawing::RSXform xform[maxGlyphCount];
589 for (int i = 0; i < maxGlyphCount; ++i) {
590 xform[i].cos_ = cos(10 * i) + 0.1 * i;
591 xform[i].sin_ = sin(10 * i);
592 xform[i].tx_ = 40 * i + 100;;
593 xform[i].ty_ = 100;
594 }
595 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromRSXform(
596 textInfo.c_str(), textInfo.size(), &xform[0], font1, Drawing::TextEncoding::UTF8);
597
598 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
599 auto rect = textBlob->Bounds();
600 playbackCanvas_->DrawRect(*rect);
601
602 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
603 std::vector<std::string> texts = {typefacestr, text4};
604
605 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
606
607 //8.调用Scale,Rotate,ConcatMatrix
608 Drawing::Matrix matrix;
609 playbackCanvas_->ConcatMatrix(matrix);
610 playbackCanvas_->Rotate(45, 50, 50);
611
612 //9.最终绘制
613 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
614 }
615
616 // 用例 Font_Scene_Transform_0284
617 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 284)
618 {
619 // 1.创建typeface
620 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
621 std::string familyName = "HMOS Color Emoji";
622 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
623 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
624 Drawing::FontStyle::INVISIBLE_WEIGHT,
625 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
626 Drawing::FontStyle::OBLIQUE_SLANT}));
627 // 2.组合typeface操作接口
628 std::string typefacestr = "IsCustomTypeface = " + std::to_string(typeface->IsCustomTypeface());
629 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
630 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
631 font.SetSubpixel(false);
632 font.SetSize(100.f);
633 auto font1 = Drawing::Font(typeface, font.GetSize(), 1.0f, 1.0f);
634 font1.SetSubpixel(font.IsSubpixel());
635
636 // 4.创建TextBlob
637 Drawing::TextBlobBuilder builder;
638 auto buffer = builder.AllocRunPos(font1, 20, nullptr);
639 for (int i = 0; i < 20; i++) {
640 buffer.glyphs[i] = font1.UnicharToGlyph(0x9088);
641 buffer.pos[i * 2] = 50.f * i;
642 buffer.pos[i * 2 + 1] = 0;
643 }
644 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
645
646 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
647 std::vector<Drawing::Point> points;
648 Drawing::TextBlob::GetDrawingPointsForTextBlob(textBlob.get(), points);
649 std::string text2 = "";
650 for (int i = 0; i < points.size(); i++) {
651 text2 += std::to_string(i) + "-- X:" + std::to_string(points[i].GetX())
652 + "Y:" + std::to_string(points[i].GetY());
653 }
654
655 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
656 std::vector<std::string> texts = {typefacestr, text2};
657
658 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
659 auto rect1 = Drawing::RectI(0, 0, 1000, 1000);
660 playbackCanvas_->ClipIRect(rect1, Drawing::ClipOp::INTERSECT);
661
662 //8.调用Scale,Rotate,ConcatMatrix
663 playbackCanvas_->Scale(0.5, 0.5);
664 playbackCanvas_->Translate(400, 600);
665
666 //9.最终绘制
667 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
668 }
669
670 // 用例 Font_Scene_Transform_0285
671 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 285)
672 {
673 // 1.创建typeface
674 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
675 std::string familyName = "HMOS Color Emoji";
676 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
677 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
678 Drawing::FontStyle::INVISIBLE_WEIGHT,
679 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
680 Drawing::FontStyle::OBLIQUE_SLANT}));
681 // 2.组合typeface操作接口
682 std::string str = "CPAL";
683 reverse(str.begin(), str.end());
684 uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(str.c_str())));
685 std::string typefacestr = "GetTableSize = " + std::to_string(typeface->GetTableSize(tagid));
686 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
687 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
688 font.SetSubpixel(false);
689 font.SetEmbolden(false);
690 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
691 font1.SetSubpixel(font.IsSubpixel());
692 font1.SetEmbolden(font.IsEmbolden());
693
694 // 4.创建TextBlob
695 Drawing::TextBlobBuilder builder;
696 auto buffer = builder.AllocRunPos(font1, 20, nullptr);
697 for (int i = 0; i < 20; i++) {
698 buffer.glyphs[i] = font1.UnicharToGlyph(0x9088);
699 buffer.pos[i * 2] = 50.f * i;
700 buffer.pos[i * 2 + 1] = 0;
701 }
702 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
703
704 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
705 std::string text = "harmony_os";
706 std::vector<uint16_t> glyphid;
707 Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
708 std::string text2 = "";
709 for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
710 text2 += std::string(1, text[row]) + ":" + std::to_string(glyphid[row]);
711 }
712
713 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
714 std::vector<std::string> texts = {typefacestr, text2};
715
716 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
717
718 //8.调用Scale,Rotate,ConcatMatrix
719 playbackCanvas_->Translate(400, 600);
720
721 //9.最终绘制
722 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
723 }
724
725 // 用例 Font_Scene_Transform_0286
726 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 286)
727 {
728 // 1.创建typeface
729 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
730 std::string familyName = "HMOS Color Emoji";
731 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
732 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
733 Drawing::FontStyle::INVISIBLE_WEIGHT,
734 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
735 Drawing::FontStyle::OBLIQUE_SLANT}));
736 // 2.组合typeface操作接口
737 std::string s = "011c50";
738 int a;
739 std::stringstream ss;
740 ss<<std::hex<<s;
741 ss>>a;
742 uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(s.c_str())));
743 std::string typefacestr = "GetTableData = "
744 + std::to_string(typeface->GetTableData(tagid, a, typeface->GetTableSize(tagid), nullptr));
745 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
746 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
747 font.SetSubpixel(false);
748 font.SetBaselineSnap(true);
749 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
750 font1.SetSubpixel(font.IsSubpixel());
751 font1.SetBaselineSnap(font.IsBaselineSnap());
752
753 // 4.创建TextBlob
754 Drawing::TextBlobBuilder builder;
755 auto buffer = builder.AllocRunRSXform(font1, 20);
756 for (int i = 0; i < 20; i++) {
757 buffer.glyphs[i] = font1.UnicharToGlyph(0x30);
758 buffer.pos[i * 4] = cos(i * 18);
759 buffer.pos[i * 4 + 1] = sin(18 * i);
760 buffer.pos[i * 4 + 2] = 100;
761 buffer.pos[i * 4 + 3] = 100;
762 }
763 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
764
765 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
766 std::string textinfo1 = "Deserialize @Hello World";
767 Drawing::TextBlob::Context* Ctx = new (std::nothrow) Drawing::TextBlob::Context(typeface, false);
768 auto data2 = textBlob->Serialize(Ctx);
769 std::shared_ptr<Drawing::TextBlob> infoTextBlob2 =
770 Drawing::TextBlob::Deserialize(data2->GetData(), data2->GetSize(), Ctx);
771
772 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
773 std::vector<std::string> texts = {typefacestr};
774
775 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
776 auto rect1 = Drawing::Rect(0, 0, 600, 600);
777 playbackCanvas_->ClipRect(rect1);
778
779 //8.调用Scale,Rotate,ConcatMatrix
780 Drawing::Matrix matrix;
781 playbackCanvas_->ConcatMatrix(matrix);
782 playbackCanvas_->Rotate(45, 50, 50);
783 playbackCanvas_->Scale(0.5, 0.5);
784
785 //9.最终绘制
786 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
787 }
788
789 // 用例 Font_Scene_Transform_0287
790 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 287)
791 {
792 // 1.创建typeface
793 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
794 std::string familyName = "HMOS Color Emoji";
795 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
796 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
797 Drawing::FontStyle::INVISIBLE_WEIGHT,
798 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
799 Drawing::FontStyle::OBLIQUE_SLANT}));
800 // 2.组合typeface操作接口
801 std::string typefacestr = "GetUniqueID = " + std::to_string(typeface->GetUniqueID());
802 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
803 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
804 font.SetSubpixel(false);
805 font.SetScaleX(1);
806 auto font1 = Drawing::Font(typeface, 50.f, font.GetScaleX(), 1.0f);
807 font1.SetSubpixel(font.IsSubpixel());
808
809 // 4.创建TextBlob
810 Drawing::TextBlobBuilder builder;
811 auto buffer = builder.AllocRunRSXform(font1, 20);
812 for (int i = 0; i < 20; i++) {
813 buffer.glyphs[i] = font1.UnicharToGlyph(0x30);
814 buffer.pos[i * 4] = cos(i * 18);
815 buffer.pos[i * 4 + 1] = sin(18 * i);
816 buffer.pos[i * 4 + 2] = 100;
817 buffer.pos[i * 4 + 3] = 100;
818 }
819 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
820
821 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
822 std::string text = "harmony_os";
823 std::vector<uint16_t> glyphid;
824 Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
825 playbackCanvas_->Translate(200, 200);
826 for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
827 auto path = Drawing::TextBlob::GetDrawingPathforTextBlob(glyphid[row], textBlob.get());
828 playbackCanvas_->DrawPath(path);
829 playbackCanvas_->Translate(0, 100);
830 }
831
832 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
833 std::vector<std::string> texts = {typefacestr};
834
835 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
836 Drawing::Region region;
837 region.SetRect(Drawing::RectI(100, 100, 500, 500));
838 playbackCanvas_->ClipRegion(region);
839
840 //8.调用Scale,Rotate,ConcatMatrix
841 Drawing::Matrix matrix;
842 playbackCanvas_->ConcatMatrix(matrix);
843
844 //9.最终绘制
845 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
846 }
847
848 // 用例 Font_Scene_Transform_0288
849 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 288)
850 {
851 // 1.创建typeface
852 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
853 std::string familyName = "HMOS Color Emoji";
854 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
855 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
856 Drawing::FontStyle::INVISIBLE_WEIGHT,
857 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
858 Drawing::FontStyle::OBLIQUE_SLANT}));
859 // 2.组合typeface操作接口
860 typeface->SetHash(100);
861 std::string typefacestr = "GetHash = " + std::to_string(typeface->GetHash());;
862 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
863 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
864 font1.SetSubpixel(false);
865 std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
866 auto scalar = font1.UnicharToGlyph(0x44);
867 std::string text4 = "Glyphs = " + std::to_string(scalar);
868
869 // 4.创建TextBlob
870 Drawing::TextBlobBuilder builder;
871 auto buffer = builder.AllocRunRSXform(font1, 20);
872 for (int i = 0; i < 20; i++) {
873 buffer.glyphs[i] = font1.UnicharToGlyph(0x30);
874 buffer.pos[i * 4] = cos(i * 18);
875 buffer.pos[i * 4 + 1] = sin(18 * i);
876 buffer.pos[i * 4 + 2] = 100;
877 buffer.pos[i * 4 + 3] = 100;
878 }
879 std::shared_ptr<Drawing::TextBlob> textBlob = builder.Make();
880
881 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
882 auto rect = textBlob->Bounds();
883 playbackCanvas_->DrawRect(*rect);
884
885 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
886 std::vector<std::string> texts = {typefacestr, text4};
887
888 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
889 auto rect1 = Drawing::Rect(0, 0, 600, 600);
890 playbackCanvas_->ClipRect(rect1);
891
892 //8.调用Scale,Rotate,ConcatMatrix
893 Drawing::Matrix matrix;
894 playbackCanvas_->ConcatMatrix(matrix);
895 playbackCanvas_->Scale(0.5, 0.5);
896 playbackCanvas_->Translate(400, 600);
897
898 //9.最终绘制
899 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
900 }
901
902 // 用例 Font_Scene_Transform_0289
903 DEF_DTK(Font_Scene_Transform_15, TestLevel::L2, 289)
904 {
905 // 1.创建typeface
906 std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
907 std::string familyName = "HMOS Color Emoji";
908 std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->MatchFamily(familyName.c_str()));
909 auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
910 Drawing::FontStyle::INVISIBLE_WEIGHT,
911 Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
912 Drawing::FontStyle::OBLIQUE_SLANT}));
913 // 2.组合typeface操作接口
914 std::string typefacestr = "GetItalic = " + std::to_string(typeface->GetItalic());
915 // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
916 auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
917 font.SetSubpixel(false);
918 font.SetForceAutoHinting(false);
919 auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
920 font1.SetSubpixel(font.IsSubpixel());
921 font1.SetForceAutoHinting(font.IsForceAutoHinting());
922
923 // 4.创建TextBlob
924 std::string textInfo = "";
925 std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(
926 textInfo.c_str(), textInfo.size(), font1, Drawing::TextEncoding::UTF8);
927
928 // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
929 std::string name1 = "HMOS Color Emoji";
930 std::string textInfo1 = "";
931 std::shared_ptr<Drawing::TextBlob> textBlob1 = Drawing::TextBlob::MakeFromText(textInfo1.c_str(),
932 textInfo1.size(), font1, Drawing::TextEncoding::UTF8);
933 if (textBlob1->IsEmoji()) {
934 playbackCanvas_->DrawBackground(0xFF0000FF);
935 } else {
936 playbackCanvas_->DrawBackground(0xFFFF0000);
937 }
938
939 //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
940 std::vector<std::string> texts = {typefacestr};
941
942 //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
943 Drawing::Path path;
944 path.AddOval({100, 100, 356, 356});
945 playbackCanvas_->ClipPath(path);
946
947 //8.调用Scale,Rotate,ConcatMatrix
948 Drawing::Matrix matrix;
949 playbackCanvas_->ConcatMatrix(matrix);
950 playbackCanvas_->Rotate(45, 50, 50);
951 playbackCanvas_->Scale(0.5, 0.5);
952 playbackCanvas_->Translate(400, 600);
953
954 //9.最终绘制
955 DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
956 }
957
958 }
959 }
960