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