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 "dynamic_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 { DynamicFontStyleSet(std::unique_ptr<Typeface> typeface)24DynamicFontStyleSet::DynamicFontStyleSet(std::unique_ptr<Typeface> typeface): typeface_(std::move(typeface)) 25 { 26 } 27 Count() const28int DynamicFontStyleSet::Count() const 29 { 30 return typeface_ != nullptr ? 1 : 0; 31 } 32 GetStyle(int index,std::shared_ptr<TexgineFontStyle> style,std::shared_ptr<TexgineString> name) const33void DynamicFontStyleSet::GetStyle(int index, std::shared_ptr<TexgineFontStyle> style, 34 std::shared_ptr<TexgineString> name) const 35 { 36 if (style == nullptr || style->GetFontStyle() == nullptr) { 37 LOGEX_FUNC_LINE(ERROR) << "style is nullptr"; 38 throw TEXGINE_EXCEPTION(INVALID_ARGUMENT); 39 } 40 41 if (index == 0 && typeface_ != nullptr && typeface_->Get() != nullptr) { 42 *style = *typeface_->Get()->GetFontStyle(); 43 } 44 } 45 CreateTypeface(int index)46std::shared_ptr<TexgineTypeface> DynamicFontStyleSet::CreateTypeface(int index) 47 { 48 if (index == 0 && typeface_ != nullptr) { 49 return typeface_->Get(); 50 } 51 return nullptr; 52 } 53 MatchStyle(std::shared_ptr<TexgineFontStyle> pattern)54std::shared_ptr<TexgineTypeface> DynamicFontStyleSet::MatchStyle(std::shared_ptr<TexgineFontStyle> pattern) 55 { 56 if (typeface_ != nullptr) { 57 return typeface_->Get(); 58 } 59 return nullptr; 60 } 61 } // namespace TextEngine 62 } // namespace Rosen 63 } // namespace OHOS 64