diff --git a/frameworks/common/text.cpp b/frameworks/common/text.cpp index b362249863c140f50949ff0e940edf068fe641f9..59cde33c3d0091a72967745c8b82210dc198156c 100755 --- a/frameworks/common/text.cpp +++ b/frameworks/common/text.cpp @@ -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_); diff --git a/frameworks/font/ui_line_break.cpp b/frameworks/font/ui_line_break.cpp index eb27eb89f2224307f042b78aa38ff1ddbe431d2b..2ab0ecf4877dd6a8ff5126feb12ee944cf94a2d3 100755 --- a/frameworks/font/ui_line_break.cpp +++ b/frameworks/font/ui_line_break.cpp @@ -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; } diff --git a/interfaces/kits/common/text.h b/interfaces/kits/common/text.h index 048f8521960cb9b11e928d6ca231945afc9f1168..537735c52efe199677cc27a2a76e577480ac5ac3 100755 --- a/interfaces/kits/common/text.h +++ b/interfaces/kits/common/text.h @@ -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_;