diff --git a/BUILD.gn b/BUILD.gn index 65e51168b4dff424d846c2a82f02995629788f67..5ffec76f116459d62b8a9c498d615ba48ea62458 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -32,6 +32,7 @@ config("graphic_define_config") { defines = [ "ENABLE_VECTOR_FONT=1", + "ENABLE_BITMAP_FONT=0", "ENABLE_SHAPING=0", "ENABLE_ICU=1", "ENABLE_MULTI_FONT=0", @@ -67,7 +68,6 @@ shared_library("ui") { "frameworks/common/task.cpp", "frameworks/common/text.cpp", "frameworks/common/typed_text.cpp", - "frameworks/common/ui_font_header.cpp", "frameworks/components/root_view.cpp", "frameworks/components/text_adapter.cpp", "frameworks/components/ui_abstract_clock.cpp", @@ -133,6 +133,8 @@ shared_library("ui") { "frameworks/font/ui_font.cpp", "frameworks/font/ui_font_adaptor.cpp", "frameworks/font/ui_font_allocator.cpp", + "frameworks/font/ui_font_bitmap.cpp", + "frameworks/font/ui_font_builder.cpp", "frameworks/font/ui_font_cache.cpp", "frameworks/font/ui_font_vector.cpp", "frameworks/font/ui_line_break.cpp", diff --git a/frameworks/common/graphic_startup.cpp b/frameworks/common/graphic_startup.cpp index e53581986405a0534c8d57b63789a1748fc7fddf..933e791a96623aa1cc9e18250dc166d71184147b 100755 --- a/frameworks/common/graphic_startup.cpp +++ b/frameworks/common/graphic_startup.cpp @@ -47,24 +47,26 @@ void GraphicStartUp::InitFontEngine(uintptr_t cacheMemAddr, const char* dPath, const char* ttfName) { -#if ENABLE_VECTOR_FONT - UIFont* fontEngine = UIFont::GetInstance(); - if (fontEngine == nullptr) { + UIFont* uiFont = UIFont::GetInstance(); + if (uiFont == nullptr) { GRAPHIC_LOGE("Get UIFont error"); return; } - fontEngine->SetPsramMemory(cacheMemAddr, cacheMemLen); - int8_t ret = fontEngine->SetFontPath(const_cast(dPath), nullptr); + uiFont->SetPsramMemory(cacheMemAddr, cacheMemLen); + int8_t ret = uiFont->SetFontPath(const_cast(dPath), nullptr); if (ret == INVALID_RET_VALUE) { GRAPHIC_LOGW("SetFontPath failed"); } - if (ttfName != nullptr) { - uint8_t ret2 = fontEngine->RegisterFontInfo(ttfName); - if (ret2 == INVALID_UCHAR_ID) { - GRAPHIC_LOGW("SetTtfName failed"); + if (uiFont->IsVectorFont()) { + if (ttfName != nullptr) { + uint8_t ret2 = uiFont->RegisterFontInfo(ttfName); + if (ret2 == INVALID_UCHAR_ID) { + GRAPHIC_LOGW("SetTtfName failed"); + } } + } else { + (void)uiFont->SetCurrentLangId(0); // set language } -#endif } void GraphicStartUp::InitLineBreakEngine(uintptr_t cacheMemAddr, uint32_t cacheMemLen, const char* path, diff --git a/frameworks/common/text.cpp b/frameworks/common/text.cpp index b40ea4d7552eb0eae855c769d9b99a63190bc216..376553154bdd3fb1db42bf1b28f07a63988e35ef 100755 --- a/frameworks/common/text.cpp +++ b/frameworks/common/text.cpp @@ -18,6 +18,7 @@ #include "draw/draw_label.h" #include "font/ui_font.h" #include "font/ui_font_adaptor.h" +#include "font/ui_font_builder.h" #include "gfx_utils/graphic_log.h" #include "securec.h" @@ -82,7 +83,8 @@ void Text::SetFont(const char* name, uint8_t size) } if (UIFont::GetInstance()->IsVectorFont()) { uint8_t fontId = UIFont::GetInstance()->GetFontId(name); - if ((fontId != GetTotalFontId()) && ((fontId_ != fontId) || (fontSize_ != size))) { + if ((fontId != UIFontBuilder::GetInstance()->GetTotalFontId()) && + ((fontId_ != fontId) || (fontSize_ != size))) { fontId_ = fontId; fontSize_ = size; needRefresh_ = true; @@ -127,17 +129,18 @@ void Text::SetFont(const char* name, uint8_t size, char*& destName, uint8_t& des void Text::SetFontId(uint8_t fontId) { - if ((fontId >= GetTotalFontId()) || (fontId_ == fontId)) { + if ((fontId >= UIFontBuilder::GetInstance()->GetTotalFontId()) || (fontId_ == fontId)) { GRAPHIC_LOGE("Text::SetFontId invalid fontId(%d)", fontId); return; } - UITextLanguageFontParam* fontParam = GetTextLangFontsTable(fontId); + UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId); if (fontParam == nullptr) { return; } if (UIFont::GetInstance()->IsVectorFont()) { uint8_t fontId = UIFont::GetInstance()->GetFontId(fontParam->ttfName); - if ((fontId != GetTotalFontId()) && ((fontId_ != fontId) || (fontSize_ != fontParam->size))) { + if ((fontId != UIFontBuilder::GetInstance()->GetTotalFontId()) && ((fontId_ != fontId) || + (fontSize_ != fontParam->size))) { fontId_ = fontId; fontSize_ = fontParam->size; needRefresh_ = true; diff --git a/frameworks/common/ui_font_header.cpp b/frameworks/common/ui_font_header.cpp deleted file mode 100755 index df0301886e079e90827fc1b056a28c54b4213863..0000000000000000000000000000000000000000 --- a/frameworks/common/ui_font_header.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at. - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "font/ui_font.h" -#include "font/ui_font_header.h" - -namespace OHOS { -UITextLanguageFontParam* GetTextLangFontsTable(uint8_t langFontId) -{ - // Need to be implemented - return nullptr; -} - -uint8_t GetTotalLangId() -{ - // Need to be implemented - return 0; -} - -uint8_t GetBitmapFontIdMax() -{ - // Need to be implemented - return 0; -} - -uint8_t GetTotalFontId() -{ - // Need to be implemented - return 0xFF; -} - -uint16_t GetTotalTextId() -{ - // Need to be implemented - return 0; -} - -LangTextParam* GetLangTextDefaultParamTable() -{ - // Need to be implemented - return nullptr; -} -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/font/base_font.cpp b/frameworks/font/base_font.cpp index 4d99d3c7f39df730734e53f98e75973b514ca149..7128d222173ebbaede0a2f04ed8aafed04968387 100755 --- a/frameworks/font/base_font.cpp +++ b/frameworks/font/base_font.cpp @@ -49,11 +49,11 @@ void BaseFont::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen) int8_t BaseFont::GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const { - if ((langId >= GetTotalLangId()) || (pParam == nullptr)) { + if ((langId >= UIFontBuilder::GetInstance()->GetTotalLangId()) || (pParam == nullptr)) { return INVALID_RET_VALUE; } - LangTextParam *pTable = GetLangTextDefaultParamTable(); + LangTextParam *pTable = UIFontBuilder::GetInstance()->GetLangTextDefaultParamTable(); if (pTable == nullptr) { return INVALID_RET_VALUE; } diff --git a/frameworks/font/glyphs_manager.cpp b/frameworks/font/glyphs_manager.cpp index 86863718c0b3ec5ec4c1bc99747b6f02c9b26005..5e8ebfb2153ed9f43a735447a496574fa5483367 100755 --- a/frameworks/font/glyphs_manager.cpp +++ b/frameworks/font/glyphs_manager.cpp @@ -14,6 +14,7 @@ */ #include "font/glyphs_manager.h" +#include "font/ui_font_builder.h" #include "gfx_utils/file.h" #include "securec.h" @@ -43,7 +44,7 @@ GlyphsManager::GlyphsManager() isFileSet_(false), isFontIdSet_(false) { - fontId_ = GetBitmapFontIdMax(); + fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); } GlyphsManager::~GlyphsManager() {} @@ -179,7 +180,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start) if (strncmp(binHeader_.fontMagic, FONT_MAGIC_NUMBER, FONT_MAGIC_NUM_LEN) != 0) { return INVALID_RET_VALUE; } - if (binHeader_.fontNum > GetBitmapFontIdMax()) { + if (binHeader_.fontNum > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) { return INVALID_RET_VALUE; } @@ -211,7 +212,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start) isFileSet_ = true; } - fontId_ = GetBitmapFontIdMax(); + fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); return ret; } @@ -221,7 +222,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) if (!isFileSet_) { return INVALID_RET_VALUE; } - if (fontId > GetBitmapFontIdMax()) { + if (fontId > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) { return INVALID_RET_VALUE; } if (fontId_ == fontId) { @@ -247,7 +248,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) if (!found) { isFontIdSet_ = false; curFontHeader_ = nullptr; - fontId_ = GetBitmapFontIdMax(); + fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); return INVALID_RET_VALUE; } diff --git a/frameworks/font/ui_font.cpp b/frameworks/font/ui_font.cpp index 15c039f642210b11c66bf9ba705583bad27d2cd9..0a4536f6793d5ad649c8fb75ee7627803df24c60 100755 --- a/frameworks/font/ui_font.cpp +++ b/frameworks/font/ui_font.cpp @@ -18,7 +18,9 @@ #include "font/ui_font_cache.h" #if ENABLE_VECTOR_FONT #include "font/ui_font_vector.h" -#endif // ENABLE_VECTOR_FONT +#else +#include "font/ui_font_bitmap.h" +#endif #include "graphic_config.h" #if ENABLE_MULTI_FONT #include "font/ui_multi_font_manager.h" @@ -37,6 +39,11 @@ UIFont* UIFont::GetInstance() instance.defaultInstance_ = new UIFontVector(); instance.instance_ = instance.defaultInstance_; } +#else + if (instance.instance_ == nullptr) { + instance.defaultInstance_ = new UIFontBitmap(); + instance.instance_ = instance.defaultInstance_; + } #endif return &instance; } diff --git a/frameworks/font/ui_font_bitmap.cpp b/frameworks/font/ui_font_bitmap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6309e98555dac3bcf1de0538500c8a7d8cabec3d --- /dev/null +++ b/frameworks/font/ui_font_bitmap.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "font/ui_font_bitmap.h" + +#include "font/ui_font_adaptor.h" +#include "font/ui_font_builder.h" +#include "gfx_utils/file.h" +#include "graphic_config.h" +#if ENABLE_MULTI_FONT +#include "font/ui_multi_font_manager.h" +#endif +#if ENABLE_SHAPING +#include "font/ui_text_shaping.h" +#endif + +namespace OHOS { +UIFontBitmap::UIFontBitmap() : dynamicFont_(), dynamicFontRamUsed_(0), dynamicFontFd_(-1) +{ + SetBaseFontId(UIFontBuilder::GetInstance()->GetBitmapFontIdMax()); + bitmapCache_ = nullptr; + bitmapRamUsed_ = FONT_BITMAP_CACHE_SIZE; +} + +UIFontBitmap:: ~UIFontBitmap() +{ + if (dynamicFontFd_ >= 0) { + close(dynamicFontFd_); + } + if (bitmapCache_ != nullptr) { + delete bitmapCache_; + bitmapCache_ = nullptr; + } +} + +bool UIFontBitmap::IsVectorFont() const +{ + return false; +} + +uint8_t UIFontBitmap::GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const +{ +#if ENABLE_MULTI_FONT + return UIMultiFontManager::GetInstance()->GetShapingFontId(text, fontId, ttfId, script); +#else + UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId); + if (fontParam == nullptr) { + return 0; + } + ttfId = fontParam->ttfId; + return fontParam->shaping; +#endif +} + +uint8_t UIFontBitmap::GetFontWeight(uint8_t fontId) +{ + UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId); + if (fontParam == nullptr) { + return 0; + } + return fontParam->fontWeight; +} + +int8_t UIFontBitmap::SetFontPath(const char* dpath, const char* spath) +{ + if (dpath == nullptr) { + return INVALID_RET_VALUE; + } +#ifdef _WIN32 + dynamicFontFd_ = open(dpath, O_RDONLY | O_BINARY); +#else + dynamicFontFd_ = open(dpath, O_RDONLY); +#endif + if (dynamicFontFd_ < 0) { + return INVALID_RET_VALUE; + } + dynamicFont_.SetRamBuffer(GetRamAddr()); + uint32_t start = 0; + int32_t ret = dynamicFont_.SetFile(dynamicFontFd_, start); + if (ret == INVALID_RET_VALUE) { + close(dynamicFontFd_); + dynamicFontFd_ = -1; + return ret; + } + dynamicFontRamUsed_ = dynamicFont_.GetRamUsedLen(); + return RET_VALUE_OK; +} + +int8_t UIFontBitmap::SetCurrentFontId(uint8_t fontId, uint8_t size) +{ + int8_t ret = SetDynamicFontId(fontId); + if (ret == RET_VALUE_OK) { + SetBaseFontId(fontId); + } + return ret; +} + +uint16_t UIFontBitmap::GetHeight() +{ + int16_t ret = dynamicFont_.SetCurrentFontId(GetBaseFontId()); + if (ret == INVALID_RET_VALUE) { + return ret; + } + return dynamicFont_.GetFontHeight(); +} + +uint8_t UIFontBitmap::GetFontId(const char* ttfName, uint8_t size) const +{ + if (ttfName == nullptr) { + return UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); + } + uint8_t id; + for (id = 0; id < UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); ++id) { + UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(id); + if (fontParam != nullptr) { + if ((fontParam->size == size) && (strncmp(fontParam->ttfName, ttfName, TTF_NAME_LEN_MAX) == 0)) { + break; + } + } + } + return id; +} + +int16_t UIFontBitmap::GetWidth(uint32_t unicode, uint8_t fontId) +{ + return GetWidthInFontId(unicode, fontId); +} + +uint8_t* UIFontBitmap::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) +{ + return SearchInFont(unicode, glyphNode, fontId); +} + +int8_t UIFontBitmap::GetCurrentFontHeader(FontHeader& fontHeader) +{ + int8_t ret = dynamicFont_.SetCurrentFontId(GetBaseFontId()); + if (ret == INVALID_RET_VALUE) { + return ret; + } + const FontHeader* header = dynamicFont_.GetCurrentFontHeader(); + if (header != nullptr) { + fontHeader = *header; + return RET_VALUE_OK; + } + return INVALID_RET_VALUE; +} + +int8_t UIFontBitmap::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) +{ + int8_t ret = dynamicFont_.SetCurrentFontId(GetBaseFontId()); + if (ret == INVALID_RET_VALUE) { + return ret; + } + const GlyphNode* node = dynamicFont_.GetGlyphNode(unicode); + if (node != nullptr) { + glyphNode = *node; + return RET_VALUE_OK; + } + return INVALID_RET_VALUE; +} + +int8_t UIFontBitmap::GetFontVersion(char* dVersion, uint8_t dLen, char* sVersion, uint8_t sLen) const +{ + return dynamicFont_.GetFontVersion(dVersion, dLen); +} + +int8_t UIFontBitmap::SetCurrentLangId(uint8_t langId) +{ + if (bitmapCache_ == nullptr) { + uint8_t* bitmapCacheAddr = reinterpret_cast(GetRamAddr() + dynamicFontRamUsed_); + bitmapCache_ = new UIFontCache(bitmapCacheAddr, bitmapRamUsed_); + } + uint32_t total = dynamicFontRamUsed_ + bitmapRamUsed_; + return (total <= GetRamLen()) ? RET_VALUE_OK : INVALID_RET_VALUE; +} + +UITextLanguageFontParam* UIFontBitmap::GetFontInfo(uint8_t fontId) const +{ + return UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId); +} + + +uint32_t UIFontBitmap::GetBitmapRamUsed() +{ + return bitmapRamUsed_; +} + +uint32_t UIFontBitmap::GetDynamicFontRamUsed() +{ + return dynamicFontRamUsed_; +} + +uint32_t UIFontBitmap::GetRamUsedLen(uint32_t textManagerRamUsed, uint32_t langFontRamUsed) +{ + if (bitmapCache_ == nullptr) { + uint8_t* bitmapCacheAddr = reinterpret_cast(GetRamAddr() + dynamicFontRamUsed_ + textManagerRamUsed); + bitmapCache_ = new UIFontCache(bitmapCacheAddr, bitmapRamUsed_); + } + return dynamicFontRamUsed_ + textManagerRamUsed + bitmapRamUsed_ + langFontRamUsed; +} + +int8_t UIFontBitmap::GetDynamicFotBitmap(uint32_t unicode, uint8_t* bitmap) +{ + return dynamicFont_.GetBitmap(unicode, bitmap); +} + +uint8_t* UIFontBitmap::GetCacheBitmap(uint8_t fontId, uint32_t unicode) +{ + if (bitmapCache_ != nullptr) { + return bitmapCache_->GetBitmap(fontId, unicode); + } + return nullptr; +} + +uint8_t* UIFontBitmap::GetCacheSpace(uint8_t fontId, uint32_t unicode, uint32_t size) +{ + if (bitmapCache_ != nullptr) { + return bitmapCache_->GetSpace(fontId, unicode, size); + } + return nullptr; +} + +void UIFontBitmap::PutCacheSpace(uint8_t* addr) +{ + if (bitmapCache_ != nullptr) { + bitmapCache_->PutSpace(addr); + } +} + +int8_t UIFontBitmap::SetDynamicFontId(uint8_t fontId) +{ + return dynamicFont_.SetCurrentFontId(fontId); +} + +int16_t UIFontBitmap::GetDynamicFontWidth(uint32_t unicode, uint8_t fontId) +{ + int16_t ret = dynamicFont_.SetCurrentFontId(fontId); + if (ret == INVALID_RET_VALUE) { + return ret; + } + return dynamicFont_.GetFontWidth(unicode); +} + +uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) +{ + if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) { + return nullptr; + } + if (fontId != GetBaseFontId()) { + SetCurrentFontId(fontId); + } + if (bitmapCache_ == nullptr) { + return nullptr; + } + uint8_t* bitmap = bitmapCache_->GetBitmap(GetBaseFontId(), unicode); + if (bitmap != nullptr) { + GetGlyphNode(unicode, glyphNode); + return bitmap; + } + + int8_t ret = GetGlyphNode(unicode, glyphNode); + if (ret != RET_VALUE_OK) { + return nullptr; + } + + if (glyphNode.kernOff <= glyphNode.dataOff) { + return nullptr; + } + uint32_t bitmapSize = glyphNode.kernOff - glyphNode.dataOff; + bitmap = bitmapCache_->GetSpace(GetBaseFontId(), unicode, bitmapSize); + ret = dynamicFont_.GetBitmap(unicode, bitmap); + if (ret == RET_VALUE_OK) { + return bitmap; + } + bitmapCache_->PutSpace(bitmap); + return nullptr; +} + +int16_t UIFontBitmap::GetWidthInFontId(uint32_t unicode, uint8_t fontId) +{ + if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) { + return INVALID_RET_VALUE; + } + if (fontId != GetBaseFontId()) { + SetCurrentFontId(fontId); + } + return GetDynamicFontWidth(unicode, GetBaseFontId()); +} +} // namespace diff --git a/frameworks/font/ui_font_builder.cpp b/frameworks/font/ui_font_builder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16529742895ffffe855bbd644c47bfd74e3a0cb0 --- /dev/null +++ b/frameworks/font/ui_font_builder.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "font/ui_font_builder.h" +#include "font/ui_font.h" + +namespace OHOS { +UIFontBuilder::UIFontBuilder() : totalLangId_(0), totalFontId_(0), totalTextId_(0), + uiTextLangFontsTable_(nullptr), langTextDefaultParamTable_(nullptr) {} + +UIFontBuilder* UIFontBuilder::GetInstance() +{ + static UIFontBuilder uiFontBuilder; + return &uiFontBuilder; +} + +void UIFontBuilder::SetTextLangFontsTable(const UITextLanguageFontParam* uiTextLangFontsTable, + uint8_t totalFontId) +{ + if ((uiTextLangFontsTable != nullptr) && (totalFontId > 0)) { + uiTextLangFontsTable_ = const_cast(uiTextLangFontsTable); + totalFontId_ = totalFontId; + } +} + +void UIFontBuilder::SetLangTextDefaultParamTable(const LangTextParam* langTextDefaultParamTable, + uint8_t totalLangId) +{ + if ((langTextDefaultParamTable != nullptr) && (totalLangId > 0)) { + langTextDefaultParamTable_ = const_cast(langTextDefaultParamTable); + totalLangId_ = totalLangId; + } +} + +void UIFontBuilder::SetMaxTextId(uint16_t totalTextId) +{ + totalTextId_ = totalTextId; +} + +UITextLanguageFontParam* UIFontBuilder::GetTextLangFontsTable(uint8_t langFontId) +{ + if ((langFontId >= totalFontId_) || (uiTextLangFontsTable_ == nullptr)) { + return nullptr; + } + return &(uiTextLangFontsTable_[langFontId]); +} + +uint8_t UIFontBuilder::GetTotalLangId() const +{ + return totalLangId_; +} + +uint8_t UIFontBuilder::GetTotalFontId() const +{ + uint8_t fontIdMax = 0xFF; + if (!UIFont::GetInstance()->IsVectorFont()) { + fontIdMax = totalFontId_; + } + return fontIdMax; +} + +uint8_t UIFontBuilder::GetBitmapFontIdMax() const +{ + return totalFontId_; +} + +uint16_t UIFontBuilder::GetTotalTextId() const +{ + return totalTextId_; +} + +LangTextParam* UIFontBuilder::GetLangTextDefaultParamTable() +{ + if (langTextDefaultParamTable_ == nullptr) { + return nullptr; + } + return langTextDefaultParamTable_; +} +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/font/ui_multi_font_manager.cpp b/frameworks/font/ui_multi_font_manager.cpp index 360e67f86a8d5f5ed1f235579c254b5df6a5645a..d01ba215b8d685836d805a408a6dd6c41aeb5906 100755 --- a/frameworks/font/ui_multi_font_manager.cpp +++ b/frameworks/font/ui_multi_font_manager.cpp @@ -30,7 +30,7 @@ UIMultiFontManager::UIMultiFontManager() bengaliTtfId_(0), topIndex_(0) { const UITextLanguageFontParam* fontParam = nullptr; - uint8_t totalFontId = GetTotalFontId(); + uint8_t totalFontId = UIFontBuilder::GetInstance()->GetTotalFontId(); for (uint8_t i = 0; i < totalFontId; i++) { fontParam = UIFont::GetInstance()->GetFontInfo(i); if (fontParam == nullptr) { @@ -121,7 +121,7 @@ void UIMultiFontManager::UpdateScript(UITextLanguageFontParam& fonts) void UIMultiFontManager::ClearSearchFontList() { - uint8_t totalFontId = GetTotalFontId(); + uint8_t totalFontId = UIFontBuilder::GetInstance()->GetTotalFontId(); for (uint8_t index = 0; index < totalFontId; index++) { fontIdIndex_[index] = MAX_LIST_NUM; } @@ -136,7 +136,7 @@ void UIMultiFontManager::ClearSearchFontList() int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontIds, uint8_t size) { - if ((fontListId >= GetTotalFontId()) || (fontIds == nullptr) || (size == 0) || + if ((fontListId >= UIFontBuilder::GetInstance()->GetTotalFontId()) || (fontIds == nullptr) || (size == 0) || (fontIdIndex_ == nullptr) || (topIndex_ >= MAX_LIST_NUM)) { return INVALID_RET_VALUE; } @@ -146,7 +146,7 @@ int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontId int8_t UIMultiFontManager::GetSearchFontList(uint8_t fontListId, uint8_t **fontIds) { - if ((fontListId >= GetTotalFontId()) || (fontIds == nullptr) || + if ((fontListId >= UIFontBuilder::GetInstance()->GetTotalFontId()) || (fontIds == nullptr) || (fontIdIndex_ == nullptr) || (fontIdIndex_[fontListId] >= MAX_LIST_NUM)) { return INVALID_RET_VALUE; } diff --git a/interfaces/innerkits/font/ui_font_bitmap.h b/interfaces/innerkits/font/ui_font_bitmap.h new file mode 100644 index 0000000000000000000000000000000000000000..cac8b2f9a13db06781a5f89aa9f25cd120d9c54f --- /dev/null +++ b/interfaces/innerkits/font/ui_font_bitmap.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_FONT_BITMAP_H +#define UI_FONT_BITMAP_H + +#include "font/base_font.h" +#include "font/glyphs_manager.h" +#include "font/ui_font_cache.h" + +namespace OHOS { +class UIFontBitmap : public BaseFont { +public: + UIFontBitmap(); + virtual ~UIFontBitmap(); + UIFontBitmap(const UIFontBitmap&) = delete; + UIFontBitmap& operator=(const UIFontBitmap&) noexcept = delete; + bool IsVectorFont() const override; + uint8_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const override; + int8_t SetFontPath(const char* dpath, const char* spath) override; + int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0) override; + uint16_t GetHeight() override; + uint8_t GetFontId(const char* ttfName, uint8_t size = 0) const override; + int16_t GetWidth(uint32_t unicode, uint8_t fontId) override; + uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) override; + int8_t GetCurrentFontHeader(FontHeader& fontHeader) override; + int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) override; + uint8_t GetFontWeight(uint8_t fontId) override; + int8_t GetFontVersion(char* dVersion, uint8_t dLen, char* sVersion, uint8_t sLen) const override; + int8_t SetCurrentLangId(uint8_t langId) override; + UITextLanguageFontParam* GetFontInfo(uint8_t fontId) const override; + +protected: + uint32_t GetBitmapRamUsed(); + uint32_t GetDynamicFontRamUsed(); + uint32_t GetRamUsedLen(uint32_t textManagerRamUsed, uint32_t langFontRamUsed); + int8_t GetDynamicFotBitmap(uint32_t unicode, uint8_t* bitmap); + uint8_t* GetCacheBitmap(uint8_t fontId, uint32_t unicode); + uint8_t* GetCacheSpace(uint8_t fontId, uint32_t unicode, uint32_t size); + void PutCacheSpace(uint8_t* addr); + int8_t SetDynamicFontId(uint8_t fontId); + int16_t GetDynamicFontWidth(uint32_t unicode, uint8_t fontId); + +private: + uint8_t* SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId); + int16_t GetWidthInFontId(uint32_t unicode, uint8_t fontId); + + static constexpr uint32_t FONT_BITMAP_CACHE_SIZE = 0x64000; + static constexpr uint8_t FONT_ID_MAX = 0xFF; + static constexpr uint8_t TTF_NAME_LEN_MAX = 128; + GlyphsManager dynamicFont_; + uint32_t dynamicFontRamUsed_; + uint32_t bitmapRamUsed_; + UIFontCache* bitmapCache_; + int32_t dynamicFontFd_; +}; +} // namespce OHOS +#endif // UI_FONT_BITMAP_H \ No newline at end of file diff --git a/interfaces/innerkits/font/ui_font_builder.h b/interfaces/innerkits/font/ui_font_builder.h new file mode 100644 index 0000000000000000000000000000000000000000..0570eabde745fd838ecbc18795d4143be7a13866 --- /dev/null +++ b/interfaces/innerkits/font/ui_font_builder.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GRAPHIC_LITE_UI_FONT_BUILDER_H +#define GRAPHIC_LITE_UI_FONT_BUILDER_H + +#include "font/ui_font_header.h" + +namespace OHOS { +class UIFontBuilder { +public: + + static UIFontBuilder* GetInstance(); + + void SetTextLangFontsTable(const UITextLanguageFontParam* uiTextLangFontsTable, uint8_t totalFontId); + + void SetLangTextDefaultParamTable(const LangTextParam* langTextDefaultParamTable, uint8_t totalLangId); + + void SetMaxTextId(uint16_t totalTextId); + + UITextLanguageFontParam* GetTextLangFontsTable(uint8_t langFontId); + + uint8_t GetTotalLangId() const; + + uint8_t GetTotalFontId() const; + + uint8_t GetBitmapFontIdMax() const; + + uint16_t GetTotalTextId() const; + + LangTextParam* GetLangTextDefaultParamTable(); + + UITextLanguageFontParam* uiTextLangFontsTable_; + LangTextParam* langTextDefaultParamTable_; +private: + UIFontBuilder(); + ~UIFontBuilder() {} + uint8_t totalLangId_; + uint8_t totalFontId_; + uint16_t totalTextId_; +}; +} +#endif // GRAPHIC_LITE_UI_FONT_BUILDER_H \ No newline at end of file diff --git a/interfaces/kits/font/base_font.h b/interfaces/kits/font/base_font.h index fe055f606537b98f468b2948655c19a36e4062f2..c1984bceb4334ad43a6119eaf920f1879cd6863a 100755 --- a/interfaces/kits/font/base_font.h +++ b/interfaces/kits/font/base_font.h @@ -16,6 +16,7 @@ #ifndef BASE_FONT #define BASE_FONT #include "font/ui_font_header.h" +#include "font/ui_font_builder.h" #include "graphic_config.h" namespace OHOS { @@ -101,7 +102,7 @@ public: virtual uint8_t GetCurrentLangId() const { - return GetTotalLangId(); + return UIFontBuilder::GetInstance()->GetTotalLangId(); } int8_t GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const; diff --git a/test/framework/BUILD.gn b/test/framework/BUILD.gn index d5d7164a689bf5aba65ffb26ddf396b082afa7c2..5487f319f494d6ebcb8aab165b69d4d9d6655283 100755 --- a/test/framework/BUILD.gn +++ b/test/framework/BUILD.gn @@ -61,6 +61,7 @@ test_sources = [ "../uitest/test_view_percent/ui_test_view_percent.cpp", "../uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp", "../uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp", + "common/ui_text_language.cpp", "src/test_ability.cpp", "src/test_case_list_adapter.cpp", "src/ui_test_app.cpp", @@ -77,7 +78,9 @@ static_library("framework") { sources = test_sources include_dirs = [ + "common", "include", + "../framework", "../uitest", "../../tools", "../../interfaces", @@ -98,7 +101,9 @@ static_library("auto_framework") { sources = test_sources include_dirs = [ + "common", "include", + "../framework", "../uitest", "../../tools", "../../interfaces", diff --git a/test/framework/common/ui_text_language.cpp b/test/framework/common/ui_text_language.cpp new file mode 100644 index 0000000000000000000000000000000000000000..548156d7c615743be252ff56bdc8fb4fa0fbe475 --- /dev/null +++ b/test/framework/common/ui_text_language.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ui_text_language.h" +#include "font/ui_font_builder.h" +#include "font/ui_font_header.h" + +namespace OHOS { +const UITextLanguageFontParam g_uiTextLangFontsTable[LANGUAGE_FONT_ID_MAX] = { + {14, 4, 0, 0, "RobotoCondensed-Regular"}, + {18, 4, 0, 0, "RobotoCondensed-Regular"}, + {20, 4, 0, 0, "RobotoCondensed-Regular"}, + {26, 4, 0, 0, "RobotoCondensed-Regular"}, + {30, 4, 0, 0, "RobotoCondensed-Regular"}, + {38, 4, 0, 0, "RobotoCondensed-Regular"}, + {14, 4, 0, 1, "SourceHanSansSC-Regular"}, + {18, 4, 0, 1, "SourceHanSansSC-Regular"}, + {20, 4, 0, 1, "SourceHanSansSC-Regular"}, + {26, 4, 0, 1, "SourceHanSansSC-Regular"}, + {30, 4, 0, 1, "SourceHanSansSC-Regular"}, + {38, 4, 0, 1, "SourceHanSansSC-Regular"}, +}; // g_uiTextLangFontsTable + +const LangTextParam g_langTextDefaultParamTable[LANGUAGE_MAX] = { + {0, 30, "SourceHanSansSC-Regular", "zh"}, + {0, 30, "RobotoCondensed-Regular", "en"}, + {0, 30, "RobotoCondensed-Regular", "en"}, +}; // g_langTextDefaultParamTable + +void BitmapFontInit() +{ + UIFontBuilder* uiFontBuilder = UIFontBuilder::GetInstance(); + if (uiFontBuilder == nullptr) { + return; + } + uiFontBuilder->SetTextLangFontsTable(g_uiTextLangFontsTable, LANGUAGE_FONT_ID_MAX); + uiFontBuilder->SetLangTextDefaultParamTable(g_langTextDefaultParamTable, LANGUAGE_MAX); + uiFontBuilder->SetMaxTextId(LANGUAGE_TEXT_ID_MAX); +} +} // namespace OHOS diff --git a/test/framework/common/ui_text_language.h b/test/framework/common/ui_text_language.h new file mode 100644 index 0000000000000000000000000000000000000000..c91784d4bacdc2b7ed7d268c225cb47f4a7a3590 --- /dev/null +++ b/test/framework/common/ui_text_language.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UI_TEXT_LANGUAGE_H +#define UI_TEXT_LANGUAGE_H +#include +namespace OHOS { +void BitmapFontInit(); + +enum UITextLanguageLangId : uint8_t { + LANGUAGE_CH = 0, + LANGUAGE_GB = 1, + LANGUAGE_EN = 2, + LANGUAGE_MAX = 3 +}; // UITextLanguageLangId + +enum UITextLanguageFontId : uint8_t { + F_ROBOTOCONDENSED_REGULAR_14_4 = 0, + F_ROBOTOCONDENSED_REGULAR_18_4 = 1, + F_ROBOTOCONDENSED_REGULAR_20_4 = 2, + F_ROBOTOCONDENSED_REGULAR_26_4 = 3, + F_ROBOTOCONDENSED_REGULAR_30_4 = 4, + F_ROBOTOCONDENSED_REGULAR_38_4 = 5, + F_SOURCEHANSANSSC_REGULAR_14_4 = 6, + F_SOURCEHANSANSSC_REGULAR_18_4 = 7, + F_SOURCEHANSANSSC_REGULAR_20_4 = 8, + F_SOURCEHANSANSSC_REGULAR_26_4 = 9, + F_SOURCEHANSANSSC_REGULAR_30_4 = 10, + F_SOURCEHANSANSSC_REGULAR_38_4 = 11, + LANGUAGE_FONT_ID_MAX = 12 +}; // UITextLanguageFontId + +enum UITextLanguageTextId : uint16_t { + LANGUAGE_TEXT_ID_MAX = 0 +}; // UITextLanguageTextId +} // namespace OHOS +#endif // UI_TEXT_LANGUAGE_H diff --git a/test/uitest/test_font/ui_test_font.cpp b/test/uitest/test_font/ui_test_font.cpp index e55ce6addf17dbc748d9c9308cad4570c704e9cd..6ee50852aa4367e34bcbee24decb2ee941b2ae66 100755 --- a/test/uitest/test_font/ui_test_font.cpp +++ b/test/uitest/test_font/ui_test_font.cpp @@ -15,18 +15,25 @@ #include "ui_test_font.h" #include "common/screen.h" -#include "components/ui_checkbox.h" +#if ENABLE_VECTOR_FONT +#else +#include "common/ui_text_language.h" +#endif #include "components/ui_label.h" #include "font/ui_font.h" +#if ENABLE_MULTI_FONT +#include "font/ui_multi_font_manager.h" +#endif namespace OHOS { namespace { -const int16_t GAP = 15; +const int16_t GAP = 5; const int16_t TITLE_HEIGHT = 20; const uint16_t LABEL_WIDTH = 400; const uint16_t LABEL_HEIGHT = 50; -const uint16_t BUF_SIZE = 200; -static uint8_t g_newFontPsramBaseAddr[OHOS::MIN_FONT_PSRAM_LENGTH]; +const uint16_t FONT_SIZE = 30; +const char* SOURCE_HAN_SANS_SC_REGULAR = "SourceHanSansSC-Regular.otf"; +const char* ROBOTO_CONDENSED_REGULAR = "RobotoCondensed-Regulat.ttf"; } // namespace void UITestFont::SetUp() @@ -52,7 +59,11 @@ void UITestFont::InnerTestTitle(const char* title) UILabel* titleLabel = new UILabel(); titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); +#if ENABLE_VECTOR_FONT + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_VECTOR_FONT_SIZE); +#else + titleLabel->SetFontId(F_SOURCEHANSANSSC_REGULAR_18_4); +#endif titleLabel->SetText(title); container_->Add(titleLabel); positionY_ += TITLE_HEIGHT + GAP; @@ -60,149 +71,243 @@ void UITestFont::InnerTestTitle(const char* title) const UIView* UITestFont::GetTestView() { - Font_FontEngine_FontConvert_Test_FontTestSetFontId_001(); - Font_FontEngine_FontConvert_Test_FontTestSetFont_001(); - Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001(); - Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001(); - Font_FontEngine_FontConvert_Test_FontTestGetFontId_001(); - Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001(); - Font_FontEngine_FontConvert_Test_FontTestPsram_001(); - Font_FontEngine_FontConvert_Test_FontTestFontPath_001(); + UIKitFontTestDispaly001(); + UIKitFontTestDispaly002(); + UIKitFontTestDispaly003(); + UIKitFontTestDispaly004(); + UIKitFontTestDispaly005(); + UIKitFontTestDispaly006(); + UIKitFontTestDispaly007(); + UIKitFontTestDispaly008(); +#if ENABLE_MULTI_FONT + UIKitFontMultiLanguage001(); + UIKitFontMultiLanguage002(); +#endif return container_; } +void UITestFont::UIKitFontTestDispaly001() +{ + if (container_ == nullptr) { + return; + } + InnerTestTitle(" Display single line Chinese"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT); +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText("轻量图形子系统"); + container_->Add(label); + positionY_ += LABEL_HEIGHT + GAP; +} -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestPsram_001() +void UITestFont::UIKitFontTestDispaly002() { - if (container_ != nullptr) { - InnerTestTitle("Test Psram"); - UIFont::GetInstance()->SetPsramMemory(reinterpret_cast(g_newFontPsramBaseAddr), - OHOS::MIN_FONT_PSRAM_LENGTH); - UILabel* label = new UILabel(); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18 : size - char buf[BUF_SIZE] = {0}; - label->SetText(reinterpret_cast(buf)); - container_->Add(label); - positionY_ += LABEL_HEIGHT + GAP; + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display multiline Chinese"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText(" 你好\n轻量图形子系统"); + container_->Add(label); + positionY_ += LABEL_HEIGHT * 2 + GAP; // 2 : double } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestFontPath_001() + +void UITestFont::UIKitFontTestDispaly003() { - if (container_ != nullptr) { - InnerTestTitle("Test Font Path"); - std::string dpath; - std::string spath; - size_t len = dpath.size(); - size_t pos = dpath.find_last_of('\\'); - dpath.replace((pos + 1), (len - pos), "..\\..\\config\\font.bin"); - spath.replace((pos + 1), (len - pos), "..\\..\\config\\glyphs.bin"); - UILabel* label = new UILabel(); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - char buf[BUF_SIZE] = {0}; - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18 : size - label->SetText(reinterpret_cast(buf)); - container_->Add(label); - positionY_ += LABEL_HEIGHT + GAP; + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display single line English"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT); +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText("uikit test"); + container_->Add(label); + positionY_ += LABEL_HEIGHT + GAP; } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestSetFontId_001() + +void UITestFont::UIKitFontTestDispaly004() { - if (container_ != nullptr) { - InnerTestTitle("Test Set Font Id"); - UILabel* label = new UILabel(); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - UIFont::GetInstance()->SetCurrentFontId(0); - label->SetFontId(0); - label->SetText("Hello!\nOHOS UIKIT!"); - label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); - container_->Add(label); - positionY_ += LABEL_HEIGHT + GAP; + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display multiline English"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText(" Hello\n uikit"); + container_->Add(label); + positionY_ += LABEL_HEIGHT * 2 + GAP; // 2 : double } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestSetFont_001() + +void UITestFont::UIKitFontTestDispaly005() { - if (container_ != nullptr) { - InnerTestTitle("Test Set Font"); - UILabel* label = new UILabel(); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - uint8_t fontId = UIFont::GetInstance()->GetFontId("RobotoCondensed-Regular"); - UIFont::GetInstance()->SetCurrentFontId(fontId, 18); // 18: means font size - label->SetFont("RobotoCondensed-Regular", 18); // 18: means font size - label->SetText("Hello!\nOHOS UIKIT!"); - label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); - container_->Add(label); - positionY_ += LABEL_HEIGHT + GAP; + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display single line Chinese and English"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT); +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText("你好,轻量级图形 uikit"); + container_->Add(label); + positionY_ += LABEL_HEIGHT + GAP; } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001() +void UITestFont::UIKitFontTestDispaly006() { - if (container_ != nullptr) { - InnerTestTitle("Test Get Font Height"); - UILabel* label = new UILabel(); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18 : size - char buf[BUF_SIZE] = {0}; - label->SetText(reinterpret_cast(buf)); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - positionY_ += LABEL_HEIGHT + GAP; - container_->Add(label); + if (container_ == nullptr) { + return; + } + InnerTestTitle(" Display multiline Chinese and English"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetText("你好\n轻量级图形 uikit"); + container_->Add(label); + positionY_ += LABEL_HEIGHT * 2 + GAP; // 2 : double +} + + +void UITestFont::UIKitFontTestDispaly007() +{ + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display single line text color"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT); +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetStyle(STYLE_TEXT_COLOR, Color::Red().full); + label->SetText("你好,轻量级图形"); + container_->Add(label); + positionY_ += LABEL_HEIGHT + GAP; } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001() +void UITestFont::UIKitFontTestDispaly008() { - if (container_ != nullptr) { - InnerTestTitle("Test Get Font Version"); - UILabel* label = new UILabel(); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - char buf[BUF_SIZE] = {0}; - label->SetText(reinterpret_cast(buf)); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - positionY_ += LABEL_HEIGHT + GAP; - container_->Add(label); + if (container_ == nullptr) { + return; } + InnerTestTitle(" Display multiline text color"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + label->SetFont(SOURCE_HAN_SANS_SC_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_SOURCEHANSANSSC_REGULAR_30_4); +#endif + label->SetStyle(STYLE_TEXT_COLOR, Color::Yellow().full); + label->SetText("你好\n 轻量级图形 uikit"); + container_->Add(label); + positionY_ += LABEL_HEIGHT * 2 + GAP; // 2 : double } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestGetFontId_001() +#if ENABLE_MULTI_FONT +void UITestFont::UIKitFontMultiLanguage001() { - if (container_ != nullptr) { - InnerTestTitle("Test Get Font Id"); - UILabel* label = new UILabel(); - label->SetFont("HYQiHei-65S", 18); // 18: means font size - UIFont::GetInstance()->GetFontId("HYQiHei-65S", 18); // 18: means font size - char buf[BUF_SIZE] = {0}; - label->SetText(reinterpret_cast(buf)); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - positionY_ += LABEL_HEIGHT + GAP; - container_->Add(label); + if (container_ == nullptr) { + return; } +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + UIFont::GetInstance()->RegisterFontInfo(ROBOTO_CONDENSED_REGULAR); + uint8_t findPath[] = {UIFont::GetInstance()->GetFontId(SOURCE_HAN_SANS_SC_REGULAR)}; + UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(ROBOTO_CONDENSED_REGULAR), + findPath, sizeof(findPath)); +#else + uint8_t findPath[] = {F_SOURCEHANSANSSC_REGULAR_30_4}; + UIMultiFontManager::GetInstance()->SetSearchFontList(F_ROBOTOCONDENSED_REGULAR_30_4, findPath, sizeof(findPath)); +#endif + InnerTestTitle(" Display multilingual display"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT); +#if ENABLE_VECTOR_FONT + label->SetFont(ROBOTO_CONDENSED_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_ROBOTOCONDENSED_REGULAR_30_4); +#endif + label->SetText("Hello, 鸿蒙轻量级GUI"); + container_->Add(label); + positionY_ += LABEL_HEIGHT + GAP; } -void UITestFont::Font_FontEngine_FontConvert_Test_FontTestGetFontHeader_001() +void UITestFont::UIKitFontMultiLanguage002() { - if (container_ != nullptr) { - InnerTestTitle("Test Get Font Header"); - UILabel* label = new UILabel(); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); - FontHeader fontHeader; - UIFont::GetInstance()->GetCurrentFontHeader(fontHeader); - char buf[BUF_SIZE] = {0}; - label->SetText(reinterpret_cast(buf)); - label->SetPosition(positionX_, positionY_); - label->Resize(LABEL_WIDTH, LABEL_HEIGHT); - positionY_ += LABEL_HEIGHT + GAP; - container_->Add(label); + if (container_ == nullptr) { + return; } +#if ENABLE_VECTOR_FONT + UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR); + UIFont::GetInstance()->RegisterFontInfo(ROBOTO_CONDENSED_REGULAR); + uint8_t findPath[] = {UIFont::GetInstance()->GetFontId(SOURCE_HAN_SANS_SC_REGULAR)}; + UIMultiFontManager::GetInstance()->SetSearchFontList(UIFont::GetInstance()->GetFontId(ROBOTO_CONDENSED_REGULAR), + findPath, sizeof(findPath)); +#else + uint8_t findPath[] = {F_SOURCEHANSANSSC_REGULAR_30_4}; + UIMultiFontManager::GetInstance()->SetSearchFontList(F_ROBOTOCONDENSED_REGULAR_30_4, findPath, sizeof(findPath)); +#endif + InnerTestTitle(" Display multilingual display"); + UILabel* label = new UILabel(); + label->SetPosition(positionX_, positionY_); + label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double +#if ENABLE_VECTOR_FONT + label->SetFont(ROBOTO_CONDENSED_REGULAR, FONT_SIZE); +#else + label->SetFontId(F_ROBOTOCONDENSED_REGULAR_30_4); +#endif + label->SetText("Hello\n 鸿蒙轻量级GUI"); + container_->Add(label); + positionY_ += LABEL_HEIGHT * 2 + GAP; // 2 : double } -} // namespace OHOS \ No newline at end of file +#endif // ENABLE_MULTI_FONT +} // namespace OHOS diff --git a/test/uitest/test_font/ui_test_font.h b/test/uitest/test_font/ui_test_font.h index 5d4bf87b35444856234731c59f9798f26da15980..63bac32ce4826992a3622651aa537e28b8dcd533 100755 --- a/test/uitest/test_font/ui_test_font.h +++ b/test/uitest/test_font/ui_test_font.h @@ -30,45 +30,55 @@ public: const UIView* GetTestView() override; /** - * @brief Test psram + * @brief Test single line Chinese display */ - void Font_FontEngine_FontConvert_Test_FontTestPsram_001(); + void UIKitFontTestDispaly001(); /** - * @brief Test Font path + * @brief Test multiline Chinese display */ - void Font_FontEngine_FontConvert_Test_FontTestFontPath_001(); + void UIKitFontTestDispaly002(); /** - * @brief Test Set Font Id + * @brief Test single line English display */ - void Font_FontEngine_FontConvert_Test_FontTestSetFontId_001(); + void UIKitFontTestDispaly003(); /** - * @brief Test Set Font + * @brief Test multiline English display */ - void Font_FontEngine_FontConvert_Test_FontTestSetFont_001(); + void UIKitFontTestDispaly004(); /** - * @brief Test Get Font Height + * @brief Test single line Chinese and English display */ - void Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001(); + void UIKitFontTestDispaly005(); /** - * @brief Test get font version + * @brief Test multiline Chinese and English display */ - void Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001(); + void UIKitFontTestDispaly006(); /** - * @brief Test get font Id + * @brief Test single line text color display */ - void Font_FontEngine_FontConvert_Test_FontTestGetFontId_001(); + void UIKitFontTestDispaly007(); /** - * @brief Test get font header + * @brief Test multiline line text color display */ - void Font_FontEngine_FontConvert_Test_FontTestGetFontHeader_001(); + void UIKitFontTestDispaly008(); +#if ENABLE_MULTI_FONT + /** + * @brief Test multilingual display + */ + void UIKitFontMultiLanguage001(); + /** + * @brief Test multilingual display + */ + void UIKitFontMultiLanguage002(); +#endif // ENABLE_MULTI_FONT private: UIScrollView* container_ = nullptr; void InnerTestTitle(const char* title); diff --git a/test/uitest/test_label/ui_test_label.cpp b/test/uitest/test_label/ui_test_label.cpp index ded2ff0f415110f06cac932a71884d4e309add11..b847ba37a37d93acb1d5694648c74a73d355b3ed 100755 --- a/test/uitest/test_label/ui_test_label.cpp +++ b/test/uitest/test_label/ui_test_label.cpp @@ -99,7 +99,7 @@ void UITestLabel::UIKit_UILabel_Test_Display_001() uiViewGroupFrame->SetStyle(STYLE_BACKGROUND_OPA, 0); uiLabel = new UILabel(); uiLabel->SetText("鸿蒙轻量级图形子系统"); - uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: font size + uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); // 26: font size uiLabel->SetPosition(0, 141, 280, 336); // 141: y-coordinate; 280: width; 336: height uiViewGroupFrame->Add(uiLabel); positionX_ += 336; // 336: x-coordinate @@ -123,7 +123,7 @@ void UITestLabel::CreateLabels(UIViewGroup* uiViewGroup) label1->SetText("字号"); label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); labelFontSizeBtn1_ = SetUpButton("18 ", 24, 48, uiViewGroup); // 24: x-coordinate; 48: y-coordinate - labelFontSizeBtn2_ = SetUpButton("24", 116, 48, uiViewGroup); // 116: x-coordinate; 48: y-coordinate + labelFontSizeBtn2_ = SetUpButton("26", 116, 48, uiViewGroup); // 116: x-coordinate; 48: y-coordinate labelFontSizeBtn3_ = SetUpButton("30", 208, 48, uiViewGroup); // 208: x-coordinate; 48: y-coordinate UILabel* label2 = new UILabel(); @@ -210,11 +210,11 @@ void UITestLabel::UIKit_UILabel_Test_Display_003() bool UITestLabel::OnClick(UIView& view, const ClickEvent& event) { uiLabel->Resize(288, 100); // 288: width; 100: height - uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: font size + uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); // 26: font size if (&view == labelFontSizeBtn1_) { uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: font size } else if (&view == labelFontSizeBtn2_) { - uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); // 24: font size + uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); // 26: font size } else if (&view == labelFontSizeBtn3_) { uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size } else if (&view == labelHorAlignBtn1_) { diff --git a/test/unittest/font/ui_font_unit_test.cpp b/test/unittest/font/ui_font_unit_test.cpp index 580bbd819baad653aac91c739d35f4972bebff46..3af76e728a3380ecb459cf676636a994a0e0425c 100755 --- a/test/unittest/font/ui_font_unit_test.cpp +++ b/test/unittest/font/ui_font_unit_test.cpp @@ -14,8 +14,11 @@ */ #include "font/ui_font.h" +#if ENABLE_VECTOR_FONT #include "font/ui_font_vector.h" - +#else +#include "font/ui_font_bitmap.h" +#endif #include #include @@ -23,16 +26,40 @@ using namespace testing::ext; namespace OHOS { namespace { constexpr uint8_t FONT_ERROR_RET = 0xFF; + constexpr int8_t INVALID_RET = -1; + constexpr uint8_t FONT_ID = 0xFF; + constexpr uint8_t FONT_BPP = 8; } class UIFontTest : public testing::Test { public: UIFontTest() {} virtual ~UIFontTest() {} - - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; + static void SetUpTestCase(); + static void TearDownTestCase(); + static BaseFont* font_; }; +BaseFont* UIFontTest::font_ = nullptr; + +void UIFontTest::SetUpTestCase() +{ + if (font_ == nullptr) { +#if ENABLE_VECTOR_FONT + font_ = new UIFontVector(); +#else + font_ = new UIFontBitmap(); +#endif + } +} + +void UIFontTest::TearDownTestCase() +{ + if (font_ != nullptr) { + delete font_; + font_ = nullptr; + } +} + /** * @tc.name: Graphic_Font_Test_GetInstance_001 * @tc.desc: Verify UIFont::GetInstance function, not nullptr. @@ -46,16 +73,181 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_001, TestSize.Level0) } /** - * @tc.name: Graphic_Font_Test_GetInstance_002 - * @tc.desc: Verify UIFont::GetInstance function, equal. + * @tc.name: Graphic_Font_Test_IsVectorFont_001 + * @tc.desc: Verify IsVectorFont function, equal. * @tc.type: FUNC - * @tc.require: SR000F3PEK + * @tc.require: SR000FQNFQ */ -HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_002, TestSize.Level1) +HWTEST_F(UIFontTest, Graphic_Font_Test_IsVectorFont_001, TestSize.Level1) { - UIFont* font = UIFont::GetInstance(); + UIFont::GetInstance()->SetFont(font_); +#if ENABLE_VECTOR_FONT bool ret = UIFont::GetInstance()->IsVectorFont(); EXPECT_EQ(ret, true); +#else + bool ret = UIFont::GetInstance()->IsVectorFont(); + EXPECT_EQ(ret, false); +#endif +} + +/** + * @tc.name: Graphic_Font_Test_SetFontPath_001 + * @tc.desc: Verify SetFontPath function, nullptr test. + * @tc.type: FUNC + * @tc.require: SR000FQNFQ + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_SetFontPath_001, TestSize.Level1) +{ + int8_t ret = UIFont::GetInstance()->SetFontPath(nullptr, nullptr); + EXPECT_EQ(ret, INVALID_RET); +} + +/** + * @tc.name: Graphic_Font_Test_SetFontPath_002 + * @tc.desc: Verify SetFontPath function, empty string test. + * @tc.type: FUNC + * @tc.require: SR000FQNFQ + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_SetFontPath_002, TestSize.Level1) +{ + int8_t ret = UIFont::GetInstance()->SetFontPath("", nullptr); +#if ENABLE_VECTOR_FONT + EXPECT_EQ(ret, 0); +#else + EXPECT_EQ(ret, INVALID_RET); +#endif +} + +/** + * @tc.name: Graphic_Font_Test_SetCurrentFontId_001 + * @tc.desc: Verify SetCurrentFontId function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_SetCurrentFontId_001, TestSize.Level1) +{ + int8_t ret = UIFont::GetInstance()->SetCurrentFontId(0, 0); + EXPECT_EQ(ret, INVALID_RET); +} + +/** + * @tc.name: Graphic_Font_Test_GetFontId_001 + * @tc.desc: Verify GetFontId function, nullptr test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontId_001, TestSize.Level1) +{ + uint8_t ret = UIFont::GetInstance()->GetFontId(nullptr); + EXPECT_EQ(ret, UIFontBuilder::GetInstance()->GetTotalFontId()); +} + +/** + * @tc.name: Graphic_Font_Test_GetFontId_002 + * @tc.desc: Verify GetFontId function, empty string test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontId_002, TestSize.Level1) +{ + uint8_t id = UIFont::GetInstance()->GetFontId("", 0); + EXPECT_EQ(id, UIFontBuilder::GetInstance()->GetTotalFontId()); +} + +/** + * @tc.name: Graphic_Font_Test_GetHeight_001 + * @tc.desc: Verify GetHeight function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetHeight_001, TestSize.Level1) +{ + uint16_t height = UIFont::GetInstance()->GetHeight(); +#if ENABLE_VECTOR_FONT + EXPECT_EQ(height, 0); +#else + EXPECT_EQ(height, static_cast(INVALID_RET)); +#endif +} + +/** + * @tc.name: Graphic_Font_Test_GetWidth_001 + * @tc.desc: Verify GetWidth function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetWidth_001, TestSize.Level1) +{ + uint16_t width = UIFont::GetInstance()->GetWidth(0, 0); + EXPECT_EQ(width, 0); +} + +/** + * @tc.name: Graphic_Font_Test_GetBitmap_001 + * @tc.desc: Verify GetBitmap function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetBitmap_001, TestSize.Level1) +{ + GlyphNode node; + uint8_t* bitmap = UIFont::GetInstance()->GetBitmap(0, node, 0); + EXPECT_EQ(bitmap, nullptr); +} + +/** + * @tc.name: Graphic_Font_Test_GetCurrentFontHeader_001 + * @tc.desc: Verify GetCurrentFontHeader function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetCurrentFontHeader_001, TestSize.Level1) +{ + FontHeader header; + int8_t res = UIFont::GetInstance()->GetCurrentFontHeader(header); + EXPECT_EQ(res, INVALID_RET); +} + +/** + * @tc.name: Graphic_Font_Test_GetFontWeight_001 + * @tc.desc: Verify GetFontWeight function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontWeight_001, TestSize.Level1) +{ + uint8_t fontWeight = UIFont::GetInstance()->GetFontWeight(FONT_ID); +#if ENABLE_VECTOR_FONT + EXPECT_EQ(fontWeight, FONT_BPP); +#else + EXPECT_EQ(fontWeight, 0); +#endif +} + +/** + * @tc.name: Graphic_Font_Test_GetFontInfo_001 + * @tc.desc: Verify GetFontInfo function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontInfo_001, TestSize.Level1) +{ + const UITextLanguageFontParam* fontParam = UIFont::GetInstance()->GetFontInfo(FONT_ID); + EXPECT_EQ(fontParam, nullptr); +} + +/** + * @tc.name: Graphic_Font_Test_GetShapingFontId_001 + * @tc.desc: Verify GetShapingFontId function, abnormal value test. + * @tc.type: FUNC + * @tc.require: AR000FQNFR + */ +HWTEST_F(UIFontTest, Graphic_Font_Test_GetShapingFontId_001, TestSize.Level1) +{ + uint8_t ttfId = 0; + uint32_t script = 0; + uint8_t fontId = UIFont::GetInstance()->GetShapingFontId("", ttfId, script, FONT_ID, 0); + EXPECT_EQ(fontId, 0); } /** @@ -67,7 +259,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_002, TestSize.Level1) HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1) { uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("error"); +#if ENABLE_VECTOR_FONT EXPECT_EQ(ret, FONT_ERROR_RET); +#else + EXPECT_EQ(ret, 0); +#endif } /** @@ -79,7 +275,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1) HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0) { uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("ui-font.ttf"); +#if ENABLE_VECTOR_FONT EXPECT_EQ(ret, FONT_ERROR_RET); +#else + EXPECT_EQ(ret, 0); +#endif } /** @@ -91,7 +291,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0) HWTEST_F(UIFontTest, Graphic_Font_Test_UnregisterFontInfo_001, TestSize.Level1) { uint8_t ret = UIFont::GetInstance()->UnregisterFontInfo("error font name"); +#if ENABLE_VECTOR_FONT EXPECT_EQ(ret, FONT_ERROR_RET); +#else + EXPECT_EQ(ret, 0); +#endif } /** diff --git a/tools/qt/simulator/drivers/display/monitor.cpp b/tools/qt/simulator/drivers/display/monitor.cpp index 17d31de6a5613d792e5ec22bc4ac1689ba1ab745..e324ae07a582e7ec1d086030f4317da6b16c00b0 100755 --- a/tools/qt/simulator/drivers/display/monitor.cpp +++ b/tools/qt/simulator/drivers/display/monitor.cpp @@ -21,7 +21,12 @@ #include "draw/draw_utils.h" #include "font/ui_font.h" #include "font/ui_font_header.h" +#if ENABLE_VECTOR_FONT #include "font/ui_font_vector.h" +#else +#include "common/ui_text_language.h" +#include "font/ui_font_bitmap.h" +#endif #include "key_input.h" #include "mouse_input.h" #include "mousewheel_input.h" @@ -77,8 +82,19 @@ static uint8_t g_icuMemBaseAddr[OHOS::SHAPING_WORD_DICT_LENGTH]; void Monitor::InitFontEngine() { +#if ENABLE_VECTOR_FONT GraphicStartUp::InitFontEngine(reinterpret_cast(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH, VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); +#else + BitmapFontInit(); + std::string dPath(_pgmptr); + size_t len = dPath.size(); + size_t pos = dPath.find_last_of('\\'); + dPath.replace((pos + 1), (len - pos), "..\\..\\simulator\\font\\font.bin"); + GraphicStartUp::InitFontEngine(reinterpret_cast(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH, + dPath.c_str(), nullptr); +#endif + #if ENABLE_ICU GraphicStartUp::InitLineBreakEngine(reinterpret_cast(g_icuMemBaseAddr), SHAPING_WORD_DICT_LENGTH, VECTOR_FONT_DIR, DEFAULT_LINE_BREAK_RULE_FILENAME); diff --git a/tools/qt/simulator/libui/libui.pro b/tools/qt/simulator/libui/libui.pro index 770e7f2005dab077f0a59b9eb62bdb03f76fab5b..5782a6a9f8707fdf766cd2e5f952cb4320c5adb5 100644 --- a/tools/qt/simulator/libui/libui.pro +++ b/tools/qt/simulator/libui/libui.pro @@ -36,7 +36,6 @@ SOURCES += \ ../../../../frameworks/common/task.cpp \ ../../../../frameworks/common/text.cpp \ ../../../../frameworks/common/typed_text.cpp \ - ../../../../frameworks/common/ui_font_header.cpp \ ../../../../frameworks/components/root_view.cpp \ ../../../../frameworks/components/text_adapter.cpp \ ../../../../frameworks/components/ui_abstract_clock.cpp \ @@ -99,6 +98,8 @@ SOURCES += \ ../../../../frameworks/font/ui_font.cpp \ ../../../../frameworks/font/ui_font_adaptor.cpp \ ../../../../frameworks/font/ui_font_allocator.cpp \ + ../../../../frameworks/font/ui_font_bitmap.cpp \ + ../../../../frameworks/font/ui_font_builder.cpp \ ../../../../frameworks/font/ui_font_cache.cpp \ ../../../../frameworks/font/ui_font_vector.cpp \ ../../../../frameworks/font/ui_line_break.cpp \ @@ -155,6 +156,7 @@ HEADERS += \ ../../../../interfaces/innerkits/dock/rotate_input_device.h \ ../../../../interfaces/innerkits/engines/gfx/gfx_engine_manager.h \ ../../../../interfaces/innerkits/dock/vibrator_manager.h \ + ../../../../interfaces/innerkits/font/ui_font_builder.h \ ../../../../interfaces/kits/animator/animator.h \ ../../../../interfaces/kits/animator/easing_equation.h \ ../../../../interfaces/kits/animator/interpolation.h \ diff --git a/tools/qt/simulator/test/test.pro b/tools/qt/simulator/test/test.pro index 6422b8540ac7c25786ce7c152066417e369c4d50..85de034e6afd12b96e6b7dcb8b6217e2d0091834 100755 --- a/tools/qt/simulator/test/test.pro +++ b/tools/qt/simulator/test/test.pro @@ -11,7 +11,8 @@ CONFIG += c++11 # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS \ "ENABLE_ICU=1" \ - "ENABLE_VECTOR_FONT=1" + "ENABLE_VECTOR_FONT=1" \ + "ENABLE_BITMAP_FONT=0" DEFINES += QT_COMPILER @@ -23,6 +24,7 @@ DEFINES += QT_COMPILER DESTDIR = ../libs SOURCES += \ + ../../../../test/framework/common/ui_text_language.cpp \ ../../../../test/framework/src/test_case_list_adapter.cpp \ ../../../../test/framework/src/ui_test_group.cpp \ ../../../../test/framework/src/test_ability.cpp \ @@ -77,6 +79,7 @@ SOURCES += \ ../../../../test/uitest/test_render/ui_auto_test_render.cpp \ HEADERS += \ + ../../../../test/framework/common/ui_text_language.h \ ../../../../test/framework/include/test_case_list_adapter.h \ ../../../../test/framework/include/ui_test_app.h \ ../../../../test/framework/include/test_resource_config.h \ @@ -138,6 +141,7 @@ INCLUDEPATH += \ ../../../../../ui/interfaces/frameworks \ ../../../../../ui/interfaces/innerkits \ ../../../../../ui/interfaces/kits \ + ../../../../test/framework \ ../../../../test/framework/include \ ../../../../test/uitest \ ../../../../../../../third_party/bounds_checking_function/include \ diff --git a/tools/qt/simulator/uitest/UITest.pro b/tools/qt/simulator/uitest/UITest.pro index 2d062a9539212ca1a05d2d8b4715dfacf78e097e..6eb608cbb43baf68bb92b075d00f719fa464a4a2 100755 --- a/tools/qt/simulator/uitest/UITest.pro +++ b/tools/qt/simulator/uitest/UITest.pro @@ -42,7 +42,6 @@ SOURCES += \ ../../../../frameworks/common/task.cpp \ ../../../../frameworks/common/text.cpp \ ../../../../frameworks/common/typed_text.cpp \ - ../../../../frameworks/common/ui_font_header.cpp \ ../../../../frameworks/components/root_view.cpp \ ../../../../frameworks/components/text_adapter.cpp \ ../../../../frameworks/components/ui_abstract_clock.cpp \ @@ -104,6 +103,8 @@ SOURCES += \ ../../../../frameworks/font/ui_font.cpp \ ../../../../frameworks/font/ui_font_adaptor.cpp \ ../../../../frameworks/font/ui_font_allocator.cpp \ + ../../../../frameworks/font/ui_font_bitmap.cpp \ + ../../../../frameworks/font/ui_font_builder.cpp \ ../../../../frameworks/font/ui_font_cache.cpp \ ../../../../frameworks/font/ui_font_vector.cpp \ ../../../../frameworks/font/ui_line_break.cpp \ @@ -130,6 +131,7 @@ SOURCES += \ ../../../../../../../third_party/cJSON/cJSON.c SOURCES += \ + ../../../../test/framework/common/ui_text_language.cpp \ ../../../../test/framework/src/test_case_list_adapter.cpp \ ../../../../test/framework/src/ui_test_group.cpp \ ../../../../test/framework/src/test_ability.cpp \ @@ -223,6 +225,7 @@ HEADERS += \ ../../../../interfaces/innerkits/dock/focus_manager.h \ ../../../../interfaces/innerkits/dock/rotate_input_device.h \ ../../../../interfaces/innerkits/dock/vibrator_manager.h \ + ../../../../interfaces/innerkits/font/ui_font_builder.h \ ../../../../interfaces/innerkits/engines/gfx/gfx_engine_manager.h \ ../../../../interfaces/kits/animator/animator.h \ ../../../../interfaces/kits/animator/easing_equation.h \ @@ -319,6 +322,7 @@ HEADERS += \ ../../../../../../../tools/developer_tools_lite/graphic_tool/iar_project/config/gpu_2d/graphic_config.h HEADERS += \ + ../../../../test/framework/common/ui_text_language.h \ ../../../../test/framework/include/test_case_list_adapter.h \ ../../../../test/framework/include/ui_test_app.h \ ../../../../test/framework/include/test_resource_config.h \ @@ -389,6 +393,7 @@ INCLUDEPATH += \ ../drivers/indev \ ../drivers \ ../../../../frameworks \ + ../../../../test/framework \ ../../../../test/framework/include \ ../../../../test/uitest \ ../../../../../utils/frameworks/windows \