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