diff --git a/frameworks/common/text.cpp b/frameworks/common/text.cpp index 715e1ba9f751410bc95b5770aab1999dee05c9eb..d1c3009f61f483bff93a4bc10e8ae1937d8bc1ae 100644 --- a/frameworks/common/text.cpp +++ b/frameworks/common/text.cpp @@ -299,7 +299,7 @@ void Text::Draw(BufferInfo& gfxDstBuffer, uint16_t lineCount = GetLine(lineMaxWidth, style.letterSpace_, ellipsisIndex, maxLineBytes); int16_t lineHeight = style.lineHeight_; int16_t curLineHeight; - if (lineHeight == 0) { + if (lineHeight <= 0) { lineHeight = UIFont::GetInstance()->GetHeight(fontId_, fontSize_); lineHeight += style.lineSpace_; } diff --git a/test/uitest/test_label/ui_test_label.cpp b/test/uitest/test_label/ui_test_label.cpp index 83910dd39f1f5199351438fa82ff33accc5a6377..10b114327f359d6b1fe70d4d42956135ca46e2a2 100644 --- a/test/uitest/test_label/ui_test_label.cpp +++ b/test/uitest/test_label/ui_test_label.cpp @@ -60,6 +60,9 @@ void UITestLabel::TearDown() labelDirectionBtn2_ = nullptr; labelSizeBtn1_ = nullptr; labelSizeBtn2_ = nullptr; + labelLineHeightBtn1_ = nullptr; + labelLineHeightBtn2_ = nullptr; + labelLineHeightBtn3_ = nullptr; } const UIView* UITestLabel::GetTestView() @@ -179,6 +182,14 @@ void UITestLabel::UIKitUILabeTestDisplay002() label3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); labelDirectionBtn1_ = SetUpButton("左往右 ", 24, 240, uiViewGroup); // 24: x-coordinate; 240: y-coordinate labelDirectionBtn2_ = SetUpButton("右往左 ", 116, 240, uiViewGroup); // 116: x-coordinate; 240: y-coordinate + UILabel* label4 = new UILabel(); + uiViewGroup->Add(label4); + label4->SetPosition(24, 299, 288, 48); // 24: x-coordinate, 299: y-coordinate, 288: width; 48: height + label4->SetText("行高"); + label4->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + labelLineHeightBtn1_ = SetUpButton("行高20 ", 24, 336, uiViewGroup); // 24: x-coordinate; 336: y-coordinate + labelLineHeightBtn2_ = SetUpButton("行高35 ", 116, 336, uiViewGroup); // 116: x-coordinate; 336: y-coordinate + labelLineHeightBtn3_ = SetUpButton("行高50 ", 208, 336, uiViewGroup); // 208: x-coordinate; 336: y-coordinate positionY_ += 384; // 384: increase x-coordinate positionX_ -= 312; // 312: increase y-coordinate } @@ -270,6 +281,12 @@ void UITestLabel::ExpandClick(UIView& view, const ClickEvent& event) const } else if (&view == labelSizeBtn2_) { uiLabel->SetText("Test of 图形子系统,Test of 图形子系统 "); uiLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + } else if (&view == labelLineHeightBtn1_) { + uiLabel->SetStyle(STYLE_LINE_HEIGHT, 20); // 20: lineHeight + } else if (&view == labelLineHeightBtn2_) { + uiLabel->SetStyle(STYLE_LINE_HEIGHT, 35); // 35: lineHeight + } else if (&view == labelLineHeightBtn3_) { + uiLabel->SetStyle(STYLE_LINE_HEIGHT, 50); // 50: lineHeight } } } // namespace OHOS diff --git a/test/uitest/test_label/ui_test_label.h b/test/uitest/test_label/ui_test_label.h index 836305b7920f7911f197d7c5bc165b5a6a0a9539..c63dcb19795623d8a32b78a369d8c78296abc907 100644 --- a/test/uitest/test_label/ui_test_label.h +++ b/test/uitest/test_label/ui_test_label.h @@ -65,6 +65,9 @@ private: UILabelButton* labelDirectionBtn2_ = nullptr; UILabelButton* labelSizeBtn1_ = nullptr; UILabelButton* labelSizeBtn2_ = nullptr; + UILabelButton* labelLineHeightBtn1_ = nullptr; + UILabelButton* labelLineHeightBtn2_ = nullptr; + UILabelButton* labelLineHeightBtn3_ = nullptr; void InnerTestTitle(const char* title); UILabelButton* SetUpButton(const char* title, int16_t x, int16_t y, UIViewGroup* uiViewGroup,