diff --git a/frameworks/common/text.cpp b/frameworks/common/text.cpp index 70c901918e734786f5b658a0c509177618643f9b..9de9faf77262fea2de704d9ab4f636f29df9795f 100644 --- a/frameworks/common/text.cpp +++ b/frameworks/common/text.cpp @@ -220,14 +220,13 @@ void Text::ReMeasureTextSize(const Rect& textRect, const Style& style) if (fontSize_ == 0) { return; } - UIFont::GetInstance()->SetCurrentFontId(fontId_, fontSize_); int16_t maxWidth = (expandWidth_ ? COORD_MAX : textRect.GetWidth()); if (maxWidth > 0) { - textSize_ = TypedText::GetTextSize(text_, style.letterSpace_, style.lineHeight_, maxWidth, - sizeSpans_, style.lineSpace_); + textSize_ = TypedText::GetTextSize(text_, fontId_, fontSize_, style.letterSpace_, style.lineHeight_, maxWidth, + style.lineSpace_, sizeSpans_); if (baseLine_) { FontHeader head; - if (UIFont::GetInstance()->GetCurrentFontHeader(head) != 0) { + if (UIFont::GetInstance()->GetFontHeader(head, fontId_, fontSize_) != 0) { return; } textSize_.y += fontSize_ - head.ascender; @@ -268,7 +267,6 @@ void Text::OnDraw(BufferInfo& gfxDstBuffer, if ((text_ == nullptr) || (strlen(text_) == 0) || (fontSize_ == 0)) { return; } - UIFont::GetInstance()->SetCurrentFontId(fontId_, fontSize_); Rect mask = invalidatedArea; if (mask.Intersect(mask, textRect)) { @@ -292,8 +290,8 @@ void Text::Draw(BufferInfo& gfxDstBuffer, int16_t lineHeight = style.lineHeight_; if (lineHeight == 0) { uint16_t letterIndex = 0; - int16_t lineMaxHeight = UIFont::GetInstance()->GetLineMaxHeight(text_, textLine_[0].lineBytes, 0, - letterIndex, sizeSpans_); + int16_t lineMaxHeight = UIFont::GetInstance()->GetLineMaxHeight(text_, textLine_[0].lineBytes, fontId_, + fontSize_, letterIndex, sizeSpans_); lineHeight = lineMaxHeight + style.lineSpace_; } Point pos; @@ -332,8 +330,8 @@ void Text::Draw(BufferInfo& gfxDstBuffer, } else { letterIndex = TypedText::GetUTF8CharacterSize(text_, lineBegin + textLine_[i].lineBytes); } - lineHeight = UIFont::GetInstance()->GetLineMaxHeight(&text_[lineBegin], textLine_[i].lineBytes, 0, - tempLetterIndex, sizeSpans_); + lineHeight = UIFont::GetInstance()->GetLineMaxHeight(&text_[lineBegin], textLine_[i].lineBytes, fontId_, + fontSize_, tempLetterIndex, sizeSpans_); lineBegin += textLine_[i].lineBytes; pos.y += lineHeight + style.lineSpace_; } @@ -386,7 +384,7 @@ uint16_t Text::GetLine(int16_t width, uint8_t letterSpace, uint16_t ellipsisInde lineNum++; } if ((lineNum != 0) && (ellipsisIndex != TEXT_ELLIPSIS_END_INV)) { - uint16_t ellipsisWidth = UIFont::GetInstance()->GetWidth('.', 0) + letterSpace; + uint16_t ellipsisWidth = UIFont::GetInstance()->GetWidth('.', fontId_, fontSize_, 0) + letterSpace; textLine_[lineNum - 1].linePixelWidth += ellipsisWidth * TEXT_ELLIPSIS_DOT_NUM; if (textLine_[lineNum - 1].linePixelWidth > width) { int16_t newWidth = width - ellipsisWidth * TEXT_ELLIPSIS_DOT_NUM; @@ -428,8 +426,9 @@ uint32_t Text::GetTextLine(uint32_t begin, uint32_t textLen, int16_t width, uint { int16_t lineWidth = width; int16_t lineHeight = 0; - uint16_t nextLineBytes = UIFontAdaptor::GetNextLineAndWidth(&text_[begin], letterSpace, lineWidth, lineHeight, - letterIndex, sizeSpans, false, textLen - begin); + uint16_t nextLineBytes = UIFontAdaptor::GetNextLineAndWidth(&text_[begin], fontId_, fontSize_, letterSpace, + lineWidth, lineHeight, letterIndex, sizeSpans, false, + textLen - begin); if (nextLineBytes + begin > textLen) { nextLineBytes = textLen - begin; } @@ -444,14 +443,13 @@ uint16_t Text::GetEllipsisIndex(const Rect& textRect, const Style& style) return TEXT_ELLIPSIS_END_INV; } UIFont* fontEngine = UIFont::GetInstance(); - fontEngine->SetCurrentFontId(fontId_, fontSize_); - int16_t letterWidth = fontEngine->GetWidth('.', 0) + style.letterSpace_; + int16_t letterWidth = fontEngine->GetWidth('.', fontId_, fontSize_, 0) + style.letterSpace_; Point p; p.x = textRect.GetWidth() - letterWidth * TEXT_ELLIPSIS_DOT_NUM; p.y = textRect.GetHeight(); int16_t height = style.lineHeight_; if (height == 0) { - height = fontEngine->GetHeight() + style.lineSpace_; + height = fontEngine->GetHeight(fontId_, fontSize_) + style.lineSpace_; } if (height) { p.y -= p.y % height; @@ -470,7 +468,7 @@ uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style uint32_t lineStart = 0; uint32_t nextLineStart = 0; int16_t lineHeight = style.lineHeight_; - uint16_t letterHeight = UIFont::GetInstance()->GetHeight(); + uint16_t letterHeight = UIFont::GetInstance()->GetHeight(fontId_, fontSize_); if (lineHeight == 0) { lineHeight = letterHeight + style.lineSpace_; } @@ -486,8 +484,8 @@ uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style uint16_t letterIndex = 0; while ((lineStart < textLen) && (text_[lineStart] != '\0')) { width = textRect.GetWidth(); - nextLineStart += UIFontAdaptor::GetNextLineAndWidth(&text_[lineStart], style.letterSpace_, width, lineHeight, - letterIndex, sizeSpans_); + nextLineStart += UIFontAdaptor::GetNextLineAndWidth(&text_[lineStart], fontId_, fontSize_, style.letterSpace_, + width, lineHeight, letterIndex, sizeSpans_); if (nextLineStart == 0) { break; } @@ -502,8 +500,9 @@ uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style } /* Calculate the x coordinate */ width = pos.x; - lineStart += UIFontAdaptor::GetNextLineAndWidth(&text_[lineStart], style.letterSpace_, width, lineHeight, - letterIndex, sizeSpans_, true); + lineStart += + UIFontAdaptor::GetNextLineAndWidth(&text_[lineStart], fontId_, fontSize_, style.letterSpace_, width, lineHeight, + letterIndex, sizeSpans_, true); return (lineStart < textLen) ? lineStart : TEXT_ELLIPSIS_END_INV; } diff --git a/frameworks/common/typed_text.cpp b/frameworks/common/typed_text.cpp index 555df5abb89245dc286859522fbb74b75cf254b8..dcd38c6265bf4b3816ae881ad1acef11a643ae1c 100644 --- a/frameworks/common/typed_text.cpp +++ b/frameworks/common/typed_text.cpp @@ -22,8 +22,8 @@ namespace OHOS { #ifndef _FONT_TOOL -Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t lineHeight, int16_t maxWidth, - SizeSpan* sizeSpans, int8_t lineSpace) +Point TypedText::GetTextSize(const char* text, uint8_t fontId, uint8_t fontSize, int16_t letterSpace, + int16_t lineHeight, int16_t maxWidth, int8_t lineSpace, SizeSpan* sizeSpans) { Point size{0, 0}; @@ -34,7 +34,7 @@ Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t line uint32_t lineBegin = 0; uint32_t newLineBegin = 0; - uint16_t letterHeight = UIFont::GetInstance()->GetHeight(); + uint16_t letterHeight = UIFont::GetInstance()->GetHeight(fontId, fontSize); uint16_t height = lineHeight; if (lineHeight == 0) { lineHeight = letterHeight + lineSpace; @@ -43,8 +43,8 @@ Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t line uint16_t letterIndex = 0; while (text[lineBegin] != '\0') { int16_t lineWidth = maxWidth; - newLineBegin += UIFontAdaptor::GetNextLineAndWidth(&text[lineBegin], letterSpace, lineWidth, lineHeight, - letterIndex, sizeSpans); + newLineBegin += UIFontAdaptor::GetNextLineAndWidth(&text[lineBegin], fontId, fontSize, letterSpace, + lineWidth, lineHeight, letterIndex, sizeSpans); if (newLineBegin == lineBegin) { break; } @@ -75,6 +75,8 @@ Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t line } Rect TypedText::GetArcTextRect(const char* text, + uint8_t fontId, + uint8_t fontSize, const Point& arcCenter, int16_t letterSpace, UIArcLabel::TextOrientation orientation, @@ -85,7 +87,7 @@ Rect TypedText::GetArcTextRect(const char* text, return Rect(); } - uint16_t letterHeight = UIFont::GetInstance()->GetHeight(); + uint16_t letterHeight = UIFont::GetInstance()->GetHeight(fontId, fontSize); bool xorFlag = (orientation == UIArcLabel::TextOrientation::INSIDE) ^ (arcTextInfo.direct == TEXT_DIRECT_LTR); float posX = 0; float posY = 0; @@ -103,7 +105,7 @@ Rect TypedText::GetArcTextRect(const char* text, if ((letter == '\r') || (letter == '\n')) { break; } - uint16_t letterWidth = UIFont::GetInstance()->GetWidth(letter, 0); + uint16_t letterWidth = UIFont::GetInstance()->GetWidth(letter, fontId, fontSize, 0); if (tmp == arcTextInfo.lineStart) { angle += xorFlag ? GetAngleForArcLen(static_cast(letterWidth), letterHeight, arcTextInfo.radius, arcTextInfo.direct, orientation) @@ -157,18 +159,19 @@ void TypedText::GetArcLetterPos(const Point& arcCenter, uint16_t radius, float a posY = arcCenter.y - (static_cast(radius) * Sin(angle + QUARTER_IN_DEGREE)); } -uint32_t TypedText::GetNextLine(const char* text, int16_t letterSpace, int16_t maxWidth) +uint32_t TypedText::GetNextLine(const char* text, uint8_t fontId, uint8_t fontSize, int16_t letterSpace, + int16_t maxWidth) { uint32_t index = 0; if ((text == nullptr) || (GetWrapPoint(text, index) && - (TypedText::GetTextWidth(text, index, letterSpace) <= maxWidth))) { + (TypedText::GetTextWidth(text, fontId, fontSize, index, letterSpace) <= maxWidth))) { return index; } uint32_t lastBreakPos = 0; int16_t curW; uint32_t tmp = 0; while (true) { - curW = TypedText::GetTextWidth(text, index, letterSpace); + curW = TypedText::GetTextWidth(text, fontId, fontSize, index, letterSpace); if (curW > maxWidth) { index = lastBreakPos; if (lastBreakPos == 0) { @@ -179,7 +182,7 @@ uint32_t TypedText::GetNextLine(const char* text, int16_t letterSpace, int16_t m while (text[i] != '\0') { tmp = i; letter = TypedText::GetUTF8Next(text, tmp, i); - letterWidth = UIFont::GetInstance()->GetWidth(letter, 0); + letterWidth = UIFont::GetInstance()->GetWidth(letter, fontId, fontSize, 0); curW += letterWidth; if (letterWidth > 0) { curW += letterSpace; @@ -200,7 +203,8 @@ uint32_t TypedText::GetNextLine(const char* text, int16_t letterSpace, int16_t m if (text[index] == '\0') { break; } - if (GetWrapPoint(text + index, tmp) && (TypedText::GetTextWidth(text, index + tmp, letterSpace) <= maxWidth)) { + if (GetWrapPoint(text + index, tmp) && + (TypedText::GetTextWidth(text, fontId, fontSize, index + tmp, letterSpace) <= maxWidth)) { return index + tmp; } index += tmp; @@ -238,7 +242,8 @@ bool TypedText::GetWrapPoint(const char* text, uint32_t& breakPoint) return false; } -int16_t TypedText::GetTextWidth(const char* text, uint16_t length, int16_t letterSpace) +int16_t TypedText::GetTextWidth(const char* text, uint8_t fontId, uint8_t fontSize, uint16_t length, + int16_t letterSpace) { if ((text == nullptr) || (length == 0) || (length > strlen(text))) { GRAPHIC_LOGE("TypedText::GetTextWidth invalid parameter\n"); @@ -254,7 +259,7 @@ int16_t TypedText::GetTextWidth(const char* text, uint16_t length, int16_t lette if ((letter == 0) || (letter == '\n') || (letter == '\r')) { continue; } - uint16_t charWidth = UIFont::GetInstance()->GetWidth(letter, 0); + uint16_t charWidth = UIFont::GetInstance()->GetWidth(letter, fontId, fontSize, 0); width += charWidth + letterSpace; } if (width > 0) { @@ -405,7 +410,6 @@ uint32_t TypedText::GetUtf16Cnt(const char* utf8Str) return len; } -#if ENABLE_VECTOR_FONT bool TypedText::IsEmoji(uint32_t codePoint) { // Miscellaneous symbols and symbol fonts @@ -450,14 +454,17 @@ bool TypedText::IsEmojiBase(uint32_t codePoint) return false; } } -#endif -bool TypedText::IsColourWord(uint32_t codePoint) +bool TypedText::IsColourWord(uint32_t codePoint, uint8_t fontId, uint8_t fontSize) { -#if ENABLE_VECTOR_FONT - return IsEmoji(codePoint) || IsEmojiModifier(codePoint) || IsEmojiBase(codePoint); -#else - return codePoint >= 0xF000 && codePoint <= 0xF8FF; -#endif + 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 cab9bd456aba4a0ea7594b41e5988367cc8d5515..17214a5ffea4c05d5d6ef0296fdcf8963337b5bb 100644 --- a/frameworks/common/typed_text.h +++ b/frameworks/common/typed_text.h @@ -19,7 +19,6 @@ #include "graphic_config.h" #ifndef _FONT_TOOL #include "components/ui_arc_label.h" -#include "draw/draw_utils.h" #include "font/ui_font_header.h" #include "gfx_utils/geometry2d.h" #endif @@ -40,21 +39,29 @@ public: static constexpr uint8_t UTF8_TO_UNICODE_SHIFT3 = 18; static Point GetTextSize(const char* text, + uint8_t fontId, + uint8_t fontSize, int16_t letterSpace, int16_t lineHeight, int16_t maxWidth, - SizeSpan* sizeSpans = nullptr, - int8_t lineSpace = 0); + int8_t lineSpace, + SizeSpan* sizeSpans = nullptr); static uint32_t GetNextLine(const char* text, + uint8_t fontId, + uint8_t fontSize, int16_t letterSpace, int16_t maxWidth); static int16_t GetTextWidth(const char* text, + uint8_t fontId, + uint8_t fontSize, uint16_t length, int16_t letterSpace); static Rect GetArcTextRect(const char* text, + uint8_t fontId, + uint8_t fontSize, const Point& arcCenter, int16_t letterSpace, UIArcLabel::TextOrientation orientation, @@ -78,12 +85,12 @@ public: static uint32_t GetUTF8CharacterSize(const char* text, uint32_t byteIndex = UINT32_MAX); static void Utf8ToUtf16(const char* utf8Str, uint16_t* utf16Str, uint32_t len); static uint32_t GetUtf16Cnt(const char* utf8Str); -#if ENABLE_VECTOR_FONT + static bool IsEmoji(uint32_t codePoint); static bool IsEmojiModifier(uint32_t codePoint); static bool IsEmojiBase(uint32_t codePoint); -#endif - static bool IsColourWord(uint32_t codePoint); + + 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/components/ui_arc_label.cpp b/frameworks/components/ui_arc_label.cpp index 3fb45b608b457061bd8d34d96a4f0fdb0e507629..460d047fa689af47d3264b3ddd6cd31c93c8d19b 100644 --- a/frameworks/components/ui_arc_label.cpp +++ b/frameworks/components/ui_arc_label.cpp @@ -14,6 +14,7 @@ */ #include "components/ui_arc_label.h" + #include "common/typed_text.h" #include "draw/draw_label.h" #include "engines/gfx/gfx_engine_manager.h" @@ -134,9 +135,8 @@ void UIArcLabel::DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, Opacity center.x = arcTextInfo_.arcCenter.x + GetRect().GetX(); center.y = arcTextInfo_.arcCenter.y + GetRect().GetY(); InitArcLabelText(); - UIFont::GetInstance()->SetCurrentFontId(arcLabelText_->GetFontId(), arcLabelText_->GetFontSize()); DrawLabel::DrawArcText(gfxDstBuffer, mask, arcLabelText_->GetText(), center, arcLabelText_->GetFontId(), - arcTextInfo_, orientation_, *style_, opaScale); + arcLabelText_->GetFontSize(), arcTextInfo_, orientation_, *style_, opaScale); } void UIArcLabel::RefreshArcLabel() @@ -154,11 +154,11 @@ void UIArcLabel::ReMeasure() } needRefresh_ = false; InitArcLabelText(); - UIFont::GetInstance()->SetCurrentFontId(arcLabelText_->GetFontId(), arcLabelText_->GetFontSize()); MeasureArcTextInfo(); - Rect textRect = TypedText::GetArcTextRect(arcLabelText_->GetText(), arcCenter_, style_->letterSpace_, orientation_, - arcTextInfo_); + Rect textRect = + TypedText::GetArcTextRect(arcLabelText_->GetText(), arcLabelText_->GetFontId(), arcLabelText_->GetFontSize(), + arcCenter_, style_->letterSpace_, orientation_, arcTextInfo_); int16_t arcTextWidth = textRect.GetWidth(); int16_t arcTextHeight = textRect.GetHeight(); @@ -177,7 +177,7 @@ void UIArcLabel::MeasureArcTextInfo() if (text == nullptr) { return; } - uint16_t letterHeight = UIFont::GetInstance()->GetHeight(); + uint16_t letterHeight = UIFont::GetInstance()->GetHeight(arcLabelText_->GetFontId(), arcLabelText_->GetFontSize()); arcTextInfo_.radius = ((orientation_ == TextOrientation::INSIDE) ? radius_ : (radius_ - letterHeight)); if (arcTextInfo_.radius == 0) { return; @@ -196,11 +196,13 @@ void UIArcLabel::MeasureArcTextInfo() // calculate max arc length float maxLength = static_cast((UI_PI * radius_ * arcAngle) / SEMICIRCLE_IN_DEGREE); arcTextInfo_.lineStart = 0; - arcTextInfo_.lineEnd = - TypedText::GetNextLine(&text[arcTextInfo_.lineStart], style_->letterSpace_, static_cast(maxLength)); + arcTextInfo_.lineEnd = TypedText::GetNextLine(&text[arcTextInfo_.lineStart], arcLabelText_->GetFontId(), + arcLabelText_->GetFontSize(), style_->letterSpace_, + static_cast(maxLength)); arcTextInfo_.startAngle = startAngle_ % CIRCLE_IN_DEGREE; - int16_t actLength = TypedText::GetTextWidth(&text[arcTextInfo_.lineStart], - arcTextInfo_.lineEnd - arcTextInfo_.lineStart, style_->letterSpace_); + int16_t actLength = + TypedText::GetTextWidth(&text[arcTextInfo_.lineStart], arcLabelText_->GetFontId(), arcLabelText_->GetFontSize(), + arcTextInfo_.lineEnd - arcTextInfo_.lineStart, style_->letterSpace_); if ((arcLabelText_->GetHorAlign() != TEXT_ALIGNMENT_LEFT) && (actLength < maxLength)) { float gapLength = maxLength - actLength; if (arcLabelText_->GetHorAlign() == TEXT_ALIGNMENT_CENTER) { diff --git a/frameworks/components/ui_dialog.cpp b/frameworks/components/ui_dialog.cpp index 143ed1c1030527b45063fdfee03966ad73938e1f..d493ad8f9979d409c06fd41c5da5ec975fba7de7 100644 --- a/frameworks/components/ui_dialog.cpp +++ b/frameworks/components/ui_dialog.cpp @@ -477,18 +477,24 @@ uint16_t UIDialog::MeasureButtonWidth() if (button1_ != nullptr) { const char* text1 = button1_->GetText(); - buttonTextWidth = MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text1, - button1_->GetStyleConst().letterSpace_, button1_->GetStyleConst().lineHeight_, widthMax_).x); + buttonTextWidth = + MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text1, button1_->GetFontId(), BUTTON_FONT_SIZE, + button1_->GetStyleConst().letterSpace_, + button1_->GetStyleConst().lineHeight_, widthMax_, 0).x); } if (button2_ != nullptr) { const char* text2 = button2_->GetText(); - buttonTextWidth = MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text2, - button2_->GetStyleConst().letterSpace_, button2_->GetStyleConst().lineHeight_, widthMax_).x); + buttonTextWidth = + MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text2, button2_->GetFontId(), BUTTON_FONT_SIZE, + button2_->GetStyleConst().letterSpace_, + button2_->GetStyleConst().lineHeight_, widthMax_, 0).x); } if (button3_ != nullptr) { const char* text3 = button3_->GetText(); - buttonTextWidth = MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text3, - button3_->GetStyleConst().letterSpace_, button3_->GetStyleConst().lineHeight_, widthMax_).x); + buttonTextWidth = + MATH_MAX(buttonTextWidth, TypedText::GetTextSize(text3, button3_->GetFontId(), BUTTON_FONT_SIZE, + button3_->GetStyleConst().letterSpace_, + button3_->GetStyleConst().lineHeight_, widthMax_, 0).x); } return (buttonTextWidth + BUTTON_HEIGHT) > buttonMaxWidth ? buttonMaxWidth : (buttonTextWidth + BUTTON_HEIGHT); } diff --git a/frameworks/draw/draw_label.cpp b/frameworks/draw/draw_label.cpp index 96ec645e193c8edd8282a304db25f0c01db698de..1944759dc228da68adbbe46178cb7a0513cdaf62 100644 --- a/frameworks/draw/draw_label.cpp +++ b/frameworks/draw/draw_label.cpp @@ -42,19 +42,18 @@ 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.fontSize); - uint8_t maxLetterSize = GetLineMaxLetterSize(labelLine.text, labelLine.lineLength, labelLine.fontSize, - letterIndex, labelLine.sizeSpans); + 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); while (i < labelLine.lineLength) { letter = TypedText::GetUTF8Next(labelLine.text, i, i); uint8_t fontId = labelLine.fontId; uint8_t fontSize = labelLine.fontSize; - bool isSpanLetter = false; if (labelLine.sizeSpans != nullptr && labelLine.sizeSpans[letterIndex].isSizeSpan) { fontId = labelLine.sizeSpans[letterIndex].fontId; fontSize = labelLine.sizeSpans[letterIndex].size; - isSpanLetter = true; } bool havebackgroundColor = false; ColorType backgroundColor; @@ -87,7 +86,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf labelLine.style.lineSpace_, havebackgroundColor, backgroundColor}; - if (TypedText::IsColourWord(letterInfo.letter)) { + if (TypedText::IsColourWord(letter, fontId, fontSize)) { if (!isEmoijLerge) { letterInfo.offsetY = offsetPosY; } @@ -97,15 +96,9 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf letterInfo.offsetY = labelLine.ellipsisOssetY == 0 ? offsetPosY : labelLine.ellipsisOssetY; retOffsetY = offsetPosY; } - DrawUtils::GetInstance()->DrawNormalLetter(gfxDstBuffer, letterInfo, maxLetterSize, isSpanLetter); - } - if (isSpanLetter) { - letterWidth = fontEngine->GetWidthSpannable(letter, - labelLine.sizeSpans[letterIndex].fontId, - labelLine.sizeSpans[letterIndex].size); - } else { - letterWidth = fontEngine->GetWidth(letter, 0); + 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_); } else { @@ -117,7 +110,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf return retOffsetY; } -uint8_t DrawLabel::GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint8_t fontSize, +uint8_t DrawLabel::GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t letterIndex, SizeSpan* sizeSpans) { uint32_t i = 0; @@ -125,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(unicode)) { + if (TypedText::IsColourWord(unicode, fontId, fontSize)) { letterIndex++; continue; } @@ -145,6 +138,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer, const char* text, const Point& arcCenter, uint8_t fontId, + uint8_t fontSize, const UIArcLabel::ArcTextInfo arcTextInfo, UIArcLabel::TextOrientation orientation, const Style& style, @@ -159,7 +153,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer, return; } uint16_t letterWidth; - uint16_t letterHeight = UIFont::GetInstance()->GetHeight(); + uint16_t letterHeight = UIFont::GetInstance()->GetHeight(fontId, fontSize); uint32_t i = arcTextInfo.lineStart; float angle = arcTextInfo.startAngle; float posX; @@ -179,7 +173,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer, if ((letter == '\r') || (letter == '\n')) { break; } - letterWidth = UIFont::GetInstance()->GetWidth(letter, 0); + letterWidth = UIFont::GetInstance()->GetWidth(letter, fontId, fontSize, 0); if ((tmp == arcTextInfo.lineStart) && xorFlag) { angle += TypedText::GetAngleForArcLen(static_cast(letterWidth), letterHeight, arcTextInfo.radius, arcTextInfo.direct, orientation); @@ -199,7 +193,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer, TypedText::GetArcLetterPos(arcCenter, arcTextInfo.radius, angle, posX, posY); angle += incrementAngle; - DrawLetterWithRotate(gfxDstBuffer, mask, fontId, letter, Point { MATH_ROUND(posX), MATH_ROUND(posY) }, + DrawLetterWithRotate(gfxDstBuffer, mask, fontId, fontSize, letter, Point { MATH_ROUND(posX), MATH_ROUND(posY) }, static_cast(rotateAngle), style.textColor_, opaScale); } } @@ -207,6 +201,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer, void DrawLabel::DrawLetterWithRotate(BufferInfo& gfxDstBuffer, const Rect& mask, uint8_t fontId, + uint8_t fontSize, uint32_t letter, const Point& pos, int16_t rotateAngle, @@ -219,11 +214,11 @@ void DrawLabel::DrawLetterWithRotate(BufferInfo& gfxDstBuffer, #if ENABLE_VECTOR_FONT node.textStyle = TEXT_STYLE_NORMAL; #endif - if (fontEngine->GetCurrentFontHeader(head) != 0) { + if (fontEngine->GetFontHeader(head, fontId, fontSize) != 0) { return; } - const uint8_t* fontMap = fontEngine->GetBitmap(letter, node, 0); + const uint8_t* fontMap = fontEngine->GetBitmap(letter, node, fontId, fontSize, 0); if (fontMap == nullptr) { return; } @@ -256,7 +251,6 @@ void DrawLabel::DrawLetterWithRotate(BufferInfo& gfxDstBuffer, letterTranDataInfo); } - void DrawLabel::GetLineBackgroundColor(uint16_t letterIndex, List* linebackgroundColor, bool& havelinebackground, ColorType& linebgColor) { diff --git a/frameworks/draw/draw_label.h b/frameworks/draw/draw_label.h index 3a8fc50ea5aafc234e7079e7061565db548f88e8..b21d9ec427464ca4b17fbddd989c686b798dd634 100644 --- a/frameworks/draw/draw_label.h +++ b/frameworks/draw/draw_label.h @@ -28,20 +28,21 @@ public: static uint16_t DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInfo& labelLine, uint16_t& letterIndex); - static void DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, const char* text, - const Point& arcCenter, uint8_t fontId, const UIArcLabel::ArcTextInfo arcTextInfo, + static void DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, const char* text, const Point& arcCenter, + uint8_t fontId, uint8_t fontSize, const UIArcLabel::ArcTextInfo arcTextInfo, UIArcLabel::TextOrientation orientation, const Style& style, uint8_t opaScale); static void DrawLetterWithRotate(BufferInfo& gfxDstBuffer, const Rect& mask, uint8_t fontId, + uint8_t fontSize, uint32_t letter, const Point& pos, int16_t rotateAngle, const ColorType& color, OpacityType opaScale); -private: - static uint8_t GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint8_t fontSize, + + static uint8_t GetLineMaxLetterSize(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t letterIndex, SizeSpan* sizeSpans); static void GetLineBackgroundColor(uint16_t letterIndex, List* linebackgroundColor, bool& havelinebackground, ColorType& linebgColor); diff --git a/frameworks/draw/draw_utils.cpp b/frameworks/draw/draw_utils.cpp index 12316a7ad35a199d60895f108e9169eaad189e8d..9944bcc7e41e173359c814ebc5a33a42a07dbe56 100644 --- a/frameworks/draw/draw_utils.cpp +++ b/frameworks/draw/draw_utils.cpp @@ -275,7 +275,8 @@ void DrawUtils::DrawColorLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo #if ENABLE_VECTOR_FONT node.textStyle = letterInfo.textStyle; #endif - const uint8_t* fontMap = fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.shapingId); + const uint8_t* fontMap = + fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.fontId, letterInfo.fontSize, letterInfo.shapingId); if (fontMap == nullptr) { return; } @@ -287,7 +288,7 @@ void DrawUtils::DrawColorLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo posY = letterInfo.pos.y + letterInfo.offsetY; } else { FontHeader head; - if (fontEngine->GetCurrentFontHeader(head) != 0) { + if (fontEngine->GetFontHeader(head, letterInfo.fontId, letterInfo.fontSize) != 0) { return; } posY = letterInfo.pos.y + head.ascender - letterInfo.offsetY; @@ -315,19 +316,15 @@ void DrawUtils::DrawColorLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo } void DrawUtils::DrawNormalLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo &letterInfo, - uint8_t maxLetterSize, bool isSpanLetter) const + uint8_t maxLetterSize) const { UIFont* fontEngine = UIFont::GetInstance(); GlyphNode node; #if ENABLE_VECTOR_FONT node.textStyle = letterInfo.textStyle; #endif - const uint8_t* fontMap = nullptr; - if (isSpanLetter) { - fontMap = fontEngine->GetBitmapSpannable(letterInfo.letter, node, letterInfo.fontId, letterInfo.fontSize); - } else { - fontMap = fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.shapingId); - } + const uint8_t* fontMap = + fontEngine->GetBitmap(letterInfo.letter, node, letterInfo.fontId, letterInfo.fontSize, letterInfo.shapingId); if (fontMap == nullptr) { return; } @@ -341,7 +338,7 @@ void DrawUtils::DrawNormalLetter(BufferInfo &gfxDstBuffer, const LabelLetterInfo posY = letterInfo.pos.y + maxLetterSize - node.top + letterInfo.offsetY; } else { FontHeader head; - if (fontEngine->GetCurrentFontHeader(head) != 0) { + if (fontEngine->GetFontHeader(head, letterInfo.fontId, letterInfo.fontSize) != 0) { return; } posY = letterInfo.pos.y + head.ascender - node.top - letterInfo.offsetY; diff --git a/frameworks/draw/draw_utils.h b/frameworks/draw/draw_utils.h index f86c38117830d227fd563547f5b0e6b0caba1996..c07968c7f05a19e2fd42f5dd4f89c48e77293b54 100644 --- a/frameworks/draw/draw_utils.h +++ b/frameworks/draw/draw_utils.h @@ -210,8 +210,7 @@ public: const ColorType& color, OpacityType opa) const; void DrawColorLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo) const; - void DrawNormalLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo, - uint8_t maxLetterSize, bool isSpanLetter) const; + void DrawNormalLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& letterInfo, uint8_t maxLetterSize) const; void DrawLetter(BufferInfo& gfxDstBuffer, const uint8_t* fontMap, diff --git a/frameworks/font/base_font.cpp b/frameworks/font/base_font.cpp index 7128d222173ebbaede0a2f04ed8aafed04968387..abe47d2cb4c280300cb5ce577d6d1f3af170d09f 100644 --- a/frameworks/font/base_font.cpp +++ b/frameworks/font/base_font.cpp @@ -15,15 +15,6 @@ #include "font/base_font.h" namespace OHOS { -uint8_t BaseFont::GetBaseFontId() -{ - return fontId_; -} -void BaseFont::SetBaseFontId(uint8_t fontId) -{ - fontId_ = fontId; -} - uintptr_t BaseFont::GetRamAddr() { return ramAddr_; diff --git a/frameworks/font/glyphs_manager.cpp b/frameworks/font/glyphs_manager.cpp index 81d104e587e205bc5a8f2a66c0e840719257e1e9..91909fdd6a182019073e9aaaba34aeb6232f02a7 100644 --- a/frameworks/font/glyphs_manager.cpp +++ b/frameworks/font/glyphs_manager.cpp @@ -26,26 +26,18 @@ GlyphsManager::GlyphsManager() start_(0), fontHeaderSectionStart_(0), fontIndexSectionStart_(0), - curFontIndexSectionStart_(0), glyphNodeSectionStart_(0), - curGlyphNodeSectionStart_(0), bitMapSectionStart_(0), - curBitMapSectionStart_(0), ramAddr_(nullptr), ramUsedLen_(0), fontHeaderCache_(nullptr), indexCache_(nullptr), - curIndexCache_(nullptr), nodeCache_(nullptr), cacheStatus_(nullptr), fp_(-1), - curFontHeader_(nullptr), - curGlyphNode_(nullptr), isRamSet_(false), - isFileSet_(false), - isFontIdSet_(false) + isFileSet_(false) { - fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); } GlyphsManager::~GlyphsManager() {} @@ -132,26 +124,22 @@ GlyphNode* GlyphsManager::GetNodeFromFile(uint32_t unicode, uint8_t fontId) uint16_t idx = 0; uint8_t key; uint32_t offset; - uint8_t* tmpIndexCache = curIndexCache_; - uint32_t tmpGlyphNodeSectionStart = curGlyphNodeSectionStart_; - while (fontId_ != fontId) { - if (SetCurrentFontId(fontId) == INVALID_RET_VALUE) { - return nullptr; - } - tmpIndexCache = curIndexCache_; - tmpGlyphNodeSectionStart = curGlyphNodeSectionStart_; + GlyphInfo glyphInfo; + int8_t result = GetGlyphInfo(fontId, glyphInfo); + if (result != RET_VALUE_OK) { + return nullptr; } for (int32_t i = RADIX_SHIFT_START; i >= 0; i -= RADIX_TREE_BITS) { offset = idx * sizeof(IndexNode); key = static_cast((unicode >> static_cast(i)) & RADIX_TREE_MASK); offset += key * sizeof(uint16_t); - idx = *(reinterpret_cast(tmpIndexCache + offset)); + idx = *(reinterpret_cast(glyphInfo.indexCache + offset)); if (idx == 0) { return nullptr; } } - offset = tmpGlyphNodeSectionStart + (idx - 1) * sizeof(GlyphNode); + offset = glyphInfo.glyphNodeSectionStart + (idx - 1) * sizeof(GlyphNode); int32_t ret = lseek(fp_, offset, SEEK_SET); if (ret != static_cast(offset)) { GRAPHIC_LOGE("GlyphsManager::GetNodeFromFile lseek failed"); @@ -229,25 +217,21 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start) isFileSet_ = true; } - fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); return ret; } -int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) +int8_t GlyphsManager::GetGlyphInfo(uint8_t fontId, GlyphInfo& glyphInfo) { uint16_t fontIdx = 0; if (fontId > UIFontBuilder::GetInstance()->GetBitmapFontIdMax()) { - GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId fontId need less than max fontId"); + GRAPHIC_LOGE("GlyphsManager::GetGlyphInfo fontId need less than max fontId"); return INVALID_RET_VALUE; } - GraphicLockGuard guard(lock_); + if (!isFileSet_) { - GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId file not set"); + GRAPHIC_LOGE("GlyphsManager::GetGlyphInfo file not set"); return INVALID_RET_VALUE; } - if (fontId_ == fontId) { - return RET_VALUE_OK; - } int32_t low = 0; int32_t high = binHeader_.fontNum - 1; @@ -266,25 +250,21 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId) } } if (!found) { - isFontIdSet_ = false; - curFontHeader_ = nullptr; - fontId_ = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); - GRAPHIC_LOGE("GlyphsManager::SetCurrentFontId fontId not found"); + glyphInfo.fontHeader = nullptr; + glyphInfo.fontId = UIFontBuilder::GetInstance()->GetBitmapFontIdMax(); return INVALID_RET_VALUE; } uint32_t size = 0; - fontId_ = fontId; - curFontHeader_ = fontHeaderCache_ + fontIdx; - curGlyphNode_ = nullptr; - curFontIndexSectionStart_ = fontIndexSectionStart_ + curFontHeader_->indexOffset; + glyphInfo.fontId = fontId; + glyphInfo.fontHeader = fontHeaderCache_ + fontIdx; + glyphInfo.fontIndexSectionStart = fontIndexSectionStart_ + glyphInfo.fontHeader->indexOffset; for (uint32_t i = 0; i < fontIdx; i++) { size += fontHeaderCache_[i].glyphNum * sizeof(GlyphNode); } - curGlyphNodeSectionStart_ = glyphNodeSectionStart_ + size; - curBitMapSectionStart_ = bitMapSectionStart_ + curFontHeader_->glyphOffset; - curIndexCache_ = indexCache_ + curFontHeader_->indexOffset; - isFontIdSet_ = true; + glyphInfo.glyphNodeSectionStart = glyphNodeSectionStart_ + size; + glyphInfo.bitMapSectionStart = bitMapSectionStart_ + glyphInfo.fontHeader->glyphOffset; + glyphInfo.indexCache = indexCache_ + glyphInfo.fontHeader->indexOffset; return RET_VALUE_OK; } @@ -315,30 +295,24 @@ int8_t GlyphsManager::GetFontVersion(char* version, uint8_t len) const return RET_VALUE_OK; } -const FontHeader* GlyphsManager::GetCurrentFontHeader() const +const FontHeader* GlyphsManager::GetFontHeader(uint8_t fontId) { - if (!isFontIdSet_) { - return nullptr; - } - - if (curFontHeader_ == nullptr) { + GlyphInfo glyphInfo; + int8_t ret = GetGlyphInfo(fontId, glyphInfo); + if (ret != RET_VALUE_OK) { return nullptr; } - return curFontHeader_; + return glyphInfo.fontHeader; } -const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode) +const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode, uint8_t fontId) { - if (!isFontIdSet_) { + GlyphInfo glyphInfo; + int8_t ret = GetGlyphInfo(fontId, glyphInfo); + if (ret != RET_VALUE_OK) { return nullptr; } - uint8_t fontId = fontId_; - if (curGlyphNode_ != nullptr) { - if ((curGlyphNode_->unicode == unicode) && (curGlyphNode_->fontId == fontId)) { - return curGlyphNode_; - } - } GlyphNode* node = GetNodeFromCache(unicode, fontId); if (node == nullptr) { node = GetNodeFromFile(unicode, fontId); @@ -346,34 +320,23 @@ const GlyphNode* GlyphsManager::GetGlyphNode(uint32_t unicode) node->fontId = fontId; } } - curGlyphNode_ = node; return node; } -int16_t GlyphsManager::GetFontHeight() const +int16_t GlyphsManager::GetFontHeight(uint8_t fontId) { - if (!isFontIdSet_) { - GRAPHIC_LOGE("GlyphsManager::GetFontHeight fontId not set"); - return INVALID_RET_VALUE; - } - - if (curFontHeader_ == nullptr) { - GRAPHIC_LOGE("GlyphsManager::GetFontHeight curFontHeader is nullptr"); + GlyphInfo glyphInfo; + int8_t ret = GetGlyphInfo(fontId, glyphInfo); + if (ret != RET_VALUE_OK) { return INVALID_RET_VALUE; } - return curFontHeader_->fontHeight; + return glyphInfo.fontHeader->fontHeight; } -int16_t GlyphsManager::GetFontWidth(uint32_t unicode) +int16_t GlyphsManager::GetFontWidth(uint32_t unicode, uint8_t fontId) { - const GlyphNode* node = nullptr; - - if (!isFontIdSet_) { - GRAPHIC_LOGE("GlyphsManager::GetFontWidth fontId not set"); - return INVALID_RET_VALUE; - } - node = GetGlyphNode(unicode); + const GlyphNode* node = GetGlyphNode(unicode, fontId); if (node == nullptr) { return INVALID_RET_VALUE; } @@ -387,14 +350,13 @@ int8_t GlyphsManager::GetBitmap(uint32_t unicode, uint8_t* bitmap, uint8_t fontI return INVALID_RET_VALUE; } - GraphicLockGuard guard(lock_); - if (!isFontIdSet_) { - GRAPHIC_LOGE("GlyphsManager::GetBitmap fontId not set"); + GlyphInfo glyphInfo; + int8_t result = GetGlyphInfo(fontId, glyphInfo); + if (result != RET_VALUE_OK) { return INVALID_RET_VALUE; } - GlyphNode* node = const_cast(GetGlyphNode(unicode)); - uint32_t tmpBitMapSectionStart = curBitMapSectionStart_; - guard.Unlock(); + GlyphNode* node = const_cast(GetGlyphNode(unicode, fontId)); + uint32_t tmpBitMapSectionStart = glyphInfo.bitMapSectionStart; if (node == nullptr) { GRAPHIC_LOGE("GlyphsManager::GetBitmap node not found"); return INVALID_RET_VALUE; diff --git a/frameworks/font/glyphs_manager.h b/frameworks/font/glyphs_manager.h index 57e87b5eafff2a5324df0466a0b018e99951a129..011fba51f6ff723c5f288b7a4ae62fefdc14ab2b 100644 --- a/frameworks/font/glyphs_manager.h +++ b/frameworks/font/glyphs_manager.h @@ -17,7 +17,6 @@ #define GLYPHS_MANAGER_FONT_H #include "font/ui_font_header.h" -#include "graphic_locker.h" namespace OHOS { class GlyphsManager { @@ -34,13 +33,13 @@ public: int8_t GetFontVersion(char* version, uint8_t len) const; - int16_t GetFontHeight() const; + int16_t GetFontHeight(uint8_t fontId); - int16_t GetFontWidth(uint32_t unicode); + int16_t GetFontWidth(uint32_t unicode, uint8_t fontId); - const FontHeader* GetCurrentFontHeader() const; + const FontHeader* GetFontHeader(uint8_t fontId); - const GlyphNode* GetGlyphNode(uint32_t unicode); + const GlyphNode* GetGlyphNode(uint32_t unicode, uint8_t fontId); int8_t GetBitmap(uint32_t unicode, uint8_t* bitmap, uint8_t fontId); @@ -48,8 +47,6 @@ public: int8_t SetFile(int32_t fp, uint32_t start); - int8_t SetCurrentFontId(uint8_t fontId); - private: static constexpr uint8_t RADIX_TREE_BITS = 4; static constexpr uint8_t RADIX_SHIFT_START = 32 - RADIX_TREE_BITS; @@ -72,6 +69,15 @@ private: uint16_t stubs[RADIX_TREE_SLOT_NUM]; }; + struct GlyphInfo { + uint8_t fontId; + uint32_t glyphNodeSectionStart; + uint32_t bitMapSectionStart; + uint32_t fontIndexSectionStart; + uint8_t* indexCache; + FontHeader* fontHeader; + }; + int8_t GlyphNodeCacheInit(); GlyphNode* GetNodeFromCache(uint32_t unicode, uint8_t fontId); GlyphNode* GetNodeCacheSpace(uint32_t unicode, uint8_t fontId); @@ -80,36 +86,28 @@ private: { return (((addr + (1 << align)) >> align) << align); } + int8_t GetGlyphInfo(uint8_t fontId, GlyphInfo& glyphInfo); BinHeader binHeader_; uint8_t fontNum_; uint32_t start_; uint32_t fontHeaderSectionStart_; uint32_t fontIndexSectionStart_; - uint32_t curFontIndexSectionStart_; uint32_t glyphNodeSectionStart_; - uint32_t curGlyphNodeSectionStart_; uint32_t bitMapSectionStart_; - uint32_t curBitMapSectionStart_; uint8_t* ramAddr_; uint32_t ramUsedLen_; FontHeader* fontHeaderCache_; uint8_t* indexCache_; - uint8_t* curIndexCache_; CacheType* nodeCache_; CacheState* cacheStatus_; - GraphicMutex lock_; int32_t fp_; - uint8_t fontId_; - FontHeader* curFontHeader_; - GlyphNode* curGlyphNode_; bool isRamSet_; bool isFileSet_; - bool isFontIdSet_; }; } // namespace OHOS #endif /* GLYPHS_MANAGER_FONT_H */ diff --git a/frameworks/font/ui_font.cpp b/frameworks/font/ui_font.cpp index 26840c5d92c8a5f003cabc718fec091754e3f1ac..e49ea644a75af7b8fcf5c1f2f28046e6bf88ec09 100644 --- a/frameworks/font/ui_font.cpp +++ b/frameworks/font/ui_font.cpp @@ -64,113 +64,104 @@ void UIFont::SetFont(BaseFont* font) } } -uint8_t* UIFont::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t shapingFont) +uint8_t* UIFont::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize, + uint8_t shapingFont) { uint8_t* bitmap = nullptr; - uint8_t currentFontId = GetCurrentFontId(); #if ENABLE_MULTI_FONT // shaping font is in search list, search shaping font first if (shapingFont > 1) { - bitmap = instance_->GetBitmap(unicode, glyphNode, shapingFont); - SetCurrentFontId(currentFontId); + bitmap = instance_->GetBitmap(unicode, glyphNode, shapingFont, fontSize); if (bitmap != nullptr) { return bitmap; } } #endif - bitmap = instance_->GetBitmap(unicode, glyphNode, currentFontId); + bitmap = instance_->GetBitmap(unicode, glyphNode, fontId, fontSize); if (bitmap != nullptr) { return bitmap; } #if ENABLE_MULTI_FONT uint8_t* searchLists = nullptr; - int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(currentFontId, &searchLists); + int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); int8_t currentIndex = 0; if ((searchLists == nullptr) || (listSize == 0)) { return nullptr; } do { - SetCurrentFontId(searchLists[currentIndex], 0); - bitmap = instance_->GetBitmap(unicode, glyphNode, GetCurrentFontId()); + bitmap = instance_->GetBitmap(unicode, glyphNode, searchLists[currentIndex], fontSize); if (bitmap != nullptr) { - SetCurrentFontId(currentFontId, 0); return bitmap; } // switch to next search List currentIndex++; } while ((currentIndex < listSize) && (searchLists != nullptr)); - SetCurrentFontId(currentFontId); #endif return nullptr; } -uint8_t* UIFont::GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size) +int8_t UIFont::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { - uint8_t* bitmap = nullptr; - bitmap = instance_->GetBitmapSpannable(unicode, glyphNode, fontId, size); - if (bitmap != nullptr) { - return bitmap; + int8_t result = instance_->GetGlyphNode(unicode, glyphNode, fontId, fontSize); + if (result == RET_VALUE_OK) { + return result; } - return nullptr; + +#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 shapingId) +uint16_t UIFont::GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize, uint8_t shapingId) { int16_t result; - uint8_t currentFontId = GetCurrentFontId(); #if ENABLE_MULTI_FONT if (shapingId > 1) { - result = instance_->GetWidth(unicode, shapingId); - SetCurrentFontId(currentFontId); + result = instance_->GetWidth(unicode, shapingId, fontSize); if (result >= 0) { return result; } } #endif - result = instance_->GetWidth(unicode, currentFontId); + result = instance_->GetWidth(unicode, fontId, fontSize); if (result >= 0) { return result; } #if ENABLE_MULTI_FONT uint8_t* searchLists = nullptr; - int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(currentFontId, &searchLists); + int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(fontId, &searchLists); if ((searchLists == nullptr) || (listSize == 0)) { return 0; } int8_t currentIndex = 0; do { - SetCurrentFontId(searchLists[currentIndex], 0); - result = instance_->GetWidth(unicode, GetCurrentFontId()); + result = instance_->GetWidth(unicode, searchLists[currentIndex], fontSize); if (result >= 0) { - SetCurrentFontId(currentFontId, 0); return result; } currentIndex++; } while ((currentIndex < listSize) && (searchLists != nullptr)); - SetCurrentFontId(currentFontId); #endif return 0; } -uint16_t UIFont::GetHeightSpannable(uint8_t fontId, uint8_t size) -{ - return instance_->GetHeightByFontId(fontId, size); -} - -uint16_t UIFont::GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size) -{ - int16_t result = instance_->GetWidthSpannable(unicode, fontId, size); - if (result >= 0) { - return result; - } else { - return 0; - } -} - -uint16_t UIFont::GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, +uint16_t UIFont::GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t letterIndex, SizeSpan* sizeSpans) { - return instance_->GetLineMaxHeight(text, lineLength, fontId, letterIndex, sizeSpans); + return instance_->GetLineMaxHeight(text, lineLength, fontId, fontSize, letterIndex, sizeSpans); } } // namespace OHOS diff --git a/frameworks/font/ui_font_adaptor.cpp b/frameworks/font/ui_font_adaptor.cpp index 87cd161afdf3660c21be011fe39169bb112a4282..1a2cbc022960eeb8d5c1ebd7ba7fa749ac62595d 100644 --- a/frameworks/font/ui_font_adaptor.cpp +++ b/frameworks/font/ui_font_adaptor.cpp @@ -23,17 +23,23 @@ #include "font/ui_text_shaping.h" #endif namespace OHOS { -uint32_t UIFontAdaptor::GetNextLineAndWidth(const char* txt, int16_t letterSpace, - int16_t& maxWidth, int16_t& maxHeight, - uint16_t& letterIndex, SizeSpan* sizeSpans, - bool allBreak, uint16_t len) +uint32_t UIFontAdaptor::GetNextLineAndWidth(const char* txt, + uint8_t fontId, + uint8_t fontSize, + int16_t letterSpace, + int16_t& maxWidth, + int16_t& maxHeight, + uint16_t& letterIndex, + SizeSpan* sizeSpans, + bool allBreak, + uint16_t len) { #if ENABLE_ICU - return UILineBreakEngine::GetInstance().GetNextLineAndWidth(txt, letterSpace, allBreak, maxWidth, maxHeight, - letterIndex, sizeSpans, len); + return UILineBreakEngine::GetInstance().GetNextLineAndWidth(txt, fontId, fontSize, letterSpace, allBreak, maxWidth, + maxHeight, letterIndex, sizeSpans, len); #else - uint32_t index = TypedText::GetNextLine(txt, letterSpace, maxWidth); - maxWidth = TypedText::GetTextWidth(txt, index, letterSpace); + uint32_t index = TypedText::GetNextLine(txt, fontId, fontSize, letterSpace, maxWidth); + maxWidth = TypedText::GetTextWidth(txt, fontId, fontSize, index, letterSpace); return index; #endif } @@ -47,4 +53,3 @@ bool UIFontAdaptor::IsSameTTFId(uint8_t fontId, uint32_t unicode) #endif } } // namespace OHOS - diff --git a/frameworks/font/ui_font_adaptor.h b/frameworks/font/ui_font_adaptor.h index 75cfd587d0f2b7e449c3e779db29afafb0fcd086..efe9b5b91311d41b15efba21d736f04bde012e71 100644 --- a/frameworks/font/ui_font_adaptor.h +++ b/frameworks/font/ui_font_adaptor.h @@ -22,10 +22,16 @@ namespace OHOS { class UIFontAdaptor : public HeapBase { public: - static uint32_t GetNextLineAndWidth(const char* txt, int16_t letterSpace, - int16_t& maxWidth, int16_t& maxHeight, - uint16_t& letterIndex, SizeSpan* sizeSpans, - bool allBreak = false, uint16_t len = 0xFFFF); + static uint32_t GetNextLineAndWidth(const char* txt, + uint8_t fontId, + uint8_t fontSize, + int16_t letterSpace, + int16_t& maxWidth, + int16_t& maxHeight, + uint16_t& letterIndex, + SizeSpan* sizeSpans, + bool allBreak = false, + uint16_t len = 0xFFFF); static bool IsSameTTFId(uint8_t fontId, uint32_t unicode); }; diff --git a/frameworks/font/ui_font_bitmap.cpp b/frameworks/font/ui_font_bitmap.cpp index 9c3562c596f66d92f8bcd2b15b67f423db2881e9..df61c1b2855581b8dacb2de536b30afbe4529563 100644 --- a/frameworks/font/ui_font_bitmap.cpp +++ b/frameworks/font/ui_font_bitmap.cpp @@ -15,7 +15,6 @@ #include "font/ui_font_bitmap.h" -#include "draw/draw_utils.h" #include "font/ui_font_adaptor.h" #include "font/ui_font_builder.h" #include "gfx_utils/file.h" @@ -31,7 +30,6 @@ namespace OHOS { UIFontBitmap::UIFontBitmap() : offset_(0), dynamicFont_(), dynamicFontRamUsed_(0), dynamicFontFd_(-1) { - SetBaseFontId(UIFontBuilder::GetInstance()->GetBitmapFontIdMax()); bitmapCache_ = nullptr; bitmapRamUsed_ = FONT_BITMAP_CACHE_SIZE; } @@ -103,27 +101,9 @@ int8_t UIFontBitmap::SetFontPath(const char* dpath, const char* spath) return RET_VALUE_OK; } -int8_t UIFontBitmap::SetCurrentFontId(uint8_t fontId, uint8_t size) +uint16_t UIFontBitmap::GetHeight(uint8_t fontId, uint8_t fontSize) { - int8_t ret = SetDynamicFontId(fontId); - if (ret == RET_VALUE_OK) { - SetBaseFontId(fontId); - } - return ret; -} - -uint16_t UIFontBitmap::GetHeight() -{ - return GetHeightByFontId(GetBaseFontId()); -} - -uint16_t UIFontBitmap::GetHeightByFontId(uint8_t fontId, uint8_t size) -{ - int16_t ret = dynamicFont_.SetCurrentFontId(fontId); - if (ret == INVALID_RET_VALUE) { - return 0; - } - return dynamicFont_.GetFontHeight(); + return dynamicFont_.GetFontHeight(fontId); } uint8_t UIFontBitmap::GetFontId(const char* ttfName, uint8_t size) const @@ -143,62 +123,24 @@ uint8_t UIFontBitmap::GetFontId(const char* ttfName, uint8_t size) const return id; } -int16_t UIFontBitmap::GetWidth(uint32_t unicode, uint8_t fontId) +int16_t UIFontBitmap::GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize) { -#if ENABLE_MULTI_FONT - if (TypedText::IsColourWord(unicode)) { - uint8_t* searchLists = nullptr; - uint8_t baseId = GetBaseFontId(); - int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(baseId, &searchLists); - int8_t currentIndex = 0; - int16_t ret; - if ((searchLists == nullptr) || (listSize == 0)) { - return false; - } - do { - ret = GetWidthSpannable(unicode, searchLists[currentIndex]); - if (ret != INVALID_RET_VALUE) { - return ret; - } - // switch to next search List - currentIndex++; - } while ((currentIndex < listSize) && (searchLists != nullptr)); - } -#endif return GetWidthInFontId(unicode, fontId); } -int16_t UIFontBitmap::GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size) -{ - if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) { - GRAPHIC_LOGE("UIFontBitmap::GetWidthInFontId fontId and unicode not match"); - return INVALID_RET_VALUE; - } - return GetDynamicFontWidth(unicode, fontId); -} - -uint8_t* UIFontBitmap::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) +uint8_t* UIFontBitmap::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { return SearchInFont(unicode, glyphNode, fontId); } -uint8_t* UIFontBitmap::GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size) -{ - return SearchInFont(unicode, glyphNode, fontId, true); -} - bool UIFontBitmap::IsEmojiFont(uint8_t fontId) { return false; } -int8_t UIFontBitmap::GetCurrentFontHeader(FontHeader& fontHeader) +int8_t UIFontBitmap::GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize) { - int8_t ret = dynamicFont_.SetCurrentFontId(GetBaseFontId()); - if (ret == INVALID_RET_VALUE) { - return ret; - } - const FontHeader* header = dynamicFont_.GetCurrentFontHeader(); + const FontHeader* header = dynamicFont_.GetFontHeader(fontId); if (header != nullptr) { fontHeader = *header; return RET_VALUE_OK; @@ -207,45 +149,34 @@ int8_t UIFontBitmap::GetCurrentFontHeader(FontHeader& fontHeader) } #if ENABLE_MULTI_FONT -int8_t UIFontBitmap::GetMultiGlyphNode( uint32_t unicode, GlyphNode& glyphNode) +int8_t UIFontBitmap::GetMultiGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) { - if (TypedText::IsColourWord(unicode)) { - int8_t ret; - uint8_t* searchLists = nullptr; - uint8_t baseId = GetBaseFontId(); - int8_t listSize = UIMultiFontManager::GetInstance()->GetSearchFontList(baseId, &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, GetBaseFontId()); + 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) +int8_t UIFontBitmap::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { - return GetGlyphNode(unicode, glyphNode, GetBaseFontId()); -} - -int8_t UIFontBitmap::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) -{ - int8_t ret = dynamicFont_.SetCurrentFontId(fontId); - if (ret == INVALID_RET_VALUE) { - return ret; - } - const GlyphNode* node = dynamicFont_.GetGlyphNode(unicode); + const GlyphNode* node = dynamicFont_.GetGlyphNode(unicode, fontId); if (node != nullptr) { glyphNode = *node; return RET_VALUE_OK; @@ -295,10 +226,6 @@ uint32_t UIFontBitmap::GetRamUsedLen(uint32_t textManagerRamUsed, uint32_t langF int8_t UIFontBitmap::GetDynamicFontBitmap(uint32_t unicode, uint8_t* bitmap, uint8_t fontId) { - int16_t ret = dynamicFont_.SetCurrentFontId(fontId); - if (ret == INVALID_RET_VALUE) { - return ret; - } return dynamicFont_.GetBitmap(unicode, bitmap, fontId); } @@ -328,38 +255,22 @@ void UIFontBitmap::PutCacheSpace(uint8_t* addr) GRAPHIC_LOGE("UIFontBitmap::PutCacheSpace invalid bitmapCache"); } -int8_t UIFontBitmap::SetDynamicFontId(uint8_t fontId) -{ - return dynamicFont_.SetCurrentFontId(fontId); -} - int16_t UIFontBitmap::GetDynamicFontWidth(uint32_t unicode, uint8_t fontId) { - int16_t ret = dynamicFont_.SetCurrentFontId(fontId); - if (ret == INVALID_RET_VALUE) { - return ret; - } - return dynamicFont_.GetFontWidth(unicode); + return dynamicFont_.GetFontWidth(unicode, fontId); } -uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, bool isSpanLetter) +uint8_t* UIFontBitmap::SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) { + GraphicLockGuard guard(lock_); if (bitmapCache_ == nullptr) { return nullptr; } if (!UIFontAdaptor::IsSameTTFId(fontId, unicode)) { - GRAPHIC_LOGE("UIFontBitmap::GetWidthInFontId fontId and unicode not match"); + GRAPHIC_LOGE("UIFontBitmap::SearchInFont fontId and unicode not match"); return nullptr; } - int8_t ret = INVALID_RET_VALUE; - if (isSpanLetter) { - ret = GetGlyphNode(unicode, glyphNode, fontId); - } else { - if (fontId != GetBaseFontId()) { - SetCurrentFontId(fontId); - } - ret = GetGlyphNode(unicode, glyphNode); - } + int8_t ret = GetGlyphNode(unicode, glyphNode, fontId); if (ret != RET_VALUE_OK) { return nullptr; } @@ -392,10 +303,7 @@ int16_t UIFontBitmap::GetWidthInFontId(uint32_t unicode, uint8_t fontId) GRAPHIC_LOGE("UIFontBitmap::GetWidthInFontId fontId and unicode not match"); return INVALID_RET_VALUE; } - if (fontId != GetBaseFontId()) { - SetCurrentFontId(fontId); - } - return GetDynamicFontWidth(unicode, GetBaseFontId()); + return GetDynamicFontWidth(unicode, fontId); } void UIFontBitmap::SetFontFileOffset(uint32_t offset) @@ -403,12 +311,8 @@ void UIFontBitmap::SetFontFileOffset(uint32_t offset) offset_ = offset; } -uint16_t UIFontBitmap::GetHeight(uint32_t unicode, uint8_t fontId) -{ - return GetHeight(); -} - -uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, bool& isEmoijLarge, uint8_t fontSize) +uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, + bool& isEmoijLarge, uint8_t fontId, uint8_t fontSize) { uint32_t i = 0; uint32_t unicode; @@ -417,17 +321,18 @@ uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, bool uint16_t loopNum = 0; GlyphNode glyphNode; - GlyphNode emoijMaxNode; + GlyphNode emoijMaxNode = {}; uint8_t maxFontSie = fontSize; while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); #if ENABLE_MULTI_FONT - uint8_t ret = GetMultiGlyphNode(unicode, glyphNode); + uint8_t ret = GetMultiGlyphNode(unicode, glyphNode, fontId); #else - uint8_t ret = GetGlyphNode(unicode, glyphNode); + uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); #endif if (ret == RET_VALUE_OK) { - if (TypedText::IsColourWord(unicode)) { + uint8_t weight = GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: bit rgb565 rgba8888 emoijMaxNode = glyphNode.rows > emoijMaxNode.rows ? glyphNode : emoijMaxNode; emojiNum++; } else { @@ -459,20 +364,19 @@ uint16_t UIFontBitmap::GetOffsetPosY(const char *text, uint16_t lineLength, bool return offset; } -uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, uint8_t fontId, +uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) { uint32_t i = 0; uint32_t unicode; - uint16_t maxHeight = GetHeight(); + uint16_t maxHeight = GetHeight(fontId, fontSize); GlyphNode glyphNode; while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); if (sizeSpans != nullptr && sizeSpans[letterIndex].isSizeSpan) { uint16_t spannableHeight = 0; if (sizeSpans[letterIndex].height == 0) { - spannableHeight = GetHeightByFontId(sizeSpans[letterIndex].fontId, - sizeSpans[letterIndex].size); + spannableHeight = GetHeight(sizeSpans[letterIndex].fontId, sizeSpans[letterIndex].size); sizeSpans[letterIndex].height = spannableHeight; } else { spannableHeight = sizeSpans[letterIndex].height; @@ -480,9 +384,9 @@ uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, u maxHeight = spannableHeight > maxHeight ? spannableHeight : maxHeight; } else { #if ENABLE_MULTI_FONT - uint8_t ret = GetMultiGlyphNode(unicode, glyphNode); + uint8_t ret = GetMultiGlyphNode(unicode, glyphNode, fontId); #else - uint8_t ret = GetGlyphNode(unicode, glyphNode); + uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); #endif if (ret == RET_VALUE_OK) { maxHeight = glyphNode.rows > maxHeight ? glyphNode.rows : maxHeight; @@ -497,4 +401,4 @@ uint16_t UIFontBitmap::GetLineMaxHeight(const char *text, uint16_t lineLength, u return maxHeight; } -} // namespace +} // namespace OHOS diff --git a/frameworks/font/ui_font_cache.h b/frameworks/font/ui_font_cache.h index 14b00b62f90c437a2ae66c3be7bfe85c2bb78e44..3ea643e2e0f854995418b42b82470149935635fb 100644 --- a/frameworks/font/ui_font_cache.h +++ b/frameworks/font/ui_font_cache.h @@ -43,11 +43,10 @@ public: ~UIFontCache(); -// uint8_t* GetSpace(uint8_t fontId, uint32_t unicode, uint32_t size); - uint8_t* GetSpace(uint8_t fontId, uint32_t unicode, uint32_t size, TextStyle textStyle = TEXT_STYLE_NORMAL); void PutSpace(uint8_t* addr); uint8_t* GetBitmap(uint8_t fontId, uint32_t unicode, TextStyle textStyle = TEXT_STYLE_NORMAL); + private: void UpdateLru(Bitmap* bitmap); void ListInit(ListHead* head) diff --git a/frameworks/font/ui_font_vector.cpp b/frameworks/font/ui_font_vector.cpp index 65de40773912a605fd2e80e85ac018da359ab598..14cda7de13a27d22f7337168a59ebdadfb23420e 100644 --- a/frameworks/font/ui_font_vector.cpp +++ b/frameworks/font/ui_font_vector.cpp @@ -42,7 +42,6 @@ UIFontVector::UIFontVector() #endif // _WIN32 ftLibrary_ = nullptr; freeTypeInited_ = ((FT_Init_FreeType(&ftLibrary_) == 0) ? true : false); - SetBaseFontId(FONT_ID_MAX); bitmapCache_ = nullptr; } @@ -67,28 +66,39 @@ bool UIFontVector::IsColorEmojiFont(FT_Face &face) return false; } -void SetupColorFont(FT_Face face) +int8_t SetupColorFont(FT_Face face) { if (face->num_fixed_sizes == 0) { - return; + return INVALID_RET_VALUE; } - FT_Int best_match = 0; + FT_Int bestMatch = 0; const int32_t kDefaultPixelSize = 128; int32_t diff = MATH_ABS(kDefaultPixelSize - face->available_sizes[0].width); for (int32_t i = 1; i < face->num_fixed_sizes; ++i) { int32_t ndiff = MATH_ABS(kDefaultPixelSize - face->available_sizes[i].width); if (ndiff < diff) { - best_match = i; + bestMatch = i; diff = ndiff; } } - FT_Select_Size(face, best_match); // FT_Match_Size + return FT_Select_Size(face, bestMatch); // FT_Match_Size } + uint8_t UIFontVector::RegisterFontInfo(const char* ttfName, uint8_t shaping) { if ((ttfName == nullptr) || !freeTypeInited_) { return FONT_INVALID_TTF_ID; } + + if (bitmapCache_ == nullptr) { + uintptr_t ramAddr = GetRamAddr(); + uint32_t ramLen = GetRamLen(); + bitmapCache_ = new(std::nothrow) UIFontCache(reinterpret_cast(ramAddr), ramLen); + if (bitmapCache_ == nullptr) { + return INVALID_RET_VALUE; + } + } + int32_t j = 0; while (j < FONT_ID_MAX) { if ((fontInfo_[j].ttfName != nullptr) && !strncmp(fontInfo_[j].ttfName, ttfName, TTF_NAME_LEN_MAX)) { @@ -216,11 +226,8 @@ int8_t UIFontVector::SetFontPath(const char* dpath, const char* spath) return RET_VALUE_OK; } -int8_t UIFontVector::SetCurrentFontId(uint8_t fontId, uint8_t size) +int8_t UIFontVector::GetFaceInfo(uint8_t fontId, uint8_t size, FaceInfo& faceInfo) { - if (size == 0) { - size = key_ & 0xFF; // the last 8bit is size - } if ((fontId >= FONT_ID_MAX) || (size == 0)) { return INVALID_RET_VALUE; } @@ -228,50 +235,33 @@ int8_t UIFontVector::SetCurrentFontId(uint8_t fontId, uint8_t size) if ((fontInfo == nullptr) || (fontInfo->ttfName == nullptr)) { return INVALID_RET_VALUE; } - uint32_t key = GetKey(fontId, size); - if (key_ == key) { - return RET_VALUE_OK; - } if (!freeTypeInited_) { return INVALID_RET_VALUE; } - if (FT_IS_SCALABLE(ftFaces_[fontId])) { - // Set the size - int32_t error = FT_Set_Char_Size(ftFaces_[fontId], size * FONT_PIXEL_IN_POINT, 0, 0, 0); - if (error != 0) { - return INVALID_RET_VALUE; - } - } - key_ = key; - SetBaseFontId(fontId); - uintptr_t ramAddr_ = GetRamAddr(); - uint32_t ramLen_ = GetRamLen(); - if (bitmapCache_ == nullptr) { - bitmapCache_ = new(std::nothrow) UIFontCache(reinterpret_cast(ramAddr_), ramLen_); - if (bitmapCache_ == nullptr) { - return INVALID_RET_VALUE; - } + + faceInfo.key = GetKey(fontId, size); + faceInfo.face = ftFaces_[fontId]; + + // Set the size + int error = FT_Set_Char_Size(faceInfo.face, size * FONT_PIXEL_IN_POINT, 0, 0, 0); + if (error != 0) { + return INVALID_RET_VALUE; } return RET_VALUE_OK; } -uint16_t UIFontVector::GetHeight() +uint16_t UIFontVector::GetHeight(uint8_t fontId, uint8_t fontSize) { - uint8_t fontId_ = GetBaseFontId(); - if (!freeTypeInited_ || (ftFaces_[fontId_] == nullptr) || (bitmapCache_ == nullptr)) { + FaceInfo faceInfo; + int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo); + if (ret != RET_VALUE_OK) { + return INVALID_RET_VALUE; + } + if (!freeTypeInited_ || (faceInfo.face == nullptr) || (bitmapCache_ == nullptr)) { return 0; } - return static_cast(ftFaces_[fontId_]->size->metrics.height / FONT_PIXEL_IN_POINT); -} - -uint16_t UIFontVector::GetHeightByFontId(uint8_t fontId, uint8_t size) -{ - uint8_t temSize = key_ & 0xff; - SetCurrentFontId(fontId, size); - uint16_t height = GetHeight(); - SetCurrentFontId(fontId, temSize); - return height; + return static_cast(faceInfo.face->size->metrics.height / FONT_PIXEL_IN_POINT); } uint8_t UIFontVector::GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const @@ -314,7 +304,7 @@ uint8_t UIFontVector::GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& scr return fontInfo->shaping; #endif } -uint8_t UIFontVector::GetFontId(const char* ttfName, uint8_t size) const +uint8_t UIFontVector::GetFontId(const char* ttfName, uint8_t fontSize) const { if (ttfName != nullptr) { int32_t i = 0; @@ -346,57 +336,86 @@ uint8_t UIFontVector::GetFontId(uint32_t unicode) const return FONT_INVALID_TTF_ID; } -int16_t UIFontVector::GetWidth(uint32_t unicode, uint8_t fontId) +int16_t UIFontVector::GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize) { - if (!freeTypeInited_ || (ftFaces_[fontId] == nullptr) || (bitmapCache_ == nullptr)) { + FaceInfo faceInfo = {}; + int8_t ret = INVALID_RET_VALUE; + + if (TypedText::IsColourWord(unicode, fontId, fontSize)) { + ret = LoadGlyphIntoFace(fontId, unicode, faceInfo.face); + if (ret != RET_VALUE_OK) { + return INVALID_RET_VALUE; + } + + if ((fontId >= FONT_ID_MAX) || (fontSize == 0)) { + return INVALID_RET_VALUE; + } + const UITextLanguageFontParam* fontInfo = GetFontInfo(fontId); + if ((fontInfo == nullptr) || (fontInfo->ttfName == nullptr)) { + return INVALID_RET_VALUE; + } + + if (!freeTypeInited_) { + return INVALID_RET_VALUE; + } + + faceInfo.key = GetKey(fontId, fontSize); + faceInfo.face = ftFaces_[fontId]; + ret = SetupColorFont(ftFaces_[fontId]); + } else { + ret = GetFaceInfo(fontId, fontSize, faceInfo); + } + + if (ret != RET_VALUE_OK) { + return INVALID_RET_VALUE; + } + if (!freeTypeInited_ || (faceInfo.face == nullptr) || (bitmapCache_ == nullptr)) { return INVALID_RET_VALUE; } - uint8_t* bitmap = bitmapCache_->GetBitmap(key_, unicode); + uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode); if (bitmap != nullptr) { return reinterpret_cast(bitmap)->advance; } - int8_t error = LoadGlyphIntoFace(fontId, unicode); + int8_t error = LoadGlyphIntoFace(fontId, unicode, faceInfo.face); if (error != RET_VALUE_OK) { return INVALID_RET_VALUE; } - SetFace(ftFaces_[fontId], unicode); - - return static_cast(ftFaces_[fontId]->glyph->advance.x / FONT_PIXEL_IN_POINT); -} - -int16_t UIFontVector::GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size) -{ - uint8_t temSize = key_ & 0xff; - SetCurrentFontId(fontId, size); - uint16_t width = GetWidth(unicode, fontId); - SetCurrentFontId(fontId, temSize); - return width; + SetFace(faceInfo, unicode); + return static_cast(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT); } -int8_t UIFontVector::GetCurrentFontHeader(FontHeader& fontHeader) +int8_t UIFontVector::GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize) { - uint8_t fontId_ = GetBaseFontId(); - if (!freeTypeInited_ || (ftFaces_[fontId_] == nullptr) || (bitmapCache_ == nullptr)) { + FaceInfo faceInfo; + int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo); + if (ret != RET_VALUE_OK) { + return INVALID_RET_VALUE; + } + if (!freeTypeInited_ || (faceInfo.face == nullptr) || (bitmapCache_ == nullptr)) { return INVALID_RET_VALUE; } - fontHeader.ascender = static_cast(ftFaces_[fontId_]->size->metrics.ascender / FONT_PIXEL_IN_POINT); - fontHeader.descender = static_cast(ftFaces_[fontId_]->size->metrics.descender / FONT_PIXEL_IN_POINT); - fontHeader.fontHeight = static_cast(ftFaces_[fontId_]->size->metrics.height / FONT_PIXEL_IN_POINT); + fontHeader.ascender = static_cast(faceInfo.face->size->metrics.ascender / FONT_PIXEL_IN_POINT); + fontHeader.descender = static_cast(faceInfo.face->size->metrics.descender / FONT_PIXEL_IN_POINT); + fontHeader.fontHeight = static_cast(faceInfo.face->size->metrics.height / FONT_PIXEL_IN_POINT); return RET_VALUE_OK; } -int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) +int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { - uint8_t fontId_ = GetBaseFontId(); - if (!freeTypeInited_ || (ftFaces_[fontId_] == nullptr) || (bitmapCache_ == nullptr)) { + FaceInfo faceInfo; + int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo); + if (ret != RET_VALUE_OK) { + return INVALID_RET_VALUE; + } + if (!freeTypeInited_ || (faceInfo.face == nullptr) || (bitmapCache_ == nullptr)) { return INVALID_RET_VALUE; } #if ENABLE_VECTOR_FONT - uint8_t* bitmap = bitmapCache_->GetBitmap(key_, unicode, glyphNode.textStyle); + uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode, glyphNode.textStyle); #else - uint8_t* bitmap = bitmapCache_->GetBitmap(key_, unicode); + uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode); #endif if (bitmap != nullptr) { Metric* f = reinterpret_cast(bitmap); @@ -408,55 +427,51 @@ int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) return RET_VALUE_OK; } #if ENABLE_VECTOR_FONT - int8_t error = LoadGlyphIntoFace(fontId_, unicode, glyphNode.textStyle); + int8_t error = LoadGlyphIntoFace(fontId, unicode, faceInfo.face, glyphNode.textStyle); #else - int8_t error = LoadGlyphIntoFace(fontId_, unicode); + int8_t error = LoadGlyphIntoFace(fontId, unicode, faceInfo.face); #endif if (error != RET_VALUE_OK) { return INVALID_RET_VALUE; } - glyphNode.left = ftFaces_[fontId_]->glyph->bitmap_left; - glyphNode.top = ftFaces_[fontId_]->glyph->bitmap_top; - glyphNode.cols = ftFaces_[fontId_]->glyph->bitmap.width; - glyphNode.rows = ftFaces_[fontId_]->glyph->bitmap.rows; - glyphNode.advance = static_cast(ftFaces_[fontId_]->glyph->advance.x / FONT_PIXEL_IN_POINT); + glyphNode.left = faceInfo.face->glyph->bitmap_left; + glyphNode.top = faceInfo.face->glyph->bitmap_top; + glyphNode.cols = faceInfo.face->glyph->bitmap.width; + glyphNode.rows = faceInfo.face->glyph->bitmap.rows; + glyphNode.advance = static_cast(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT); #if ENABLE_VECTOR_FONT - SetFace(ftFaces_[fontId_], unicode, glyphNode.textStyle); + SetFace(faceInfo, unicode, glyphNode.textStyle); #else - SetFace(ftFaces_[fontId_], unicode); + SetFace(faceInfo, unicode); #endif return RET_VALUE_OK; } -uint8_t* UIFontVector::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) +uint8_t* UIFontVector::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) { - if (GetGlyphNode(unicode, glyphNode) != RET_VALUE_OK) { + if (GetGlyphNode(unicode, glyphNode, fontId, fontSize) != RET_VALUE_OK) { + return nullptr; + } + FaceInfo faceInfo; + int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo); + if (ret != RET_VALUE_OK) { return nullptr; } #if ENABLE_VECTOR_FONT - uint8_t* bitmap = bitmapCache_->GetBitmap(key_, unicode, glyphNode.textStyle); + uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode, glyphNode.textStyle); #else - uint8_t* bitmap = bitmapCache_->GetBitmap(key_, unicode); + uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode); #endif if (bitmap != nullptr) { return bitmap + sizeof(Metric); } #if ENABLE_VECTOR_FONT - SetFace(ftFaces_[fontId], unicode, glyphNode.textStyle); + SetFace(faceInfo, unicode, glyphNode.textStyle); #else - SetFace(ftFaces_[fontId], unicode); + SetFace(faceInfo, unicode); #endif - return static_cast(ftFaces_[fontId]->glyph->bitmap.buffer); -} - -uint8_t* UIFontVector::GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size) -{ - uint8_t temSize = key_ & 0xff; - SetCurrentFontId(fontId, size); - uint8_t* bitmap = GetBitmap(unicode, glyphNode, fontId); - SetCurrentFontId(fontId, temSize); - return bitmap; + return static_cast(faceInfo.face->glyph->bitmap.buffer); } bool UIFontVector::IsEmojiFont(uint8_t fontId) @@ -507,7 +522,7 @@ void UIFontVector::SetBold(uint8_t fontId) } #endif -int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode) +int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, FT_Face face) { bool isHaveBitmap = false; int32_t error; @@ -516,7 +531,7 @@ int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode) return INVALID_RET_VALUE; } unicode = unicode & (0xFFFFFF); // Whether 0 ~24 bit storage is unicode - error = FT_Load_Glyph(ftFaces_[fontId], unicode, FT_LOAD_RENDER); + error = FT_Load_Glyph(face, unicode, FT_LOAD_RENDER); isHaveBitmap = true; } else { for (uint8_t i = 0; i < currentFontInfoNum_; i++) { @@ -542,7 +557,7 @@ int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode) } #if ENABLE_VECTOR_FONT -int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, TextStyle textStyle) +int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, FT_Face face, TextStyle textStyle) { int32_t error; bool isHaveBitmap = false; @@ -551,7 +566,7 @@ int8_t UIFontVector::LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, TextSt return INVALID_RET_VALUE; } unicode = unicode & (0xFFFFFF); // Whether 0 ~24 bit storage is unicode - error = FT_Load_Glyph(ftFaces_[fontId], unicode, FT_LOAD_NO_BITMAP); + error = FT_Load_Glyph(face, unicode, FT_LOAD_NO_BITMAP); isHaveBitmap = true; } else { for (uint8_t i = 0; i < currentFontInfoNum_; i++) { @@ -600,29 +615,29 @@ uint8_t UIFontVector::IsGlyphFont(uint32_t unicode) } } -void UIFontVector::SetFace(FT_Face ftFace, uint32_t unicode) const +void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode) const { #if ENABLE_VECTOR_FONT - SetFace(ftFace, unicode, TEXT_STYLE_NORMAL); + SetFace(faceInfo, unicode, TEXT_STYLE_NORMAL); #else Metric f; - f.advance = static_cast(ftFace->glyph->advance.x / FONT_PIXEL_IN_POINT); - f.left = ftFace->glyph->bitmap_left; - f.top = ftFace->glyph->bitmap_top; - f.cols = ftFace->glyph->bitmap.width; - f.rows = ftFace->glyph->bitmap.rows; + f.advance = static_cast(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT); + f.left = faceInfo.face->glyph->bitmap_left; + f.top = faceInfo.face->glyph->bitmap_top; + f.cols = faceInfo.face->glyph->bitmap.width; + f.rows = faceInfo.face->glyph->bitmap.rows; int16_t pixSize = 1; - if (ftFace->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { + if (faceInfo.face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { pixSize = 0x04; // 4 Byte } - uint32_t bitmapSize = ftFace->glyph->bitmap.width * ftFace->glyph->bitmap.rows * pixSize; - uint8_t* bitmap = bitmapCache_->GetSpace(key_, unicode, bitmapSize + sizeof(Metric)); + uint32_t bitmapSize = faceInfo.face->glyph->bitmap.width * faceInfo.face->glyph->bitmap.rows * pixSize; + uint8_t* bitmap = bitmapCache_->GetSpace(faceInfo.key, unicode, bitmapSize + sizeof(Metric)); if (bitmap != nullptr) { if (memcpy_s(bitmap, sizeof(Metric), &f, sizeof(Metric)) != EOK) { return; } - if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, ftFace->glyph->bitmap.buffer, bitmapSize) != EOK) { + if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, faceInfo.face->glyph->bitmap.buffer, bitmapSize) != EOK) { return; } } @@ -630,26 +645,26 @@ void UIFontVector::SetFace(FT_Face ftFace, uint32_t unicode) const } #if ENABLE_VECTOR_FONT -void UIFontVector::SetFace(FT_Face ftFace, uint32_t unicode, TextStyle textStyle) const +void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textStyle) const { Metric f; - f.advance = static_cast(ftFace->glyph->advance.x / FONT_PIXEL_IN_POINT); - f.left = ftFace->glyph->bitmap_left; - f.top = ftFace->glyph->bitmap_top; - f.cols = ftFace->glyph->bitmap.width; - f.rows = ftFace->glyph->bitmap.rows; + f.advance = static_cast(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT); + f.left = faceInfo.face->glyph->bitmap_left; + f.top = faceInfo.face->glyph->bitmap_top; + f.cols = faceInfo.face->glyph->bitmap.width; + f.rows = faceInfo.face->glyph->bitmap.rows; int16_t pixSize = 1; - if (ftFace->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { + if (faceInfo.face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { pixSize = 0x04; // 4 Byte } - uint32_t bitmapSize = ftFace->glyph->bitmap.width * ftFace->glyph->bitmap.rows * pixSize; - uint8_t* bitmap = bitmapCache_->GetSpace(key_, unicode, bitmapSize + sizeof(Metric), textStyle); + uint32_t bitmapSize = faceInfo.face->glyph->bitmap.width * faceInfo.face->glyph->bitmap.rows * pixSize; + uint8_t* bitmap = bitmapCache_->GetSpace(faceInfo.key, unicode, bitmapSize + sizeof(Metric), textStyle); if (bitmap != nullptr) { if (memcpy_s(bitmap, sizeof(Metric), &f, sizeof(Metric)) != EOK) { return; } - if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, ftFace->glyph->bitmap.buffer, bitmapSize) != EOK) { + if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, faceInfo.face->glyph->bitmap.buffer, bitmapSize) != EOK) { return; } } @@ -661,18 +676,11 @@ inline uint32_t UIFontVector::GetKey(uint8_t fontId, uint32_t size) return ((static_cast(fontId)) << 24) + size; // fontId store at the (24+1)th bit } -uint16_t UIFontVector::GetHeight(uint32_t unicode, uint8_t fontId) -{ - GlyphNode glyphNode; - -#if ENABLE_VECTOR_FONT - glyphNode.textStyle = TEXT_STYLE_NORMAL; -#endif - GetBitmap(unicode, glyphNode, fontId); - return glyphNode.rows; -} - -uint16_t UIFontVector::GetOffsetPosY(const char *text, uint16_t lineLength, bool& isEmojiLarge, uint8_t fontSize) +uint16_t UIFontVector::GetOffsetPosY(const char* text, + uint16_t lineLength, + bool& isEmojiLarge, + uint8_t fontId, + uint8_t fontSize) { if (!freeTypeInited_ || (bitmapCache_ == nullptr)) { return INVALID_RET_VALUE; @@ -683,13 +691,14 @@ uint16_t UIFontVector::GetOffsetPosY(const char *text, uint16_t lineLength, bool uint16_t emojiNum = 0; uint16_t loopNum = 0; GlyphNode glyphNode; - GlyphNode emojiMaxNode; + GlyphNode emojiMaxNode = {}; uint8_t maxFontSize = fontSize; while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); - uint8_t ret = GetGlyphNode(unicode, glyphNode); + uint8_t ret = GetGlyphNode(unicode, glyphNode, fontId, fontSize); if (ret == RET_VALUE_OK) { - if (TypedText::IsColourWord(unicode)) { + uint8_t weight = GetFontWeight(glyphNode.fontId); + if (weight >= 16) { // 16: bit rgb565 rgba8888 emojiMaxNode = glyphNode.rows > emojiMaxNode.rows ? glyphNode : emojiMaxNode; emojiNum++; } else { @@ -720,7 +729,7 @@ uint16_t UIFontVector::GetOffsetPosY(const char *text, uint16_t lineLength, bool return offset; } -uint16_t UIFontVector::GetLineMaxHeight(const char *text, uint16_t lineLength, uint8_t fontId, +uint16_t UIFontVector::GetLineMaxHeight(const char *text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) { if (!freeTypeInited_) { @@ -731,15 +740,15 @@ uint16_t UIFontVector::GetLineMaxHeight(const char *text, uint16_t lineLength, u uint16_t textNum = 0; uint16_t emojiNum = 0; uint16_t loopNum = 0; - uint16_t maxHeight = GetHeight(); + uint16_t maxHeight = GetHeight(fontId, fontSize); while (i < lineLength) { unicode = TypedText::GetUTF8Next(text, i, i); - TypedText::IsColourWord(unicode) ? emojiNum++ : textNum++; + TypedText::IsColourWord(unicode, fontId, fontSize) ? emojiNum++ : textNum++; loopNum++; if (sizeSpans != nullptr && sizeSpans[letterIndex].isSizeSpan) { uint16_t spannableHeight = 0; if (sizeSpans[letterIndex].height == 0) { - spannableHeight = GetHeightByFontId(sizeSpans[letterIndex].fontId, sizeSpans[letterIndex].size); + spannableHeight = GetHeight(sizeSpans[letterIndex].fontId, sizeSpans[letterIndex].size); sizeSpans[letterIndex].height = spannableHeight; } else { spannableHeight = sizeSpans[letterIndex].height; diff --git a/frameworks/font/ui_line_break.cpp b/frameworks/font/ui_line_break.cpp index 6b834833081576388fab2653a615999198fe4149..a65b704b6912ec9be52d9b7d23b598e9b889afa5 100644 --- a/frameworks/font/ui_line_break.cpp +++ b/frameworks/font/ui_line_break.cpp @@ -109,6 +109,8 @@ void UILineBreakEngine::LoadRule() } uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, + uint8_t fontId, + uint8_t fontSize, int16_t space, bool allBreak, int16_t& maxWidth, @@ -135,16 +137,16 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, preIndex = byteIdx; continue; } - if (isAllCanBreak || IsBreakPos(unicode, state)) { - if (!TypedText::IsColourWord(unicode)) { + 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, state); + IsBreakPos(unicode, fontId, fontSize, state); lastIndex = preIndex; lastWidth = curWidth; } - width = GetLetterWidth(unicode, letterIndex, height, sizeSpans); + width = GetLetterWidth(unicode, letterIndex, height, fontId, fontSize, sizeSpans); letterIndex++; if (height > maxHeight) { maxHeight = height; @@ -169,30 +171,29 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, } int16_t UILineBreakEngine::GetLetterWidth(uint32_t unicode, uint16_t& letterIndex, int16_t& height, - SizeSpan* sizeSpans) + uint8_t fontId, uint8_t fontSize, SizeSpan* sizeSpans) { if (sizeSpans != nullptr && sizeSpans[letterIndex].isSizeSpan) { - int16_t width = UIFont::GetInstance()->GetWidthSpannable(unicode, - sizeSpans[letterIndex].fontId, - sizeSpans[letterIndex].size); + int16_t width = UIFont::GetInstance()->GetWidth(unicode, sizeSpans[letterIndex].fontId, + sizeSpans[letterIndex].size, 0); if (sizeSpans[letterIndex].height == 0) { - height = UIFont::GetInstance()->GetHeightSpannable(sizeSpans[letterIndex].fontId, - sizeSpans[letterIndex].size); + height = UIFont::GetInstance()->GetHeight(sizeSpans[letterIndex].fontId, + sizeSpans[letterIndex].size); sizeSpans[letterIndex].height = height; } else { height = sizeSpans[letterIndex].height; } return width; } else { - height = UIFont::GetInstance()->GetHeight(unicode, 0); - return UIFont::GetInstance()->GetWidth(unicode, 0); + height = UIFont::GetInstance()->GetHeight(fontId, fontSize); + return UIFont::GetInstance()->GetWidth(unicode, fontId, fontSize, 0); } } -bool UILineBreakEngine::IsBreakPos(uint32_t unicode, int32_t& state) +bool UILineBreakEngine::IsBreakPos(uint32_t unicode, uint8_t fontId, uint8_t fontSize, int32_t& state) { - if (TypedText::IsColourWord(unicode)) { + 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 050db775cb212c247b039bb9f643014fb505dea8..ba800288c33b89b3d3b6b1904dd55d4d6f4b7c00 100644 --- a/frameworks/font/ui_line_break.h +++ b/frameworks/font/ui_line_break.h @@ -18,12 +18,14 @@ #include "graphic_config.h" #if ENABLE_ICU +#include +#include + #include "font/ui_font_header.h" #include "gfx_utils/file.h" #include "gfx_utils/heap_base.h" #include "gfx_utils/mem_api.h" -#include -#include + namespace OHOS { class UILineBreakProxy; /** @@ -107,11 +109,17 @@ public: } // 0xFFFF: unlimit the length until the end null. - uint32_t GetNextLineAndWidth(const char* text, int16_t space, bool allBreak, - int16_t& maxWidth, int16_t& maxHeight, - uint16_t& letterIndex, SizeSpan* sizeSpans, + uint32_t GetNextLineAndWidth(const char* text, + uint8_t fontId, + uint8_t fontSize, + int16_t space, + bool allBreak, + int16_t& maxWidth, + int16_t& maxHeight, + uint16_t& letterIndex, + SizeSpan* sizeSpans, uint16_t len = 0xFFFF); - bool IsBreakPos(uint32_t unicode, int32_t& state); + bool IsBreakPos(uint32_t unicode, uint8_t fontId, uint8_t fontSize, int32_t& state); private: UILineBreakEngine() @@ -122,7 +130,7 @@ private: void LoadRule(); int16_t GetLetterWidth(uint32_t unicode, uint16_t& letterIndex, int16_t& maxHeight, - SizeSpan* sizeSpans); + uint8_t fontId, uint8_t fontSize, SizeSpan* sizeSpans); static constexpr const int32_t LINE_BREAK_STATE_START = 1; static constexpr const int32_t LINE_BREAK_STATE_STOP = 0; bool initSuccess_; diff --git a/interfaces/innerkits/font/ui_font_bitmap.h b/interfaces/innerkits/font/ui_font_bitmap.h index 5cf220bc7ade679ce4f43092c0dadd002a7d6c9e..308ab9dfbb2269ad9e36f3de9068623e65b45097 100644 --- a/interfaces/innerkits/font/ui_font_bitmap.h +++ b/interfaces/innerkits/font/ui_font_bitmap.h @@ -19,6 +19,7 @@ #include "font/base_font.h" #include "font/glyphs_manager.h" #include "font/ui_font_cache.h" +#include "graphic_locker.h" namespace OHOS { class UIFontBitmap : public BaseFont { @@ -30,25 +31,21 @@ public: bool IsVectorFont() const override; uint8_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const override; int8_t SetFontPath(const char* dpath, const char* spath) override; - int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0) override; - uint16_t GetHeight() override; - uint8_t GetFontId(const char* ttfName, uint8_t size = 0) const override; - int16_t GetWidth(uint32_t unicode, uint8_t fontId) override; - uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) override; - int8_t GetCurrentFontHeader(FontHeader& fontHeader) override; - int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) override; + uint16_t GetHeight(uint8_t fontId, uint8_t fontSize = 0) override; + uint8_t GetFontId(const char* ttfName, uint8_t fontSize = 0) const override; + int16_t GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize = 0) override; + uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize = 0) override; + int8_t GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize = 0) override; + int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize = 0) override; uint8_t GetFontWeight(uint8_t fontId) override; int8_t GetFontVersion(char* dVersion, uint8_t dLen, char* sVersion, uint8_t sLen) const override; int8_t SetCurrentLangId(uint8_t langId) override; UITextLanguageFontParam* GetFontInfo(uint8_t fontId) const override; void SetFontFileOffset(uint32_t offset) override; - uint16_t GetHeight(uint32_t unicode, uint8_t fontId) override; - uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLerge, uint8_t fontSize) override; - uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, + uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLerge, + uint8_t fontId, uint8_t fontSize) override; + uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) override; - uint16_t GetHeightByFontId(uint8_t fontId, uint8_t size = 0) override; - int16_t GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size = 0) override; - uint8_t* GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size = 0) override; bool IsEmojiFont(uint8_t fontId) override; protected: uint32_t GetBitmapRamUsed(); @@ -58,16 +55,15 @@ protected: uint8_t* GetCacheBitmap(uint8_t fontId, uint32_t unicode); uint8_t* GetCacheSpace(uint8_t fontId, uint32_t unicode, uint32_t size); void PutCacheSpace(uint8_t* addr); - int8_t SetDynamicFontId(uint8_t fontId); int16_t GetDynamicFontWidth(uint32_t unicode, uint8_t fontId); uint32_t offset_; + GraphicMutex lock_; private: - uint8_t* SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, bool isSpanLetter = false); + uint8_t* SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId); int16_t GetWidthInFontId(uint32_t unicode, uint8_t fontId); - int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId); #if ENABLE_MULTI_FONT - int8_t GetMultiGlyphNode(uint32_t unicode, GlyphNode& glyphNode); + int8_t GetMultiGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId); #endif static constexpr uint32_t FONT_BITMAP_CACHE_SIZE = 0x64000; static constexpr uint8_t FONT_ID_MAX = 0xFF; diff --git a/interfaces/innerkits/font/ui_font_vector.h b/interfaces/innerkits/font/ui_font_vector.h index b11d08f342b1b04e6fbd7b61376bacb9f7892b1d..c4e39552b52e552daf797392f639d4457d9e88ed 100644 --- a/interfaces/innerkits/font/ui_font_vector.h +++ b/interfaces/innerkits/font/ui_font_vector.h @@ -33,13 +33,12 @@ public: UIFontVector& operator=(const UIFontVector&) noexcept = delete; bool IsVectorFont() const override; int8_t SetFontPath(const char* dpath, const char* spath) override; - int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0) override; - uint16_t GetHeight() override; - uint8_t GetFontId(const char* ttfName, uint8_t size = 0) const override; - int16_t GetWidth(uint32_t unicode, uint8_t fontId) override; - uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) override; - int8_t GetCurrentFontHeader(FontHeader& fontHeader) override; - int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) override; + uint16_t GetHeight(uint8_t fontId, uint8_t fontSize) override; + uint8_t GetFontId(const char* ttfName, uint8_t fontSize = 0) const override; + int16_t GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize) override; + uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) override; + int8_t GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize) override; + int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) override; uint8_t GetFontWeight(uint8_t fontId) override; uint8_t GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint8_t fontId, uint8_t size) const override; @@ -50,13 +49,11 @@ public: const UITextLanguageFontParam* GetFontInfo(uint8_t fontId) const override; int32_t OpenVectorFont(uint8_t ttfId) override; bool IsColorEmojiFont(FT_Face &face); - uint16_t GetHeight(uint32_t unicode, uint8_t fontId) override; - uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmojiLarge, uint8_t fontSize) override; - uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, + uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, + bool& isEmojiLarge, uint8_t fontId, uint8_t fontSize) override; + uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) override; - uint16_t GetHeightByFontId(uint8_t fontId, uint8_t size = 0) override; - int16_t GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size) override; - uint8_t* GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size = 0) override; + bool IsEmojiFont(uint8_t fontId) override; private: static constexpr uint8_t FONT_ID_MAX = 0xFF; @@ -69,8 +66,11 @@ private: FT_Face ftFaces_[FONT_ID_MAX] = {0}; uint8_t currentFontInfoNum_ = 0; bool freeTypeInited_; - uint32_t key_ = 0; UIFontCache* bitmapCache_; + struct FaceInfo { + FT_Face face; + uint32_t key; + }; struct Metric { int left; int top; @@ -79,23 +79,23 @@ private: int advance; uint8_t buf[0]; }; - void SetFace(FT_Face ftface, uint32_t unicode) const; + void SetFace(FaceInfo& faceInfo, uint32_t unicode) const; #if ENABLE_VECTOR_FONT - void SetFace(FT_Face ftface, uint32_t unicode, TextStyle textStyle) const; + void SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textStyle) const; #endif uint8_t GetFontId(uint32_t unicode) const; uint32_t GetKey(uint8_t fontId, uint32_t size); + int8_t LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, FT_Face face); #if ENABLE_VECTOR_FONT - int8_t LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, TextStyle textStyle); + int8_t LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode, FT_Face face, TextStyle textStyle); #endif - int8_t LoadGlyphIntoFace(uint8_t& fontId, uint32_t unicode); uint8_t IsGlyphFont(uint32_t unicode); #if ENABLE_VECTOR_FONT void SetItaly(FT_GlyphSlot slot); void SetBold(uint8_t fontId); #endif + int8_t GetFaceInfo(uint8_t fontId, uint8_t fontSize, FaceInfo& faceInfo); uint16_t GetMaxSubLineHeight(uint16_t textNum, uint16_t loopNum, uint16_t maxHeight, uint16_t emojiNum); }; } // namespace OHOS #endif - diff --git a/interfaces/kits/font/base_font.h b/interfaces/kits/font/base_font.h index 24479a6ac987cf5c92d1bc3606fd5d15c0ba4654..12e8eb195fa66446509730ec666009a8389536e4 100644 --- a/interfaces/kits/font/base_font.h +++ b/interfaces/kits/font/base_font.h @@ -23,7 +23,7 @@ namespace OHOS { class BaseFont : public HeapBase { public: - BaseFont() : fontId_(0), ramAddr_(0), ramLen_(0) {} + BaseFont() : ramAddr_(0), ramLen_(0) {} virtual ~BaseFont() {} /** @@ -32,23 +32,12 @@ public: */ virtual bool IsVectorFont() const = 0; - /** - * @brief Set font by id - * - * @param fontid [in] the font id - * @param size [in] the font size - * @return int8_t: -1 failed, 0 success - */ - virtual int8_t SetCurrentFontId(uint8_t fontId, uint8_t size) = 0; - /** * @brief Get height for specific font * * @return uint16_t */ - virtual uint16_t GetHeight() = 0; - - virtual uint16_t GetHeightByFontId(uint8_t fontId, uint8_t size) = 0; + virtual uint16_t GetHeight(uint8_t fontId, uint8_t fontSize) = 0; /** * @brief Get font id @@ -57,7 +46,7 @@ public: * @param size 0: invalid size * @return uint8_t */ - virtual uint8_t GetFontId(const char* ttfName, uint8_t size) const = 0; + virtual uint8_t GetFontId(const char* ttfName, uint8_t fontSize) const = 0; /** * @brief Get width @@ -65,9 +54,7 @@ public: * @param unicode * @return int16_t */ - virtual int16_t GetWidth(uint32_t unicode, uint8_t fontId) = 0; - - virtual int16_t GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size) = 0; + virtual int16_t GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize) = 0; virtual int32_t OpenVectorFont(uint8_t ttfId) { @@ -79,9 +66,7 @@ public: * @param unicode * @return uint8_t* */ - virtual uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId) = 0; - - virtual uint8_t* GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size) = 0; + virtual uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) = 0; /** * @brief Get font header @@ -89,7 +74,7 @@ public: * @param fontHeader * @return int8_t */ - virtual int8_t GetCurrentFontHeader(FontHeader& fontHeader) = 0; + virtual int8_t GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize) = 0; /** * @brief Get the glyph node @@ -99,7 +84,7 @@ public: * @param isGlyph * @return int8_t */ - virtual int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode) = 0; + virtual int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize) = 0; virtual uint8_t GetFontWeight(uint8_t fontId) = 0; virtual int8_t SetCurrentLangId(uint8_t langId) @@ -210,34 +195,19 @@ public: virtual void SetFontFileOffset(uint32_t offset) {} - /** - * @brief Get current font id - * - * @return uint8_t - */ - void SetBaseFontId(uint8_t fontId); - uint8_t GetBaseFontId(); void SetRamAddr(uintptr_t ramAddr); uintptr_t GetRamAddr(); uint32_t GetRamLen(); void SetRamLen(uint32_t ramLen); void SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen); - /** - * @brief Get Height - * - * @param unicode - * @return int16_t - */ - virtual uint16_t GetHeight(uint32_t unicode, uint8_t fontId) = 0; - - virtual uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLarge, uint8_t fontSize) = 0; - - virtual uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, + virtual uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLarge, + uint8_t fontId, uint8_t fontSize) = 0; + virtual uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t& letterIndex, SizeSpan* sizeSpans) = 0; virtual bool IsEmojiFont(uint8_t fontId) = 0; + private: - uint8_t fontId_; uintptr_t ramAddr_; uint32_t ramLen_; }; diff --git a/interfaces/kits/font/ui_font.h b/interfaces/kits/font/ui_font.h index 5e2e68d7ebf1438ba5d92325eda561bc0a3f0aef..453087150302aa4e372ef309cb2c14be3b35ce85 100644 --- a/interfaces/kits/font/ui_font.h +++ b/interfaces/kits/font/ui_font.h @@ -37,41 +37,30 @@ public: return instance_->GetShapingFontId(text, ttfId, script, fontId, size); } - /** - * @brief Set font id - * - * @param fontId - * @param size - * @return int8_t - */ - int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0) - { - return instance_->SetCurrentFontId(fontId, size); - } - /** * @brief Get width of the letter * * @param unicode: [in] unicode or glyph index according to isGlyph param - * @param shapingId: [in] + * @param fontId: [in] font id + * @param fontSize: [in] font size + * @param shapingId: [in] font shaping id * @return uint16_t: the letter width */ - uint16_t GetWidth(uint32_t unicode, uint8_t shapingId); - - uint16_t GetWidthSpannable(uint32_t unicode, uint8_t fontId, uint8_t size); + uint16_t GetWidth(uint32_t unicode, uint8_t fontId, uint8_t fontSize, uint8_t shapingId); /** * @brief Get height for specific font * + * @param fontId: font id + * @param fontSize: font size + * * @return uint16_t */ - uint16_t GetHeight() + uint16_t GetHeight(uint8_t fontId, uint8_t fontSize) { - return instance_->GetHeight(); + return instance_->GetHeight(fontId, fontSize); } - uint16_t GetHeightSpannable(uint8_t fontId, uint8_t size); - /** * @brief Get the font weight * @param fontId @@ -88,9 +77,9 @@ public: * @param fontHeader * @return int8_t */ - int8_t GetCurrentFontHeader(FontHeader& fontHeader) + int8_t GetFontHeader(FontHeader& fontHeader, uint8_t fontId, uint8_t fontSize) { - return instance_->GetCurrentFontHeader(fontHeader); + return instance_->GetFontHeader(fontHeader, fontId, fontSize); } /** @@ -122,9 +111,9 @@ public: * @param unicode * @return uint8_t* */ - uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t shapingFont); + uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t fontSize, uint8_t shapingFont); - uint8_t* GetBitmapSpannable(uint32_t unicode, GlyphNode& glyphNode, uint8_t fontId, uint8_t size); + 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. @@ -135,16 +124,6 @@ public: return instance_->IsVectorFont(); } - /** - * @brief Get current font id - * - * @return uint8_t - */ - uint8_t GetCurrentFontId() - { - return instance_->GetBaseFontId(); - } - int8_t SetCurrentLangId(uint8_t langId) { return instance_->SetCurrentLangId(langId); @@ -234,18 +213,15 @@ public: instance_->SetFontFileOffset(offset); } - uint16_t GetHeight(uint32_t unicode, uint8_t fontId) + virtual uint16_t + GetOffsetPosY(const char* text, uint16_t lineLength, bool& isAllEmoji, uint8_t fontId, uint8_t fontSize) { - return instance_->GetHeight(unicode, fontId); + return instance_->GetOffsetPosY(text, lineLength, isAllEmoji, fontId, fontSize); } - virtual uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isAllEmoji, uint8_t fontSize) - { - return instance_->GetOffsetPosY(text, lineLength, isAllEmoji, fontSize); - } - - virtual uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, + virtual uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint8_t fontId, uint8_t fontSize, uint16_t letterIndex, SizeSpan* sizeSpans); + bool IsEmojiFont(uint8_t fontid) { return instance_->IsEmojiFont(fontid); diff --git a/test/unittest/font/ui_font_unit_test.cpp b/test/unittest/font/ui_font_unit_test.cpp index 67023f617dc3545fbf55a17e7bb895bb5ac4817d..4b024d89636bb4cb717e63f46989a30597bcbb51 100644 --- a/test/unittest/font/ui_font_unit_test.cpp +++ b/test/unittest/font/ui_font_unit_test.cpp @@ -117,18 +117,6 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_SetFontPath_002, TestSize.Level1) #endif } -/** - * @tc.name: Graphic_Font_Test_SetCurrentFontId_001 - * @tc.desc: Verify SetCurrentFontId function, abnormal value test. - * @tc.type: FUNC - * @tc.require: AR000FQNFR - */ -HWTEST_F(UIFontTest, Graphic_Font_Test_SetCurrentFontId_001, TestSize.Level1) -{ - int8_t ret = UIFont::GetInstance()->SetCurrentFontId(0, 0); - EXPECT_EQ(ret, INVALID_RET); -} - /** * @tc.name: Graphic_Font_Test_GetFontId_001 * @tc.desc: Verify GetFontId function, nullptr test. @@ -161,7 +149,7 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontId_002, TestSize.Level1) */ HWTEST_F(UIFontTest, Graphic_Font_Test_GetHeight_001, TestSize.Level1) { - uint16_t height = UIFont::GetInstance()->GetHeight(); + uint16_t height = UIFont::GetInstance()->GetHeight(FONT_ID, 0); #if ENABLE_VECTOR_FONT EXPECT_EQ(height, 0); #else @@ -177,7 +165,7 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetHeight_001, TestSize.Level1) */ HWTEST_F(UIFontTest, Graphic_Font_Test_GetWidth_001, TestSize.Level1) { - uint16_t width = UIFont::GetInstance()->GetWidth(0, 0); + uint16_t width = UIFont::GetInstance()->GetWidth(0, 0, 0, 0); EXPECT_EQ(width, 0); } @@ -190,20 +178,20 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetWidth_001, TestSize.Level1) HWTEST_F(UIFontTest, Graphic_Font_Test_GetBitmap_001, TestSize.Level1) { GlyphNode node; - uint8_t* bitmap = UIFont::GetInstance()->GetBitmap(0, node, 0); + uint8_t* bitmap = UIFont::GetInstance()->GetBitmap(0, node, 0, 0, 0); EXPECT_EQ(bitmap, nullptr); } /** - * @tc.name: Graphic_Font_Test_GetCurrentFontHeader_001 - * @tc.desc: Verify GetCurrentFontHeader function, abnormal value test. + * @tc.name: Graphic_Font_Test_GetFontHeader_001 + * @tc.desc: Verify GetFontHeader function, abnormal value test. * @tc.type: FUNC * @tc.require: AR000FQNFR */ -HWTEST_F(UIFontTest, Graphic_Font_Test_GetCurrentFontHeader_001, TestSize.Level1) +HWTEST_F(UIFontTest, Graphic_Font_Test_GetFontHeader_001, TestSize.Level1) { FontHeader header; - int8_t res = UIFont::GetInstance()->GetCurrentFontHeader(header); + int8_t res = UIFont::GetInstance()->GetFontHeader(header, FONT_ID, 0); EXPECT_EQ(res, INVALID_RET); }