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(RSFontStyleSet * set)21 TexgineFontStyleSet::TexgineFontStyleSet(RSFontStyleSet *set)
22 {
23     set_ = set;
24 }
25 
~TexgineFontStyleSet()26 TexgineFontStyleSet::~TexgineFontStyleSet()
27 {
28     if (set_) {
29         delete set_;
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     set_->GetStyle(index, style->GetFontStyle().get(), name->GetString());
48 }
49 
CreateTypeface(int index)50 std::shared_ptr<TexgineTypeface> TexgineFontStyleSet::CreateTypeface(int index)
51 {
52     if (set_ == nullptr) {
53         return nullptr;
54     }
55     RSTypeface* typeface = set_->CreateTypeface(index);
56     return std::make_shared<TexgineTypeface>(typeface);
57 }
58 
MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)59 std::shared_ptr<TexgineTypeface> TexgineFontStyleSet::MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)
60 {
61     if (set_ == nullptr || pattern == nullptr || pattern->GetFontStyle() == nullptr) {
62         return nullptr;
63     }
64     auto style = *pattern->GetFontStyle();
65     RSTypeface* typeface = set_->MatchStyle(style);
66     return std::make_shared<TexgineTypeface>(typeface);
67 }
68 } // namespace TextEngine
69 } // namespace Rosen
70 } // namespace OHOS
71