提交 175e871e 编写于 作者: W wangtiantian

IssueNo:https://gitee.com/openharmony/graphic_ui/issues/I4FT6N

Description:fix text display bug
Sig:graphic
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: Nwangtiantian <wangtiantian19@huawei.com>
上级 f400063f
......@@ -306,10 +306,33 @@ uint16_t Text::GetLine(int16_t width, uint8_t letterSpace, uint16_t ellipsisInde
if ((lineNum != 0) && (ellipsisIndex != TEXT_ELLIPSIS_END_INV)) {
uint16_t ellipsisWidth = UIFont::GetInstance()->GetWidth('.', 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;
maxLineBytes = CalculateLineWithEllipsis(begin, textLen, newWidth, letterSpace, lineNum);
textLine_[lineNum - 1].linePixelWidth += ellipsisWidth * TEXT_ELLIPSIS_DOT_NUM;
}
}
return lineNum;
}
uint32_t Text::CalculateLineWithEllipsis(uint32_t begin, uint32_t textLen, int16_t width,
uint8_t letterSpace, uint16_t& lineNum)
{
begin -= textLine_[lineNum - 1].lineBytes;
lineNum--;
while ((begin < textLen) && (text_[begin] != '\0') && (lineNum < MAX_LINE_COUNT)) {
begin += GetTextLine(begin, textLen, width, lineNum, letterSpace);
lineNum++;
}
uint32_t maxLineBytes = 0;
for (uint16_t i = 0; i < lineNum; i++) {
if (maxLineBytes < textLine_[i].lineBytes) {
maxLineBytes = textLine_[i].lineBytes;
}
}
return maxLineBytes;
}
uint32_t Text::GetTextStrLen()
{
return strlen(text_);
......
......@@ -121,7 +121,7 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, int16_t space,
int16_t curWidth = 0;
int32_t state = LINE_BREAK_STATE_START;
int16_t width = 0;
while ((text[byteIdx] != '\0') && (byteIdx <= len)) {
while ((text[byteIdx] != '\0') && (byteIdx < len)) {
uint32_t unicode = TypedText::GetUTF8Next(text, preIndex, byteIdx);
if (unicode == 0) {
preIndex = byteIdx;
......@@ -150,10 +150,6 @@ uint32_t UILineBreakEngine::GetNextLineAndWidth(const char* text, int16_t space,
}
}
maxWidth = curWidth;
if (preIndex > len) {
maxWidth = maxWidth - width;
preIndex = len;
}
return preIndex;
}
......
......@@ -362,6 +362,8 @@ protected:
int16_t TextPositionY(const Rect& textRect, int16_t textHeight);
int16_t LineStartPos(const Rect& textRect, uint16_t lineWidth);
void DrawEllipsis(BufferInfo& gfxDstBuffer, LabelLineInfo& labelLine);
uint32_t CalculateLineWithEllipsis(uint32_t begin, uint32_t textLen, int16_t width,
uint8_t letterSpace, uint16_t& lineNum);
char* text_;
uint8_t fontId_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册