Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
889e6803
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,发现更多精彩内容 >>
提交
889e6803
编写于
6月 24, 2021
作者:
O
openharmony_ci
提交者:
Gitee
6月 24, 2021
浏览文件
操作
浏览文件
下载
差异文件
!205 支持多语言字体对齐
Merge pull request !205 from wangtiantian/lineHeight
上级
2073c6a0
e9a3076c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
192 addition
and
20 deletion
+192
-20
frameworks/common/text.cpp
frameworks/common/text.cpp
+16
-9
frameworks/common/typed_text.cpp
frameworks/common/typed_text.cpp
+10
-6
frameworks/common/typed_text.h
frameworks/common/typed_text.h
+1
-1
frameworks/components/ui_dialog.cpp
frameworks/components/ui_dialog.cpp
+3
-3
test/uitest/test_font/ui_test_font.cpp
test/uitest/test_font/ui_test_font.cpp
+141
-1
test/uitest/test_font/ui_test_font.h
test/uitest/test_font/ui_test_font.h
+21
-0
未找到文件。
frameworks/common/text.cpp
浏览文件 @
889e6803
...
...
@@ -160,7 +160,7 @@ void Text::ReMeasureTextSize(const Rect& textRect, const Style& style)
UIFont
::
GetInstance
()
->
SetCurrentFontId
(
fontId_
,
fontSize_
);
int16_t
maxWidth
=
(
expandWidth_
?
COORD_MAX
:
textRect
.
GetWidth
());
if
(
maxWidth
>
0
)
{
textSize_
=
TypedText
::
GetTextSize
(
text_
,
style
.
letterSpace_
,
style
.
line
Space
_
,
maxWidth
);
textSize_
=
TypedText
::
GetTextSize
(
text_
,
style
.
letterSpace_
,
style
.
line
Height
_
,
maxWidth
);
FontHeader
head
;
if
(
UIFont
::
GetInstance
()
->
GetCurrentFontHeader
(
head
)
!=
0
)
{
return
;
...
...
@@ -210,12 +210,15 @@ void Text::Draw(BufferInfo& gfxDstBuffer,
{
Point
offset
=
{
offsetX
,
0
};
int16_t
lineMaxWidth
=
expandWidth_
?
textSize_
.
x
:
coords
.
GetWidth
();
int16_t
lineHeight
=
UIFont
::
GetInstance
()
->
GetHeight
()
+
style
.
lineSpace_
;
int16_t
lineHeight
=
style
.
lineHeight_
;
if
(
lineHeight
==
0
)
{
lineHeight
=
UIFont
::
GetInstance
()
->
GetHeight
();
}
uint16_t
lineBegin
=
0
;
uint32_t
maxLineBytes
=
0
;
uint16_t
lineCount
=
GetLine
(
lineMaxWidth
,
style
.
letterSpace_
,
ellipsisIndex
,
maxLineBytes
);
Point
pos
;
pos
.
y
=
TextPositionY
(
coords
,
(
lineCount
*
lineHeight
-
style
.
lineSpace_
));
pos
.
y
=
TextPositionY
(
coords
,
(
lineCount
*
lineHeight
));
OpacityType
opa
=
DrawUtils
::
GetMixOpacity
(
opaScale
,
style
.
textOpa_
);
for
(
int
i
=
0
;
i
<
lineCount
;
i
++
)
{
if
(
pos
.
y
>
mask
.
GetBottom
())
{
...
...
@@ -335,12 +338,13 @@ uint16_t Text::GetEllipsisIndex(const Rect& textRect, const Style& style)
Point
p
;
p
.
x
=
textRect
.
GetWidth
()
-
letterWidth
*
TEXT_ELLIPSIS_DOT_NUM
;
p
.
y
=
textRect
.
GetHeight
();
int16_t
height
=
fontEngine
->
GetHeight
()
+
style
.
lineSpace_
;
int16_t
height
=
style
.
lineHeight_
;
if
(
height
==
0
)
{
height
=
fontEngine
->
GetHeight
();
}
if
(
height
)
{
p
.
y
-=
p
.
y
%
height
;
}
p
.
y
-=
style
.
lineSpace_
;
return
GetLetterIndexByPosition
(
textRect
,
style
,
p
);
}
...
...
@@ -351,7 +355,10 @@ uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style
}
uint32_t
lineStart
=
0
;
uint32_t
nextLineStart
=
0
;
uint16_t
letterHeight
=
UIFont
::
GetInstance
()
->
GetHeight
();
uint16_t
lineHeight
=
style
.
lineHeight_
;
if
(
lineHeight
==
0
)
{
lineHeight
=
UIFont
::
GetInstance
()
->
GetHeight
();
}
int16_t
y
=
0
;
uint32_t
textLen
=
static_cast
<
uint32_t
>
(
strlen
(
text_
));
int16_t
width
=
0
;
...
...
@@ -361,10 +368,10 @@ uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style
if
(
nextLineStart
==
0
)
{
break
;
}
if
(
pos
.
y
<=
y
+
l
etter
Height
)
{
if
(
pos
.
y
<=
y
+
l
ine
Height
)
{
break
;
}
y
+=
l
etterHeight
+
style
.
lineSpace_
;
y
+=
l
ineHeight
;
lineStart
=
nextLineStart
;
}
/* Calculate the x coordinate */
...
...
frameworks/common/typed_text.cpp
浏览文件 @
889e6803
...
...
@@ -22,7 +22,7 @@
namespace
OHOS
{
#ifndef _FONT_TOOL
Point
TypedText
::
GetTextSize
(
const
char
*
text
,
int16_t
letterSpace
,
int16_t
line
Space
,
int16_t
maxWidth
)
Point
TypedText
::
GetTextSize
(
const
char
*
text
,
int16_t
letterSpace
,
int16_t
line
Height
,
int16_t
maxWidth
)
{
Point
size
{
0
,
0
};
...
...
@@ -34,6 +34,9 @@ Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t line
uint32_t
lineBegin
=
0
;
uint32_t
newLineBegin
=
0
;
uint16_t
letterHeight
=
UIFont
::
GetInstance
()
->
GetHeight
();
if
(
lineHeight
==
0
)
{
lineHeight
=
letterHeight
;
}
while
(
text
[
lineBegin
]
!=
'\0'
)
{
int16_t
lineWidth
=
maxWidth
;
...
...
@@ -41,19 +44,20 @@ Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t line
if
(
newLineBegin
==
lineBegin
)
{
break
;
}
size
.
y
+=
l
etterHeight
+
lineSpace
;
size
.
y
+=
l
ineHeight
;
size
.
x
=
MATH_MAX
(
lineWidth
,
size
.
x
);
lineBegin
=
newLineBegin
;
}
if
((
lineBegin
!=
0
)
&&
((
text
[
lineBegin
-
1
]
==
'\n'
)
||
(
text
[
lineBegin
-
1
]
==
'\r'
)))
{
size
.
y
+=
l
etterHeight
+
lineSpace
;
size
.
y
+=
l
ineHeight
;
}
if
(
size
.
y
==
0
)
{
size
.
y
=
letterHeight
;
}
else
{
size
.
y
-=
lineSpace
;
size
.
y
=
lineHeight
;
}
if
(
lineHeight
<
letterHeight
)
{
size
.
y
+=
letterHeight
-
lineHeight
;
}
return
size
;
}
...
...
frameworks/common/typed_text.h
浏览文件 @
889e6803
...
...
@@ -40,7 +40,7 @@ public:
static
Point
GetTextSize
(
const
char
*
text
,
int16_t
letterSpace
,
int16_t
line
Space
,
int16_t
line
Height
,
int16_t
maxWidth
);
static
uint32_t
GetNextLine
(
const
char
*
text
,
...
...
frameworks/components/ui_dialog.cpp
浏览文件 @
889e6803
...
...
@@ -478,17 +478,17 @@ uint16_t UIDialog::MeasureButtonWidth()
if
(
button1_
!=
nullptr
)
{
const
char
*
text1
=
button1_
->
GetText
();
buttonTextWidth
=
MATH_MAX
(
buttonTextWidth
,
TypedText
::
GetTextSize
(
text1
,
button1_
->
GetStyleConst
().
letterSpace_
,
button1_
->
GetStyleConst
().
line
Space
_
,
widthMax_
).
x
);
button1_
->
GetStyleConst
().
letterSpace_
,
button1_
->
GetStyleConst
().
line
Height
_
,
widthMax_
).
x
);
}
if
(
button2_
!=
nullptr
)
{
const
char
*
text2
=
button2_
->
GetText
();
buttonTextWidth
=
MATH_MAX
(
buttonTextWidth
,
TypedText
::
GetTextSize
(
text2
,
button2_
->
GetStyleConst
().
letterSpace_
,
button2_
->
GetStyleConst
().
line
Space
_
,
widthMax_
).
x
);
button2_
->
GetStyleConst
().
letterSpace_
,
button2_
->
GetStyleConst
().
line
Height
_
,
widthMax_
).
x
);
}
if
(
button3_
!=
nullptr
)
{
const
char
*
text3
=
button3_
->
GetText
();
buttonTextWidth
=
MATH_MAX
(
buttonTextWidth
,
TypedText
::
GetTextSize
(
text3
,
button3_
->
GetStyleConst
().
letterSpace_
,
button3_
->
GetStyleConst
().
line
Space
_
,
widthMax_
).
x
);
button3_
->
GetStyleConst
().
letterSpace_
,
button3_
->
GetStyleConst
().
line
Height
_
,
widthMax_
).
x
);
}
return
(
buttonTextWidth
+
BUTTON_HEIGHT
)
>
buttonMaxWidth
?
buttonMaxWidth
:
(
buttonTextWidth
+
BUTTON_HEIGHT
);
}
...
...
test/uitest/test_font/ui_test_font.cpp
浏览文件 @
889e6803
...
...
@@ -33,7 +33,7 @@ const uint16_t LABEL_WIDTH = 400;
const
uint16_t
LABEL_HEIGHT
=
50
;
const
uint16_t
FONT_SIZE
=
30
;
const
char
*
SOURCE_HAN_SANS_SC_REGULAR
=
"SourceHanSansSC-Regular.otf"
;
const
char
*
ROBOTO_CONDENSED_REGULAR
=
"RobotoCondensed-Regula
t
.ttf"
;
const
char
*
ROBOTO_CONDENSED_REGULAR
=
"RobotoCondensed-Regula
r
.ttf"
;
}
// namespace
void
UITestFont
::
SetUp
()
...
...
@@ -79,6 +79,10 @@ const UIView* UITestFont::GetTestView()
UIKitFontTestDispaly006
();
UIKitFontTestDispaly007
();
UIKitFontTestDispaly008
();
UIKitFontTestBaseline001
();
UIKitFontTestBaseline002
();
UIKitFontTestLineHeight001
();
UIKitFontTestLineHeight002
();
#if ENABLE_MULTI_FONT
UIKitFontMultiLanguage001
();
UIKitFontMultiLanguage002
();
...
...
@@ -251,6 +255,142 @@ void UITestFont::UIKitFontTestDispaly008()
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
UIKitFontTestBaseline001
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
"Font baseline alignment"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
label
->
SetFont
(
SOURCE_HAN_SANS_SC_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_SOURCEHANSANSSC_REGULAR_30_4
);
#endif
label
->
SetText
(
"hello, uikit"
);
UILabel
*
label2
=
new
UILabel
();
label2
->
SetPosition
(
positionX_
+
(
LABEL_WIDTH
/
2
),
positionY_
);
// 2 : half
label2
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
label2
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label2
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label2
->
SetText
(
"hello, uikit"
);
container_
->
Add
(
label
);
container_
->
Add
(
label2
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
UIKitFontTestBaseline002
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Font baseline alignment"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
label
->
SetFont
(
SOURCE_HAN_SANS_SC_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_SOURCEHANSANSSC_REGULAR_30_4
);
#endif
label
->
SetText
(
"hello, uikit"
);
label
->
SetStyle
(
STYLE_LINE_HEIGHT
,
30
);
// 30 : line height
UILabel
*
label2
=
new
UILabel
();
label2
->
SetPosition
(
positionX_
+
(
LABEL_WIDTH
/
2
),
positionY_
);
// 2 : half
label2
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
label2
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label2
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label2
->
SetText
(
"hello, uikit"
);
label2
->
SetStyle
(
STYLE_LINE_HEIGHT
,
30
);
// 30 : line height
container_
->
Add
(
label
);
container_
->
Add
(
label2
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
UIKitFontTestLineHeight001
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Font lineheight alignment"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
*
2
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
label
->
SetFont
(
SOURCE_HAN_SANS_SC_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_SOURCEHANSANSSC_REGULAR_30_4
);
#endif
label
->
SetText
(
"hello,
\n
uikit"
);
UILabel
*
label2
=
new
UILabel
();
label2
->
SetPosition
(
positionX_
+
(
LABEL_WIDTH
/
2
),
positionY_
);
// 2 : half
label2
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
*
2
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
label2
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label2
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label2
->
SetText
(
"hello,
\n
uikit"
);
container_
->
Add
(
label
);
container_
->
Add
(
label2
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
UIKitFontTestLineHeight002
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Font lineheight alignment"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
*
2
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
label
->
SetFont
(
SOURCE_HAN_SANS_SC_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_SOURCEHANSANSSC_REGULAR_30_4
);
#endif
label
->
SetText
(
"hello,
\n
uikit"
);
label
->
SetStyle
(
STYLE_LINE_HEIGHT
,
40
);
// 40 : line height
UILabel
*
label2
=
new
UILabel
();
label2
->
SetPosition
(
positionX_
+
(
LABEL_WIDTH
/
2
),
positionY_
);
// 2 : half
label2
->
Resize
(
LABEL_WIDTH
/
2
,
LABEL_HEIGHT
*
2
);
// 2 : half
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
label2
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label2
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label2
->
SetText
(
"hello,
\n
uikit"
);
label2
->
SetStyle
(
STYLE_LINE_HEIGHT
,
40
);
// 40 : line height
container_
->
Add
(
label
);
container_
->
Add
(
label2
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
#if ENABLE_MULTI_FONT
void
UITestFont
::
UIKitFontMultiLanguage001
()
{
...
...
test/uitest/test_font/ui_test_font.h
浏览文件 @
889e6803
...
...
@@ -68,6 +68,27 @@ public:
* @brief Test multiline line text color display
*/
void
UIKitFontTestDispaly008
();
/**
* @brief Test font baseline alignment
*/
void
UIKitFontTestBaseline001
();
/**
* @brief Test font baseline alignment
*/
void
UIKitFontTestBaseline002
();
/**
* @brief Test font lineheight alignment
*/
void
UIKitFontTestLineHeight001
();
/**
* @brief Test font lineheight alignment
*/
void
UIKitFontTestLineHeight002
();
#if ENABLE_MULTI_FONT
/**
* @brief Test multilingual display
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录