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