• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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.h"
17 #include "recording/mem_allocator.h"
18 #include "text/font_mgr.h"
19 #include "text/font_style_set.h"
20 #include "text/rs_xform.h"
21 #include "utils/point.h"
22 #include "utils/rect.h"
23 #include "text/typeface.h"
24 
25 /*
26 测试类:FontMgr
27 测试接口:CreateStyleSet
28 测试内容:对接口index取等价值有效值等,构造typeface字体格式,并指定在font上,最终通过drawtextblob接口将text值绘制在画布上
29 */
30 
31 namespace OHOS {
32 namespace Rosen {
33 
CommonCreateStyleSet(TestPlaybackCanvas * playbackCanvas,std::shared_ptr<Drawing::FontMgr> & fontMgr,int index)34 void CommonCreateStyleSet(TestPlaybackCanvas* playbackCanvas, std::shared_ptr<Drawing::FontMgr>& fontMgr, int index)
35 {
36     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(index));
37     auto typeface = std::shared_ptr<Drawing::Typeface>(fontStyleSet->CreateTypeface(0));
38 
39     auto font = Drawing::Font(typeface, 50.f, 1.0f, 0.f);
40     std::string text1 = "DDGR ddgr 鸿蒙 !@#%¥^&*;:,。";
41     std::string text2 = "-_=+()123`.---~|{}【】,./?、?<>《》";
42     std::string text3 = "\xE2\x99\x88\xE2\x99\x8A\xE2\x99\x88\xE2\x99\x8C\xE2\x99\x8D\xE2\x99\x8D";
43     std::string texts[] = {text1, text2, text3};
44     int line = 200;
45     int interval2 = 200;
46     for (auto text : texts) {
47         std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(text.c_str(), text.size(), font);
48         Drawing::Brush brush;
49         playbackCanvas->AttachBrush(brush);
50         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
51         line += interval2;
52         playbackCanvas->DetachBrush();
53         Drawing::Pen pen;
54         playbackCanvas->AttachPen(pen);
55         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
56         line += interval2;
57         playbackCanvas->DetachPen();
58     }
59 }
60 
61 //对应用例 FontMgr_CreateStyleSet_3001
62 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 1)
63 {
64     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
65     CommonCreateStyleSet(playbackCanvas_, fontMgr, -1);
66 }
67 
68 //对应用例 FontMgr_CreateStyleSet_3002
69 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 2)
70 {
71     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
72     CommonCreateStyleSet(playbackCanvas_, fontMgr, 50);
73 }
74 
75 //对应用例 FontMgr_CreateStyleSet_3003
76 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 3)
77 {
78     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
79     CommonCreateStyleSet(playbackCanvas_, fontMgr, -1);
80 }
81 
82 //对应用例 FontMgr_CreateStyleSet_3004
83 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 4)
84 {
85     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
86     CommonCreateStyleSet(playbackCanvas_, fontMgr, 0);
87 }
88 
89 //对应用例 FontMgr_CreateStyleSet_3005
90 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 5)
91 {
92     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
93     CommonCreateStyleSet(playbackCanvas_, fontMgr, 50);
94 }
95 
96 //对应用例 FontMgr_CreateStyleSet_3006
97 DEF_DTK(fontmgr_createstyleset, TestLevel::L1, 6)
98 {
99     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
100     CommonCreateStyleSet(playbackCanvas_, fontMgr, 0);
101 }
102 
103 }
104 }
105