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