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