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