diff --git a/frameworks/common/text.cpp b/frameworks/common/text.cpp index 9de9faf77262fea2de704d9ab4f636f29df9795f..f653bb97a8a2e6586820f8cda1e49db7c506fa35 100644 --- a/frameworks/common/text.cpp +++ b/frameworks/common/text.cpp @@ -288,11 +288,18 @@ void Text::Draw(BufferInfo& gfxDstBuffer, uint32_t maxLineBytes = 0; uint16_t lineCount = GetLine(lineMaxWidth, style.letterSpace_, ellipsisIndex, maxLineBytes); int16_t lineHeight = style.lineHeight_; + int16_t curLineHeight; if (lineHeight == 0) { + lineHeight = UIFont::GetInstance()->GetHeight(fontId_, fontSize_); + lineHeight += style.lineSpace_; + } + if ((style.lineSpace_ == 0) && (sizeSpans_ != nullptr)) { uint16_t letterIndex = 0; - int16_t lineMaxHeight = UIFont::GetInstance()->GetLineMaxHeight(text_, textLine_[0].lineBytes, fontId_, - fontSize_, letterIndex, sizeSpans_); - lineHeight = lineMaxHeight + style.lineSpace_; + curLineHeight = UIFont::GetInstance()->GetLineMaxHeight(text_, textLine_[0].lineBytes, fontId_, fontSize_, + letterIndex, sizeSpans_); + curLineHeight += style.lineSpace_; + } else { + curLineHeight = lineHeight; } Point pos; if (lineHeight == style.lineHeight_) { @@ -306,14 +313,14 @@ void Text::Draw(BufferInfo& gfxDstBuffer, if (pos.y > mask.GetBottom()) { return; } - int16_t nextLine = pos.y + lineHeight; + int16_t nextLine = pos.y + curLineHeight; if (lineHeight != style.lineHeight_) { nextLine -= style.lineSpace_; } int16_t tempLetterIndex = letterIndex; if (nextLine >= mask.GetTop()) { pos.x = LineStartPos(coords, textLine_[i].linePixelWidth); - LabelLineInfo labelLine{pos, offset, mask, lineHeight, textLine_[i].lineBytes, + LabelLineInfo labelLine{pos, offset, mask, curLineHeight, textLine_[i].lineBytes, 0, opa, style, &text_[lineBegin], textLine_[i].lineBytes, lineBegin, fontId_, fontSize_, 0, static_cast(direct_), nullptr, baseLine_, @@ -330,10 +337,15 @@ void Text::Draw(BufferInfo& gfxDstBuffer, } else { letterIndex = TypedText::GetUTF8CharacterSize(text_, lineBegin + textLine_[i].lineBytes); } - lineHeight = UIFont::GetInstance()->GetLineMaxHeight(&text_[lineBegin], textLine_[i].lineBytes, fontId_, - fontSize_, tempLetterIndex, sizeSpans_); + if ((style.lineSpace_ == 0) && (sizeSpans_ != nullptr)) { + curLineHeight = UIFont::GetInstance()->GetLineMaxHeight(&text_[lineBegin], textLine_[i].lineBytes, fontId_, + fontSize_, tempLetterIndex, sizeSpans_); + curLineHeight += style.lineSpace_; + } else { + curLineHeight = lineHeight; + } lineBegin += textLine_[i].lineBytes; - pos.y += lineHeight + style.lineSpace_; + pos.y += curLineHeight; } } diff --git a/frameworks/common/typed_text.cpp b/frameworks/common/typed_text.cpp index dcd38c6265bf4b3816ae881ad1acef11a643ae1c..809d165ee903ce97f33312b0d20abe731aa061ea 100644 --- a/frameworks/common/typed_text.cpp +++ b/frameworks/common/typed_text.cpp @@ -19,6 +19,9 @@ #include "gfx_utils/graphic_log.h" #include "gfx_utils/mem_api.h" #include "gfx_utils/transform.h" +#if ENABLE_MULTI_FONT +#include "font/ui_multi_font_manager.h" +#endif namespace OHOS { #ifndef _FONT_TOOL @@ -457,6 +460,29 @@ bool TypedText::IsEmojiBase(uint32_t codePoint) bool TypedText::IsColourWord(uint32_t codePoint, uint8_t fontId, uint8_t fontSize) { + bool hasColor = false; + uint8_t weight = UIFont::GetInstance()->GetFontWeight(fontId); + if (weight >= 16) { // 16: rgb565->16 rgba8888->32 font with rgba + hasColor = true; + } else { +#if ENABLE_MULTI_FONT + uint8_t* searchLists = nullptr; + int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); + int8_t currentIndex = 0; + if ((listSize > 0) && (searchLists != nullptr)) { + do { + weight = UIFont::GetInstance()->GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: rgb565->16 rgba8888->32 font with rgba + hasColor = true; + } + currentIndex++; + } while ((currentIndex < listSize) && (searchLists != nullptr)); + } +#endif + } + if (!hasColor) { + return false; + } GlyphNode glyphNode; int8_t ret = UIFont::GetInstance()->GetGlyphNode(codePoint, glyphNode, fontId, fontSize); if (ret != RET_VALUE_OK) { @@ -464,7 +490,7 @@ bool TypedText::IsColourWord(uint32_t codePoint, uint8_t fontId, uint8_t fontSiz return false; } - uint8_t weight = UIFont::GetInstance()->GetFontWeight(glyphNode.fontId); + weight = UIFont::GetInstance()->GetFontWeight(glyphNode.fontId); return (weight >= 16); // 16: rgb565->16 rgba8888->32 font with rgba } } // namespace OHOS diff --git a/frameworks/draw/draw_label.cpp b/frameworks/draw/draw_label.cpp index 1944759dc228da68adbbe46178cb7a0513cdaf62..ddee445687746c02ef401a1a4c0349d2f36a9aea 100644 --- a/frameworks/draw/draw_label.cpp +++ b/frameworks/draw/draw_label.cpp @@ -38,15 +38,14 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf uint32_t i = 0; uint32_t letter; - uint16_t letterWidth; 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, - labelLine.fontSize); uint8_t maxLetterSize = GetLineMaxLetterSize(labelLine.text, labelLine.lineLength, labelLine.fontId, labelLine.fontSize, letterIndex, labelLine.sizeSpans); DrawLineBackgroundColor(gfxDstBuffer, letterIndex, labelLine); + GlyphNode glyphNode; + uint8_t* fontMap; + uint8_t weight; while (i < labelLine.lineLength) { letter = TypedText::GetUTF8Next(labelLine.text, i, i); uint8_t fontId = labelLine.fontId; @@ -86,23 +85,26 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf labelLine.style.lineSpace_, havebackgroundColor, backgroundColor}; - if (TypedText::IsColourWord(letter, fontId, fontSize)) { - if (!isEmoijLerge) { - letterInfo.offsetY = offsetPosY; - } - DrawUtils::GetInstance()->DrawColorLetter(gfxDstBuffer, letterInfo); - } else { - if (isEmoijLerge) { +#if ENABLE_VECTOR_FONT + glyphNode.textStyle = letterInfo.textStyle; +#endif + glyphNode.advance = 0; + fontMap = fontEngine->GetBitmap(letterInfo.letter, glyphNode, letterInfo.fontId, letterInfo.fontSize, + letterInfo.shapingId); + if (fontMap != nullptr) { + weight = UIFont::GetInstance()->GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: rgb565->16 rgba8888->32 font with rgba + DrawUtils::GetInstance()->DrawColorLetter(gfxDstBuffer, letterInfo, fontMap, glyphNode); + } else { letterInfo.offsetY = labelLine.ellipsisOssetY == 0 ? offsetPosY : labelLine.ellipsisOssetY; retOffsetY = offsetPosY; + DrawUtils::GetInstance()->DrawNormalLetter(gfxDstBuffer, letterInfo, fontMap, glyphNode, maxLetterSize); } - DrawUtils::GetInstance()->DrawNormalLetter(gfxDstBuffer, letterInfo, maxLetterSize); } - letterWidth = fontEngine->GetWidth(letter, letterInfo.fontId, letterInfo.fontSize, letterInfo.shapingId); if (labelLine.direct == TEXT_DIRECT_RTL) { - labelLine.pos.x -= (letterWidth + labelLine.style.letterSpace_); + labelLine.pos.x -= (glyphNode.advance + labelLine.style.letterSpace_); } else { - labelLine.pos.x += (letterWidth + labelLine.style.letterSpace_); + labelLine.pos.x += (glyphNode.advance + labelLine.style.letterSpace_); } letterIndex++; @@ -113,6 +115,9 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf uint8_t DrawLabel::GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t letterIndex, SizeSpan* sizeSpans) { + if (sizeSpans == nullptr) { + return fontSize; + } uint32_t i = 0; uint32_t unicode; uint8_t maxLetterSize = fontSize; diff --git a/frameworks/draw/draw_utils.cpp b/frameworks/draw/draw_utils.cpp index 9944bcc7e41e173359c814ebc5a33a42a07dbe56..54dfa105ebb1425932e47794a9be5b18e40f638e 100644 --- a/frameworks/draw/draw_utils.cpp +++ b/frameworks/draw/draw_utils.cpp @@ -268,18 +268,15 @@ void DrawUtils::DrawPixel(BufferInfo& gfxDstBuffer, COLOR_FILL_BLEND(screenBuffer, bufferMode, &fillColor, ARGB8888, opa); } -void DrawUtils::DrawColorLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo &letterInfo) const +void DrawUtils::DrawColorLetter(BufferInfo& gfxDstBuffer, + const LabelLetterInfo& letterInfo, + uint8_t* fontMap, + GlyphNode node) const { - UIFont* fontEngine = UIFont::GetInstance(); - GlyphNode node; -#if ENABLE_VECTOR_FONT - node.textStyle = letterInfo.textStyle; -#endif - const uint8_t* fontMap = - fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.fontId, letterInfo.fontSize, letterInfo.shapingId); if (fontMap == nullptr) { return; } + UIFont* fontEngine = UIFont::GetInstance(); uint16_t letterW = node.cols; uint16_t letterH = node.rows; int16_t posX; @@ -315,20 +312,17 @@ void DrawUtils::DrawColorLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo DrawImage(gfxDstBuffer, srcRect, letterInfo.mask, fontMap, letterInfo.opa, pxSize, ARGB8888); } -void DrawUtils::DrawNormalLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo &letterInfo, +void DrawUtils::DrawNormalLetter(BufferInfo& gfxDstBuffer, + const LabelLetterInfo& letterInfo, + uint8_t* fontMap, + GlyphNode node, uint8_t maxLetterSize) const { - UIFont* fontEngine = UIFont::GetInstance(); - GlyphNode node; -#if ENABLE_VECTOR_FONT - node.textStyle = letterInfo.textStyle; -#endif - const uint8_t* fontMap = - fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.fontId, letterInfo.fontSize, letterInfo.shapingId); if (fontMap == nullptr) { return; } + UIFont* fontEngine = UIFont::GetInstance(); uint16_t letterW = node.cols; uint16_t letterH = node.rows; int16_t posX; diff --git a/frameworks/draw/draw_utils.h b/frameworks/draw/draw_utils.h index c07968c7f05a19e2fd42f5dd4f89c48e77293b54..fdf015bbbeb20a76072556b583bac2b80b9b2b43 100644 --- a/frameworks/draw/draw_utils.h +++ b/frameworks/draw/draw_utils.h @@ -209,8 +209,15 @@ public: void DrawPixel(BufferInfo& gfxDstBuffer, int16_t x, int16_t y, const Rect& mask, const ColorType& color, OpacityType opa) const; - void DrawColorLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo) const; - void DrawNormalLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo, uint8_t maxLetterSize) const; + void DrawColorLetter(BufferInfo& gfxDstBuffer, + const LabelLetterInfo& letterInfo, + uint8_t* fontMap, + GlyphNode node) const; + void DrawNormalLetter(BufferInfo& gfxDstBuffer, + const LabelLetterInfo& letterInfo, + uint8_t* fontMap, + GlyphNode node, + uint8_t maxLetterSize) const; void DrawLetter(BufferInfo& gfxDstBuffer, const uint8_t* fontMap, diff --git a/frameworks/font/glyphs_manager.cpp b/frameworks/font/glyphs_manager.cpp index 91909fdd6a182019073e9aaaba34aeb6232f02a7..5bcd24784ce08f1bb4b2c40c3b2fa6c97e481e7e 100644 --- a/frameworks/font/glyphs_manager.cpp +++ b/frameworks/font/glyphs_manager.cpp @@ -308,11 +308,6 @@ const FontHeader* GlyphsManager::GetFontHeader(uint8_t fontId) const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode, uint8_t fontId) { - GlyphInfo glyphInfo; - int8_t ret = GetGlyphInfo(fontId, glyphInfo); - if (ret != RET_VALUE_OK) { - return nullptr; - } GlyphNode* node = GetNodeFromCache(unicode, fontId); if (node == nullptr) { node = GetNodeFromFile(unicode, fontId); diff --git a/frameworks/font/ui_font_bitmap.cpp b/frameworks/font/ui_font_bitmap.cpp index df61c1b2855581b8dacb2de536b30afbe4529563..3f26b611d899b1476ddcca0a38c45b157a3aaceb 100644 --- a/frameworks/font/ui_font_bitmap.cpp +++ b/frameworks/font/ui_font_bitmap.cpp @@ -367,9 +367,13 @@ uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) { + uint16_t maxHeight = GetHeight(fontId, fontSize); + if (sizeSpans == nullptr) { + return maxHeight; + } + uint32_t i = 0; uint32_t unicode; - uint16_t maxHeight = GetHeight(fontId, fontSize); GlyphNode glyphNode; while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); @@ -382,15 +386,6 @@ uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, u spannableHeight = sizeSpans[letterIndex].height; } maxHeight = spannableHeight > maxHeight ? spannableHeight : maxHeight; - } else { -#if ENABLE_MULTI_FONT - uint8_t ret = GetMultiGlyphNode(unicode, glyphNode, fontId); -#else - uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); -#endif - if (ret == RET_VALUE_OK) { - maxHeight = glyphNode.rows > maxHeight ? glyphNode.rows : maxHeight; - } } letterIndex++; diff --git a/frameworks/font/ui_line_break.cpp b/frameworks/font/ui_line_break.cpp index a65b704b6912ec9be52d9b7d23b598e9b889afa5..e39826e56655ba1f27bfc737398647ad50cb79ba 100644 --- a/frameworks/font/ui_line_break.cpp +++ b/frameworks/font/ui_line_break.cpp @@ -138,9 +138,7 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, continue; } if (isAllCanBreak || IsBreakPos(unicode, fontId, fontSize, state)) { - if (!TypedText::IsColourWord(unicode, fontId, fontSize)) { - state = LINE_BREAK_STATE_START; - } + state = LINE_BREAK_STATE_START; // Accumulates the status value from the current character. IsBreakPos(unicode, fontId, fontSize, state); lastIndex = preIndex; @@ -193,9 +191,6 @@ int16_t UILineBreakEngine::GetLetterWidth(uint32_t unicode, uint16_t& letterInde bool UILineBreakEngine::IsBreakPos(uint32_t unicode, uint8_t fontId, uint8_t fontSize, int32_t& state) { - if (TypedText::IsColourWord(unicode, fontId, fontSize)) { - return true; - } if ((unicode > TypedText::MAX_UINT16_HIGH_SCOPE) || (stateTbl_ == nullptr) || (lineBreakTrie_ == nullptr)) { return true; }