• 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 测试接口:CountFamilies
28 测试内容:对接口取返回值,并构造typeface字体格式,并指定在font上,最终通过drawtextblob接口将countFamilies值绘制在画布上
29 */
30 namespace OHOS {
31 namespace Rosen {
32 
CommonCountFamilies(TestPlaybackCanvas * playbackCanvas,std::shared_ptr<Drawing::FontMgr> & fontMgr)33 void CommonCountFamilies(TestPlaybackCanvas* playbackCanvas, std::shared_ptr<Drawing::FontMgr>& fontMgr)
34 {
35     std::shared_ptr<Drawing::FontStyleSet> fontStyleSet(fontMgr->CreateStyleSet(0));
36     int countFamilies = fontMgr->CountFamilies();
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 text4 = "CountFamilies = " + std::to_string(countFamilies);
44     std::string texts[] = {text1, text2, text3, text4};
45     int line = 200;
46     int interval2 = 200;
47     for (auto text : texts) {
48         std::shared_ptr<Drawing::TextBlob> textBlob = Drawing::TextBlob::MakeFromText(text.c_str(), text.size(), font);
49         Drawing::Brush brush;
50         playbackCanvas->AttachBrush(brush);
51         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
52         line += interval2;
53         playbackCanvas->DetachBrush();
54         Drawing::Pen pen;
55         playbackCanvas->AttachPen(pen);
56         playbackCanvas->DrawTextBlob(textBlob.get(), interval2, line);
57         line += interval2;
58         playbackCanvas->DetachPen();
59     }
60 }
61 
62 //对应用例 FontMgr_CountFamilies_3001
63 DEF_DTK(fontmgr_countfamilies, TestLevel::L1, 1)
64 {
65     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDefaultFontMgr());
66     CommonCountFamilies(playbackCanvas_, fontMgr);
67 }
68 
69 //对应用例 FontMgr_CountFamilies_3002
70 DEF_DTK(fontmgr_countfamilies, TestLevel::L1, 2)
71 {
72     std::shared_ptr<Drawing::FontMgr> fontMgr(Drawing::FontMgr::CreateDynamicFontMgr());
73     CommonCountFamilies(playbackCanvas_, fontMgr);
74 }
75 
76 }
77 }
78