1/* 2 * Copyright (c) 2020-2021 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 "font/ui_font_builder.h" 17#include "font/ui_font.h" 18 19namespace OHOS { 20UIFontBuilder::UIFontBuilder() : uiTextLangFontsTable_(nullptr), langTextDefaultParamTable_(nullptr), 21 totalLangId_(0), totalFontId_(0), totalTextId_(0) {} 22 23UIFontBuilder* UIFontBuilder::GetInstance() 24{ 25 static UIFontBuilder uiFontBuilder; 26 return &uiFontBuilder; 27} 28 29void UIFontBuilder::SetTextLangFontsTable(const UITextLanguageFontParam* uiTextLangFontsTable, 30 uint16_t totalFontId) 31{ 32 if ((uiTextLangFontsTable != nullptr) && (totalFontId > 0)) { 33 uiTextLangFontsTable_ = const_cast<UITextLanguageFontParam*>(uiTextLangFontsTable); 34 totalFontId_ = totalFontId; 35 } 36} 37 38void UIFontBuilder::SetLangTextDefaultParamTable(const LangTextParam* langTextDefaultParamTable, 39 uint8_t totalLangId) 40{ 41 if ((langTextDefaultParamTable != nullptr) && (totalLangId > 0)) { 42 langTextDefaultParamTable_ = const_cast<LangTextParam*>(langTextDefaultParamTable); 43 totalLangId_ = totalLangId; 44 } 45} 46 47void UIFontBuilder::SetMaxTextId(uint16_t totalTextId) 48{ 49 totalTextId_ = totalTextId; 50} 51 52UITextLanguageFontParam* UIFontBuilder::GetTextLangFontsTable(uint16_t langFontId) 53{ 54 if ((langFontId >= totalFontId_) || (uiTextLangFontsTable_ == nullptr)) { 55 return nullptr; 56 } 57 return &(uiTextLangFontsTable_[langFontId]); 58} 59 60uint8_t UIFontBuilder::GetTotalLangId() const 61{ 62 return totalLangId_; 63} 64 65uint16_t UIFontBuilder::GetTotalFontId() const 66{ 67 uint16_t fontIdMax = 0xFF; 68 if (!UIFont::GetInstance()->IsVectorFont()) { 69 fontIdMax = totalFontId_; 70 } 71 return fontIdMax; 72} 73 74uint16_t UIFontBuilder::GetBitmapFontIdMax() const 75{ 76 return totalFontId_; 77} 78 79uint16_t UIFontBuilder::GetTotalTextId() const 80{ 81 return totalTextId_; 82} 83 84LangTextParam* UIFontBuilder::GetLangTextDefaultParamTable() 85{ 86 if (langTextDefaultParamTable_ == nullptr) { 87 return nullptr; 88 } 89 return langTextDefaultParamTable_; 90} 91} // namespace OHOS 92