提交 c01ff5b4 编写于 作者: L lancer

Description: fix font garbled on wearable device

IssueNo: https://gitee.com/openharmony/graphic_ui/issues/I4T8JZ
Feature or Bugfix: Bugfix
Binary Source:No
Signed-off-by: Nlancer <haoshuo@huawei.com>
上级 9ab0efdd
......@@ -101,7 +101,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;
}
......@@ -337,7 +337,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_;
}
}
......@@ -345,7 +345,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;
......@@ -388,19 +388,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<GlyphNode*>(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");
......@@ -420,6 +415,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
......@@ -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
......@@ -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
};
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册