diff --git a/frameworks/font/glyphs_manager.cpp b/frameworks/font/glyphs_manager.cpp index f08fa21d9482490362bda16dfeb7ca9f8923cc63..81d104e587e205bc5a8f2a66c0e840719257e1e9 100755 --- a/frameworks/font/glyphs_manager.cpp +++ b/frameworks/font/glyphs_manager.cpp @@ -100,7 +100,7 @@ GlyphNode* GlyphsManager::GetNodeFromCache(uint32_t unicode, uint8_t fontId) uint8_t uc = unicode & UNICODE_HASH_MASK; for (uint8_t i = 0; i < NODE_HASH_NR; i++) { GlyphNode* p = &((*nodeCache_)[font][uc][i]); - if ((p->unicode == unicode) && (p->reserve == fontId)) { + if ((p->unicode == unicode) && (p->fontId == fontId)) { node = p; break; } @@ -335,7 +335,7 @@ const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode) } uint8_t fontId = fontId_; if (curGlyphNode_ != nullptr) { - if ((curGlyphNode_->unicode == unicode) && (curGlyphNode_->reserve == fontId)) { + if ((curGlyphNode_->unicode == unicode) && (curGlyphNode_->fontId == fontId)) { return curGlyphNode_; } } @@ -343,7 +343,7 @@ const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode) if (node == nullptr) { node = GetNodeFromFile(unicode, fontId); if (node != nullptr) { - node->reserve = fontId; + node->fontId = fontId; } } curGlyphNode_ = node; @@ -386,19 +386,14 @@ int8_t GlyphsManager::GetBitmap(uint32_t unicode, uint8_t* bitmap, uint8_t fontI GRAPHIC_LOGE("GlyphsManager::GetBitmap invalid parameter"); return INVALID_RET_VALUE; } - + GraphicLockGuard guard(lock_); if (!isFontIdSet_) { GRAPHIC_LOGE("GlyphsManager::GetBitmap fontId not set"); return INVALID_RET_VALUE; } - const GlyphNode* node = GetGlyphNode(unicode); + GlyphNode* node = const_cast(GetGlyphNode(unicode)); uint32_t tmpBitMapSectionStart = curBitMapSectionStart_; - while ((node != nullptr) && ((node->reserve != fontId) || (node->unicode != unicode))) { - SetCurrentFontId(fontId); - node = GetGlyphNode(unicode); - tmpBitMapSectionStart = curBitMapSectionStart_; - } guard.Unlock(); if (node == nullptr) { GRAPHIC_LOGE("GlyphsManager::GetBitmap node not found"); @@ -418,6 +413,7 @@ int8_t GlyphsManager::GetBitmap(uint32_t unicode, uint8_t* bitmap, uint8_t fontI return INVALID_RET_VALUE; } + node->dataFlag = fontId; return RET_VALUE_OK; } } // namespace OHOS diff --git a/frameworks/font/ui_font_bitmap.cpp b/frameworks/font/ui_font_bitmap.cpp index eaf85b01a0b2cd87471b2ca430a0d9e967b2571b..66b40ed9a5557cf10594aed38fc771713b6893b0 100644 --- a/frameworks/font/ui_font_bitmap.cpp +++ b/frameworks/font/ui_font_bitmap.cpp @@ -35,7 +35,7 @@ UIFontBitmap::UIFontBitmap() : offset_(0), dynamicFont_(), dynamicFontRamUsed_(0 bitmapRamUsed_ = FONT_BITMAP_CACHE_SIZE; } -UIFontBitmap:: ~UIFontBitmap() +UIFontBitmap::~UIFontBitmap() { if (dynamicFontFd_ >= 0) { close(dynamicFontFd_); @@ -83,7 +83,7 @@ int8_t UIFontBitmap::SetFontPath(const char* dpath, const char* spath) } #ifdef _WIN32 dynamicFontFd_ = open(dpath, O_RDONLY | O_BINARY); -#else +#else dynamicFontFd_ = open(dpath, O_RDONLY); #endif if (dynamicFontFd_ < 0) { @@ -277,22 +277,27 @@ uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint SetCurrentFontId(fontId); } int8_t ret = GetGlyphNode(unicode, glyphNode); - while ((ret == RET_VALUE_OK) && ((glyphNode.reserve != fontId) || (glyphNode.unicode != unicode))) { - SetCurrentFontId(fontId); - ret = GetGlyphNode(unicode, glyphNode); - } if (ret != RET_VALUE_OK) { return nullptr; } uint8_t* bitmap = bitmapCache_->GetBitmap(fontId, unicode); if (bitmap != nullptr) { - return bitmap; + GetGlyphNode(unicode, glyphNode); + const GlyphNode* node = nullptr; + node = dynamicFont_.GetGlyphNode(unicode); + if (node != nullptr && node->dataFlag == node->fontId && fontId == node->fontId) { + return bitmap; + } else { + GRAPHIC_LOGE("DataFlag of bitmap node not equal to fontId."); + } } if (glyphNode.kernOff <= glyphNode.dataOff) { return nullptr; } uint32_t bitmapSize = glyphNode.kernOff - glyphNode.dataOff; - bitmap = bitmapCache_->GetSpace(fontId, unicode, bitmapSize); + if (bitmap == nullptr) { + bitmap = bitmapCache_->GetSpace(fontId, unicode, bitmapSize); + } ret = dynamicFont_.GetBitmap(unicode, bitmap, fontId); if (ret == RET_VALUE_OK) { return bitmap; @@ -317,4 +322,4 @@ void UIFontBitmap::SetFontFileOffset(uint32_t offset) { offset_ = offset; } -} // namespace +} // namespace OHOS diff --git a/interfaces/kits/font/ui_font_header.h b/interfaces/kits/font/ui_font_header.h index 57ce84e52fc4654fccf8d664713695a54b26e722..9510d7806a86a678b56cba1e635993d6ed6fde8a 100755 --- a/interfaces/kits/font/ui_font_header.h +++ b/interfaces/kits/font/ui_font_header.h @@ -277,7 +277,8 @@ struct GlyphNode { uint32_t dataOff; // GLYPH_DATA_OFF_OFFSET uint32_t kernOff; // GLYPH_KERN_OFF_OFFSET uint16_t kernSize; // GLYPH_KERN_SIZE_OFFSET - uint16_t reserve; // GLYPH_HEAD_RES_OFFSET + uint8_t fontId; // GLYPH_FONT_ID + uint8_t dataFlag; // GLYPH_DATA_HEAD_FLAG }; /**