未验证 提交 ee6a30ec 编写于 作者: O openharmony_ci 提交者: Gitee

!663 字体引擎支持并发解析

Merge pull request !663 from Lizhiqi/font0528
......@@ -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;
}
......
......@@ -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<float>(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<float>(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
......@@ -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);
......
......@@ -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<float>((UI_PI * radius_ * arcAngle) / SEMICIRCLE_IN_DEGREE);
arcTextInfo_.lineStart = 0;
arcTextInfo_.lineEnd =
TypedText::GetNextLine(&text[arcTextInfo_.lineStart], style_->letterSpace_, static_cast<int16_t>(maxLength));
arcTextInfo_.lineEnd = TypedText::GetNextLine(&text[arcTextInfo_.lineStart], arcLabelText_->GetFontId(),
arcLabelText_->GetFontSize(), style_->letterSpace_,
static_cast<int16_t>(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) {
......
......@@ -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);
}
......
......@@ -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<float>(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<int16_t>(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>* linebackgroundColor,
bool& havelinebackground, ColorType& linebgColor)
{
......
......@@ -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>* linebackgroundColor,
bool& havelinebackground, ColorType& linebgColor);
......
......@@ -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;
......
......@@ -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,
......
......@@ -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_;
......
......@@ -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<uint8_t>((unicode >> static_cast<uint8_t>(i)) & RADIX_TREE_MASK);
offset += key * sizeof(uint16_t);
idx = *(reinterpret_cast<uint16_t*>(tmpIndexCache + offset));
idx = *(reinterpret_cast<uint16_t*>(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<int32_t>(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<GlyphNode*>(GetGlyphNode(unicode));
uint32_t tmpBitMapSectionStart = curBitMapSectionStart_;
guard.Unlock();
GlyphNode* node = const_cast<GlyphNode*>(GetGlyphNode(unicode, fontId));
uint32_t tmpBitMapSectionStart = glyphInfo.bitMapSectionStart;
if (node == nullptr) {
GRAPHIC_LOGE("GlyphsManager::GetBitmap node not found");
return INVALID_RET_VALUE;
......
......@@ -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 */
......@@ -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
......@@ -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
......@@ -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);
};
......
......@@ -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
......@@ -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)
......
此差异已折叠。
......@@ -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)) {
......
......@@ -18,12 +18,14 @@
#include "graphic_config.h"
#if ENABLE_ICU
#include <cstdint>
#include <string>
#include "font/ui_font_header.h"
#include "gfx_utils/file.h"
#include "gfx_utils/heap_base.h"
#include "gfx_utils/mem_api.h"
#include <cstdint>
#include <string>
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_;
......
......@@ -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;
......
......@@ -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
......@@ -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_;
};
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册