Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
9e45d1be
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,发现更多精彩内容 >>
未验证
提交
9e45d1be
编写于
1月 06, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
!857 矢量字体性能优化
Merge pull request !857 from Lizhiqi/font_opt
上级
2d2bf1bb
8723e111
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
170 addition
and
101 deletion
+170
-101
frameworks/common/spannable_string.cpp
frameworks/common/spannable_string.cpp
+1
-1
frameworks/common/text.cpp
frameworks/common/text.cpp
+5
-5
frameworks/components/ui_label.cpp
frameworks/components/ui_label.cpp
+1
-1
frameworks/draw/draw_label.cpp
frameworks/draw/draw_label.cpp
+4
-4
frameworks/draw/draw_utils.h
frameworks/draw/draw_utils.h
+2
-2
frameworks/font/glyphs_cache.cpp
frameworks/font/glyphs_cache.cpp
+2
-2
frameworks/font/glyphs_cache.h
frameworks/font/glyphs_cache.h
+4
-0
frameworks/font/ui_font_cache.cpp
frameworks/font/ui_font_cache.cpp
+2
-2
frameworks/font/ui_font_cache.h
frameworks/font/ui_font_cache.h
+1
-1
frameworks/font/ui_font_vector.cpp
frameworks/font/ui_font_vector.cpp
+126
-65
interfaces/innerkits/font/ui_font_vector.h
interfaces/innerkits/font/ui_font_vector.h
+8
-5
interfaces/kits/common/spannable_string.h
interfaces/kits/common/spannable_string.h
+1
-1
interfaces/kits/common/text.h
interfaces/kits/common/text.h
+4
-3
interfaces/kits/components/ui_label.h
interfaces/kits/components/ui_label.h
+3
-3
interfaces/kits/font/ui_font_header.h
interfaces/kits/font/ui_font_header.h
+1
-1
test/uitest/test_vector_font/ui_test_vector_font.cpp
test/uitest/test_vector_font/ui_test_vector_font.cpp
+2
-2
test/uitest/test_vector_font/ui_test_vector_font.h
test/uitest/test_vector_font/ui_test_vector_font.h
+1
-1
test/unittest/common/text_unit_test.cpp
test/unittest/common/text_unit_test.cpp
+1
-1
test/unittest/components/ui_label_unit_test.cpp
test/unittest/components/ui_label_unit_test.cpp
+1
-1
未找到文件。
frameworks/common/spannable_string.cpp
浏览文件 @
9e45d1be
...
...
@@ -17,7 +17,7 @@
#include "gfx_utils/graphic_log.h"
#include "securec.h"
namespace
OHOS
{
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
SpannableString
::~
SpannableString
()
{
if
(
text_
!=
nullptr
)
{
...
...
frameworks/common/text.cpp
浏览文件 @
9e45d1be
...
...
@@ -40,7 +40,7 @@ Text::Text()
horizontalAlign_
(
TEXT_ALIGNMENT_LEFT
),
verticalAlign_
(
TEXT_ALIGNMENT_TOP
)
{
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyles_
=
nullptr
;
#endif
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
DEFAULT_VECTOR_FONT_SIZE
);
...
...
@@ -52,7 +52,7 @@ Text::~Text()
UIFree
(
text_
);
text_
=
nullptr
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
if
(
textStyles_
!=
nullptr
)
{
UIFree
(
textStyles_
);
textStyles_
=
nullptr
;
...
...
@@ -73,7 +73,7 @@ Text::~Text()
}
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
Text
::
SetSpannableString
(
const
SpannableString
*
spannableString
)
{
SetText
(
spannableString
->
text_
);
...
...
@@ -130,7 +130,7 @@ void Text::SetText(const char* text)
text_
=
nullptr
;
return
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
if
(
textStyles_
!=
nullptr
)
{
UIFree
(
textStyles_
);
textStyles_
=
nullptr
;
...
...
@@ -334,7 +334,7 @@ void Text::Draw(BufferInfo& gfxDstBuffer,
0
,
opa
,
style
,
&
text_
[
lineBegin
],
textLine_
[
i
].
lineBytes
,
lineBegin
,
fontId_
,
fontSize_
,
0
,
static_cast
<
UITextLanguageDirect
>
(
direct_
),
nullptr
,
baseLine_
,
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyles_
,
#endif
&
backgroundColor_
,
&
foregroundColor_
,
&
linebackgroundColor_
,
sizeSpans_
,
0
};
...
...
frameworks/components/ui_label.cpp
浏览文件 @
9e45d1be
...
...
@@ -183,7 +183,7 @@ void UILabel::SetText(const char* text)
}
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
UILabel
::
SetText
(
const
SpannableString
*
text
)
{
InitLabelText
();
...
...
frameworks/draw/draw_label.cpp
浏览文件 @
9e45d1be
...
...
@@ -57,7 +57,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
ColorType
foregroundColor
=
labelLine
.
style
.
textColor_
;
GetForegroundColor
(
letterIndex
,
labelLine
.
foregroundColor
,
foregroundColor
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
textStyle
=
TEXT_STYLE_NORMAL
;
if
(
labelLine
.
textStyles
)
{
textStyle
=
labelLine
.
textStyles
[
letterIndex
];
...
...
@@ -74,7 +74,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
fontId
,
0
,
fontSize
,
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyle
,
#endif
labelLine
.
baseLine
,
...
...
@@ -82,7 +82,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
labelLine
.
style
.
lineSpace_
,
havebackgroundColor
,
backgroundColor
};
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
glyphNode
.
textStyle
=
letterInfo
.
textStyle
;
#endif
glyphNode
.
advance
=
0
;
...
...
@@ -217,7 +217,7 @@ void DrawLabel::DrawLetterWithRotate(BufferInfo& gfxDstBuffer,
UIFont
*
fontEngine
=
UIFont
::
GetInstance
();
FontHeader
head
;
GlyphNode
node
;
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
node
.
textStyle
=
TEXT_STYLE_NORMAL
;
#endif
if
(
fontEngine
->
GetFontHeader
(
head
,
fontId
,
fontSize
)
!=
0
)
{
...
...
frameworks/draw/draw_utils.h
浏览文件 @
9e45d1be
...
...
@@ -74,7 +74,7 @@ struct LabelLineInfo {
UITextLanguageDirect
direct
;
uint32_t
*
codePoints
;
bool
baseLine
;
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
*
textStyles
;
#endif
List
<
BackgroundColor
>*
backgroundColor
;
...
...
@@ -97,7 +97,7 @@ struct LabelLetterInfo {
uint16_t
fontId
;
uint8_t
shapingId
;
uint8_t
fontSize
;
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
textStyle
;
#endif
bool
baseLine
;
...
...
frameworks/font/glyphs_cache.cpp
浏览文件 @
9e45d1be
...
...
@@ -67,7 +67,7 @@ GlyphNode* GlyphsCache::GetNodeFromCache(uint32_t unicode, uint16_t fontId)
{
GlyphNode
*
node
=
nullptr
;
uint8_t
font
=
fontId
&
FONT_HASH_MASK
;
uint8_t
font
=
(
fontId
|
unicode
)
&
FONT_HASH_MASK
;
uint8_t
uc
=
unicode
&
UNICODE_HASH_MASK
;
for
(
uint8_t
i
=
0
;
i
<
NODE_HASH_NR
;
i
++
)
{
GlyphNode
*
p
=
&
((
*
nodeCache_
)[
font
][
uc
][
i
]);
...
...
@@ -81,7 +81,7 @@ GlyphNode* GlyphsCache::GetNodeFromCache(uint32_t unicode, uint16_t fontId)
GlyphNode
*
GlyphsCache
::
GetNodeCacheSpace
(
uint32_t
unicode
,
uint16_t
fontId
)
{
uint8_t
font
=
fontId
&
FONT_HASH_MASK
;
uint8_t
font
=
(
fontId
|
unicode
)
&
FONT_HASH_MASK
;
uint8_t
uc
=
unicode
&
UNICODE_HASH_MASK
;
uint8_t
i
=
(
*
cacheStatus_
)[
font
][
uc
];
GlyphNode
*
node
=
&
((
*
nodeCache_
)[
font
][
uc
][
i
]);
...
...
frameworks/font/glyphs_cache.h
浏览文件 @
9e45d1be
...
...
@@ -39,7 +39,11 @@ public:
GlyphNode
*
GetNodeCacheSpace
(
uint32_t
unicode
,
uint16_t
fontId
);
private:
#if (defined(ENABLE_MIX_FONT) && (ENABLE_MIX_FONT ==1))
static
constexpr
uint8_t
FONT_HASH_SHIFT
=
1
;
#else
static
constexpr
uint8_t
FONT_HASH_SHIFT
=
3
;
#endif
static
constexpr
uint8_t
FONT_HASH_NR
=
1
<<
FONT_HASH_SHIFT
;
static
constexpr
uint32_t
FONT_HASH_MASK
=
FONT_HASH_NR
-
1
;
static
constexpr
uint8_t
UNICODE_HASH_SHIFT
=
6
;
...
...
frameworks/font/ui_font_cache.cpp
浏览文件 @
9e45d1be
...
...
@@ -73,7 +73,7 @@ uint8_t* UIFontCache::GetSpace(uint32_t fontId, uint32_t unicode, uint32_t size,
bitmap
->
fontId
=
fontId
;
bitmap
->
unicode
=
unicode
;
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
bitmap
->
textStyle
=
textStyle
;
#endif
...
...
@@ -101,7 +101,7 @@ uint8_t* UIFontCache::GetBitmap(uint32_t fontId, uint32_t unicode, TextStyle tex
bitmap
=
reinterpret_cast
<
struct
Bitmap
*>
(
reinterpret_cast
<
uint8_t
*>
(
node
)
-
offsetof
(
struct
Bitmap
,
hashHead
));
if
((
bitmap
->
fontId
==
fontId
)
&&
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
(
bitmap
->
textStyle
==
textStyle
)
&&
#endif
(
bitmap
->
unicode
==
unicode
))
{
...
...
frameworks/font/ui_font_cache.h
浏览文件 @
9e45d1be
...
...
@@ -54,7 +54,7 @@ public:
ListHead
lruHead
;
uint32_t
fontId
;
// bitmap font: fontId vector font: fontKey ttfId + fontsize
uint32_t
unicode
;
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
textStyle
;
#endif
uint8_t
data
[];
...
...
frameworks/font/ui_font_vector.cpp
浏览文件 @
9e45d1be
...
...
@@ -580,28 +580,12 @@ int16_t UIFontVector::GetWidth(uint32_t unicode, uint16_t fontId, uint8_t fontSi
return
INVALID_RET_VALUE
;
}
if
(
!
freeTypeInited_
||
(
bitmapCache_
==
nullptr
))
{
return
INVALID_RET_VALUE
;
}
FaceInfo
faceInfo
=
{};
faceInfo
.
key
=
GetKey
(
fontId
,
fontSize
);
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
faceInfo
.
key
,
unicode
);
if
(
bitmap
!=
nullptr
)
{
return
reinterpret_cast
<
Metric
*>
(
bitmap
)
->
advance
;
}
int8_t
ret
=
GetFaceInfo
(
fontId
,
fontSize
,
faceInfo
);
if
((
ret
!=
RET_VALUE_OK
)
||
(
faceInfo
.
face
==
nullptr
))
{
return
INVALID_RET_VALUE
;
}
int8_t
error
=
LoadGlyphIntoFace
(
fontId
,
unicode
);
if
(
error
!=
RET_VALUE_OK
)
{
GlyphNode
node
;
int8_t
ret
=
GetGlyphNode
(
unicode
,
node
,
fontId
,
fontSize
);
if
(
ret
!=
RET_VALUE_OK
)
{
return
INVALID_RET_VALUE
;
}
SetFace
(
faceInfo
,
unicode
);
return
static_cast
<
uint16_t
>
(
faceInfo
.
face
->
glyph
->
advance
.
x
/
FONT_PIXEL_IN_POINT
);
return
node
.
advance
;
}
int8_t
UIFontVector
::
GetFontHeader
(
FontHeader
&
fontHeader
,
uint16_t
fontId
,
uint8_t
fontSize
)
...
...
@@ -621,20 +605,39 @@ int8_t UIFontVector::GetFontHeader(FontHeader& fontHeader, uint16_t fontId, uint
return
RET_VALUE_OK
;
}
void
UIFontVector
::
SaveGlyphNode
(
uint32_t
unicode
,
uint32_t
fontKey
,
Metric
*
metric
)
{
GlyphNode
*
node
=
glyphsCache_
.
GetNodeCacheSpace
(
unicode
,
fontKey
);
if
(
node
==
nullptr
)
{
return
;
}
node
->
left
=
metric
->
left
;
node
->
top
=
metric
->
top
;
node
->
cols
=
metric
->
cols
;
node
->
rows
=
metric
->
rows
;
node
->
advance
=
metric
->
advance
;
node
->
unicode
=
unicode
;
node
->
fontId
=
fontKey
;
}
int8_t
UIFontVector
::
GetGlyphNode
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint16_t
fontId
,
uint8_t
fontSize
)
{
FaceInfo
faceInfo
;
int8_t
ret
=
GetFaceInfo
(
fontId
,
fontSize
,
faceInfo
);
if
(
ret
!=
RET_VALUE_OK
)
{
return
INVALID_RET_VALUE
;
// get glyph from glyph cache
uint32_t
fontKey
=
GetKey
(
fontId
,
fontSize
);
GlyphNode
*
node
=
glyphsCache_
.
GetNodeFromCache
(
unicode
,
fontKey
);
if
(
node
!=
nullptr
)
{
glyphNode
=
*
node
;
return
RET_VALUE_OK
;
}
if
(
!
freeTypeInited_
||
(
faceInfo
.
face
==
nullptr
)
||
(
bitmapCache_
==
nullptr
))
{
// get glyph from bitmap cache
if
(
bitmapCache_
==
nullptr
)
{
return
INVALID_RET_VALUE
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
f
aceInfo
.
k
ey
,
unicode
,
glyphNode
.
textStyle
);
#if defined(ENABLE_
SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
f
ontK
ey
,
unicode
,
glyphNode
.
textStyle
);
#else
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
f
aceInfo
.
k
ey
,
unicode
);
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
f
ontK
ey
,
unicode
);
#endif
if
(
bitmap
!=
nullptr
)
{
Metric
*
f
=
reinterpret_cast
<
Metric
*>
(
bitmap
);
...
...
@@ -644,45 +647,69 @@ int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16
glyphNode
.
rows
=
f
->
rows
;
glyphNode
.
advance
=
f
->
advance
;
glyphNode
.
fontId
=
fontId
;
SaveGlyphNode
(
unicode
,
fontKey
,
f
);
return
RET_VALUE_OK
;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
int8_t
error
=
LoadGlyphIntoFace
(
fontId
,
unicode
,
faceInfo
.
face
,
glyphNode
.
textStyle
);
#else
int8_t
error
=
LoadGlyphIntoFace
(
fontId
,
unicode
);
#endif
FaceInfo
faceInfo
;
int8_t
ret
=
GetFaceInfo
(
fontId
,
fontSize
,
faceInfo
);
if
(
ret
!=
RET_VALUE_OK
)
{
return
INVALID_RET_VALUE
;
}
if
(
faceInfo
.
face
==
nullptr
)
{
return
INVALID_RET_VALUE
;
}
int8_t
error
=
LoadGlyphIntoFace
(
fontId
,
fontSize
,
unicode
,
glyphNode
);
if
(
error
!=
RET_VALUE_OK
)
{
return
INVALID_RET_VALUE
;
}
glyphNode
.
left
=
faceInfo
.
face
->
glyph
->
bitmap_left
;
glyphNode
.
top
=
faceInfo
.
face
->
glyph
->
bitmap_top
;
glyphNode
.
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
glyphNode
.
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
glyphNode
.
advance
=
static_cast
<
uint16_t
>
(
faceInfo
.
face
->
glyph
->
advance
.
x
/
FONT_PIXEL_IN_POINT
);
glyphNode
.
fontId
=
fontId
;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
SetFace
(
faceInfo
,
unicode
,
glyphNode
.
textStyle
);
#else
SetFace
(
faceInfo
,
unicode
);
#endif
return
RET_VALUE_OK
;
}
uint8_t
*
UIFontVector
::
GetBitmap
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint16_t
fontId
,
uint8_t
fontSize
)
{
if
(
GetGlyphNode
(
unicode
,
glyphNode
,
fontId
,
fontSize
)
!=
RET_VALUE_OK
)
{
if
(
bitmapCache_
==
nullptr
)
{
return
nullptr
;
}
uint32_t
fontKey
=
GetKey
(
fontId
,
fontSize
);
#if ENABLE_SPANNALBE_STRING
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
fontKey
,
unicode
,
glyphNode
.
textStyle
);
#else
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
fontKey
,
unicode
);
#endif
if
(
bitmap
!=
nullptr
)
{
Metric
*
f
=
reinterpret_cast
<
Metric
*>
(
bitmap
);
glyphNode
.
left
=
f
->
left
;
glyphNode
.
top
=
f
->
top
;
glyphNode
.
cols
=
f
->
cols
;
glyphNode
.
rows
=
f
->
rows
;
glyphNode
.
advance
=
f
->
advance
;
glyphNode
.
fontId
=
fontId
;
SaveGlyphNode
(
unicode
,
fontKey
,
f
);
return
bitmap
+
sizeof
(
Metric
);
}
FaceInfo
faceInfo
;
int8_t
ret
=
GetFaceInfo
(
fontId
,
fontSize
,
faceInfo
);
if
(
ret
!=
RET_VALUE_OK
)
{
return
nullptr
;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
faceInfo
.
key
,
unicode
,
glyphNode
.
textStyle
);
if
(
faceInfo
.
face
==
nullptr
)
{
return
nullptr
;
}
int8_t
error
=
LoadGlyphIntoFace
(
fontId
,
fontSize
,
unicode
,
glyphNode
);
if
(
error
!=
RET_VALUE_OK
)
{
return
nullptr
;
}
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
bitmap
=
bitmapCache_
->
GetBitmap
(
fontKey
,
unicode
,
glyphNode
.
textStyle
);
#else
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
faceInfo
.
k
ey
,
unicode
);
bitmap
=
bitmapCache_
->
GetBitmap
(
fontK
ey
,
unicode
);
#endif
if
(
bitmap
!=
nullptr
)
{
return
bitmap
+
sizeof
(
Metric
);
...
...
@@ -699,7 +726,7 @@ bool UIFontVector::IsEmojiFont(uint16_t fontId)
return
(
fontInfo_
[
fontId
].
fontWeight
>=
16
);
// 16: rgb color font
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
void
UIFontVector
::
SetItaly
(
FT_GlyphSlot
slot
)
{
if
(
slot
->
format
!=
FT_GLYPH_FORMAT_OUTLINE
)
{
...
...
@@ -742,15 +769,14 @@ void UIFontVector::SetBold(uint16_t fontId)
}
#endif
int8_t
UIFontVector
::
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint
32_t
unic
ode
)
int8_t
UIFontVector
::
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint
8_t
fontSize
,
uint32_t
unicode
,
GlyphNode
&
glyphN
ode
)
{
int32_t
error
;
if
(
IsGlyphFont
(
unicode
)
!=
0
)
{
if
(
fontId
!=
GetFontId
(
unicode
))
{
return
INVALID_RET_VALUE
;
}
unicode
=
unicode
&
(
0xFFFFFF
);
// Whether 0 ~24 bit storage is unicode
error
=
FT_Load_Glyph
(
ftFaces_
[
fontId
],
unicode
,
FT_LOAD_RENDER
);
error
=
FT_Load_Glyph
(
ftFaces_
[
fontId
],
unicode
&
(
0xFFFFFF
),
FT_LOAD_RENDER
);
}
else
{
if
(
IsEmojiFont
(
fontId
))
{
error
=
FT_Load_Char
(
ftFaces_
[
fontId
],
unicode
,
FT_LOAD_COLOR
);
...
...
@@ -761,10 +787,27 @@ int8_t UIFontVector::LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode)
if
((
error
!=
0
)
||
(
ftFaces_
[
fontId
]
->
glyph
->
glyph_index
==
0
))
{
return
INVALID_RET_VALUE
;
}
FaceInfo
faceInfo
;
faceInfo
.
key
=
GetKey
(
fontId
,
fontSize
);
faceInfo
.
face
=
ftFaces_
[
fontId
];
glyphNode
.
left
=
faceInfo
.
face
->
glyph
->
bitmap_left
;
glyphNode
.
top
=
faceInfo
.
face
->
glyph
->
bitmap_top
;
glyphNode
.
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
glyphNode
.
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
glyphNode
.
advance
=
static_cast
<
uint16_t
>
(
faceInfo
.
face
->
glyph
->
advance
.
x
/
FONT_PIXEL_IN_POINT
);
glyphNode
.
fontId
=
fontId
;
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
SetFace
(
faceInfo
,
unicode
,
glyphNode
.
textStyle
);
#else
SetFace
(
faceInfo
,
unicode
);
#endif
return
RET_VALUE_OK
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
int8_t
UIFontVector
::
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint32_t
unicode
,
FT_Face
face
,
TextStyle
textStyle
)
{
int32_t
error
;
...
...
@@ -814,7 +857,7 @@ uint8_t UIFontVector::IsGlyphFont(uint32_t unicode)
void
UIFontVector
::
SetFace
(
FaceInfo
&
faceInfo
,
uint32_t
unicode
)
{
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
SetFace
(
faceInfo
,
unicode
,
TEXT_STYLE_NORMAL
);
#else
Metric
f
;
...
...
@@ -824,17 +867,24 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
f
.
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
f
.
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
// cache glyph
SaveGlyphNode
(
unicode
,
faceInfo
.
key
,
&
f
);
int16_t
pixSize
=
1
;
if
(
faceInfo
.
face
->
glyph
->
bitmap
.
pixel_mode
==
FT_PIXEL_MODE_BGRA
)
{
pixSize
=
0x04
;
// 4 Byte
}
uint32_t
bitmapSize
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
*
faceInfo
.
face
->
glyph
->
bitmap
.
rows
*
pixSize
;
// cache bitmap
uint8_t
*
bitmap
=
bitmapCache_
->
GetSpace
(
faceInfo
.
key
,
unicode
,
bitmapSize
+
sizeof
(
Metric
));
if
(
bitmap
!=
nullptr
)
{
if
(
memcpy_s
(
bitmap
,
sizeof
(
Metric
),
&
f
,
sizeof
(
Metric
))
!=
EOK
)
{
bitmapCache_
->
PutSpace
(
bitmap
);
return
;
}
if
(
memcpy_s
(
bitmap
+
sizeof
(
Metric
),
bitmapSize
,
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
,
bitmapSize
)
!=
EOK
)
{
if
((
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
!=
nullptr
)
&&
(
memcpy_s
(
bitmap
+
sizeof
(
Metric
),
bitmapSize
,
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
,
bitmapSize
)
!=
EOK
))
{
bitmapCache_
->
PutSpace
(
bitmap
);
return
;
}
ClearFontGlyph
(
faceInfo
.
face
);
...
...
@@ -842,7 +892,7 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
#endif
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
void
UIFontVector
::
SetFace
(
FaceInfo
&
faceInfo
,
uint32_t
unicode
,
TextStyle
textStyle
)
{
Metric
f
;
...
...
@@ -852,17 +902,23 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textS
f
.
cols
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
;
f
.
rows
=
faceInfo
.
face
->
glyph
->
bitmap
.
rows
;
// cache glyph
SaveGlyphNode
(
unicode
,
faceInfo
.
key
,
&
f
);
int16_t
pixSize
=
1
;
if
(
faceInfo
.
face
->
glyph
->
bitmap
.
pixel_mode
==
FT_PIXEL_MODE_BGRA
)
{
pixSize
=
0x04
;
// 4 Byte
}
uint32_t
bitmapSize
=
faceInfo
.
face
->
glyph
->
bitmap
.
width
*
faceInfo
.
face
->
glyph
->
bitmap
.
rows
*
pixSize
;
// cache bitmap
uint8_t
*
bitmap
=
bitmapCache_
->
GetSpace
(
faceInfo
.
key
,
unicode
,
bitmapSize
+
sizeof
(
Metric
),
textStyle
);
if
(
bitmap
!=
nullptr
)
{
if
(
memcpy_s
(
bitmap
,
sizeof
(
Metric
),
&
f
,
sizeof
(
Metric
))
!=
EOK
)
{
bitmapCache_
->
PutSpace
(
bitmap
);
return
;
}
if
(
memcpy_s
(
bitmap
+
sizeof
(
Metric
),
bitmapSize
,
faceInfo
.
face
->
glyph
->
bitmap
.
buffer
,
bitmapSize
)
!=
EOK
)
{
bitmapCache_
->
PutSpace
(
bitmap
);
return
;
}
ClearFontGlyph
(
faceInfo
.
face
);
...
...
@@ -1014,26 +1070,31 @@ void UIFontVector::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen)
{
BaseFont
::
SetPsramMemory
(
psramAddr
,
psramLen
);
FontRamAllocator
::
GetInstance
().
SetRamAddr
(
psramAddr
,
psramLen
);
Bitmap
CacheInit
();
Font
CacheInit
();
}
void
UIFontVector
::
Bitmap
CacheInit
()
void
UIFontVector
::
Font
CacheInit
()
{
if
(
bitmapCache_
!=
nullptr
)
{
// glyph cache
if
(
glyphsCache_
.
CacheInit
()
!=
RET_VALUE_OK
)
{
GRAPHIC_LOGE
(
"UIFontVector::FontCacheInit glyphs cache init failed"
);
return
;
}
// bitmap cache
if
(
bitmapCache_
!=
nullptr
)
{
return
;
}
#if (defined(ENABLE_MIX_FONT) && (ENABLE_MIX_FONT == 1))
uint32_t
c
acheSize
=
FONT_BITMAP_CACHE_SIZE
;
uint32_t
bitmapC
acheSize
=
FONT_BITMAP_CACHE_SIZE
;
#else
uint32_t
cacheSize
=
GetRam
Len
();
uint32_t
bitmapCacheSize
=
GetRamLen
()
-
FontRamAllocator
::
GetInstance
().
GetRamUsed
Len
();
#endif
uint8_t
*
bitmapCacheAddr
=
reinterpret_cast
<
uint8_t
*>
(
FontRamAllocator
::
GetInstance
().
Allocate
(
c
acheSize
));
uint8_t
*
bitmapCacheAddr
=
reinterpret_cast
<
uint8_t
*>
(
FontRamAllocator
::
GetInstance
().
Allocate
(
bitmapC
acheSize
));
if
(
bitmapCacheAddr
==
nullptr
)
{
GRAPHIC_LOGE
(
"UIFontVector::
Bitmap
CacheInit allocate failed"
);
GRAPHIC_LOGE
(
"UIFontVector::
Font
CacheInit allocate failed"
);
return
;
}
bitmapCache_
=
new
UIFontCache
(
bitmapCacheAddr
,
FONT_BITMAP_CACHE_SIZE
);
bitmapCache_
=
new
UIFontCache
(
bitmapCacheAddr
,
bitmapCacheSize
);
}
}
// namespace OHOS
interfaces/innerkits/font/ui_font_vector.h
浏览文件 @
9e45d1be
...
...
@@ -20,6 +20,7 @@
#include "ft2build.h"
#include "freetype/freetype.h"
#include "freetype/tttables.h"
#include "font/glyphs_cache.h"
#include "font/ui_font_cache.h"
#include <memory>
...
...
@@ -72,6 +73,7 @@ private:
uint8_t
currentFontInfoNum_
=
0
;
bool
freeTypeInited_
;
UIFontCache
*
bitmapCache_
;
GlyphsCache
glyphsCache_
;
struct
FaceInfo
{
FT_Face
face
;
uint32_t
key
;
...
...
@@ -90,17 +92,18 @@ private:
};
TtcInfo
ttcInfos_
[
FONT_TTC_MAX
]
=
{};
void
SetFace
(
FaceInfo
&
faceInfo
,
uint32_t
unicode
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
SetFace
(
FaceInfo
&
faceInfo
,
uint32_t
unicode
,
TextStyle
textStyle
);
#endif
uint16_t
GetFontId
(
uint32_t
unicode
)
const
;
uint32_t
GetKey
(
uint16_t
fontId
,
uint32_t
size
);
int8_t
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint
32_t
unic
ode
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
int8_t
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint
8_t
fontSize
,
uint32_t
unicode
,
GlyphNode
&
glyphN
ode
);
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
int8_t
LoadGlyphIntoFace
(
uint16_t
&
fontId
,
uint32_t
unicode
,
FT_Face
face
,
TextStyle
textStyle
);
#endif
void
SaveGlyphNode
(
uint32_t
unicode
,
uint32_t
fontKey
,
Metric
*
metric
);
uint8_t
IsGlyphFont
(
uint32_t
unicode
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
SetItaly
(
FT_GlyphSlot
slot
);
void
SetBold
(
uint16_t
fontId
);
#endif
...
...
@@ -114,7 +117,7 @@ private:
uint32_t
ttfBufferSize
,
TtfHeader
&
ttfHeader
,
UITextLanguageFontParam
fontInfo
);
void
Bitmap
CacheInit
();
void
Font
CacheInit
();
void
ClearFontGlyph
(
FT_Face
face
);
};
}
// namespace OHOS
...
...
interfaces/kits/common/spannable_string.h
浏览文件 @
9e45d1be
...
...
@@ -18,7 +18,7 @@
#include "gfx_utils/list.h"
#include "font/ui_font_header.h"
namespace
OHOS
{
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
class
StyleSpan
:
public
HeapBase
{
public:
StyleSpan
()
{};
...
...
interfaces/kits/common/text.h
浏览文件 @
9e45d1be
...
...
@@ -43,7 +43,7 @@
#include "gfx_utils/vector.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "font/ui_font_header.h"
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
#include "common/spannable_string.h"
#endif
...
...
@@ -164,7 +164,7 @@ public:
*/
virtual
void
SetText
(
const
char
*
text
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @brief Sets the SpannableString for this text.
*
...
...
@@ -515,8 +515,9 @@ protected:
SizeSpan
*
sizeSpans
);
uint8_t
GetSpanFontIdBySize
(
uint8_t
size
);
void
InitSizeSpans
();
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
*
textStyles_
;
#endif
char
*
text_
;
uint16_t
fontId_
;
uint8_t
fontSize_
;
// Only the vector font library has a valid value.
...
...
interfaces/kits/components/ui_label.h
浏览文件 @
9e45d1be
...
...
@@ -38,7 +38,7 @@
#include "animator/animator.h"
#include "common/text.h"
#include "components/ui_view.h"
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
#include "common/spannable_string.h"
#endif
...
...
@@ -188,7 +188,7 @@ public:
*/
void
SetText
(
const
char
*
text
);
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @brief Sets the SpannableString content for this label.
*
...
...
interfaces/kits/font/ui_font_header.h
浏览文件 @
9e45d1be
...
...
@@ -290,7 +290,7 @@ struct GlyphNode {
uint16_t
kernSize
;
// GLYPH_KERN_SIZE_OFFSET
uint16_t
fontId
;
// GLYPH_FONT_ID
uint16_t
dataFlag
;
// GLYPH_DATA_HEAD_FLAG
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle
textStyle
;
// GLYPH_TEXT_STYLE
#endif
};
...
...
test/uitest/test_vector_font/ui_test_vector_font.cpp
浏览文件 @
9e45d1be
...
...
@@ -75,7 +75,7 @@ void UITestVectorFont::InnerTestTitle(const char* title)
const
UIView
*
UITestVectorFont
::
GetTestView
()
{
#if
ENABLE_VECTOR_FONT
#if
defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TestDrawTextITALYBOLD
();
#endif
FontFontEngineVectorTestCHLang001
();
...
...
@@ -340,7 +340,7 @@ void UITestVectorFont::FontFontEngineMultiLanguageTestROLang001()
}
}
#endif
#if
ENABLE_VECTOR_FONT
#if
defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
UITestVectorFont
::
TestDrawTextITALYBOLD
()
{
if
(
container_
!=
nullptr
)
{
...
...
test/uitest/test_vector_font/ui_test_vector_font.h
浏览文件 @
9e45d1be
...
...
@@ -74,7 +74,7 @@ public:
void
FontFontEngineMultiLanguageTestROLang001
();
#endif
#if
ENABLE_VECTOR_FONT
#if
defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void
TestDrawTextITALYBOLD
();
#endif
private:
...
...
test/unittest/common/text_unit_test.cpp
浏览文件 @
9e45d1be
...
...
@@ -185,7 +185,7 @@ HWTEST_F(TextTest, TextSetRelativeSpan_001, TestSize.Level1)
text
=
nullptr
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
HWTEST_F
(
TextTest
,
TextSetStyleSpan_001
,
TestSize
.
Level1
)
{
SpannableString
spannableString
(
"图形子系统测试正常粗体斜体粗斜体"
);
...
...
test/unittest/components/ui_label_unit_test.cpp
浏览文件 @
9e45d1be
...
...
@@ -263,7 +263,7 @@ HWTEST_F(UILabelTest, UILabelOnPreDraw_001, TestSize.Level1)
invalidatedArea
=
nullptr
;
}
#if defined(ENABLE_
VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_
SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @tc.name: UILabelSetText_002
* @tc.desc: Verify SetText function.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录