• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "variant_font_style_set.h"
17 
18 #include "texgine_exception.h"
19 #include "texgine/utils/exlog.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace TextEngine {
VariantFontStyleSet(const std::shared_ptr<TexgineFontStyleSet> & tfss)24 VariantFontStyleSet::VariantFontStyleSet(const std::shared_ptr<TexgineFontStyleSet> &tfss) noexcept(true): tfss_(tfss)
25 {
26 }
27 
VariantFontStyleSet(const std::shared_ptr<DynamicFontStyleSet> & dfss)28 VariantFontStyleSet::VariantFontStyleSet(const std::shared_ptr<DynamicFontStyleSet> &dfss) noexcept(true): dfss_(dfss)
29 {
30 }
31 
VariantFontStyleSet(std::shared_ptr<TexgineFontStyleSet> & tfss)32 VariantFontStyleSet::VariantFontStyleSet(
33     std::shared_ptr<TexgineFontStyleSet> &tfss) noexcept(true): tfss_(std::move(tfss))
34 {
35 }
36 
VariantFontStyleSet(std::shared_ptr<DynamicFontStyleSet> & dfss)37 VariantFontStyleSet::VariantFontStyleSet(
38     std::shared_ptr<DynamicFontStyleSet> &dfss) noexcept(true): dfss_(std::move(dfss))
39 {
40 }
41 
VariantFontStyleSet(std::nullptr_t)42 VariantFontStyleSet::VariantFontStyleSet(std::nullptr_t) noexcept(true)
43 {
44 }
45 
TryToTexgineFontStyleSet() const46 std::shared_ptr<TexgineFontStyleSet> VariantFontStyleSet::TryToTexgineFontStyleSet() const noexcept(false)
47 {
48     CheckPointer(true);
49     return tfss_;
50 }
51 
TryToDynamicFontStyleSet() const52 std::shared_ptr<DynamicFontStyleSet> VariantFontStyleSet::TryToDynamicFontStyleSet() const noexcept(false)
53 {
54     CheckPointer(true);
55     return dfss_;
56 }
57 
Count()58 int VariantFontStyleSet::Count()
59 {
60     CheckPointer();
61     if (tfss_) {
62         return tfss_->Count();
63     }
64 
65     if (dfss_) {
66         return dfss_->Count();
67     }
68 
69     return 0;
70 }
71 
GetStyle(int index,std::shared_ptr<TexgineFontStyle> style,std::shared_ptr<TexgineString> name)72 void VariantFontStyleSet::GetStyle(int index, std::shared_ptr<TexgineFontStyle> style,
73     std::shared_ptr<TexgineString> name)
74 {
75     CheckPointer();
76     if (tfss_) {
77         return tfss_->GetStyle(index, style, name);
78     }
79 
80     if (dfss_) {
81         return dfss_->GetStyle(index, style, name);
82     }
83 }
84 
CreateTypeface(int index)85 std::shared_ptr<TexgineTypeface> VariantFontStyleSet::CreateTypeface(int index)
86 {
87     CheckPointer();
88     if (tfss_) {
89         return tfss_->CreateTypeface(index);
90     }
91 
92     if (dfss_) {
93         return dfss_->CreateTypeface(index);
94     }
95 
96     return nullptr;
97 }
98 
MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)99 std::shared_ptr<TexgineTypeface> VariantFontStyleSet::MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)
100 {
101     CheckPointer();
102     if (tfss_) {
103         return tfss_->MatchStyle(pattern);
104     }
105 
106     if (dfss_) {
107         return dfss_->MatchStyle(pattern);
108     }
109 
110     return nullptr;
111 }
112 
CheckPointer(bool nullable) const113 void VariantFontStyleSet::CheckPointer(bool nullable) const noexcept(false)
114 {
115     if (!nullable && tfss_ == nullptr && dfss_ == nullptr) {
116         throw TEXGINE_EXCEPTION(NULLPTR);
117     }
118 
119     if (tfss_ != nullptr && dfss_ != nullptr) {
120         throw TEXGINE_EXCEPTION(ERROR_STATUS);
121     }
122 }
123 } // namespace TextEngine
124 } // namespace Rosen
125 } // namespace OHOS
126