1 /*
2 * Copyright (c) 2023 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
16 #include "texgine_font_style_set.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace TextEngine {
TexgineFontStyleSet(SkFontStyleSet * set)21 TexgineFontStyleSet::TexgineFontStyleSet(SkFontStyleSet *set)
22 {
23 set_ = set;
24 }
25
~TexgineFontStyleSet()26 TexgineFontStyleSet::~TexgineFontStyleSet()
27 {
28 if (set_) {
29 set_->unref();
30 }
31 }
32
Count() const33 int TexgineFontStyleSet::Count() const
34 {
35 if (set_ == nullptr) {
36 return 0;
37 }
38 return set_->count();
39 }
40
GetStyle(const int index,std::shared_ptr<TexgineFontStyle> style,std::shared_ptr<TexgineString> name) const41 void TexgineFontStyleSet::GetStyle(const int index, std::shared_ptr<TexgineFontStyle> style,
42 std::shared_ptr<TexgineString> name) const
43 {
44 if (set_ == nullptr || style == nullptr || name == nullptr) {
45 return;
46 }
47
48 set_->getStyle(index, style->GetFontStyle().get(), name->GetString());
49 }
50
CreateTypeface(int index)51 std::shared_ptr<TexgineTypeface> TexgineFontStyleSet::CreateTypeface(int index)
52 {
53 if (set_ == nullptr) {
54 return nullptr;
55 }
56 auto typeface = set_->createTypeface(index);
57 return std::make_shared<TexgineTypeface>(typeface);
58 }
59
MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)60 std::shared_ptr<TexgineTypeface> TexgineFontStyleSet::MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)
61 {
62 if (set_ == nullptr || pattern == nullptr || pattern->GetFontStyle() == nullptr) {
63 return nullptr;
64 }
65 auto style = *pattern->GetFontStyle();
66 auto typeface = set_->matchStyle(style);
67 return std::make_shared<TexgineTypeface>(typeface);
68 }
69
CreateEmpty()70 std::shared_ptr<TexgineFontStyleSet> TexgineFontStyleSet::CreateEmpty()
71 {
72 auto fss = SkFontStyleSet::CreateEmpty();
73 return std::make_shared<TexgineFontStyleSet>(fss);
74 }
75 } // namespace TextEngine
76 } // namespace Rosen
77 } // namespace OHOS
78