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