diff --git a/frameworks/common/typed_text.cpp b/frameworks/common/typed_text.cpp index 382abbab79dd8aff80db35a5f8a6665fe3681d2e..ab932dba138b354c80cefb2da632aa3fc661b1cc 100755 --- a/frameworks/common/typed_text.cpp +++ b/frameworks/common/typed_text.cpp @@ -455,9 +455,16 @@ bool TypedText::IsEmojiBase(uint32_t codePoint) } } -bool TypedText::IsColourWord(uint32_t fontId) +bool TypedText::IsColourWord(uint32_t codePoint, uint8_t fontId, uint8_t fontSize) { - uint8_t weight = UIFont::GetInstance()->GetFontWeight(fontId); + GlyphNode glyphNode; + int8_t ret = UIFont::GetInstance()->GetGlyphNode(codePoint, glyphNode, fontId, fontSize); + if (ret != RET_VALUE_OK) { + GRAPHIC_LOGE("Failed to get glyphNode for color word"); + return false; + } + + uint8_t weight = UIFont::GetInstance()->GetFontWeight(glyphNode.fontId); return (weight >= 16); // 16: rgb565->16 rgba8888->32 font with rgba } } // namespace OHOS diff --git a/frameworks/common/typed_text.h b/frameworks/common/typed_text.h index 03c44827a3a6dd5caa3f43e7c9346f4f4a328cb2..17214a5ffea4c05d5d6ef0296fdcf8963337b5bb 100755 --- a/frameworks/common/typed_text.h +++ b/frameworks/common/typed_text.h @@ -90,7 +90,7 @@ public: static bool IsEmojiModifier(uint32_t codePoint); static bool IsEmojiBase(uint32_t codePoint); - static bool IsColourWord(uint32_t fontId); + static bool IsColourWord(uint32_t codePoint, uint8_t fontId, uint8_t fontSize); private: static bool GetWrapPoint(const char* text, uint32_t& breakPoint); diff --git a/frameworks/draw/draw_label.cpp b/frameworks/draw/draw_label.cpp index a3828d32f7f69741e05faa6c6c89eae6c3dc38c8..7cf923b810844a584d5b30818468910d6183aa2c 100755 --- a/frameworks/draw/draw_label.cpp +++ b/frameworks/draw/draw_label.cpp @@ -42,7 +42,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf uint16_t retOffsetY = 0; // ret value elipse offsetY bool isEmoijLerge = true; uint16_t offsetPosY = 0; - offsetPosY = fontEngine->GetOffsetPosY(labelLine.text, labelLine.lineLength, isEmoijLerge, labelLine.fontId, + offsetPosY = fontEngine->GetOffsetPosY(labelLine.text, labelLine.lineLength, isEmoijLerge, labelLine.fontId, labelLine.fontSize); uint8_t maxLetterSize = GetLineMaxLetterSize(labelLine.text, labelLine.lineLength, labelLine.fontId, labelLine.fontSize, letterIndex, labelLine.sizeSpans); @@ -86,7 +86,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf labelLine.style.lineSpace_, havebackgroundColor, backgroundColor}; - if (TypedText::IsColourWord(letterInfo.fontId)) { + if (TypedText::IsColourWord(letter, fontId, fontSize)) { if (!isEmoijLerge) { letterInfo.offsetY = offsetPosY; } @@ -118,7 +118,7 @@ uint8_t DrawLabel::GetLineMaxLetterSize(const char* text, uint16_t lineLength, u uint8_t maxLetterSize = fontSize; while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); - if (TypedText::IsColourWord(fontId)) { + if (TypedText::IsColourWord(unicode, fontId, fontSize)) { letterIndex++; continue; } diff --git a/frameworks/font/ui_font.cpp b/frameworks/font/ui_font.cpp index 30b6286cd8c0340d19d9ebfc771fe73ff535af59..0e7e291c4955686cdc3550c6a684654168d6b710 100755 --- a/frameworks/font/ui_font.cpp +++ b/frameworks/font/ui_font.cpp @@ -100,6 +100,31 @@ uint8_t* UIFont::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontI return nullptr; } +int8_t UIFont::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) +{ + int8_t result = instance_->GetGlyphNode(unicode, glyphNode, fontId, fontSize); + if (result == RET_VALUE_OK) { + return result; + } + +#if ENABLE_MULTI_FONT + uint8_t* searchLists = nullptr; + int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); + if ((searchLists == nullptr) || (listSize == 0)) { + return INVALID_RET_VALUE; + } + int8_t currentIndex = 0; + do { + result = instance_->GetGlyphNode(unicode, glyphNode, searchLists[currentIndex], fontSize); + if (result == RET_VALUE_OK) { + return result; + } + currentIndex++; + } while ((currentIndex < listSize) && (searchLists != nullptr)); +#endif + return INVALID_RET_VALUE; +} + uint16_t UIFont::GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize, uint8_t shapingId) { int16_t result; diff --git a/frameworks/font/ui_font_bitmap.cpp b/frameworks/font/ui_font_bitmap.cpp index 378a36c438d8d3b8cc9cf9dce50f91c3d80c7f8a..aa5651794269034591046e7078c996173dae0559 100644 --- a/frameworks/font/ui_font_bitmap.cpp +++ b/frameworks/font/ui_font_bitmap.cpp @@ -151,30 +151,29 @@ int8_t UIFontBitmap::GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8 #if ENABLE_MULTI_FONT int8_t UIFontBitmap::GetMultiGlyphNode( uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) { - if (TypedText::IsColourWord(fontId)) { - int8_t ret; - uint8_t* searchLists = nullptr; - //uint8_t baseId = GetBaseFontId(); - int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); - int8_t currentIndex = 0; - if ((searchLists == nullptr) || (listSize == 0)) { - return INVALID_RET_VALUE; - } - do { - ret = GetGlyphNode(unicode, glyphNode, searchLists[currentIndex]); - if (ret != INVALID_RET_VALUE) { - return ret; - } - // switch to next search List - currentIndex++; - } while ((currentIndex < listSize) && (searchLists != nullptr)); - return INVALID_RET_VALUE; - } else { - return GetGlyphNode(unicode, glyphNode, fontId); + int8_t ret = GetGlyphNode(unicode, glyphNode, fontId); + if (ret == RET_VALUE_OK) { + return ret; } + uint8_t* searchLists = nullptr; + int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); + int8_t currentIndex = 0; + if ((searchLists == nullptr) || (listSize == 0)) { + return INVALID_RET_VALUE; + } + do { + ret = GetGlyphNode(unicode, glyphNode, searchLists[currentIndex]); + if (ret != INVALID_RET_VALUE) { + return ret; + } + // switch to next search List + currentIndex++; + } while ((currentIndex < listSize) && (searchLists != nullptr)); + return INVALID_RET_VALUE; } #endif + int8_t UIFontBitmap::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { const GlyphNode* node = dynamicFont_.GetGlyphNode(unicode, fontId); @@ -332,7 +331,8 @@ uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); #endif if (ret == RET_VALUE_OK) { - if (TypedText::IsColourWord(fontId)) { + uint8_t weight = GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: bit rgb565 rgba8888 emoijMaxNode = glyphNode.rows > emoijMaxNode.rows ? glyphNode : emoijMaxNode; emojiNum++; } else { diff --git a/frameworks/font/ui_font_vector.cpp b/frameworks/font/ui_font_vector.cpp index 3b66318d31a07189c022018cfe7b1124ce836831..d83ef5fb22fb7ce3607c9f04e05ae99a7835642f 100755 --- a/frameworks/font/ui_font_vector.cpp +++ b/frameworks/font/ui_font_vector.cpp @@ -341,7 +341,7 @@ int16_t UIFontVector::GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSiz FaceInfo faceInfo = {}; int8_t ret = INVALID_RET_VALUE; - if (TypedText::IsColourWord(fontId)) { + if (TypedText::IsColourWord(unicode, fontId, fontSize)) { ret = LoadGlyphIntoFace(fontId, unicode, faceInfo.face); @@ -695,7 +695,8 @@ uint16_t UIFontVector::GetOffsetPosY(const char *text, uint16_t lineLength, bool unicode = TypedText::GetUTF8Next(text, i, i); uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); if (ret == RET_VALUE_OK) { - if (TypedText::IsColourWord(fontId)) { + uint8_t weight = GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: bit rgb565 rgba8888 emojiMaxNode = glyphNode.rows > emojiMaxNode.rows ? glyphNode : emojiMaxNode; emojiNum++; } else { @@ -740,7 +741,7 @@ uint16_t UIFontVector::GetLineMaxHeight(const char *text, uint16_t lineLength, u uint16_t maxHeight = GetHeight(fontId, fontSize); while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); - TypedText::IsColourWord(fontId) ? emojiNum++ : textNum++; + TypedText::IsColourWord(unicode, fontId, fontSize) ? emojiNum++ : textNum++; loopNum++; if (sizeSpans != nullptr && sizeSpans[letterIndex].isSizeSpan) { uint16_t spannableHeight = 0; diff --git a/frameworks/font/ui_line_break.cpp b/frameworks/font/ui_line_break.cpp index 84c8d39780372130883f56cc585bd9db956a13b5..9bd11723e6bf4e9f44d9359f22c9c913689bba18 100755 --- a/frameworks/font/ui_line_break.cpp +++ b/frameworks/font/ui_line_break.cpp @@ -130,12 +130,12 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, uint8_t fontId preIndex = byteIdx; continue; } - if (isAllCanBreak || IsBreakPos(unicode, fontId, state)) { - if (!TypedText::IsColourWord(fontId)) { + if (isAllCanBreak || IsBreakPos(unicode, fontId, fontSize, state)) { + if (!TypedText::IsColourWord(unicode, fontId, fontSize)) { state = LINE_BREAK_STATE_START; } // Accumulates the status value from the current character. - IsBreakPos(unicode, fontId, state); + IsBreakPos(unicode, fontId, fontSize, state); lastIndex = preIndex; lastWidth = curWidth; } @@ -185,9 +185,9 @@ int16_t UILineBreakEngine::GetLetterWidth(uint32_t unicode, uint16_t& letterInde } } -bool UILineBreakEngine::IsBreakPos(uint32_t unicode, uint8_t fontId, int32_t& state) +bool UILineBreakEngine::IsBreakPos(uint32_t unicode, uint8_t fontId, uint8_t fontSize, int32_t& state) { - if (TypedText::IsColourWord(fontId)) { + if (TypedText::IsColourWord(unicode, fontId, fontSize)) { return true; } if ((unicode > TypedText::MAX_UINT16_HIGH_SCOPE) || (stateTbl_ == nullptr) || (lineBreakTrie_ == nullptr)) { diff --git a/frameworks/font/ui_line_break.h b/frameworks/font/ui_line_break.h index 52ae24701fefc816dd313c32fbd54c5c591cb1fb..1e78d4421c02d3fb49532ff670b4efe260348e50 100755 --- a/frameworks/font/ui_line_break.h +++ b/frameworks/font/ui_line_break.h @@ -118,7 +118,7 @@ public: uint16_t& letterIndex, SizeSpan* sizeSpans, uint16_t len = 0xFFFF); - bool IsBreakPos(uint32_t unicode, uint8_t fontId, int32_t& state); + bool IsBreakPos(uint32_t unicode, uint8_t fontId, uint8_t fontSize, int32_t& state); private: UILineBreakEngine() diff --git a/interfaces/kits/font/ui_font.h b/interfaces/kits/font/ui_font.h index 0ca4bcbce11ebcf8b5b3d1885409d7942903b5fa..6a31279d8a0bd2d4b680b646073fb96eb30ed4ff 100755 --- a/interfaces/kits/font/ui_font.h +++ b/interfaces/kits/font/ui_font.h @@ -113,6 +113,8 @@ public: */ uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize, uint8_t shapingFont); + int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize); + /** * @brief Indicates whether the current font library is a vector font library. * @return uint8_t: 0 BitmapFont 1 VectorFont