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