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 
19 namespace OHOS {
UIFontBuilder()20 UIFontBuilder::UIFontBuilder() : uiTextLangFontsTable_(nullptr), langTextDefaultParamTable_(nullptr),
21                                  totalLangId_(0), totalFontId_(0), totalTextId_(0) {}
22 
GetInstance()23 UIFontBuilder* UIFontBuilder::GetInstance()
24 {
25     static UIFontBuilder uiFontBuilder;
26     return &uiFontBuilder;
27 }
28 
SetTextLangFontsTable(const UITextLanguageFontParam * uiTextLangFontsTable,uint16_t totalFontId)29 void 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 
SetLangTextDefaultParamTable(const LangTextParam * langTextDefaultParamTable,uint8_t totalLangId)38 void 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 
SetMaxTextId(uint16_t totalTextId)47 void UIFontBuilder::SetMaxTextId(uint16_t totalTextId)
48 {
49     totalTextId_ = totalTextId;
50 }
51 
GetTextLangFontsTable(uint16_t langFontId)52 UITextLanguageFontParam* UIFontBuilder::GetTextLangFontsTable(uint16_t langFontId)
53 {
54     if ((langFontId >= totalFontId_) || (uiTextLangFontsTable_ == nullptr)) {
55         return nullptr;
56     }
57     return &(uiTextLangFontsTable_[langFontId]);
58 }
59 
GetTotalLangId() const60 uint8_t UIFontBuilder::GetTotalLangId() const
61 {
62     return totalLangId_;
63 }
64 
GetTotalFontId() const65 uint16_t UIFontBuilder::GetTotalFontId() const
66 {
67     uint16_t fontIdMax = 0xFF;
68     if (!UIFont::GetInstance()->IsVectorFont()) {
69         fontIdMax = totalFontId_;
70     }
71     return fontIdMax;
72 }
73 
GetBitmapFontIdMax() const74 uint16_t UIFontBuilder::GetBitmapFontIdMax() const
75 {
76     return totalFontId_;
77 }
78 
GetTotalTextId() const79 uint16_t UIFontBuilder::GetTotalTextId() const
80 {
81     return totalTextId_;
82 }
83 
GetLangTextDefaultParamTable()84 LangTextParam* UIFontBuilder::GetLangTextDefaultParamTable()
85 {
86     if (langTextDefaultParamTable_ == nullptr) {
87         return nullptr;
88     }
89     return langTextDefaultParamTable_;
90 }
91 } // namespace OHOS
92