• 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_0326
58 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 326)
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.SetEmbolden(false);
76     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
77     font1.SetSubpixel(font.IsSubpixel());
78     font1.SetEmbolden(font.IsEmbolden());
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 name1 = "HMOS Color Emoji";
87     std::string textInfo1 = "����������������������";
88     std::shared_ptr<Drawing::TextBlob> textBlob1 = Drawing::TextBlob::MakeFromText(textInfo1.c_str(),
89                                                       textInfo1.size(), font1, Drawing::TextEncoding::UTF8);
90     if (textBlob1->IsEmoji()) {
91         playbackCanvas_->DrawBackground(0xFF0000FF);
92     } else {
93         playbackCanvas_->DrawBackground(0xFFFF0000);
94     }
95 
96     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
97     std::vector<std::string> texts = {typefacestr};
98 
99     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
100     auto rect1 = Drawing::RectI(0, 0, 1000, 1000);
101     playbackCanvas_->ClipIRect(rect1, Drawing::ClipOp::INTERSECT);
102 
103     //8.调用Scale,Rotate,ConcatMatrix
104     playbackCanvas_->Rotate(45, 50, 50);
105 
106     //9.最终绘制
107     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
108 }
109 
110 // 用例 Font_Scene_Transform_0327
111 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 327)
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 = "IsCustomTypeface = " + std::to_string(typeface->IsCustomTypeface());
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     std::string textinfo1 = "Deserialize @Hello World";
136     Drawing::TextBlob::Context* Ctx = new (std::nothrow) Drawing::TextBlob::Context(typeface, false);
137     auto data2 = textBlob->Serialize(Ctx);
138     std::shared_ptr<Drawing::TextBlob> infoTextBlob2 =
139         Drawing::TextBlob::Deserialize(data2->GetData(), data2->GetSize(), Ctx);
140 
141     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
142     std::vector<std::string> texts = {typefacestr};
143 
144     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
145     Drawing::Region region;
146     region.SetRect(Drawing::RectI(100, 100, 500, 500));
147     playbackCanvas_->ClipRegion(region);
148 
149     //8.调用Scale,Rotate,ConcatMatrix
150     playbackCanvas_->Rotate(45, 50, 50);
151     playbackCanvas_->Scale(0.5, 0.5);
152     playbackCanvas_->Translate(400, 600);
153 
154     //9.最终绘制
155     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
156 }
157 
158 // 用例 Font_Scene_Transform_0328
159 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 328)
160 {
161     // 1.创建typeface
162     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
163     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
164     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
165         Drawing::FontStyle::INVISIBLE_WEIGHT,
166         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
167         Drawing::FontStyle::OBLIQUE_SLANT}));
168     // 2.组合typeface操作接口
169     std::string typefacestr = "GetUniqueID = " + std::to_string(typeface->GetUniqueID());
170     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
171     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
172     font1.SetSubpixel(false);
173     std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
174     int glyphCount = font1.CountText(text0.c_str(), text0.length(), Drawing::TextEncoding::UTF16);
175     uint16_t glyphs[glyphCount - 1];
176     int count = font1.TextToGlyphs(text0.c_str(), text0.length(), Drawing::TextEncoding::UTF16, glyphs, glyphCount + 1);
177     std::string text4 = "TextToGlyphs = " + std::to_string(count);
178 
179     // 4.创建TextBlob
180     std::string textInfo = "����������������������";
181     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(
182         textInfo.c_str(), textInfo.size(), font1, Drawing::TextEncoding::UTF8);
183 
184     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
185     std::string textinfo1 = "Deserialize @Hello World";
186     Drawing::TextBlob::Context* Ctx = new (std::nothrow) Drawing::TextBlob::Context(typeface, false);
187     auto data2 = textBlob->Serialize(Ctx);
188     std::shared_ptr<Drawing::TextBlob> infoTextBlob2 =
189         Drawing::TextBlob::Deserialize(data2->GetData(), data2->GetSize(), Ctx);
190 
191     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
192     std::vector<std::string> texts = {typefacestr, text4};
193 
194     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
195     auto rect1 = Drawing::RectI(0, 0, 1000, 1000);
196     playbackCanvas_->ClipIRect(rect1, Drawing::ClipOp::INTERSECT);
197 
198     //8.调用Scale,Rotate,ConcatMatrix
199     Drawing::Matrix matrix;
200     playbackCanvas_->ConcatMatrix(matrix);
201     playbackCanvas_->Translate(400, 600);
202 
203     //9.最终绘制
204     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
205 }
206 
207 // 用例 Font_Scene_Transform_0329
208 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 329)
209 {
210     // 1.创建typeface
211     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
212     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
213     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
214         Drawing::FontStyle::INVISIBLE_WEIGHT,
215         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
216         Drawing::FontStyle::OBLIQUE_SLANT}));
217     // 2.组合typeface操作接口
218     typeface->SetHash(100);
219     std::string  typefacestr = "GetHash = " + std::to_string(typeface->GetHash());;
220     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
221     auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
222     font.SetSubpixel(false);
223     font.SetHinting(Drawing::FontHinting::NORMAL);
224     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
225     font1.SetSubpixel(font.IsSubpixel());
226     font1.SetHinting(font.GetHinting());
227 
228     // 4.创建TextBlob
229     std::string textInfo = "harmony_os";
230     int cont = textInfo.size();
231     Drawing::Point p[cont];
232     for (int i = 0; i < cont; i++) {
233         p[i].SetX(-100 + 50 * i);
234         p[i].SetY(1000 - 50 * i);
235     }
236     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
237         textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
238 
239     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
240     auto rect = textBlob->Bounds();
241     playbackCanvas_->DrawRect(*rect);
242 
243     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
244     std::vector<std::string> texts = {typefacestr};
245 
246     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
247     auto rect1 = Drawing::RectI(0, 0, 1000, 1000);
248     playbackCanvas_->ClipIRect(rect1, Drawing::ClipOp::INTERSECT);
249 
250     //8.调用Scale,Rotate,ConcatMatrix
251 
252     //9.最终绘制
253     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
254 }
255 
256 // 用例 Font_Scene_Transform_0330
257 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 330)
258 {
259     // 1.创建typeface
260     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
261     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
262     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
263         Drawing::FontStyle::INVISIBLE_WEIGHT,
264         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
265         Drawing::FontStyle::OBLIQUE_SLANT}));
266     // 2.组合typeface操作接口
267     std::string s = "011c50";
268     int a;
269     std::stringstream ss;
270     ss<<std::hex<<s;
271     ss>>a;
272     uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(s.c_str())));
273     std::string typefacestr = "GetTableData = "
274         + std::to_string(typeface->GetTableData(tagid, a, typeface->GetTableSize(tagid), nullptr));
275     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
276     auto font = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
277     font.SetSubpixel(false);
278     font.SetSkewX(1.0f);
279     auto font1 = Drawing::Font(typeface, 50.f, font.GetSkewX(), 1.0f);
280     font1.SetSubpixel(font.IsSubpixel());
281 
282     // 4.创建TextBlob
283     std::string textInfo = "harmony_os";
284     int cont = textInfo.size();
285     Drawing::Point p[cont];
286     for (int i = 0; i < cont; i++) {
287         p[i].SetX(-100 + 50 * i);
288         p[i].SetY(1000 - 50 * i);
289     }
290     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
291         textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
292 
293     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
294     Drawing::Paint paint;
295     paint.SetColor(0xFFFF0000);
296     float boundsx[] = {1, 2, 3};
297     int intercepts = textBlob->GetIntercepts(boundsx, nullptr, &paint);
298     std::string text2 = "intercepts = " + std::to_string(intercepts);
299 
300     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
301     std::vector<std::string> texts = {typefacestr, text2};
302 
303     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
304     auto rect1 = Drawing::Rect(0, 0, 600, 600);
305     playbackCanvas_->ClipRect(rect1);
306 
307     //8.调用Scale,Rotate,ConcatMatrix
308     Drawing::Matrix matrix;
309     playbackCanvas_->ConcatMatrix(matrix);
310     playbackCanvas_->Rotate(45, 50, 50);
311     playbackCanvas_->Scale(0.5, 0.5);
312     playbackCanvas_->Translate(400, 600);
313 
314     //9.最终绘制
315     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
316 }
317 
318 // 用例 Font_Scene_Transform_0331
319 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 331)
320 {
321     // 1.创建typeface
322     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
323     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
324     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
325         Drawing::FontStyle::INVISIBLE_WEIGHT,
326         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
327         Drawing::FontStyle::OBLIQUE_SLANT}));
328     // 2.组合typeface操作接口
329     std::string typefacestr = "GetUnitsPerEm = " + std::to_string(typeface->GetUnitsPerEm());
330     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
331     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
332     font1.SetSubpixel(false);
333     std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
334     Drawing::Rect bounds;
335     auto scalar = font1.MeasureText(text0.c_str(), text0.length(), Drawing::TextEncoding::UTF32, &bounds);
336     std::string text4 = "MeasureTextWidths = " + std::to_string(scalar);
337 
338     // 4.创建TextBlob
339     std::string textInfo = "harmony_os";
340     int cont = textInfo.size();
341     Drawing::Point p[cont];
342     for (int i = 0; i < cont; i++) {
343         p[i].SetX(-100 + 50 * i);
344         p[i].SetY(1000 - 50 * i);
345     }
346     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromPosText(
347         textInfo.c_str(), 10, p, font1, Drawing::TextEncoding::UTF8);
348 
349     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
350     std::string name1 = "HMOS Color Emoji";
351     std::string textInfo1 = "����������������������";
352     std::shared_ptr<Drawing::TextBlob> textBlob1 = Drawing::TextBlob::MakeFromText(textInfo1.c_str(),
353                                                       textInfo1.size(), font1, Drawing::TextEncoding::UTF8);
354     if (textBlob1->IsEmoji()) {
355         playbackCanvas_->DrawBackground(0xFF0000FF);
356     } else {
357         playbackCanvas_->DrawBackground(0xFFFF0000);
358     }
359 
360     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
361     std::vector<std::string> texts = {typefacestr, text4};
362 
363     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
364     auto rect1 = Drawing::Rect(0, 0, 600, 600);
365     playbackCanvas_->ClipRect(rect1);
366 
367     //8.调用Scale,Rotate,ConcatMatrix
368     playbackCanvas_->Rotate(45, 50, 50);
369     playbackCanvas_->Scale(0.5, 0.5);
370 
371     //9.最终绘制
372     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
373 }
374 
375 // 用例 Font_Scene_Transform_0332
376 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 332)
377 {
378     // 1.创建typeface
379     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
380     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
381     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
382         Drawing::FontStyle::INVISIBLE_WEIGHT,
383         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
384         Drawing::FontStyle::OBLIQUE_SLANT}));
385     // 2.组合typeface操作接口
386     auto data = typeface->Serialize();
387     uint32_t size = 10;
388     typeface->SetSize(size);
389     std::shared_ptr<Drawing::Typeface> typeface1 = Drawing::Typeface::Deserialize(data->GetData(), typeface->GetSize());
390     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
391     auto font = Drawing::Font(typeface1, 50.f, 1.0f, 1.0f);
392     font.SetSubpixel(false);
393     font.SetEmbeddedBitmaps(true);
394     auto font1 = Drawing::Font(typeface1, 50.f, 1.0f, 1.0f);
395     font1.SetSubpixel(font.IsSubpixel());
396     font1.SetEmbeddedBitmaps(font.IsEmbeddedBitmaps());
397 
398     // 4.创建TextBlob
399     std::string textInfo = "harmony_os";
400     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromString(
401         textInfo.c_str(), font1, Drawing::TextEncoding::UTF8);
402 
403     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
404     std::vector<Drawing::Point> points;
405     Drawing::TextBlob::GetDrawingPointsForTextBlob(textBlob.get(), points);
406     std::string text2 = "";
407     for (int i = 0; i < points.size(); i++) {
408         text2 += std::to_string(i) + "-- X:" + std::to_string(points[i].GetX())
409                      + "Y:" + std::to_string(points[i].GetY());
410     }
411 
412     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
413     std::vector<std::string> texts = {text2};
414 
415     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
416     auto rect1 = Drawing::Rect(0, 0, 600, 600);
417     playbackCanvas_->ClipRect(rect1);
418 
419     //8.调用Scale,Rotate,ConcatMatrix
420     Drawing::Matrix matrix;
421     playbackCanvas_->ConcatMatrix(matrix);
422     playbackCanvas_->Scale(0.5, 0.5);
423 
424     //9.最终绘制
425     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
426 }
427 
428 // 用例 Font_Scene_Transform_0334
429 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 334)
430 {
431     // 1.创建typeface
432     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
433     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
434     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
435         Drawing::FontStyle::INVISIBLE_WEIGHT,
436         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
437         Drawing::FontStyle::OBLIQUE_SLANT}));
438     // 2.组合typeface操作接口
439     std::string typefacestr = "IsCustomTypeface = " + std::to_string(typeface->IsCustomTypeface());
440     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
441     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
442     font1.SetSubpixel(false);
443     std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
444     auto SpaceLine = font1.MeasureSingleCharacter(0x44);
445     std::string text4 = "Recommended spacing between lines = " + std::to_string(SpaceLine);
446 
447     // 4.创建TextBlob
448     std::string textInfo = "harmony_os";
449     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromString(
450         textInfo.c_str(), font1, Drawing::TextEncoding::UTF8);
451 
452     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
453     Drawing::Paint paint;
454     paint.SetColor(0xFFFF0000);
455     float boundsx[] = {1, 2, 3};
456     int intercepts = textBlob->GetIntercepts(boundsx, nullptr, &paint);
457     std::string text2 = "intercepts = " + std::to_string(intercepts);
458 
459     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
460     std::vector<std::string> texts = {typefacestr, text2, text4};
461 
462     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
463     Drawing::Path path;
464     path.AddOval({100, 100, 356, 356});
465     playbackCanvas_->ClipPath(path);
466 
467     //8.调用Scale,Rotate,ConcatMatrix
468     Drawing::Matrix matrix;
469     playbackCanvas_->ConcatMatrix(matrix);
470     playbackCanvas_->Scale(0.5, 0.5);
471     playbackCanvas_->Translate(400, 600);
472 
473     //9.最终绘制
474     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
475 }
476 
477 // 用例 Font_Scene_Transform_0336
478 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 336)
479 {
480     // 1.创建typeface
481     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
482     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
483     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
484         Drawing::FontStyle::INVISIBLE_WEIGHT,
485         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
486         Drawing::FontStyle::OBLIQUE_SLANT}));
487     // 2.组合typeface操作接口
488     std::string str = "CPAL";
489     reverse(str.begin(), str.end());
490     uint32_t tagid = *(reinterpret_cast<uint32_t*>(const_cast<char*>(str.c_str())));
491     std::string typefacestr = "GetTableSize = " + std::to_string(typeface->GetTableSize(tagid));
492     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
493     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
494     font1.SetSubpixel(false);
495     std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
496     Drawing::FontMetrics metrics;
497     auto SpaceLine = font1.GetMetrics(&metrics);
498     std::string text4 = "Recommended spacing between lines = " + std::to_string(SpaceLine);
499 
500     // 4.创建TextBlob
501     std::string textInfo = "1111111111111111111111111111111111";
502     int maxGlyphCount = font1.CountText(textInfo.c_str(), textInfo.size(), Drawing::TextEncoding::UTF8);
503     Drawing::RSXform xform[maxGlyphCount];
504     for (int i = 0; i < maxGlyphCount; ++i) {
505         xform[i].cos_ = cos(10 * i) + 0.1 * i;
506         xform[i].sin_ = sin(10 * i);
507         xform[i].tx_ = 40 * i + 100;;
508         xform[i].ty_ = 100;
509     }
510     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromRSXform(
511         textInfo.c_str(), textInfo.size(), &xform[0], font1, Drawing::TextEncoding::UTF8);
512 
513     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
514     std::string text = "harmony_os";
515     std::vector<uint16_t> glyphid;
516     Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
517     playbackCanvas_->Translate(200, 200);
518     for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
519         auto path = Drawing::TextBlob::GetDrawingPathforTextBlob(glyphid[row], textBlob.get());
520         playbackCanvas_->DrawPath(path);
521         playbackCanvas_->Translate(0, 100);
522     }
523 
524     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
525     std::vector<std::string> texts = {typefacestr, text4};
526 
527     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
528     auto rrect = Drawing::RoundRect(Drawing::Rect(0, 0, 1000, 1000), 52, 52);
529     playbackCanvas_->ClipRoundRect(rrect);
530 
531     //8.调用Scale,Rotate,ConcatMatrix
532     playbackCanvas_->Scale(0.5, 0.5);
533 
534     //9.最终绘制
535     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
536 }
537 
538 // 用例 Font_Scene_Transform_0337
539 DEF_DTK(Font_Scene_Transform_18, TestLevel::L2, 337)
540 {
541     // 1.创建typeface
542     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
543     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
544     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->MatchStyle({
545         Drawing::FontStyle::INVISIBLE_WEIGHT,
546         Drawing::FontStyle::ULTRA_CONDENSED_WIDTH,
547         Drawing::FontStyle::OBLIQUE_SLANT}));
548     // 2.组合typeface操作接口
549     typeface->SetHash(100);
550     std::string  typefacestr = "GetHash = " + std::to_string(typeface->GetHash());;
551     // 3.组合Font类接口,如果是操作类有返回值的接口,获取接口返回值加入vector容器
552     auto font1 = Drawing::Font(typeface, 50.f, 1.0f, 1.0f);
553     font1.SetSubpixel(false);
554     std::string text0 = "DDGR ddgr 鸿蒙 !@#¥%^&*; : , 。";
555     auto glyphsCount = font1.CountText(text0.c_str(), text0.length(), Drawing::TextEncoding::GLYPH_ID);
556     std::string text4 = "glyphsCount = " + std::to_string(glyphsCount);
557 
558     // 4.创建TextBlob
559     std::string textInfo = "1111111111111111111111111111111111";
560     int maxGlyphCount = font1.CountText(textInfo.c_str(), textInfo.size(), Drawing::TextEncoding::UTF8);
561     Drawing::RSXform xform[maxGlyphCount];
562     for (int i = 0; i < maxGlyphCount; ++i) {
563         xform[i].cos_ = cos(10 * i) + 0.1 * i;
564         xform[i].sin_ = sin(10 * i);
565         xform[i].tx_ = 40 * i + 100;;
566         xform[i].ty_ = 100;
567     }
568     std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromRSXform(
569         textInfo.c_str(), textInfo.size(), &xform[0], font1, Drawing::TextEncoding::UTF8);
570 
571     // 5.组合textBlob类接口,如果有返回值则获取上一步创建的textBlob返回值打印
572     std::string text = "harmony_os";
573     std::vector<uint16_t> glyphid;
574     Drawing::TextBlob::GetDrawingGlyphIDforTextBlob(textBlob.get(), glyphid);
575     std::string text2 = "";
576     for (int row = 0; row < text.size() && row < glyphid.size(); row++) {
577         text2 += std::string(1, text[row]) + ":" + std::to_string(glyphid[row]);
578     }
579 
580     //6. 得到需要绘制的所有返回值text,全部适应固定的textBlob构造方式打印
581     std::vector<std::string> texts = {typefacestr, text2, text4};
582 
583     //7.调用ClipIRect截取(0,0,1000,1000)区域(缺省,默认INTERSECT、不抗锯齿)
584     auto rrect = Drawing::RoundRect(Drawing::Rect(0, 0, 1000, 1000), 52, 52);
585     playbackCanvas_->ClipRoundRect(rrect);
586 
587     //8.调用Scale,Rotate,ConcatMatrix
588     playbackCanvas_->Rotate(45, 50, 50);
589 
590     //9.最终绘制
591     DrawTextBlob(texts, textBlob, font1, playbackCanvas_);
592 }
593 
594 }
595 }
596