提交 2fd31d2f 编写于 作者: O openharmony_ci 提交者: Gitee

!189 字体模块增加失败log信息

Merge pull request !189 from wangtiantian/log
......@@ -16,6 +16,7 @@
#include "font/glyphs_manager.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/file.h"
#include "gfx_utils/graphic_log.h"
#include "securec.h"
namespace OHOS {
......@@ -62,6 +63,7 @@ int8_t GlyphsManager::GlyphNodeCacheInit()
int32_t ret = read(fp_, indexCache_, size);
if (ret != static_cast<int32_t>(size)) {
GRAPHIC_LOGE("GlyphsManager::GlyphNodeCacheInit read failed");
return INVALID_RET_VALUE;
}
......@@ -137,6 +139,7 @@ GlyphNode* GlyphsManager::GetNodeFromFile(uint32_t unicode)
offset += key * sizeof(uint16_t);
idx = *(reinterpret_cast<uint16_t*>(curIndexCache_ + offset));
if (idx == 0) {
GRAPHIC_LOGE("GlyphsManager::GetNodeFromFile unicode not found");
return nullptr;
}
}
......@@ -144,11 +147,13 @@ GlyphNode* GlyphsManager::GetNodeFromFile(uint32_t unicode)
offset = curGlyphNodeSectionStart_ + (idx - 1) * sizeof(GlyphNode);
int32_t ret = lseek(fp_, offset, SEEK_SET);
if (ret != static_cast<int32_t>(offset)) {
GRAPHIC_LOGE("GlyphsManager::GetNodeFromFile lseek failed");
return nullptr;
}
GlyphNode* node = GetNodeCacheSpace(unicode);
ret = read(fp_, node, sizeof(GlyphNode));
if (ret < 0) {
GRAPHIC_LOGE("GlyphsManager::GetNodeFromFile read failed");
return nullptr;
}
......@@ -164,6 +169,7 @@ void GlyphsManager::SetRamBuffer(uintptr_t ramAddr)
int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
{
if (!isRamSet_) {
GRAPHIC_LOGE("GlyphsManager::SetFile Ram not set");
return INVALID_RET_VALUE;
}
......@@ -171,16 +177,19 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
start_ = start;
int32_t ret = lseek(fp_, start_, SEEK_SET);
if (ret < 0) {
GRAPHIC_LOGE("GlyphsManager::SetFile lseek failed");
return INVALID_RET_VALUE;
}
ret = read(fp_, &binHeader_, sizeof(binHeader_));
if (ret != sizeof(binHeader_)) {
GRAPHIC_LOGE("GlyphsManager::SetFile read failed");
return INVALID_RET_VALUE;
}
if (strncmp(binHeader_.fontMagic, FONT_MAGIC_NUMBER, FONT_MAGIC_NUM_LEN) != 0) {
return INVALID_RET_VALUE;
}
if (binHeader_.fontNum > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) {
GRAPHIC_LOGE("GlyphsManager::SetFile data error, fontNum need less than max fontId");
return INVALID_RET_VALUE;
}
......@@ -195,6 +204,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
ret = read(fp_, fontHeaderCache_, size);
if (ret != size) {
GRAPHIC_LOGE("GlyphsManager::SetFile read failed");
return INVALID_RET_VALUE;
}
......@@ -209,6 +219,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
bitMapSectionStart_ = glyphNodeSectionStart_ + size;
ret = GlyphNodeCacheInit();
if (ret == RET_VALUE_OK) {
GRAPHIC_LOGE("GlyphsManager::SetFile GlyphNodeCacheInit failed");
isFileSet_ = true;
}
......@@ -220,9 +231,11 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
{
uint16_t fontIdx = 0;
if (!isFileSet_) {
GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId file not set");
return INVALID_RET_VALUE;
}
if (fontId > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) {
GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId fontId need less than max fontId");
return INVALID_RET_VALUE;
}
if (fontId_ == fontId) {
......@@ -249,6 +262,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
isFontIdSet_ = false;
curFontHeader_ = nullptr;
fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax();
GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId fontId not found");
return INVALID_RET_VALUE;
}
......@@ -271,6 +285,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
int32_t GlyphsManager::GetRamUsedLen() const
{
if (!isFileSet_) {
GRAPHIC_LOGE("GlyphsManager::GetRamUsedLen file not set");
return INVALID_RET_VALUE;
}
return ramUsedLen_;
......@@ -279,12 +294,15 @@ int32_t GlyphsManager::GetRamUsedLen() const
int8_t GlyphsManager::GetFontVersion(char* version, uint8_t len) const
{
if (!isFileSet_ || (version == nullptr) || (len > FONT_VERSION_LEN)) {
GRAPHIC_LOGE("GlyphsManager::GetFontVersion invalid parameters");
return INVALID_RET_VALUE;
}
if (memset_s(version, len, 0, len) != EOK) {
GRAPHIC_LOGE("GlyphsManager::GetFontVersion memset_s failed");
return INVALID_RET_VALUE;
}
if (strcpy_s(version, len, binHeader_.fontVersion) != EOK) {
GRAPHIC_LOGE("GlyphsManager::GetFontVersion strcpy_s failed");
return INVALID_RET_VALUE;
}
return RET_VALUE_OK;
......@@ -329,10 +347,12 @@ const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode)
int16_t GlyphsManager::GetFontHeight() const
{
if (!isFontIdSet_) {
GRAPHIC_LOGE("GlyphsManager::GetFontHeight fontId not set");
return INVALID_RET_VALUE;
}
if (curFontHeader_ == nullptr) {
GRAPHIC_LOGE("GlyphsManager::GetFontHeight curFontHeader is nullptr");
return INVALID_RET_VALUE;
}
......@@ -344,10 +364,12 @@ int16_t GlyphsManager::GetFontWidth(uint32_t unicode)
const GlyphNode* node = nullptr;
if (!isFontIdSet_) {
GRAPHIC_LOGE("GlyphsManager::GetFontWidth fontId not set");
return INVALID_RET_VALUE;
}
node = GetGlyphNode(unicode);
if (node == nullptr) {
GRAPHIC_LOGE("GlyphsManager::GetFontWidth node not found");
return INVALID_RET_VALUE;
}
return node->advance;
......@@ -356,14 +378,17 @@ int16_t GlyphsManager::GetFontWidth(uint32_t unicode)
int8_t GlyphsManager::GetBitmap(uint32_t unicode, uint8_t* bitmap)
{
if (bitmap == nullptr) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap invalid parameter");
return INVALID_RET_VALUE;
}
if (!isFontIdSet_) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap fontId not set");
return INVALID_RET_VALUE;
}
const GlyphNode* node = GetGlyphNode(unicode);
if (node == nullptr) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap node not found");
return INVALID_RET_VALUE;
}
......@@ -371,11 +396,13 @@ int8_t GlyphsManager::GetBitmap(uint32_t unicode, uint8_t* bitmap)
uint32_t size = node->kernOff - node->dataOff;
int32_t ret = lseek(fp_, offset, SEEK_SET);
if (ret != static_cast<int32_t>(offset)) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap lseek failed");
return INVALID_RET_VALUE;
}
int32_t readSize = read(fp_, bitmap, size);
if (readSize != static_cast<int32_t>(size)) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap read failed");
return INVALID_RET_VALUE;
}
......
......@@ -18,6 +18,7 @@
#include "font/ui_font_adaptor.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/file.h"
#include "gfx_utils/graphic_log.h"
#include "graphic_config.h"
#if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h"
......@@ -68,6 +69,7 @@ uint8_t UIFontBitmap::GetFontWeight(uint8_t fontId)
{
UITextLanguageFontParam* fontParam = UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId);
if (fontParam == nullptr) {
GRAPHIC_LOGE("UIFontBitmap::GetFontWeigh invalid fontId");
return 0;
}
return fontParam->fontWeight;
......@@ -76,6 +78,7 @@ uint8_t UIFontBitmap::GetFontWeight(uint8_t fontId)
int8_t UIFontBitmap::SetFontPath(const char* dpath, const char* spath)
{
if (dpath == nullptr) {
GRAPHIC_LOGE("UIFontBitmap::SetFontPath invalid parameter");
return INVALID_RET_VALUE;
}
#ifdef _WIN32
......@@ -84,12 +87,14 @@ int8_t UIFontBitmap::SetFontPath(const char* dpath, const char* spath)
dynamicFontFd_ = open(dpath, O_RDONLY);
#endif
if (dynamicFontFd_ < 0) {
GRAPHIC_LOGE("UIFontBitmap::SetFontPath file Open failed");
return INVALID_RET_VALUE;
}
dynamicFont_.SetRamBuffer(GetRamAddr());
uint32_t start = 0;
int32_t ret = dynamicFont_.SetFile(dynamicFontFd_, start);
if (ret == INVALID_RET_VALUE) {
GRAPHIC_LOGE("GlyphsManager::SetFile failed");
close(dynamicFontFd_);
dynamicFontFd_ = -1;
return ret;
......@@ -168,6 +173,7 @@ int8_t UIFontBitmap::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode)
glyphNode = *node;
return RET_VALUE_OK;
}
GRAPHIC_LOGE("UIFontBitmap::GetGlyphNode get glyphNode failed");
return INVALID_RET_VALUE;
}
......@@ -191,7 +197,6 @@ UITextLanguageFontParam* UIFontBitmap::GetFontInfo(uint8_t fontId) const
return UIFontBuilder::GetInstance()->GetTextLangFontsTable(fontId);
}
uint32_t UIFontBitmap::GetBitmapRamUsed()
{
return bitmapRamUsed_;
......@@ -221,6 +226,7 @@ uint8_t* UIFontBitmap::GetCacheBitmap(uint8_t fontId, uint32_t unicode)
if (bitmapCache_ != nullptr) {
return bitmapCache_->GetBitmap(fontId, unicode);
}
GRAPHIC_LOGE("UIFontBitmap::GetCacheBitmap invalid bitmapCache");
return nullptr;
}
......@@ -229,6 +235,7 @@ uint8_t* UIFontBitmap::GetCacheSpace(uint8_t fontId, uint32_t unicode, uint32_t
if (bitmapCache_ != nullptr) {
return bitmapCache_->GetSpace(fontId, unicode, size);
}
GRAPHIC_LOGE("UIFontBitmap::GetCacheSpace invalid bitmapCache");
return nullptr;
}
......@@ -237,6 +244,7 @@ void UIFontBitmap::PutCacheSpace(uint8_t* addr)
if (bitmapCache_ != nullptr) {
bitmapCache_->PutSpace(addr);
}
GRAPHIC_LOGE("UIFontBitmap::PutCacheSpace invalid bitmapCache");
}
int8_t UIFontBitmap::SetDynamicFontId(uint8_t fontId)
......@@ -256,6 +264,7 @@ int16_t UIFontBitmap::GetDynamicFontWidth(uint32_t unicode, uint8_t fontId)
uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId)
{
if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) {
GRAPHIC_LOGE("UIFontBitmap::GetWidthInFontId fontId and unicode not match");
return nullptr;
}
if (fontId != GetBaseFontId()) {
......@@ -291,6 +300,7 @@ uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint
int16_t UIFontBitmap::GetWidthInFontId(uint32_t unicode, uint8_t fontId)
{
if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) {
GRAPHIC_LOGE("UIFontBitmap::GetWidthInFontId fontId and unicode not match");
return INVALID_RET_VALUE;
}
if (fontId != GetBaseFontId()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册