提交 f52e155a 编写于 作者: O openharmony_ci 提交者: Gitee

!401 UILabel调整baseline兼容原有应用,避免出现字符截断现象

Merge pull request !401 from wangtiantian/bug_label_m
......@@ -33,6 +33,7 @@ Text::Text()
needRefresh_(false),
expandWidth_(false),
expandHeight_(false),
baseLine_(true),
direct_(TEXT_DIRECT_LTR),
horizontalAlign_(TEXT_ALIGNMENT_LEFT),
verticalAlign_(TEXT_ALIGNMENT_TOP)
......@@ -161,11 +162,13 @@ void Text::ReMeasureTextSize(const Rect& textRect, const Style& style)
int16_t maxWidth = (expandWidth_ ? COORD_MAX : textRect.GetWidth());
if (maxWidth > 0) {
textSize_ = TypedText::GetTextSize(text_, style.letterSpace_, style.lineHeight_, maxWidth, style.lineSpace_);
FontHeader head;
if (UIFont::GetInstance()->GetCurrentFontHeader(head) != 0) {
return;
if (baseLine_) {
FontHeader head;
if (UIFont::GetInstance()->GetCurrentFontHeader(head) != 0) {
return;
}
textSize_.y += fontSize_ - head.ascender;
}
textSize_.y += fontSize_ - head.ascender;
}
}
......@@ -234,7 +237,7 @@ void Text::Draw(BufferInfo& gfxDstBuffer,
LabelLineInfo labelLine{pos, offset, mask, lineHeight, textLine_[i].lineBytes,
0, opa, style, &text_[lineBegin], textLine_[i].lineBytes,
lineBegin, fontId_, fontSize_, 0, static_cast<UITextLanguageDirect>(direct_),
nullptr};
nullptr, baseLine_};
DrawLabel::DrawTextOneLine(gfxDstBuffer, labelLine);
if ((i == (lineCount - 1)) && (ellipsisIndex != TEXT_ELLIPSIS_END_INV)) {
labelLine.offset.x = 0;
......
......@@ -48,7 +48,8 @@ void DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInfo& l
labelLine.direct,
labelLine.fontId,
0,
labelLine.fontSize};
labelLine.fontSize,
labelLine.baseLine};
DrawUtils::GetInstance()->DrawLetter(gfxDstBuffer, letterInfo);
letterWidth = fontEngine->GetWidth(letter, 0);
if (labelLine.direct == TEXT_DIRECT_RTL) {
......
......@@ -285,8 +285,16 @@ void DrawUtils::DrawLetter(BufferInfo& gfxDstBuffer, const LabelLetterInfo& lett
uint16_t letterW = node.cols;
uint16_t letterH = node.rows;
int16_t posX;
int16_t posY = letterInfo.pos.y + letterInfo.fontSize - node.top - letterInfo.offsetY;
int16_t posY;
if (letterInfo.baseLine) {
posY = letterInfo.pos.y + letterInfo.fontSize - node.top - letterInfo.offsetY;
} else {
FontHeader head;
if (fontEngine->GetCurrentFontHeader(head) != 0) {
return;
}
posY = letterInfo.pos.y + head.ascender - node.top - letterInfo.offsetY;
}
if (letterInfo.direct == TEXT_DIRECT_RTL) {
/* RTL */
posX = letterInfo.pos.x - node.advance + node.left + letterInfo.offsetX;
......
......@@ -70,6 +70,7 @@ struct LabelLineInfo {
uint8_t txtFlag;
UITextLanguageDirect direct;
uint32_t* codePoints;
bool baseLine;
};
struct LabelLetterInfo {
......@@ -85,6 +86,7 @@ struct LabelLetterInfo {
uint8_t fontId;
uint8_t shapingId;
uint8_t fontSize;
bool baseLine;
};
struct TransformInitState {
......
......@@ -323,6 +323,11 @@ public:
*/
uint16_t GetEllipsisIndex(const Rect& textRect, const Style& style);
void SetSupportBaseLine(bool baseLine)
{
baseLine_ = baseLine;
}
protected:
struct TextLine {
uint16_t lineBytes;
......@@ -362,7 +367,8 @@ protected:
bool needRefresh_ : 1;
bool expandWidth_ : 1;
bool expandHeight_ : 1;
uint8_t direct_ : 5; // UITextLanguageDirect
bool baseLine_ : 1;
uint8_t direct_ : 4; // UITextLanguageDirect
private:
uint8_t horizontalAlign_ : 4; // UITextLanguageAlignment
......
......@@ -407,6 +407,12 @@ public:
void ReMeasure() override;
void SetSupportBaseLine(bool baseLine)
{
InitLabelText();
labelText_->SetSupportBaseLine(baseLine);
}
protected:
Text* labelText_;
void RefreshLabel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册