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