Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
39f36488
G
Graphic Ui
项目概览
OpenHarmony
/
Graphic Ui
大约 1 年 前同步成功
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Graphic Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
39f36488
编写于
8月 26, 2022
作者:
O
openharmony_ci
提交者:
Gitee
8月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
!729 弧形文本优化
Merge pull request !729 from 郝烁/master
上级
0950e1d8
5e144982
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
162 addition
and
55 deletion
+162
-55
frameworks/common/typed_text.cpp
frameworks/common/typed_text.cpp
+6
-6
frameworks/common/typed_text.h
frameworks/common/typed_text.h
+3
-3
frameworks/components/ui_arc_label.cpp
frameworks/components/ui_arc_label.cpp
+23
-7
frameworks/draw/draw_label.cpp
frameworks/draw/draw_label.cpp
+4
-4
frameworks/draw/draw_label.h
frameworks/draw/draw_label.h
+2
-2
interfaces/kits/common/text.h
interfaces/kits/common/text.h
+55
-0
interfaces/kits/components/ui_arc_label.h
interfaces/kits/components/ui_arc_label.h
+14
-23
test/uitest/test_arc_label/ui_test_arc_label.cpp
test/uitest/test_arc_label/ui_test_arc_label.cpp
+5
-5
test/uitest/test_arc_label/ui_test_arc_label.h
test/uitest/test_arc_label/ui_test_arc_label.h
+1
-1
test/unittest/common/text_unit_test.cpp
test/unittest/common/text_unit_test.cpp
+45
-0
test/unittest/components/ui_arc_label_unit_test.cpp
test/unittest/components/ui_arc_label_unit_test.cpp
+4
-4
未找到文件。
frameworks/common/typed_text.cpp
浏览文件 @
39f36488
...
...
@@ -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
;
}
...
...
frameworks/common/typed_text.h
浏览文件 @
39f36488
...
...
@@ -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
);
...
...
frameworks/components/ui_arc_label.cpp
浏览文件 @
39f36488
...
...
@@ -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
));
...
...
frameworks/draw/draw_label.cpp
浏览文件 @
39f36488
...
...
@@ -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
));
...
...
frameworks/draw/draw_label.h
浏览文件 @
39f36488
...
...
@@ -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
,
...
...
interfaces/kits/common/text.h
浏览文件 @
39f36488
...
...
@@ -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
;
...
...
interfaces/kits/components/ui_arc_label.h
浏览文件 @
39f36488
...
...
@@ -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_
;
...
...
test/uitest/test_arc_label/ui_test_arc_label.cpp
浏览文件 @
39f36488
...
...
@@ -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
)
{
...
...
test/uitest/test_arc_label/ui_test_arc_label.h
浏览文件 @
39f36488
...
...
@@ -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
test/unittest/common/text_unit_test.cpp
浏览文件 @
39f36488
...
...
@@ -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
test/unittest/components/ui_arc_label_unit_test.cpp
浏览文件 @
39f36488
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录