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

!729 弧形文本优化

Merge pull request !729 from 郝烁/master
......@@ -88,8 +88,8 @@ Rect TypedText::GetArcTextRect(const char* text,
uint8_t fontSize,
const Point& arcCenter,
int16_t letterSpace,
UIArcLabel::TextOrientation orientation,
const UIArcLabel::ArcTextInfo& arcTextInfo)
TextOrientation orientation,
const ArcTextInfo& arcTextInfo)
{
if ((text == nullptr) || (arcTextInfo.lineStart == arcTextInfo.lineEnd) || (arcTextInfo.radius == 0)) {
GRAPHIC_LOGE("TypedText::GetArcTextRect invalid parameter\n");
......@@ -97,7 +97,7 @@ Rect TypedText::GetArcTextRect(const char* text,
}
uint16_t letterHeight = UIFont::GetInstance()->GetHeight(fontId, fontSize);
bool xorFlag = (orientation == UIArcLabel::TextOrientation::INSIDE) ^ (arcTextInfo.direct == TEXT_DIRECT_LTR);
bool xorFlag = (orientation == TextOrientation::INSIDE) ^ (arcTextInfo.direct == TEXT_DIRECT_LTR);
float posX = 0;
float posY = 0;
uint32_t i = arcTextInfo.lineStart;
......@@ -133,7 +133,7 @@ Rect TypedText::GetArcTextRect(const char* text,
float incrementAngle = GetAngleForArcLen(static_cast<float>(arcLen), letterHeight, arcTextInfo.radius,
arcTextInfo.direct, orientation);
float rotateAngle =
(orientation == UIArcLabel::TextOrientation::INSIDE) ? angle : (angle - SEMICIRCLE_IN_DEGREE);
(orientation == TextOrientation::INSIDE) ? angle : (angle - SEMICIRCLE_IN_DEGREE);
// 2: letterWidth's half
float fineTuningAngle = incrementAngle * (static_cast<float>(letterWidth) / (2 * arcLen));
rotateAngle += (xorFlag ? -fineTuningAngle : fineTuningAngle);
......@@ -151,13 +151,13 @@ float TypedText::GetAngleForArcLen(float len,
uint16_t height,
uint16_t radius,
UITextLanguageDirect direct,
UIArcLabel::TextOrientation orientation)
TextOrientation orientation)
{
if (radius == 0) {
return 0;
}
float realRadius =
static_cast<float>((orientation == UIArcLabel::TextOrientation::OUTSIDE) ? (radius + height) : radius);
static_cast<float>((orientation == TextOrientation::OUTSIDE) ? (radius + height) : radius);
float angle = static_cast<float>(len * SEMICIRCLE_IN_DEGREE) / (UI_PI * realRadius);
return (direct == TEXT_DIRECT_LTR) ? angle : -angle;
}
......
......@@ -65,14 +65,14 @@ public:
uint8_t fontSize,
const Point& arcCenter,
int16_t letterSpace,
UIArcLabel::TextOrientation orientation,
const UIArcLabel::ArcTextInfo& arcTextInfo);
TextOrientation orientation,
const ArcTextInfo& arcTextInfo);
static float GetAngleForArcLen(float len,
uint16_t height,
uint16_t radius,
UITextLanguageDirect direct,
UIArcLabel::TextOrientation orientation);
TextOrientation orientation);
static void GetArcLetterPos(const Point& arcCenter, uint16_t radius, float angle, float& posX, float& posY);
......
......@@ -123,20 +123,28 @@ void UIArcLabel::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
if ((text == nullptr) || (radius_ == 0)) {
return;
}
Rect trunc = invalidatedArea;
OpacityType opa = GetMixOpaScale();
UIView::OnDraw(gfxDstBuffer, invalidatedArea);
DrawArcText(gfxDstBuffer, trunc, opa);
DrawArcText(gfxDstBuffer, invalidatedArea, opa, arcTextInfo_, orientation_);
}
void UIArcLabel::DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, OpacityType opaScale)
void UIArcLabel::DrawArcText(BufferInfo& gfxDstBuffer,
const Rect& mask,
OpacityType opaScale,
const ArcTextInfo arcTextInfo,
TextOrientation orientation)
{
Point center;
center.x = arcTextInfo_.arcCenter.x + GetRect().GetX();
center.y = arcTextInfo_.arcCenter.y + GetRect().GetY();
InitArcLabelText();
DrawLabel::DrawArcText(gfxDstBuffer, mask, arcLabelText_->GetText(), center, arcLabelText_->GetFontId(),
arcLabelText_->GetFontSize(), arcTextInfo_, orientation_, *style_, opaScale);
arcLabelText_->GetFontSize(), arcTextInfo, orientation, *style_, opaScale);
}
Rect UIArcLabel::GetArcTextRect(const char* text, uint8_t fontId, uint8_t fontSize, const Point& arcCenter,
int16_t letterSpace, TextOrientation orientation, const ArcTextInfo& arcTextInfo)
{
return TypedText::GetArcTextRect(text, fontId, fontSize, arcCenter, letterSpace, orientation, arcTextInfo);
}
void UIArcLabel::RefreshArcLabel()
......@@ -156,9 +164,12 @@ void UIArcLabel::ReMeasure()
InitArcLabelText();
MeasureArcTextInfo();
arcTextInfo_.shapingFontId = arcLabelText_->GetShapingFontId();
arcTextInfo_.codePoints = arcLabelText_->GetCodePoints();
arcTextInfo_.codePointsNum = arcLabelText_->GetCodePointNum();
Rect textRect =
TypedText::GetArcTextRect(arcLabelText_->GetText(), arcLabelText_->GetFontId(), arcLabelText_->GetFontSize(),
arcCenter_, style_->letterSpace_, orientation_, arcTextInfo_);
GetArcTextRect(arcLabelText_->GetText(), arcLabelText_->GetFontId(), arcLabelText_->GetFontSize(),
arcCenter_, style_->letterSpace_, orientation_, arcTextInfo_);
int16_t arcTextWidth = textRect.GetWidth();
int16_t arcTextHeight = textRect.GetHeight();
......@@ -196,6 +207,11 @@ void UIArcLabel::MeasureArcTextInfo()
// calculate max arc length
float maxLength = static_cast<float>((UI_PI * radius_ * arcAngle) / SEMICIRCLE_IN_DEGREE);
arcTextInfo_.lineStart = 0;
Rect rect;
rect.SetWidth(static_cast<int16_t>(maxLength));
arcLabelText_->ReMeasureTextSize(rect, *style_);
arcTextInfo_.lineEnd = TypedText::GetNextLine(&text[arcTextInfo_.lineStart], arcLabelText_->GetFontId(),
arcLabelText_->GetFontSize(), style_->letterSpace_,
static_cast<int16_t>(maxLength));
......
......@@ -148,8 +148,8 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer,
const Point& arcCenter,
uint8_t fontId,
uint8_t fontSize,
const UIArcLabel::ArcTextInfo arcTextInfo,
UIArcLabel::TextOrientation orientation,
const ArcTextInfo arcTextInfo,
TextOrientation orientation,
const Style& style,
OpacityType opaScale)
{
......@@ -169,7 +169,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer,
float posY;
float rotateAngle;
bool orientationFlag = (orientation == UIArcLabel::TextOrientation::INSIDE);
bool orientationFlag = (orientation == TextOrientation::INSIDE);
bool directFlag = (arcTextInfo.direct == TEXT_DIRECT_LTR);
bool xorFlag = !((orientationFlag && directFlag) || (!orientationFlag && !directFlag));
......@@ -194,7 +194,7 @@ void DrawLabel::DrawArcText(BufferInfo& gfxDstBuffer,
float incrementAngle = TypedText::GetAngleForArcLen(static_cast<float>(arcLen), letterHeight,
arcTextInfo.radius, arcTextInfo.direct, orientation);
rotateAngle = (orientation == UIArcLabel::TextOrientation::INSIDE) ? angle : (angle - SEMICIRCLE_IN_DEGREE);
rotateAngle = (orientation == TextOrientation::INSIDE) ? angle : (angle - SEMICIRCLE_IN_DEGREE);
// 2: half
float fineTuningAngle = incrementAngle * (static_cast<float>(letterWidth) / (2 * arcLen));
......
......@@ -29,8 +29,8 @@ public:
uint16_t& letterIndex);
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);
uint8_t fontId, uint8_t fontSize, const ArcTextInfo arcTextInfo,
TextOrientation orientation, const Style& style, uint8_t opaScale);
static void DrawLetterWithRotate(BufferInfo& gfxDstBuffer,
const Rect& mask,
......
......@@ -75,6 +75,31 @@ enum UITextLanguageDirect : uint8_t {
TEXT_DIRECT_MIXED,
};
/**
* @brief Stores the attribute information about this arc text to draw.
*/
struct ArcTextInfo {
uint16_t radius;
float startAngle;
Point arcCenter;
uint32_t lineStart;
uint32_t lineEnd;
UITextLanguageDirect direct;
uint32_t* codePoints;
uint16_t codePointsNum;
uint8_t shapingFontId;
};
/**
* @brief Enumerates text orientations.
*/
enum class TextOrientation : uint8_t {
/** Inside */
INSIDE,
/** Outside */
OUTSIDE,
};
struct BackgroundColor : public HeapBase {
int16_t start;
int16_t end;
......@@ -366,6 +391,36 @@ public:
*/
uint16_t GetEllipsisIndex(const Rect& textRect, const Style& style);
/**
* @brief Get the GetShapingFontId of text
*
* @return Return ShapingFontId
*/
virtual uint8_t GetShapingFontId() const
{
return 0;
}
/**
* @brief Get the GetCodePointNum of text
*
* @return Return num of CodePoints
*/
virtual uint16_t GetCodePointNum() const
{
return 0;
}
/**
* @brief Get the GetCodePoints of text
*
* @return Return CodePoints of text
*/
virtual uint32_t* GetCodePoints() const
{
return nullptr;
}
void SetSupportBaseLine(bool baseLine)
{
baseLine_ = baseLine;
......
......@@ -49,16 +49,6 @@ namespace OHOS {
*/
class UIArcLabel : public UIView {
public:
/**
* @brief Enumerates text orientations.
*/
enum class TextOrientation : uint8_t {
/** Inside */
INSIDE,
/** Outside */
OUTSIDE,
};
/**
* @brief A default constructor used to create a <b>UIArcLabel</b> instance.
*
......@@ -346,18 +336,6 @@ public:
*/
void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
/**
* @brief Stores the attribute information about this arc text to draw.
*/
struct ArcTextInfo {
uint16_t radius;
float startAngle;
Point arcCenter;
uint32_t lineStart;
uint32_t lineEnd;
UITextLanguageDirect direct;
};
protected:
Text* arcLabelText_;
......@@ -373,10 +351,23 @@ protected:
}
void RefreshArcLabel();
virtual void DrawArcText(BufferInfo& gfxDstBuffer,
const Rect& mask,
OpacityType opaScale,
const ArcTextInfo arcTextInfo,
TextOrientation orientation);
virtual Rect GetArcTextRect(const char* text,
uint8_t fontId,
uint8_t fontSize,
const Point& arcCenter,
int16_t letterSpace,
TextOrientation orientation,
const ArcTextInfo& arcTextInfo);
private:
void ReMeasure() override;
void MeasureArcTextInfo();
void DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, OpacityType opaScale);
bool needRefresh_;
Point textSize_;
......
......@@ -70,7 +70,7 @@ void UITestArcLabel::UIKit_UIArcLabel_Test_Display_001()
{
const char* title = "显示内部角度从0到270的弧形文本 ";
// 0: start angle 270: end angle
TestArcLabelDisplay(title, 0, 270, UIArcLabel::TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE,
TestArcLabelDisplay(title, 0, 270, TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE,
VIEW_DISTANCE_TO_TOP_SIDE);
}
......@@ -78,27 +78,27 @@ void UITestArcLabel::UIKit_UIArcLabel_Test_Display_002()
{
const char* title = "显示内部角度从0到-270的弧形文本 ";
// 0: start angle -270: end angle 100: y-coordinate
TestArcLabelDisplay(title, 0, -270, UIArcLabel::TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 100);
TestArcLabelDisplay(title, 0, -270, TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 100);
}
void UITestArcLabel::UIKit_UIArcLabel_Test_Display_003()
{
const char* title = "显示外部角度从0到270的弧形文本 ";
// 0: start angle 270: end angle 200: y-coordinate
TestArcLabelDisplay(title, 0, 270, UIArcLabel::TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 200);
TestArcLabelDisplay(title, 0, 270, TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 200);
}
void UITestArcLabel::UIKit_UIArcLabel_Test_Display_004()
{
const char* title = "显示外部角度从0到-270的弧形文本 ";
// 0: start angle -270: end angle 300: y-coordinate
TestArcLabelDisplay(title, 0, -270, UIArcLabel::TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 300);
TestArcLabelDisplay(title, 0, -270, TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 300);
}
void UITestArcLabel::TestArcLabelDisplay(const char* title,
const int16_t startAngle,
const int16_t endAngle,
const UIArcLabel::TextOrientation orientation,
const TextOrientation orientation,
int16_t x,
int16_t y)
{
......
......@@ -72,7 +72,7 @@ private:
// for direction and orientation
void TestArcLabelDisplay(const char* title, const int16_t startAngle, const int16_t endAngle,
const UIArcLabel::TextOrientation orientation, int16_t x, int16_t y);
const TextOrientation orientation, int16_t x, int16_t y);
};
} // namespace OHOS
#endif // UI_TEST_ARC_LABEL_H
......@@ -320,4 +320,49 @@ HWTEST_F(TextTest, TextSetText_006, TestSize.Level1)
EXPECT_EQ(strcmp(text_->GetText(), text), 0);
}
#endif
/**
* @tc.name: TextGetShapingFontId_001
* @tc.desc: Verify GetShapingFontId function, equal.
* @tc.type: FUNC
* @tc.require: AR000H8BB3
*/
HWTEST_F(TextTest, TextGetShapingFontId_001, TestSize.Level1)
{
if (text_ == nullptr) {
EXPECT_NE(0, 0);
return;
}
EXPECT_EQ(text_->GetShapingFontId(), 0);
}
/**
* @tc.name: TextGetCodePointNum_001
* @tc.desc: Verify GetCodePointNum function, equal.
* @tc.type: FUNC
* @tc.require: AR000H8BB3
*/
HWTEST_F(TextTest, TextGetCodePointNum_001, TestSize.Level1)
{
if (text_ == nullptr) {
EXPECT_NE(0, 0);
return;
}
EXPECT_EQ(text_->GetCodePointNum(), 0);
}
/**
* @tc.name: TextGetCodePoints_001
* @tc.desc: Verify GetCodePoints function, equal.
* @tc.type: FUNC
* @tc.require: AR000H8BB3
*/
HWTEST_F(TextTest, TextGetCodePoints_001, TestSize.Level1)
{
if (text_ == nullptr) {
EXPECT_NE(0, 0);
return;
}
EXPECT_EQ(text_->GetCodePoints(), nullptr);
}
} // namespace OHOS
......@@ -192,12 +192,12 @@ HWTEST_F(UIArcLabelTest, UIArcLabelSetArcTextOrientation_001, TestSize.Level1)
EXPECT_EQ(1, 0);
return;
}
arcLabel_->SetArcTextOrientation(UIArcLabel::TextOrientation::INSIDE);
arcLabel_->SetArcTextOrientation(TextOrientation::INSIDE);
EXPECT_EQ(arcLabel_->GetArcTextOrientation(),
UIArcLabel::TextOrientation::INSIDE);
arcLabel_->SetArcTextOrientation(UIArcLabel::TextOrientation::OUTSIDE);
TextOrientation::INSIDE);
arcLabel_->SetArcTextOrientation(TextOrientation::OUTSIDE);
EXPECT_EQ(arcLabel_->GetArcTextOrientation(),
UIArcLabel::TextOrientation::OUTSIDE);
TextOrientation::OUTSIDE);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册