提交 5f644078 编写于 作者: W wangtiantian

IssueNo:#I3NSQ6

Description:support bitmap font
Sig:graphic
Feature or Bugfix:Feature
Binary Source:No
上级 970dad23
...@@ -32,6 +32,7 @@ config("graphic_define_config") { ...@@ -32,6 +32,7 @@ config("graphic_define_config") {
defines = [ defines = [
"ENABLE_VECTOR_FONT=1", "ENABLE_VECTOR_FONT=1",
"ENABLE_BITMAP_FONT=0",
"ENABLE_SHAPING=0", "ENABLE_SHAPING=0",
"ENABLE_ICU=1", "ENABLE_ICU=1",
"ENABLE_MULTI_FONT=0", "ENABLE_MULTI_FONT=0",
...@@ -67,7 +68,6 @@ shared_library("ui") { ...@@ -67,7 +68,6 @@ shared_library("ui") {
"frameworks/common/task.cpp", "frameworks/common/task.cpp",
"frameworks/common/text.cpp", "frameworks/common/text.cpp",
"frameworks/common/typed_text.cpp", "frameworks/common/typed_text.cpp",
"frameworks/common/ui_font_header.cpp",
"frameworks/components/root_view.cpp", "frameworks/components/root_view.cpp",
"frameworks/components/text_adapter.cpp", "frameworks/components/text_adapter.cpp",
"frameworks/components/ui_abstract_clock.cpp", "frameworks/components/ui_abstract_clock.cpp",
...@@ -133,6 +133,8 @@ shared_library("ui") { ...@@ -133,6 +133,8 @@ shared_library("ui") {
"frameworks/font/ui_font.cpp", "frameworks/font/ui_font.cpp",
"frameworks/font/ui_font_adaptor.cpp", "frameworks/font/ui_font_adaptor.cpp",
"frameworks/font/ui_font_allocator.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_cache.cpp",
"frameworks/font/ui_font_vector.cpp", "frameworks/font/ui_font_vector.cpp",
"frameworks/font/ui_line_break.cpp", "frameworks/font/ui_line_break.cpp",
......
...@@ -42,26 +42,29 @@ ...@@ -42,26 +42,29 @@
#include "securec.h" #include "securec.h"
namespace OHOS { namespace OHOS {
void GraphicStartUp::InitFontEngine(uintptr_t cacheMemAddr, uint32_t cacheMemLen, const char* dPath, const char* ttfName) void GraphicStartUp::InitFontEngine(uintptr_t cacheMemAddr, uint32_t cacheMemLen, const char* dPath,
const char* ttfName)
{ {
#if ENABLE_VECTOR_FONT UIFont* uiFont = UIFont::GetInstance();
UIFont* fontEngine = UIFont::GetInstance(); if (uiFont == nullptr) {
if (fontEngine == nullptr) {
GRAPHIC_LOGE("Get UIFont error"); GRAPHIC_LOGE("Get UIFont error");
return; return;
} }
fontEngine->SetPsramMemory(cacheMemAddr, cacheMemLen); uiFont->SetPsramMemory(cacheMemAddr, cacheMemLen);
int8_t ret = fontEngine->SetFontPath(const_cast<char*>(dPath), nullptr); int8_t ret = uiFont->SetFontPath(const_cast<char*>(dPath), nullptr);
if (ret == INVALID_RET_VALUE) { if (ret == INVALID_RET_VALUE) {
GRAPHIC_LOGW("SetFontPath failed"); GRAPHIC_LOGW("SetFontPath failed");
} }
if (ttfName != nullptr) { if (uiFont->IsVectorFont()) {
uint8_t ret2 = fontEngine->RegisterFontInfo(ttfName); if (ttfName != nullptr) {
if (ret2 == INVALID_UCHAR_ID) { uint8_t ret2 = uiFont->RegisterFontInfo(ttfName);
GRAPHIC_LOGW("SetTtfName failed"); 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, void GraphicStartUp::InitLineBreakEngine(uintptr_t cacheMemAddr, uint32_t cacheMemLen, const char* path,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "draw/draw_label.h" #include "draw/draw_label.h"
#include "font/ui_font.h" #include "font/ui_font.h"
#include "font/ui_font_adaptor.h" #include "font/ui_font_adaptor.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/graphic_log.h" #include "gfx_utils/graphic_log.h"
#include "securec.h" #include "securec.h"
...@@ -82,7 +83,8 @@ void Text::SetFont(const char* name, uint8_t size) ...@@ -82,7 +83,8 @@ void Text::SetFont(const char* name, uint8_t size)
} }
if (UIFont::GetInstance()->IsVectorFont()) { if (UIFont::GetInstance()->IsVectorFont()) {
uint8_t fontId = UIFont::GetInstance()->GetFontId(name); 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; fontId_ = fontId;
fontSize_ = size; fontSize_ = size;
needRefresh_ = true; needRefresh_ = true;
...@@ -127,17 +129,18 @@ void Text::SetFont(const char* name, uint8_t size, char*& destName, uint8_t& des ...@@ -127,17 +129,18 @@ void Text::SetFont(const char* name, uint8_t size, char*& destName, uint8_t& des
void Text::SetFontId(uint8_t fontId) 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); GRAPHIC_LOGE("Text::SetFontId invalid fontId(%d)", fontId);
return; return;
} }
UITextLanguageFontParam* fontParam = GetTextLangFontsTable(fontId); UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId);
if (fontParam == nullptr) { if (fontParam == nullptr) {
return; return;
} }
if (UIFont::GetInstance()->IsVectorFont()) { if (UIFont::GetInstance()->IsVectorFont()) {
uint8_t fontId = UIFont::GetInstance()->GetFontId(fontParam->ttfName); 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; fontId_ = fontId;
fontSize_ = fontParam->size; fontSize_ = fontParam->size;
needRefresh_ = true; needRefresh_ = true;
......
...@@ -49,11 +49,11 @@ void BaseFont::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen) ...@@ -49,11 +49,11 @@ void BaseFont::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen)
int8_t BaseFont::GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const 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; return INVALID_RET_VALUE;
} }
LangTextParam *pTable = GetLangTextDefaultParamTable(); LangTextParam *pTable = UIFontBuilder::GetInstance()->GetLangTextDefaultParamTable();
if (pTable == nullptr) { if (pTable == nullptr) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "font/glyphs_manager.h" #include "font/glyphs_manager.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/file.h" #include "gfx_utils/file.h"
#include "securec.h" #include "securec.h"
...@@ -43,7 +44,7 @@ GlyphsManager::GlyphsManager() ...@@ -43,7 +44,7 @@ GlyphsManager::GlyphsManager()
isFileSet_(false), isFileSet_(false),
isFontIdSet_(false) isFontIdSet_(false)
{ {
fontId_ = GetBitmapFontIdMax(); fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax();
} }
GlyphsManager::~GlyphsManager() {} GlyphsManager::~GlyphsManager() {}
...@@ -179,7 +180,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start) ...@@ -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) { if (strncmp(binHeader_.fontMagic, FONT_MAGIC_NUMBER, FONT_MAGIC_NUM_LEN) != 0) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
if (binHeader_.fontNum > GetBitmapFontIdMax()) { if (binHeader_.fontNum > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
...@@ -211,7 +212,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start) ...@@ -211,7 +212,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
isFileSet_ = true; isFileSet_ = true;
} }
fontId_ = GetBitmapFontIdMax(); fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax();
return ret; return ret;
} }
...@@ -221,7 +222,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) ...@@ -221,7 +222,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
if (!isFileSet_) { if (!isFileSet_) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
if (fontId > GetBitmapFontIdMax()) { if (fontId > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
if (fontId_ == fontId) { if (fontId_ == fontId) {
...@@ -247,7 +248,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) ...@@ -247,7 +248,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
if (!found) { if (!found) {
isFontIdSet_ = false; isFontIdSet_ = false;
curFontHeader_ = nullptr; curFontHeader_ = nullptr;
fontId_ = GetBitmapFontIdMax(); fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax();
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include "font/ui_font_cache.h" #include "font/ui_font_cache.h"
#if ENABLE_VECTOR_FONT #if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h" #include "font/ui_font_vector.h"
#endif // ENABLE_VECTOR_FONT #else
#include "font/ui_font_bitmap.h"
#endif
#include "graphic_config.h" #include "graphic_config.h"
#if ENABLE_MULTI_FONT #if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h" #include "font/ui_multi_font_manager.h"
...@@ -37,6 +39,11 @@ UIFont* UIFont::GetInstance() ...@@ -37,6 +39,11 @@ UIFont* UIFont::GetInstance()
instance.defaultInstance_ = new UIFontVector(); instance.defaultInstance_ = new UIFontVector();
instance.instance_ = instance.defaultInstance_; instance.instance_ = instance.defaultInstance_;
} }
#else
if (instance.instance_ == nullptr) {
instance.defaultInstance_ = new UIFontBitmap();
instance.instance_ = instance.defaultInstance_;
}
#endif #endif
return &instance; return &instance;
} }
......
/*
* 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<uint8_t*>(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<uint8_t*>(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
/*
* 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<UITextLanguageFontParam*>(uiTextLangFontsTable);
totalFontId_ = totalFontId;
}
}
void UIFontBuilder::SetLangTextDefaultParamTable(const LangTextParam* langTextDefaultParamTable,
uint8_t totalLangId)
{
if ((langTextDefaultParamTable != nullptr) && (totalLangId > 0)) {
langTextDefaultParamTable_ = const_cast<LangTextParam*>(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
...@@ -30,7 +30,7 @@ UIMultiFontManager::UIMultiFontManager() ...@@ -30,7 +30,7 @@ UIMultiFontManager::UIMultiFontManager()
bengaliTtfId_(0), topIndex_(0) bengaliTtfId_(0), topIndex_(0)
{ {
const UITextLanguageFontParam* fontParam = nullptr; const UITextLanguageFontParam* fontParam = nullptr;
uint8_t totalFontId = GetTotalFontId(); uint8_t totalFontId = UIFontBuilder::GetInstance()->GetTotalFontId();
for (uint8_t i = 0; i < totalFontId; i++) { for (uint8_t i = 0; i < totalFontId; i++) {
fontParam = UIFont::GetInstance()->GetFontInfo(i); fontParam = UIFont::GetInstance()->GetFontInfo(i);
if (fontParam == nullptr) { if (fontParam == nullptr) {
...@@ -121,7 +121,7 @@ void UIMultiFontManager::UpdateScript(UITextLanguageFontParam& fonts) ...@@ -121,7 +121,7 @@ void UIMultiFontManager::UpdateScript(UITextLanguageFontParam& fonts)
void UIMultiFontManager::ClearSearchFontList() void UIMultiFontManager::ClearSearchFontList()
{ {
uint8_t totalFontId = GetTotalFontId(); uint8_t totalFontId = UIFontBuilder::GetInstance()->GetTotalFontId();
for (uint8_t index = 0; index < totalFontId; index++) { for (uint8_t index = 0; index < totalFontId; index++) {
fontIdIndex_[index] = MAX_LIST_NUM; fontIdIndex_[index] = MAX_LIST_NUM;
} }
...@@ -136,7 +136,7 @@ void UIMultiFontManager::ClearSearchFontList() ...@@ -136,7 +136,7 @@ void UIMultiFontManager::ClearSearchFontList()
int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontIds, uint8_t size) 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)) { (fontIdIndex_ == nullptr) || (topIndex_ >= MAX_LIST_NUM)) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
...@@ -146,7 +146,7 @@ int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontId ...@@ -146,7 +146,7 @@ int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontId
int8_t UIMultiFontManager::GetSearchFontList(uint8_t fontListId, uint8_t **fontIds) 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)) { (fontIdIndex_ == nullptr) || (fontIdIndex_[fontListId] >= MAX_LIST_NUM)) {
return INVALID_RET_VALUE; return INVALID_RET_VALUE;
} }
......
/*
* 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
/* /*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at. * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef GRAPHIC_LITE_UI_FONT_BUILDER_H
#include "font/ui_font.h" #define GRAPHIC_LITE_UI_FONT_BUILDER_H
#include "font/ui_font_header.h"
#include "font/ui_font_header.h"
namespace OHOS {
UITextLanguageFontParam* GetTextLangFontsTable(uint8_t langFontId) namespace OHOS {
{ class UIFontBuilder {
// Need to be implemented public:
return nullptr;
} static UIFontBuilder* GetInstance();
uint8_t GetTotalLangId() void SetTextLangFontsTable(const UITextLanguageFontParam* uiTextLangFontsTable, uint8_t totalFontId);
{
// Need to be implemented void SetLangTextDefaultParamTable(const LangTextParam* langTextDefaultParamTable, uint8_t totalLangId);
return 0;
} void SetMaxTextId(uint16_t totalTextId);
uint8_t GetBitmapFontIdMax() UITextLanguageFontParam* GetTextLangFontsTable(uint8_t langFontId);
{
// Need to be implemented uint8_t GetTotalLangId() const;
return 0;
} uint8_t GetTotalFontId() const;
uint8_t GetTotalFontId() uint8_t GetBitmapFontIdMax() const;
{
// Need to be implemented uint16_t GetTotalTextId() const;
return 0xFF;
} LangTextParam* GetLangTextDefaultParamTable();
uint16_t GetTotalTextId() UITextLanguageFontParam* uiTextLangFontsTable_;
{ LangTextParam* langTextDefaultParamTable_;
// Need to be implemented private:
return 0; UIFontBuilder();
} ~UIFontBuilder() {}
uint8_t totalLangId_;
LangTextParam* GetLangTextDefaultParamTable() uint8_t totalFontId_;
{ uint16_t totalTextId_;
// Need to be implemented };
return nullptr; }
} #endif // GRAPHIC_LITE_UI_FONT_BUILDER_H
} // namespace OHOS \ No newline at end of file
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef BASE_FONT #ifndef BASE_FONT
#define BASE_FONT #define BASE_FONT
#include "font/ui_font_header.h" #include "font/ui_font_header.h"
#include "font/ui_font_builder.h"
#include "graphic_config.h" #include "graphic_config.h"
namespace OHOS { namespace OHOS {
...@@ -101,7 +102,7 @@ public: ...@@ -101,7 +102,7 @@ public:
virtual uint8_t GetCurrentLangId() const virtual uint8_t GetCurrentLangId() const
{ {
return GetTotalLangId(); return UIFontBuilder::GetInstance()->GetTotalLangId();
} }
int8_t GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const; int8_t GetDefaultParamByLangId(uint8_t langId, LangTextParam** pParam) const;
......
...@@ -61,6 +61,7 @@ test_sources = [ ...@@ -61,6 +61,7 @@ test_sources = [
"../uitest/test_view_percent/ui_test_view_percent.cpp", "../uitest/test_view_percent/ui_test_view_percent.cpp",
"../uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp", "../uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp",
"../uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp", "../uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp",
"common/ui_text_language.cpp",
"src/test_ability.cpp", "src/test_ability.cpp",
"src/test_case_list_adapter.cpp", "src/test_case_list_adapter.cpp",
"src/ui_test_app.cpp", "src/ui_test_app.cpp",
...@@ -77,7 +78,9 @@ static_library("framework") { ...@@ -77,7 +78,9 @@ static_library("framework") {
sources = test_sources sources = test_sources
include_dirs = [ include_dirs = [
"common",
"include", "include",
"../framework",
"../uitest", "../uitest",
"../../tools", "../../tools",
"../../interfaces", "../../interfaces",
...@@ -98,7 +101,9 @@ static_library("auto_framework") { ...@@ -98,7 +101,9 @@ static_library("auto_framework") {
sources = test_sources sources = test_sources
include_dirs = [ include_dirs = [
"common",
"include", "include",
"../framework",
"../uitest", "../uitest",
"../../tools", "../../tools",
"../../interfaces", "../../interfaces",
......
/*
* 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
/*
* 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 <cstdint>
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
...@@ -15,18 +15,25 @@ ...@@ -15,18 +15,25 @@
#include "ui_test_font.h" #include "ui_test_font.h"
#include "common/screen.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 "components/ui_label.h"
#include "font/ui_font.h" #include "font/ui_font.h"
#if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h"
#endif
namespace OHOS { namespace OHOS {
namespace { namespace {
const int16_t GAP = 15; const int16_t GAP = 5;
const int16_t TITLE_HEIGHT = 20; const int16_t TITLE_HEIGHT = 20;
const uint16_t LABEL_WIDTH = 400; const uint16_t LABEL_WIDTH = 400;
const uint16_t LABEL_HEIGHT = 50; const uint16_t LABEL_HEIGHT = 50;
const uint16_t BUF_SIZE = 200; const uint16_t FONT_SIZE = 30;
static uint8_t g_newFontPsramBaseAddr[OHOS::MIN_FONT_PSRAM_LENGTH]; const char* SOURCE_HAN_SANS_SC_REGULAR = "SourceHanSansSC-Regular.otf";
const char* ROBOTO_CONDENSED_REGULAR = "RobotoCondensed-Regulat.ttf";
} // namespace } // namespace
void UITestFont::SetUp() void UITestFont::SetUp()
...@@ -52,7 +59,11 @@ void UITestFont::InnerTestTitle(const char* title) ...@@ -52,7 +59,11 @@ void UITestFont::InnerTestTitle(const char* title)
UILabel* titleLabel = new UILabel(); UILabel* titleLabel = new UILabel();
titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(), titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(),
TITLE_LABEL_DEFAULT_HEIGHT); 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); titleLabel->SetText(title);
container_->Add(titleLabel); container_->Add(titleLabel);
positionY_ += TITLE_HEIGHT + GAP; positionY_ += TITLE_HEIGHT + GAP;
...@@ -60,149 +71,243 @@ void UITestFont::InnerTestTitle(const char* title) ...@@ -60,149 +71,243 @@ void UITestFont::InnerTestTitle(const char* title)
UIView* UITestFont::GetTestView() UIView* UITestFont::GetTestView()
{ {
Font_FontEngine_FontConvert_Test_FontTestSetFontId_001(); UIKitFontTestDispaly001();
Font_FontEngine_FontConvert_Test_FontTestSetFont_001(); UIKitFontTestDispaly002();
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001(); UIKitFontTestDispaly003();
Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001(); UIKitFontTestDispaly004();
Font_FontEngine_FontConvert_Test_FontTestGetFontId_001(); UIKitFontTestDispaly005();
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001(); UIKitFontTestDispaly006();
Font_FontEngine_FontConvert_Test_FontTestPsram_001(); UIKitFontTestDispaly007();
Font_FontEngine_FontConvert_Test_FontTestFontPath_001(); UIKitFontTestDispaly008();
#if ENABLE_MULTI_FONT
UIKitFontMultiLanguage001();
UIKitFontMultiLanguage002();
#endif
return container_; 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) { if (container_ == nullptr) {
InnerTestTitle("Test Psram"); return;
UIFont::GetInstance()->SetPsramMemory(reinterpret_cast<uintptr_t>(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<char*>(buf));
container_->Add(label);
positionY_ += LABEL_HEIGHT + GAP;
} }
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) { if (container_ == nullptr) {
InnerTestTitle("Test Font Path"); return;
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<char*>(buf));
container_->Add(label);
positionY_ += LABEL_HEIGHT + GAP;
} }
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) { if (container_ == nullptr) {
InnerTestTitle("Test Set Font Id"); return;
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;
} }
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) { if (container_ == nullptr) {
InnerTestTitle("Test Set Font"); return;
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;
} }
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) { if (container_ == nullptr) {
InnerTestTitle("Test Get Font Height"); return;
UILabel* label = new UILabel(); }
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18 : size InnerTestTitle(" Display multiline Chinese and English");
char buf[BUF_SIZE] = {0}; UILabel* label = new UILabel();
label->SetText(reinterpret_cast<char*>(buf)); label->SetPosition(positionX_, positionY_);
label->SetPosition(positionX_, positionY_); label->Resize(LABEL_WIDTH, LABEL_HEIGHT * 2); // 2 : double
label->Resize(LABEL_WIDTH, LABEL_HEIGHT); #if ENABLE_VECTOR_FONT
positionY_ += LABEL_HEIGHT + GAP; UIFont::GetInstance()->RegisterFontInfo(SOURCE_HAN_SANS_SC_REGULAR);
container_->Add(label); 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) { if (container_ == nullptr) {
InnerTestTitle("Test Get Font Version"); return;
UILabel* label = new UILabel();
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
char buf[BUF_SIZE] = {0};
label->SetText(reinterpret_cast<char*>(buf));
label->SetPosition(positionX_, positionY_);
label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
positionY_ += LABEL_HEIGHT + GAP;
container_->Add(label);
} }
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) { if (container_ == nullptr) {
InnerTestTitle("Test Get Font Id"); return;
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<char*>(buf));
label->SetPosition(positionX_, positionY_);
label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
positionY_ += LABEL_HEIGHT + GAP;
container_->Add(label);
} }
#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) { if (container_ == nullptr) {
InnerTestTitle("Test Get Font Header"); return;
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<char*>(buf));
label->SetPosition(positionX_, positionY_);
label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
positionY_ += LABEL_HEIGHT + GAP;
container_->Add(label);
} }
#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 #endif // ENABLE_MULTI_FONT
\ No newline at end of file } // namespace OHOS
...@@ -28,47 +28,56 @@ public: ...@@ -28,47 +28,56 @@ public:
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
UIView* GetTestView() override; 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 UIKitFontTestDispaly008();
#if ENABLE_MULTI_FONT
/**
* @brief Test multilingual display
*/ */
void Font_FontEngine_FontConvert_Test_FontTestGetFontHeader_001(); void UIKitFontMultiLanguage001();
/**
* @brief Test multilingual display
*/
void UIKitFontMultiLanguage002();
#endif // ENABLE_MULTI_FONT
private: private:
UIScrollView* container_ = nullptr; UIScrollView* container_ = nullptr;
void InnerTestTitle(const char* title); void InnerTestTitle(const char* title);
......
...@@ -99,7 +99,7 @@ void UITestLabel::UIKit_UILabel_Test_Display_001() ...@@ -99,7 +99,7 @@ void UITestLabel::UIKit_UILabel_Test_Display_001()
uiViewGroupFrame->SetStyle(STYLE_BACKGROUND_OPA, 0); uiViewGroupFrame->SetStyle(STYLE_BACKGROUND_OPA, 0);
uiLabel = new UILabel(); uiLabel = new UILabel();
uiLabel->SetText("鸿蒙轻量级图形子系统"); 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 uiLabel->SetPosition(0, 141, 280, 336); // 141: y-coordinate; 280: width; 336: height
uiViewGroupFrame->Add(uiLabel); uiViewGroupFrame->Add(uiLabel);
positionX_ += 336; // 336: x-coordinate positionX_ += 336; // 336: x-coordinate
...@@ -123,7 +123,7 @@ void UITestLabel::CreateLabels(UIViewGroup* uiViewGroup) ...@@ -123,7 +123,7 @@ void UITestLabel::CreateLabels(UIViewGroup* uiViewGroup)
label1->SetText("字号"); label1->SetText("字号");
label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
labelFontSizeBtn1_ = SetUpButton("18 ", 24, 48, uiViewGroup); // 24: x-coordinate; 48: y-coordinate 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 labelFontSizeBtn3_ = SetUpButton("30", 208, 48, uiViewGroup); // 208: x-coordinate; 48: y-coordinate
UILabel* label2 = new UILabel(); UILabel* label2 = new UILabel();
...@@ -210,11 +210,11 @@ void UITestLabel::UIKit_UILabel_Test_Display_003() ...@@ -210,11 +210,11 @@ void UITestLabel::UIKit_UILabel_Test_Display_003()
bool UITestLabel::OnClick(UIView& view, const ClickEvent& event) bool UITestLabel::OnClick(UIView& view, const ClickEvent& event)
{ {
uiLabel->Resize(288, 100); // 288: width; 100: height 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_) { if (&view == labelFontSizeBtn1_) {
uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: font size uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: font size
} else if (&view == labelFontSizeBtn2_) { } 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_) { } else if (&view == labelFontSizeBtn3_) {
uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size uiLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
} else if (&view == labelHorAlignBtn1_) { } else if (&view == labelHorAlignBtn1_) {
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
*/ */
#include "font/ui_font.h" #include "font/ui_font.h"
#if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h" #include "font/ui_font_vector.h"
#else
#include "font/ui_font_bitmap.h"
#endif
#include <climits> #include <climits>
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -23,16 +26,40 @@ using namespace testing::ext; ...@@ -23,16 +26,40 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace { namespace {
constexpr uint8_t FONT_ERROR_RET = 0xFF; 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 { class UIFontTest : public testing::Test {
public: public:
UIFontTest() {} UIFontTest() {}
virtual ~UIFontTest() {} virtual ~UIFontTest() {}
static void SetUpTestCase();
static void SetUpTestCase() {}; static void TearDownTestCase();
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.name: Graphic_Font_Test_GetInstance_001
* @tc.desc: Verify UIFont::GetInstance function, not nullptr. * @tc.desc: Verify UIFont::GetInstance function, not nullptr.
...@@ -46,16 +73,181 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_001, TestSize.Level0) ...@@ -46,16 +73,181 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_001, TestSize.Level0)
} }
/** /**
* @tc.name: Graphic_Font_Test_GetInstance_002 * @tc.name: Graphic_Font_Test_IsVectorFont_001
* @tc.desc: Verify UIFont::GetInstance function, equal. * @tc.desc: Verify IsVectorFont function, equal.
* @tc.type: FUNC * @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(); bool ret = UIFont::GetInstance()->IsVectorFont();
EXPECT_EQ(ret, true); 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<uint16_t>(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) ...@@ -67,7 +259,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_002, TestSize.Level1)
HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1) HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1)
{ {
uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("error"); uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("error");
#if ENABLE_VECTOR_FONT
EXPECT_EQ(ret, FONT_ERROR_RET); 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) ...@@ -79,7 +275,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1)
HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0) HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0)
{ {
uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("ui-font.ttf"); uint8_t ret = UIFont::GetInstance()->RegisterFontInfo("ui-font.ttf");
#if ENABLE_VECTOR_FONT
EXPECT_EQ(ret, FONT_ERROR_RET); 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) ...@@ -91,7 +291,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0)
HWTEST_F(UIFontTest, Graphic_Font_Test_UnregisterFontInfo_001, TestSize.Level1) HWTEST_F(UIFontTest, Graphic_Font_Test_UnregisterFontInfo_001, TestSize.Level1)
{ {
uint8_t ret = UIFont::GetInstance()->UnregisterFontInfo("error font name"); uint8_t ret = UIFont::GetInstance()->UnregisterFontInfo("error font name");
#if ENABLE_VECTOR_FONT
EXPECT_EQ(ret, FONT_ERROR_RET); EXPECT_EQ(ret, FONT_ERROR_RET);
#else
EXPECT_EQ(ret, 0);
#endif
} }
/** /**
......
...@@ -21,7 +21,12 @@ ...@@ -21,7 +21,12 @@
#include "dock/screen_device_proxy.h" #include "dock/screen_device_proxy.h"
#include "font/ui_font.h" #include "font/ui_font.h"
#include "font/ui_font_header.h" #include "font/ui_font_header.h"
#if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h" #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 "key_input.h"
#include "mouse_input.h" #include "mouse_input.h"
#include "mousewheel_input.h" #include "mousewheel_input.h"
...@@ -66,8 +71,19 @@ static uint8_t g_icuMemBaseAddr[OHOS::SHAPING_WORD_DICT_LENGTH]; ...@@ -66,8 +71,19 @@ static uint8_t g_icuMemBaseAddr[OHOS::SHAPING_WORD_DICT_LENGTH];
void Monitor::InitFontEngine() void Monitor::InitFontEngine()
{ {
#if ENABLE_VECTOR_FONT
GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH, GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH,
VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); 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<uintptr_t>(g_fontMemBaseAddr), MIN_FONT_PSRAM_LENGTH,
dPath.c_str(), nullptr);
#endif
#if ENABLE_ICU #if ENABLE_ICU
GraphicStartUp::InitLineBreakEngine(reinterpret_cast<uintptr_t>(g_icuMemBaseAddr), SHAPING_WORD_DICT_LENGTH, GraphicStartUp::InitLineBreakEngine(reinterpret_cast<uintptr_t>(g_icuMemBaseAddr), SHAPING_WORD_DICT_LENGTH,
VECTOR_FONT_DIR, DEFAULT_LINE_BREAK_RULE_FILENAME); VECTOR_FONT_DIR, DEFAULT_LINE_BREAK_RULE_FILENAME);
......
...@@ -36,7 +36,6 @@ SOURCES += \ ...@@ -36,7 +36,6 @@ SOURCES += \
../../../../frameworks/common/task.cpp \ ../../../../frameworks/common/task.cpp \
../../../../frameworks/common/text.cpp \ ../../../../frameworks/common/text.cpp \
../../../../frameworks/common/typed_text.cpp \ ../../../../frameworks/common/typed_text.cpp \
../../../../frameworks/common/ui_font_header.cpp \
../../../../frameworks/components/root_view.cpp \ ../../../../frameworks/components/root_view.cpp \
../../../../frameworks/components/text_adapter.cpp \ ../../../../frameworks/components/text_adapter.cpp \
../../../../frameworks/components/ui_abstract_clock.cpp \ ../../../../frameworks/components/ui_abstract_clock.cpp \
...@@ -98,6 +97,8 @@ SOURCES += \ ...@@ -98,6 +97,8 @@ SOURCES += \
../../../../frameworks/font/ui_font.cpp \ ../../../../frameworks/font/ui_font.cpp \
../../../../frameworks/font/ui_font_adaptor.cpp \ ../../../../frameworks/font/ui_font_adaptor.cpp \
../../../../frameworks/font/ui_font_allocator.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_cache.cpp \
../../../../frameworks/font/ui_font_vector.cpp \ ../../../../frameworks/font/ui_font_vector.cpp \
../../../../frameworks/font/ui_line_break.cpp \ ../../../../frameworks/font/ui_line_break.cpp \
...@@ -155,6 +156,7 @@ HEADERS += \ ...@@ -155,6 +156,7 @@ HEADERS += \
../../../../interfaces/innerkits/dock/focus_manager.h \ ../../../../interfaces/innerkits/dock/focus_manager.h \
../../../../interfaces/innerkits/dock/rotate_input_device.h \ ../../../../interfaces/innerkits/dock/rotate_input_device.h \
../../../../interfaces/innerkits/dock/vibrator_manager.h \ ../../../../interfaces/innerkits/dock/vibrator_manager.h \
../../../../interfaces/innerkits/font/ui_font_builder.h \
../../../../interfaces/kits/animator/animator.h \ ../../../../interfaces/kits/animator/animator.h \
../../../../interfaces/kits/animator/easing_equation.h \ ../../../../interfaces/kits/animator/easing_equation.h \
../../../../interfaces/kits/animator/interpolation.h \ ../../../../interfaces/kits/animator/interpolation.h \
......
...@@ -11,7 +11,8 @@ CONFIG += c++11 ...@@ -11,7 +11,8 @@ CONFIG += c++11
# deprecated API in order to know how to port your code away from it. # deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS \ DEFINES += QT_DEPRECATED_WARNINGS \
"ENABLE_ICU=1" \ "ENABLE_ICU=1" \
"ENABLE_VECTOR_FONT=1" "ENABLE_VECTOR_FONT=1" \
"ENABLE_BITMAP_FONT=0"
DEFINES += QT_COMPILER DEFINES += QT_COMPILER
...@@ -23,6 +24,7 @@ DEFINES += QT_COMPILER ...@@ -23,6 +24,7 @@ DEFINES += QT_COMPILER
DESTDIR = ../libs DESTDIR = ../libs
SOURCES += \ SOURCES += \
../../../../test/framework/common/ui_text_language.cpp \
../../../../test/framework/src/test_case_list_adapter.cpp \ ../../../../test/framework/src/test_case_list_adapter.cpp \
../../../../test/framework/src/ui_test_group.cpp \ ../../../../test/framework/src/ui_test_group.cpp \
../../../../test/framework/src/test_ability.cpp \ ../../../../test/framework/src/test_ability.cpp \
...@@ -77,6 +79,7 @@ SOURCES += \ ...@@ -77,6 +79,7 @@ SOURCES += \
../../../../test/uitest/test_render/ui_auto_test_render.cpp \ ../../../../test/uitest/test_render/ui_auto_test_render.cpp \
HEADERS += \ HEADERS += \
../../../../test/framework/common/ui_text_language.h \
../../../../test/framework/include/test_case_list_adapter.h \ ../../../../test/framework/include/test_case_list_adapter.h \
../../../../test/framework/include/ui_test_app.h \ ../../../../test/framework/include/ui_test_app.h \
../../../../test/framework/include/test_resource_config.h \ ../../../../test/framework/include/test_resource_config.h \
...@@ -138,6 +141,7 @@ INCLUDEPATH += \ ...@@ -138,6 +141,7 @@ INCLUDEPATH += \
../../../../../ui/interfaces/frameworks \ ../../../../../ui/interfaces/frameworks \
../../../../../ui/interfaces/innerkits \ ../../../../../ui/interfaces/innerkits \
../../../../../ui/interfaces/kits \ ../../../../../ui/interfaces/kits \
../../../../test/framework \
../../../../test/framework/include \ ../../../../test/framework/include \
../../../../test/uitest \ ../../../../test/uitest \
../../../../../../../third_party/bounds_checking_function/include \ ../../../../../../../third_party/bounds_checking_function/include \
......
...@@ -42,7 +42,6 @@ SOURCES += \ ...@@ -42,7 +42,6 @@ SOURCES += \
../../../../frameworks/common/task.cpp \ ../../../../frameworks/common/task.cpp \
../../../../frameworks/common/text.cpp \ ../../../../frameworks/common/text.cpp \
../../../../frameworks/common/typed_text.cpp \ ../../../../frameworks/common/typed_text.cpp \
../../../../frameworks/common/ui_font_header.cpp \
../../../../frameworks/components/root_view.cpp \ ../../../../frameworks/components/root_view.cpp \
../../../../frameworks/components/text_adapter.cpp \ ../../../../frameworks/components/text_adapter.cpp \
../../../../frameworks/components/ui_abstract_clock.cpp \ ../../../../frameworks/components/ui_abstract_clock.cpp \
...@@ -104,6 +103,8 @@ SOURCES += \ ...@@ -104,6 +103,8 @@ SOURCES += \
../../../../frameworks/font/ui_font.cpp \ ../../../../frameworks/font/ui_font.cpp \
../../../../frameworks/font/ui_font_adaptor.cpp \ ../../../../frameworks/font/ui_font_adaptor.cpp \
../../../../frameworks/font/ui_font_allocator.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_cache.cpp \
../../../../frameworks/font/ui_font_vector.cpp \ ../../../../frameworks/font/ui_font_vector.cpp \
../../../../frameworks/font/ui_line_break.cpp \ ../../../../frameworks/font/ui_line_break.cpp \
...@@ -130,6 +131,7 @@ SOURCES += \ ...@@ -130,6 +131,7 @@ SOURCES += \
../../../../../../../third_party/cJSON/cJSON.c ../../../../../../../third_party/cJSON/cJSON.c
SOURCES += \ SOURCES += \
../../../../test/framework/common/ui_text_language.cpp \
../../../../test/framework/src/test_case_list_adapter.cpp \ ../../../../test/framework/src/test_case_list_adapter.cpp \
../../../../test/framework/src/ui_test_group.cpp \ ../../../../test/framework/src/ui_test_group.cpp \
../../../../test/framework/src/test_ability.cpp \ ../../../../test/framework/src/test_ability.cpp \
...@@ -225,6 +227,7 @@ HEADERS += \ ...@@ -225,6 +227,7 @@ HEADERS += \
../../../../interfaces/innerkits/dock/focus_manager.h \ ../../../../interfaces/innerkits/dock/focus_manager.h \
../../../../interfaces/innerkits/dock/rotate_input_device.h \ ../../../../interfaces/innerkits/dock/rotate_input_device.h \
../../../../interfaces/innerkits/dock/vibrator_manager.h \ ../../../../interfaces/innerkits/dock/vibrator_manager.h \
../../../../interfaces/innerkits/font/ui_font_builder.h \
../../../../interfaces/kits/animator/animator.h \ ../../../../interfaces/kits/animator/animator.h \
../../../../interfaces/kits/animator/easing_equation.h \ ../../../../interfaces/kits/animator/easing_equation.h \
../../../../interfaces/kits/animator/interpolation.h \ ../../../../interfaces/kits/animator/interpolation.h \
...@@ -320,6 +323,7 @@ HEADERS += \ ...@@ -320,6 +323,7 @@ HEADERS += \
../../../../../../../tools/developer_tools_lite/graphic_tool/iar_project/config/gpu_2d/graphic_config.h ../../../../../../../tools/developer_tools_lite/graphic_tool/iar_project/config/gpu_2d/graphic_config.h
HEADERS += \ HEADERS += \
../../../../test/framework/common/ui_text_language.h \
../../../../test/framework/include/test_case_list_adapter.h \ ../../../../test/framework/include/test_case_list_adapter.h \
../../../../test/framework/include/ui_test_app.h \ ../../../../test/framework/include/ui_test_app.h \
../../../../test/framework/include/test_resource_config.h \ ../../../../test/framework/include/test_resource_config.h \
...@@ -390,6 +394,7 @@ INCLUDEPATH += \ ...@@ -390,6 +394,7 @@ INCLUDEPATH += \
../drivers/indev \ ../drivers/indev \
../drivers \ ../drivers \
../../../../frameworks \ ../../../../frameworks \
../../../../test/framework \
../../../../test/framework/include \ ../../../../test/framework/include \
../../../../test/uitest \ ../../../../test/uitest \
../../../../../utils/frameworks/windows \ ../../../../../utils/frameworks/windows \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册