Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
7e8c8e03
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,发现更多精彩内容 >>
提交
7e8c8e03
编写于
5月 11, 2021
作者:
O
openharmony_ci
提交者:
Gitee
5月 11, 2021
浏览文件
操作
浏览文件
下载
差异文件
!137 UIKit支持点阵字体产品化解耦
Merge pull request !137 from wangtiantian/bitmap
上级
57379ad6
bed8b9d9
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
1159 addition
and
177 deletion
+1159
-177
BUILD.gn
BUILD.gn
+3
-1
frameworks/common/graphic_startup.cpp
frameworks/common/graphic_startup.cpp
+12
-10
frameworks/common/text.cpp
frameworks/common/text.cpp
+7
-4
frameworks/font/base_font.cpp
frameworks/font/base_font.cpp
+2
-2
frameworks/font/glyphs_manager.cpp
frameworks/font/glyphs_manager.cpp
+6
-5
frameworks/font/ui_font.cpp
frameworks/font/ui_font.cpp
+8
-1
frameworks/font/ui_font_bitmap.cpp
frameworks/font/ui_font_bitmap.cpp
+301
-0
frameworks/font/ui_font_builder.cpp
frameworks/font/ui_font_builder.cpp
+91
-0
frameworks/font/ui_multi_font_manager.cpp
frameworks/font/ui_multi_font_manager.cpp
+4
-4
interfaces/innerkits/font/ui_font_bitmap.h
interfaces/innerkits/font/ui_font_bitmap.h
+70
-0
interfaces/innerkits/font/ui_font_builder.h
interfaces/innerkits/font/ui_font_builder.h
+54
-0
interfaces/kits/font/base_font.h
interfaces/kits/font/base_font.h
+2
-1
test/framework/BUILD.gn
test/framework/BUILD.gn
+5
-0
test/framework/common/ui_text_language.cpp
test/framework/common/ui_text_language.cpp
+51
-0
test/framework/common/ui_text_language.h
test/framework/common/ui_text_language.h
+48
-0
test/uitest/test_font/ui_test_font.cpp
test/uitest/test_font/ui_test_font.cpp
+222
-117
test/uitest/test_font/ui_test_font.h
test/uitest/test_font/ui_test_font.h
+26
-16
test/uitest/test_label/ui_test_label.cpp
test/uitest/test_label/ui_test_label.cpp
+4
-4
test/unittest/font/ui_font_unit_test.cpp
test/unittest/font/ui_font_unit_test.cpp
+213
-9
tools/qt/simulator/drivers/display/monitor.cpp
tools/qt/simulator/drivers/display/monitor.cpp
+16
-0
tools/qt/simulator/libui/libui.pro
tools/qt/simulator/libui/libui.pro
+3
-1
tools/qt/simulator/test/test.pro
tools/qt/simulator/test/test.pro
+5
-1
tools/qt/simulator/uitest/UITest.pro
tools/qt/simulator/uitest/UITest.pro
+6
-1
未找到文件。
BUILD.gn
浏览文件 @
7e8c8e03
...
...
@@ -32,6 +32,7 @@ config("graphic_define_config") {
defines = [
"ENABLE_VECTOR_FONT=1",
"ENABLE_BITMAP_FONT=0",
"ENABLE_SHAPING=0",
"ENABLE_ICU=1",
"ENABLE_MULTI_FONT=0",
...
...
@@ -67,7 +68,6 @@ shared_library("ui") {
"frameworks/common/task.cpp",
"frameworks/common/text.cpp",
"frameworks/common/typed_text.cpp",
"frameworks/common/ui_font_header.cpp",
"frameworks/components/root_view.cpp",
"frameworks/components/text_adapter.cpp",
"frameworks/components/ui_abstract_clock.cpp",
...
...
@@ -133,6 +133,8 @@ shared_library("ui") {
"frameworks/font/ui_font.cpp",
"frameworks/font/ui_font_adaptor.cpp",
"frameworks/font/ui_font_allocator.cpp",
"frameworks/font/ui_font_bitmap.cpp",
"frameworks/font/ui_font_builder.cpp",
"frameworks/font/ui_font_cache.cpp",
"frameworks/font/ui_font_vector.cpp",
"frameworks/font/ui_line_break.cpp",
...
...
frameworks/common/graphic_startup.cpp
浏览文件 @
7e8c8e03
...
...
@@ -47,24 +47,26 @@ void GraphicStartUp::InitFontEngine(uintptr_t cacheMemAddr,
const
char
*
dPath
,
const
char
*
ttfName
)
{
#if ENABLE_VECTOR_FONT
UIFont
*
fontEngine
=
UIFont
::
GetInstance
();
if
(
fontEngine
==
nullptr
)
{
UIFont
*
uiFont
=
UIFont
::
GetInstance
();
if
(
uiFont
==
nullptr
)
{
GRAPHIC_LOGE
(
"Get UIFont error"
);
return
;
}
fontEngine
->
SetPsramMemory
(
cacheMemAddr
,
cacheMemLen
);
int8_t
ret
=
fontEngine
->
SetFontPath
(
const_cast
<
char
*>
(
dPath
),
nullptr
);
uiFont
->
SetPsramMemory
(
cacheMemAddr
,
cacheMemLen
);
int8_t
ret
=
uiFont
->
SetFontPath
(
const_cast
<
char
*>
(
dPath
),
nullptr
);
if
(
ret
==
INVALID_RET_VALUE
)
{
GRAPHIC_LOGW
(
"SetFontPath failed"
);
}
if
(
ttfName
!=
nullptr
)
{
uint8_t
ret2
=
fontEngine
->
RegisterFontInfo
(
ttfName
);
if
(
ret2
==
INVALID_UCHAR_ID
)
{
GRAPHIC_LOGW
(
"SetTtfName failed"
);
if
(
uiFont
->
IsVectorFont
())
{
if
(
ttfName
!=
nullptr
)
{
uint8_t
ret2
=
uiFont
->
RegisterFontInfo
(
ttfName
);
if
(
ret2
==
INVALID_UCHAR_ID
)
{
GRAPHIC_LOGW
(
"SetTtfName failed"
);
}
}
}
else
{
(
void
)
uiFont
->
SetCurrentLangId
(
0
);
// set language
}
#endif
}
void
GraphicStartUp
::
InitLineBreakEngine
(
uintptr_t
cacheMemAddr
,
uint32_t
cacheMemLen
,
const
char
*
path
,
...
...
frameworks/common/text.cpp
浏览文件 @
7e8c8e03
...
...
@@ -18,6 +18,7 @@
#include "draw/draw_label.h"
#include "font/ui_font.h"
#include "font/ui_font_adaptor.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/graphic_log.h"
#include "securec.h"
...
...
@@ -82,7 +83,8 @@ void Text::SetFont(const char* name, uint8_t size)
}
if
(
UIFont
::
GetInstance
()
->
IsVectorFont
())
{
uint8_t
fontId
=
UIFont
::
GetInstance
()
->
GetFontId
(
name
);
if
((
fontId
!=
GetTotalFontId
())
&&
((
fontId_
!=
fontId
)
||
(
fontSize_
!=
size
)))
{
if
((
fontId
!=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
())
&&
((
fontId_
!=
fontId
)
||
(
fontSize_
!=
size
)))
{
fontId_
=
fontId
;
fontSize_
=
size
;
needRefresh_
=
true
;
...
...
@@ -127,17 +129,18 @@ void Text::SetFont(const char* name, uint8_t size, char*& destName, uint8_t& des
void
Text
::
SetFontId
(
uint8_t
fontId
)
{
if
((
fontId
>=
GetTotalFontId
())
||
(
fontId_
==
fontId
))
{
if
((
fontId
>=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
())
||
(
fontId_
==
fontId
))
{
GRAPHIC_LOGE
(
"Text::SetFontId invalid fontId(%d)"
,
fontId
);
return
;
}
UITextLanguageFontParam
*
fontParam
=
GetTextLangFontsTable
(
fontId
);
UITextLanguageFontParam
*
fontParam
=
UIFontBuilder
::
GetInstance
()
->
GetTextLangFontsTable
(
fontId
);
if
(
fontParam
==
nullptr
)
{
return
;
}
if
(
UIFont
::
GetInstance
()
->
IsVectorFont
())
{
uint8_t
fontId
=
UIFont
::
GetInstance
()
->
GetFontId
(
fontParam
->
ttfName
);
if
((
fontId
!=
GetTotalFontId
())
&&
((
fontId_
!=
fontId
)
||
(
fontSize_
!=
fontParam
->
size
)))
{
if
((
fontId
!=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
())
&&
((
fontId_
!=
fontId
)
||
(
fontSize_
!=
fontParam
->
size
)))
{
fontId_
=
fontId
;
fontSize_
=
fontParam
->
size
;
needRefresh_
=
true
;
...
...
frameworks/font/base_font.cpp
浏览文件 @
7e8c8e03
...
...
@@ -49,11 +49,11 @@ void BaseFont::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen)
int8_t
BaseFont
::
GetDefaultParamByLangId
(
uint8_t
langId
,
LangTextParam
**
pParam
)
const
{
if
((
langId
>=
GetTotalLangId
())
||
(
pParam
==
nullptr
))
{
if
((
langId
>=
UIFontBuilder
::
GetInstance
()
->
GetTotalLangId
())
||
(
pParam
==
nullptr
))
{
return
INVALID_RET_VALUE
;
}
LangTextParam
*
pTable
=
GetLangTextDefaultParamTable
();
LangTextParam
*
pTable
=
UIFontBuilder
::
GetInstance
()
->
GetLangTextDefaultParamTable
();
if
(
pTable
==
nullptr
)
{
return
INVALID_RET_VALUE
;
}
...
...
frameworks/font/glyphs_manager.cpp
浏览文件 @
7e8c8e03
...
...
@@ -14,6 +14,7 @@
*/
#include "font/glyphs_manager.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/file.h"
#include "securec.h"
...
...
@@ -43,7 +44,7 @@ GlyphsManager::GlyphsManager()
isFileSet_
(
false
),
isFontIdSet_
(
false
)
{
fontId_
=
GetBitmapFontIdMax
();
fontId_
=
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
();
}
GlyphsManager
::~
GlyphsManager
()
{}
...
...
@@ -179,7 +180,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
if
(
strncmp
(
binHeader_
.
fontMagic
,
FONT_MAGIC_NUMBER
,
FONT_MAGIC_NUM_LEN
)
!=
0
)
{
return
INVALID_RET_VALUE
;
}
if
(
binHeader_
.
fontNum
>
GetBitmapFontIdMax
())
{
if
(
binHeader_
.
fontNum
>
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
())
{
return
INVALID_RET_VALUE
;
}
...
...
@@ -211,7 +212,7 @@ int8_t GlyphsManager::SetFile(int32_t fp, uint32_t start)
isFileSet_
=
true
;
}
fontId_
=
GetBitmapFontIdMax
();
fontId_
=
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
();
return
ret
;
}
...
...
@@ -221,7 +222,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
if
(
!
isFileSet_
)
{
return
INVALID_RET_VALUE
;
}
if
(
fontId
>
GetBitmapFontIdMax
())
{
if
(
fontId
>
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
())
{
return
INVALID_RET_VALUE
;
}
if
(
fontId_
==
fontId
)
{
...
...
@@ -247,7 +248,7 @@ int8_t GlyphsManager::SetCurrentFontId(uint8_t fontId)
if
(
!
found
)
{
isFontIdSet_
=
false
;
curFontHeader_
=
nullptr
;
fontId_
=
GetBitmapFontIdMax
();
fontId_
=
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
();
return
INVALID_RET_VALUE
;
}
...
...
frameworks/font/ui_font.cpp
浏览文件 @
7e8c8e03
...
...
@@ -18,7 +18,9 @@
#include "font/ui_font_cache.h"
#if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h"
#endif // ENABLE_VECTOR_FONT
#else
#include "font/ui_font_bitmap.h"
#endif
#include "graphic_config.h"
#if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h"
...
...
@@ -37,6 +39,11 @@ UIFont* UIFont::GetInstance()
instance
.
defaultInstance_
=
new
UIFontVector
();
instance
.
instance_
=
instance
.
defaultInstance_
;
}
#else
if
(
instance
.
instance_
==
nullptr
)
{
instance
.
defaultInstance_
=
new
UIFontBitmap
();
instance
.
instance_
=
instance
.
defaultInstance_
;
}
#endif
return
&
instance
;
}
...
...
frameworks/font/ui_font_bitmap.cpp
0 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "font/ui_font_bitmap.h"
#include "font/ui_font_adaptor.h"
#include "font/ui_font_builder.h"
#include "gfx_utils/file.h"
#include "graphic_config.h"
#if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h"
#endif
#if ENABLE_SHAPING
#include "font/ui_text_shaping.h"
#endif
namespace
OHOS
{
UIFontBitmap
::
UIFontBitmap
()
:
dynamicFont_
(),
dynamicFontRamUsed_
(
0
),
dynamicFontFd_
(
-
1
)
{
SetBaseFontId
(
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
());
bitmapCache_
=
nullptr
;
bitmapRamUsed_
=
FONT_BITMAP_CACHE_SIZE
;
}
UIFontBitmap
::
~
UIFontBitmap
()
{
if
(
dynamicFontFd_
>=
0
)
{
close
(
dynamicFontFd_
);
}
if
(
bitmapCache_
!=
nullptr
)
{
delete
bitmapCache_
;
bitmapCache_
=
nullptr
;
}
}
bool
UIFontBitmap
::
IsVectorFont
()
const
{
return
false
;
}
uint8_t
UIFontBitmap
::
GetShapingFontId
(
char
*
text
,
uint8_t
&
ttfId
,
uint32_t
&
script
,
uint8_t
fontId
,
uint8_t
size
)
const
{
#if ENABLE_MULTI_FONT
return
UIMultiFontManager
::
GetInstance
()
->
GetShapingFontId
(
text
,
fontId
,
ttfId
,
script
);
#else
UITextLanguageFontParam
*
fontParam
=
UIFontBuilder
::
GetInstance
()
->
GetTextLangFontsTable
(
fontId
);
if
(
fontParam
==
nullptr
)
{
return
0
;
}
ttfId
=
fontParam
->
ttfId
;
return
fontParam
->
shaping
;
#endif
}
uint8_t
UIFontBitmap
::
GetFontWeight
(
uint8_t
fontId
)
{
UITextLanguageFontParam
*
fontParam
=
UIFontBuilder
::
GetInstance
()
->
GetTextLangFontsTable
(
fontId
);
if
(
fontParam
==
nullptr
)
{
return
0
;
}
return
fontParam
->
fontWeight
;
}
int8_t
UIFontBitmap
::
SetFontPath
(
const
char
*
dpath
,
const
char
*
spath
)
{
if
(
dpath
==
nullptr
)
{
return
INVALID_RET_VALUE
;
}
#ifdef _WIN32
dynamicFontFd_
=
open
(
dpath
,
O_RDONLY
|
O_BINARY
);
#else
dynamicFontFd_
=
open
(
dpath
,
O_RDONLY
);
#endif
if
(
dynamicFontFd_
<
0
)
{
return
INVALID_RET_VALUE
;
}
dynamicFont_
.
SetRamBuffer
(
GetRamAddr
());
uint32_t
start
=
0
;
int32_t
ret
=
dynamicFont_
.
SetFile
(
dynamicFontFd_
,
start
);
if
(
ret
==
INVALID_RET_VALUE
)
{
close
(
dynamicFontFd_
);
dynamicFontFd_
=
-
1
;
return
ret
;
}
dynamicFontRamUsed_
=
dynamicFont_
.
GetRamUsedLen
();
return
RET_VALUE_OK
;
}
int8_t
UIFontBitmap
::
SetCurrentFontId
(
uint8_t
fontId
,
uint8_t
size
)
{
int8_t
ret
=
SetDynamicFontId
(
fontId
);
if
(
ret
==
RET_VALUE_OK
)
{
SetBaseFontId
(
fontId
);
}
return
ret
;
}
uint16_t
UIFontBitmap
::
GetHeight
()
{
int16_t
ret
=
dynamicFont_
.
SetCurrentFontId
(
GetBaseFontId
());
if
(
ret
==
INVALID_RET_VALUE
)
{
return
ret
;
}
return
dynamicFont_
.
GetFontHeight
();
}
uint8_t
UIFontBitmap
::
GetFontId
(
const
char
*
ttfName
,
uint8_t
size
)
const
{
if
(
ttfName
==
nullptr
)
{
return
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
();
}
uint8_t
id
;
for
(
id
=
0
;
id
<
UIFontBuilder
::
GetInstance
()
->
GetBitmapFontIdMax
();
++
id
)
{
UITextLanguageFontParam
*
fontParam
=
UIFontBuilder
::
GetInstance
()
->
GetTextLangFontsTable
(
id
);
if
(
fontParam
!=
nullptr
)
{
if
((
fontParam
->
size
==
size
)
&&
(
strncmp
(
fontParam
->
ttfName
,
ttfName
,
TTF_NAME_LEN_MAX
)
==
0
))
{
break
;
}
}
}
return
id
;
}
int16_t
UIFontBitmap
::
GetWidth
(
uint32_t
unicode
,
uint8_t
fontId
)
{
return
GetWidthInFontId
(
unicode
,
fontId
);
}
uint8_t
*
UIFontBitmap
::
GetBitmap
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint8_t
fontId
)
{
return
SearchInFont
(
unicode
,
glyphNode
,
fontId
);
}
int8_t
UIFontBitmap
::
GetCurrentFontHeader
(
FontHeader
&
fontHeader
)
{
int8_t
ret
=
dynamicFont_
.
SetCurrentFontId
(
GetBaseFontId
());
if
(
ret
==
INVALID_RET_VALUE
)
{
return
ret
;
}
const
FontHeader
*
header
=
dynamicFont_
.
GetCurrentFontHeader
();
if
(
header
!=
nullptr
)
{
fontHeader
=
*
header
;
return
RET_VALUE_OK
;
}
return
INVALID_RET_VALUE
;
}
int8_t
UIFontBitmap
::
GetGlyphNode
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
)
{
int8_t
ret
=
dynamicFont_
.
SetCurrentFontId
(
GetBaseFontId
());
if
(
ret
==
INVALID_RET_VALUE
)
{
return
ret
;
}
const
GlyphNode
*
node
=
dynamicFont_
.
GetGlyphNode
(
unicode
);
if
(
node
!=
nullptr
)
{
glyphNode
=
*
node
;
return
RET_VALUE_OK
;
}
return
INVALID_RET_VALUE
;
}
int8_t
UIFontBitmap
::
GetFontVersion
(
char
*
dVersion
,
uint8_t
dLen
,
char
*
sVersion
,
uint8_t
sLen
)
const
{
return
dynamicFont_
.
GetFontVersion
(
dVersion
,
dLen
);
}
int8_t
UIFontBitmap
::
SetCurrentLangId
(
uint8_t
langId
)
{
if
(
bitmapCache_
==
nullptr
)
{
uint8_t
*
bitmapCacheAddr
=
reinterpret_cast
<
uint8_t
*>
(
GetRamAddr
()
+
dynamicFontRamUsed_
);
bitmapCache_
=
new
UIFontCache
(
bitmapCacheAddr
,
bitmapRamUsed_
);
}
uint32_t
total
=
dynamicFontRamUsed_
+
bitmapRamUsed_
;
return
(
total
<=
GetRamLen
())
?
RET_VALUE_OK
:
INVALID_RET_VALUE
;
}
UITextLanguageFontParam
*
UIFontBitmap
::
GetFontInfo
(
uint8_t
fontId
)
const
{
return
UIFontBuilder
::
GetInstance
()
->
GetTextLangFontsTable
(
fontId
);
}
uint32_t
UIFontBitmap
::
GetBitmapRamUsed
()
{
return
bitmapRamUsed_
;
}
uint32_t
UIFontBitmap
::
GetDynamicFontRamUsed
()
{
return
dynamicFontRamUsed_
;
}
uint32_t
UIFontBitmap
::
GetRamUsedLen
(
uint32_t
textManagerRamUsed
,
uint32_t
langFontRamUsed
)
{
if
(
bitmapCache_
==
nullptr
)
{
uint8_t
*
bitmapCacheAddr
=
reinterpret_cast
<
uint8_t
*>
(
GetRamAddr
()
+
dynamicFontRamUsed_
+
textManagerRamUsed
);
bitmapCache_
=
new
UIFontCache
(
bitmapCacheAddr
,
bitmapRamUsed_
);
}
return
dynamicFontRamUsed_
+
textManagerRamUsed
+
bitmapRamUsed_
+
langFontRamUsed
;
}
int8_t
UIFontBitmap
::
GetDynamicFotBitmap
(
uint32_t
unicode
,
uint8_t
*
bitmap
)
{
return
dynamicFont_
.
GetBitmap
(
unicode
,
bitmap
);
}
uint8_t
*
UIFontBitmap
::
GetCacheBitmap
(
uint8_t
fontId
,
uint32_t
unicode
)
{
if
(
bitmapCache_
!=
nullptr
)
{
return
bitmapCache_
->
GetBitmap
(
fontId
,
unicode
);
}
return
nullptr
;
}
uint8_t
*
UIFontBitmap
::
GetCacheSpace
(
uint8_t
fontId
,
uint32_t
unicode
,
uint32_t
size
)
{
if
(
bitmapCache_
!=
nullptr
)
{
return
bitmapCache_
->
GetSpace
(
fontId
,
unicode
,
size
);
}
return
nullptr
;
}
void
UIFontBitmap
::
PutCacheSpace
(
uint8_t
*
addr
)
{
if
(
bitmapCache_
!=
nullptr
)
{
bitmapCache_
->
PutSpace
(
addr
);
}
}
int8_t
UIFontBitmap
::
SetDynamicFontId
(
uint8_t
fontId
)
{
return
dynamicFont_
.
SetCurrentFontId
(
fontId
);
}
int16_t
UIFontBitmap
::
GetDynamicFontWidth
(
uint32_t
unicode
,
uint8_t
fontId
)
{
int16_t
ret
=
dynamicFont_
.
SetCurrentFontId
(
fontId
);
if
(
ret
==
INVALID_RET_VALUE
)
{
return
ret
;
}
return
dynamicFont_
.
GetFontWidth
(
unicode
);
}
uint8_t
*
UIFontBitmap
::
SearchInFont
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint8_t
fontId
)
{
if
(
!
UIFontAdaptor
::
IsSameTTFId
(
fontId
,
unicode
))
{
return
nullptr
;
}
if
(
fontId
!=
GetBaseFontId
())
{
SetCurrentFontId
(
fontId
);
}
if
(
bitmapCache_
==
nullptr
)
{
return
nullptr
;
}
uint8_t
*
bitmap
=
bitmapCache_
->
GetBitmap
(
GetBaseFontId
(),
unicode
);
if
(
bitmap
!=
nullptr
)
{
GetGlyphNode
(
unicode
,
glyphNode
);
return
bitmap
;
}
int8_t
ret
=
GetGlyphNode
(
unicode
,
glyphNode
);
if
(
ret
!=
RET_VALUE_OK
)
{
return
nullptr
;
}
if
(
glyphNode
.
kernOff
<=
glyphNode
.
dataOff
)
{
return
nullptr
;
}
uint32_t
bitmapSize
=
glyphNode
.
kernOff
-
glyphNode
.
dataOff
;
bitmap
=
bitmapCache_
->
GetSpace
(
GetBaseFontId
(),
unicode
,
bitmapSize
);
ret
=
dynamicFont_
.
GetBitmap
(
unicode
,
bitmap
);
if
(
ret
==
RET_VALUE_OK
)
{
return
bitmap
;
}
bitmapCache_
->
PutSpace
(
bitmap
);
return
nullptr
;
}
int16_t
UIFontBitmap
::
GetWidthInFontId
(
uint32_t
unicode
,
uint8_t
fontId
)
{
if
(
!
UIFontAdaptor
::
IsSameTTFId
(
fontId
,
unicode
))
{
return
INVALID_RET_VALUE
;
}
if
(
fontId
!=
GetBaseFontId
())
{
SetCurrentFontId
(
fontId
);
}
return
GetDynamicFontWidth
(
unicode
,
GetBaseFontId
());
}
}
// namespace
frameworks/font/ui_font_builder.cpp
0 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "font/ui_font_builder.h"
#include "font/ui_font.h"
namespace
OHOS
{
UIFontBuilder
::
UIFontBuilder
()
:
totalLangId_
(
0
),
totalFontId_
(
0
),
totalTextId_
(
0
),
uiTextLangFontsTable_
(
nullptr
),
langTextDefaultParamTable_
(
nullptr
)
{}
UIFontBuilder
*
UIFontBuilder
::
GetInstance
()
{
static
UIFontBuilder
uiFontBuilder
;
return
&
uiFontBuilder
;
}
void
UIFontBuilder
::
SetTextLangFontsTable
(
const
UITextLanguageFontParam
*
uiTextLangFontsTable
,
uint8_t
totalFontId
)
{
if
((
uiTextLangFontsTable
!=
nullptr
)
&&
(
totalFontId
>
0
))
{
uiTextLangFontsTable_
=
const_cast
<
UITextLanguageFontParam
*>
(
uiTextLangFontsTable
);
totalFontId_
=
totalFontId
;
}
}
void
UIFontBuilder
::
SetLangTextDefaultParamTable
(
const
LangTextParam
*
langTextDefaultParamTable
,
uint8_t
totalLangId
)
{
if
((
langTextDefaultParamTable
!=
nullptr
)
&&
(
totalLangId
>
0
))
{
langTextDefaultParamTable_
=
const_cast
<
LangTextParam
*>
(
langTextDefaultParamTable
);
totalLangId_
=
totalLangId
;
}
}
void
UIFontBuilder
::
SetMaxTextId
(
uint16_t
totalTextId
)
{
totalTextId_
=
totalTextId
;
}
UITextLanguageFontParam
*
UIFontBuilder
::
GetTextLangFontsTable
(
uint8_t
langFontId
)
{
if
((
langFontId
>=
totalFontId_
)
||
(
uiTextLangFontsTable_
==
nullptr
))
{
return
nullptr
;
}
return
&
(
uiTextLangFontsTable_
[
langFontId
]);
}
uint8_t
UIFontBuilder
::
GetTotalLangId
()
const
{
return
totalLangId_
;
}
uint8_t
UIFontBuilder
::
GetTotalFontId
()
const
{
uint8_t
fontIdMax
=
0xFF
;
if
(
!
UIFont
::
GetInstance
()
->
IsVectorFont
())
{
fontIdMax
=
totalFontId_
;
}
return
fontIdMax
;
}
uint8_t
UIFontBuilder
::
GetBitmapFontIdMax
()
const
{
return
totalFontId_
;
}
uint16_t
UIFontBuilder
::
GetTotalTextId
()
const
{
return
totalTextId_
;
}
LangTextParam
*
UIFontBuilder
::
GetLangTextDefaultParamTable
()
{
if
(
langTextDefaultParamTable_
==
nullptr
)
{
return
nullptr
;
}
return
langTextDefaultParamTable_
;
}
}
// namespace OHOS
\ No newline at end of file
frameworks/font/ui_multi_font_manager.cpp
浏览文件 @
7e8c8e03
...
...
@@ -30,7 +30,7 @@ UIMultiFontManager::UIMultiFontManager()
bengaliTtfId_
(
0
),
topIndex_
(
0
)
{
const
UITextLanguageFontParam
*
fontParam
=
nullptr
;
uint8_t
totalFontId
=
GetTotalFontId
();
uint8_t
totalFontId
=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
();
for
(
uint8_t
i
=
0
;
i
<
totalFontId
;
i
++
)
{
fontParam
=
UIFont
::
GetInstance
()
->
GetFontInfo
(
i
);
if
(
fontParam
==
nullptr
)
{
...
...
@@ -121,7 +121,7 @@ void UIMultiFontManager::UpdateScript(UITextLanguageFontParam& fonts)
void
UIMultiFontManager
::
ClearSearchFontList
()
{
uint8_t
totalFontId
=
GetTotalFontId
();
uint8_t
totalFontId
=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
();
for
(
uint8_t
index
=
0
;
index
<
totalFontId
;
index
++
)
{
fontIdIndex_
[
index
]
=
MAX_LIST_NUM
;
}
...
...
@@ -136,7 +136,7 @@ void UIMultiFontManager::ClearSearchFontList()
int8_t
UIMultiFontManager
::
SetSearchFontList
(
uint8_t
fontListId
,
uint8_t
*
fontIds
,
uint8_t
size
)
{
if
((
fontListId
>=
GetTotalFontId
())
||
(
fontIds
==
nullptr
)
||
(
size
==
0
)
||
if
((
fontListId
>=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
())
||
(
fontIds
==
nullptr
)
||
(
size
==
0
)
||
(
fontIdIndex_
==
nullptr
)
||
(
topIndex_
>=
MAX_LIST_NUM
))
{
return
INVALID_RET_VALUE
;
}
...
...
@@ -146,7 +146,7 @@ int8_t UIMultiFontManager::SetSearchFontList(uint8_t fontListId, uint8_t *fontId
int8_t
UIMultiFontManager
::
GetSearchFontList
(
uint8_t
fontListId
,
uint8_t
**
fontIds
)
{
if
((
fontListId
>=
GetTotalFontId
())
||
(
fontIds
==
nullptr
)
||
if
((
fontListId
>=
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
())
||
(
fontIds
==
nullptr
)
||
(
fontIdIndex_
==
nullptr
)
||
(
fontIdIndex_
[
fontListId
]
>=
MAX_LIST_NUM
))
{
return
INVALID_RET_VALUE
;
}
...
...
interfaces/innerkits/font/ui_font_bitmap.h
0 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UI_FONT_BITMAP_H
#define UI_FONT_BITMAP_H
#include "font/base_font.h"
#include "font/glyphs_manager.h"
#include "font/ui_font_cache.h"
namespace
OHOS
{
class
UIFontBitmap
:
public
BaseFont
{
public:
UIFontBitmap
();
virtual
~
UIFontBitmap
();
UIFontBitmap
(
const
UIFontBitmap
&
)
=
delete
;
UIFontBitmap
&
operator
=
(
const
UIFontBitmap
&
)
noexcept
=
delete
;
bool
IsVectorFont
()
const
override
;
uint8_t
GetShapingFontId
(
char
*
text
,
uint8_t
&
ttfId
,
uint32_t
&
script
,
uint8_t
fontId
,
uint8_t
size
)
const
override
;
int8_t
SetFontPath
(
const
char
*
dpath
,
const
char
*
spath
)
override
;
int8_t
SetCurrentFontId
(
uint8_t
fontId
,
uint8_t
size
=
0
)
override
;
uint16_t
GetHeight
()
override
;
uint8_t
GetFontId
(
const
char
*
ttfName
,
uint8_t
size
=
0
)
const
override
;
int16_t
GetWidth
(
uint32_t
unicode
,
uint8_t
fontId
)
override
;
uint8_t
*
GetBitmap
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint8_t
fontId
)
override
;
int8_t
GetCurrentFontHeader
(
FontHeader
&
fontHeader
)
override
;
int8_t
GetGlyphNode
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
)
override
;
uint8_t
GetFontWeight
(
uint8_t
fontId
)
override
;
int8_t
GetFontVersion
(
char
*
dVersion
,
uint8_t
dLen
,
char
*
sVersion
,
uint8_t
sLen
)
const
override
;
int8_t
SetCurrentLangId
(
uint8_t
langId
)
override
;
UITextLanguageFontParam
*
GetFontInfo
(
uint8_t
fontId
)
const
override
;
protected:
uint32_t
GetBitmapRamUsed
();
uint32_t
GetDynamicFontRamUsed
();
uint32_t
GetRamUsedLen
(
uint32_t
textManagerRamUsed
,
uint32_t
langFontRamUsed
);
int8_t
GetDynamicFotBitmap
(
uint32_t
unicode
,
uint8_t
*
bitmap
);
uint8_t
*
GetCacheBitmap
(
uint8_t
fontId
,
uint32_t
unicode
);
uint8_t
*
GetCacheSpace
(
uint8_t
fontId
,
uint32_t
unicode
,
uint32_t
size
);
void
PutCacheSpace
(
uint8_t
*
addr
);
int8_t
SetDynamicFontId
(
uint8_t
fontId
);
int16_t
GetDynamicFontWidth
(
uint32_t
unicode
,
uint8_t
fontId
);
private:
uint8_t
*
SearchInFont
(
uint32_t
unicode
,
GlyphNode
&
glyphNode
,
uint8_t
fontId
);
int16_t
GetWidthInFontId
(
uint32_t
unicode
,
uint8_t
fontId
);
static
constexpr
uint32_t
FONT_BITMAP_CACHE_SIZE
=
0x64000
;
static
constexpr
uint8_t
FONT_ID_MAX
=
0xFF
;
static
constexpr
uint8_t
TTF_NAME_LEN_MAX
=
128
;
GlyphsManager
dynamicFont_
;
uint32_t
dynamicFontRamUsed_
;
uint32_t
bitmapRamUsed_
;
UIFontCache
*
bitmapCache_
;
int32_t
dynamicFontFd_
;
};
}
// namespce OHOS
#endif // UI_FONT_BITMAP_H
\ No newline at end of file
frameworks/common/ui_font_header.cpp
→
interfaces/innerkits/font/ui_font_builder.h
100755 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "font/ui_font.h"
#include "font/ui_font_header.h"
namespace
OHOS
{
UITextLanguageFontParam
*
GetTextLangFontsTable
(
uint8_t
langFontId
)
{
// Need to be implemented
return
nullptr
;
}
uint8_t
GetTotalLangId
()
{
// Need to be implemented
return
0
;
}
uint8_t
GetBitmapFontIdMax
()
{
// Need to be implemented
return
0
;
}
uint8_t
GetTotalFontId
()
{
// Need to be implemented
return
0xFF
;
}
uint16_t
GetTotalTextId
()
{
// Need to be implemented
return
0
;
}
LangTextParam
*
GetLangTextDefaultParamTable
()
{
// Need to be implemented
return
nullptr
;
}
}
// namespace OHOS
\ No newline at end of file
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GRAPHIC_LITE_UI_FONT_BUILDER_H
#define GRAPHIC_LITE_UI_FONT_BUILDER_H
#include "font/ui_font_header.h"
namespace
OHOS
{
class
UIFontBuilder
{
public:
static
UIFontBuilder
*
GetInstance
();
void
SetTextLangFontsTable
(
const
UITextLanguageFontParam
*
uiTextLangFontsTable
,
uint8_t
totalFontId
);
void
SetLangTextDefaultParamTable
(
const
LangTextParam
*
langTextDefaultParamTable
,
uint8_t
totalLangId
);
void
SetMaxTextId
(
uint16_t
totalTextId
);
UITextLanguageFontParam
*
GetTextLangFontsTable
(
uint8_t
langFontId
);
uint8_t
GetTotalLangId
()
const
;
uint8_t
GetTotalFontId
()
const
;
uint8_t
GetBitmapFontIdMax
()
const
;
uint16_t
GetTotalTextId
()
const
;
LangTextParam
*
GetLangTextDefaultParamTable
();
UITextLanguageFontParam
*
uiTextLangFontsTable_
;
LangTextParam
*
langTextDefaultParamTable_
;
private:
UIFontBuilder
();
~
UIFontBuilder
()
{}
uint8_t
totalLangId_
;
uint8_t
totalFontId_
;
uint16_t
totalTextId_
;
};
}
#endif // GRAPHIC_LITE_UI_FONT_BUILDER_H
\ No newline at end of file
interfaces/kits/font/base_font.h
浏览文件 @
7e8c8e03
...
...
@@ -16,6 +16,7 @@
#ifndef BASE_FONT
#define BASE_FONT
#include "font/ui_font_header.h"
#include "font/ui_font_builder.h"
#include "graphic_config.h"
namespace
OHOS
{
...
...
@@ -101,7 +102,7 @@ public:
virtual
uint8_t
GetCurrentLangId
()
const
{
return
GetTotalLangId
();
return
UIFontBuilder
::
GetInstance
()
->
GetTotalLangId
();
}
int8_t
GetDefaultParamByLangId
(
uint8_t
langId
,
LangTextParam
**
pParam
)
const
;
...
...
test/framework/BUILD.gn
浏览文件 @
7e8c8e03
...
...
@@ -61,6 +61,7 @@ test_sources = [
"../uitest/test_view_percent/ui_test_view_percent.cpp",
"../uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp",
"../uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp",
"common/ui_text_language.cpp",
"src/test_ability.cpp",
"src/test_case_list_adapter.cpp",
"src/ui_test_app.cpp",
...
...
@@ -77,7 +78,9 @@ static_library("framework") {
sources = test_sources
include_dirs = [
"common",
"include",
"../framework",
"../uitest",
"../../tools",
"../../interfaces",
...
...
@@ -98,7 +101,9 @@ static_library("auto_framework") {
sources = test_sources
include_dirs = [
"common",
"include",
"../framework",
"../uitest",
"../../tools",
"../../interfaces",
...
...
test/framework/common/ui_text_language.cpp
0 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ui_text_language.h"
#include "font/ui_font_builder.h"
#include "font/ui_font_header.h"
namespace
OHOS
{
const
UITextLanguageFontParam
g_uiTextLangFontsTable
[
LANGUAGE_FONT_ID_MAX
]
=
{
{
14
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
18
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
20
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
26
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
30
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
38
,
4
,
0
,
0
,
"RobotoCondensed-Regular"
},
{
14
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
{
18
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
{
20
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
{
26
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
{
30
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
{
38
,
4
,
0
,
1
,
"SourceHanSansSC-Regular"
},
};
// g_uiTextLangFontsTable
const
LangTextParam
g_langTextDefaultParamTable
[
LANGUAGE_MAX
]
=
{
{
0
,
30
,
"SourceHanSansSC-Regular"
,
"zh"
},
{
0
,
30
,
"RobotoCondensed-Regular"
,
"en"
},
{
0
,
30
,
"RobotoCondensed-Regular"
,
"en"
},
};
// g_langTextDefaultParamTable
void
BitmapFontInit
()
{
UIFontBuilder
*
uiFontBuilder
=
UIFontBuilder
::
GetInstance
();
if
(
uiFontBuilder
==
nullptr
)
{
return
;
}
uiFontBuilder
->
SetTextLangFontsTable
(
g_uiTextLangFontsTable
,
LANGUAGE_FONT_ID_MAX
);
uiFontBuilder
->
SetLangTextDefaultParamTable
(
g_langTextDefaultParamTable
,
LANGUAGE_MAX
);
uiFontBuilder
->
SetMaxTextId
(
LANGUAGE_TEXT_ID_MAX
);
}
}
// namespace OHOS
test/framework/common/ui_text_language.h
0 → 100644
浏览文件 @
7e8c8e03
/*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UI_TEXT_LANGUAGE_H
#define UI_TEXT_LANGUAGE_H
#include <cstdint>
namespace
OHOS
{
void
BitmapFontInit
();
enum
UITextLanguageLangId
:
uint8_t
{
LANGUAGE_CH
=
0
,
LANGUAGE_GB
=
1
,
LANGUAGE_EN
=
2
,
LANGUAGE_MAX
=
3
};
// UITextLanguageLangId
enum
UITextLanguageFontId
:
uint8_t
{
F_ROBOTOCONDENSED_REGULAR_14_4
=
0
,
F_ROBOTOCONDENSED_REGULAR_18_4
=
1
,
F_ROBOTOCONDENSED_REGULAR_20_4
=
2
,
F_ROBOTOCONDENSED_REGULAR_26_4
=
3
,
F_ROBOTOCONDENSED_REGULAR_30_4
=
4
,
F_ROBOTOCONDENSED_REGULAR_38_4
=
5
,
F_SOURCEHANSANSSC_REGULAR_14_4
=
6
,
F_SOURCEHANSANSSC_REGULAR_18_4
=
7
,
F_SOURCEHANSANSSC_REGULAR_20_4
=
8
,
F_SOURCEHANSANSSC_REGULAR_26_4
=
9
,
F_SOURCEHANSANSSC_REGULAR_30_4
=
10
,
F_SOURCEHANSANSSC_REGULAR_38_4
=
11
,
LANGUAGE_FONT_ID_MAX
=
12
};
// UITextLanguageFontId
enum
UITextLanguageTextId
:
uint16_t
{
LANGUAGE_TEXT_ID_MAX
=
0
};
// UITextLanguageTextId
}
// namespace OHOS
#endif // UI_TEXT_LANGUAGE_H
test/uitest/test_font/ui_test_font.cpp
浏览文件 @
7e8c8e03
...
...
@@ -15,18 +15,25 @@
#include "ui_test_font.h"
#include "common/screen.h"
#include "components/ui_checkbox.h"
#if ENABLE_VECTOR_FONT
#else
#include "common/ui_text_language.h"
#endif
#include "components/ui_label.h"
#include "font/ui_font.h"
#if ENABLE_MULTI_FONT
#include "font/ui_multi_font_manager.h"
#endif
namespace
OHOS
{
namespace
{
const
int16_t
GAP
=
1
5
;
const
int16_t
GAP
=
5
;
const
int16_t
TITLE_HEIGHT
=
20
;
const
uint16_t
LABEL_WIDTH
=
400
;
const
uint16_t
LABEL_HEIGHT
=
50
;
const
uint16_t
BUF_SIZE
=
200
;
static
uint8_t
g_newFontPsramBaseAddr
[
OHOS
::
MIN_FONT_PSRAM_LENGTH
];
const
uint16_t
FONT_SIZE
=
30
;
const
char
*
SOURCE_HAN_SANS_SC_REGULAR
=
"SourceHanSansSC-Regular.otf"
;
const
char
*
ROBOTO_CONDENSED_REGULAR
=
"RobotoCondensed-Regulat.ttf"
;
}
// namespace
void
UITestFont
::
SetUp
()
...
...
@@ -52,7 +59,11 @@ void UITestFont::InnerTestTitle(const char* title)
UILabel
*
titleLabel
=
new
UILabel
();
titleLabel
->
SetPosition
(
TEXT_DISTANCE_TO_LEFT_SIDE
,
positionY_
,
Screen
::
GetInstance
().
GetWidth
(),
TITLE_LABEL_DEFAULT_HEIGHT
);
titleLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
FONT_DEFAULT_SIZE
);
#if ENABLE_VECTOR_FONT
titleLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
DEFAULT_VECTOR_FONT_SIZE
);
#else
titleLabel
->
SetFontId
(
F_SOURCEHANSANSSC_REGULAR_18_4
);
#endif
titleLabel
->
SetText
(
title
);
container_
->
Add
(
titleLabel
);
positionY_
+=
TITLE_HEIGHT
+
GAP
;
...
...
@@ -60,149 +71,243 @@ void UITestFont::InnerTestTitle(const char* title)
const
UIView
*
UITestFont
::
GetTestView
()
{
Font_FontEngine_FontConvert_Test_FontTestSetFontId_001
();
Font_FontEngine_FontConvert_Test_FontTestSetFont_001
();
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001
();
Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001
();
Font_FontEngine_FontConvert_Test_FontTestGetFontId_001
();
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001
();
Font_FontEngine_FontConvert_Test_FontTestPsram_001
();
Font_FontEngine_FontConvert_Test_FontTestFontPath_001
();
UIKitFontTestDispaly001
();
UIKitFontTestDispaly002
();
UIKitFontTestDispaly003
();
UIKitFontTestDispaly004
();
UIKitFontTestDispaly005
();
UIKitFontTestDispaly006
();
UIKitFontTestDispaly007
();
UIKitFontTestDispaly008
();
#if ENABLE_MULTI_FONT
UIKitFontMultiLanguage001
();
UIKitFontMultiLanguage002
();
#endif
return
container_
;
}
void
UITestFont
::
UIKitFontTestDispaly001
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display single line Chinese"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#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
(
"轻量图形子系统"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestPsram_001
()
void
UITestFont
::
UIKitFontTestDispaly002
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Psram"
);
UIFont
::
GetInstance
()
->
SetPsramMemory
(
reinterpret_cast
<
uintptr_t
>
(
g_newFontPsramBaseAddr
),
OHOS
::
MIN_FONT_PSRAM_LENGTH
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
label
->
SetLineBreakMode
(
UILabel
::
LINE_BREAK_WRAP
);
label
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
18
);
// 18 : size
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display multiline Chinese"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
*
2
);
// 2 : double
#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
(
" 你好
\n
轻量图形子系统"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestFontPath_001
()
void
UITestFont
::
UIKitFontTestDispaly003
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Font Path"
);
std
::
string
dpath
;
std
::
string
spath
;
size_t
len
=
dpath
.
size
();
size_t
pos
=
dpath
.
find_last_of
(
'\\'
);
dpath
.
replace
((
pos
+
1
),
(
len
-
pos
),
"..
\\
..
\\
config
\\
font.bin"
);
spath
.
replace
((
pos
+
1
),
(
len
-
pos
),
"..
\\
..
\\
config
\\
glyphs.bin"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
18
);
// 18 : size
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display single line English"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#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
(
"uikit test"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestSetFontId_001
()
void
UITestFont
::
UIKitFontTestDispaly004
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Set Font Id"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
UIFont
::
GetInstance
()
->
SetCurrentFontId
(
0
);
label
->
SetFontId
(
0
);
label
->
SetText
(
"Hello!
\n
OHOS UIKIT!"
);
label
->
SetLineBreakMode
(
UILabel
::
LINE_BREAK_WRAP
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display multiline English"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
*
2
);
// 2 : double
#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"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestSetFont_001
()
void
UITestFont
::
UIKitFontTestDispaly005
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Set Font"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
uint8_t
fontId
=
UIFont
::
GetInstance
()
->
GetFontId
(
"RobotoCondensed-Regular"
);
UIFont
::
GetInstance
()
->
SetCurrentFontId
(
fontId
,
18
);
// 18: means font size
label
->
SetFont
(
"RobotoCondensed-Regular"
,
18
);
// 18: means font size
label
->
SetText
(
"Hello!
\n
OHOS UIKIT!"
);
label
->
SetLineBreakMode
(
UILabel
::
LINE_BREAK_WRAP
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display single line Chinese and English"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#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
(
"你好,轻量级图形 uikit"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001
()
void
UITestFont
::
UIKitFontTestDispaly006
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Get Font Height"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
18
);
// 18 : size
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
container_
->
Add
(
label
);
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display multiline Chinese and English"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
*
2
);
// 2 : double
#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
(
"你好
\n
轻量级图形 uikit"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
UIKitFontTestDispaly007
()
{
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display single line text color"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#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
->
SetStyle
(
STYLE_TEXT_COLOR
,
Color
::
Red
().
full
);
label
->
SetText
(
"你好,轻量级图形"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001
()
void
UITestFont
::
UIKitFontTestDispaly008
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Get Font Version"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
FONT_DEFAULT_SIZE
);
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
container_
->
Add
(
label
);
if
(
container_
==
nullptr
)
{
return
;
}
InnerTestTitle
(
" Display multiline text color"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
*
2
);
// 2 : double
#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
->
SetStyle
(
STYLE_TEXT_COLOR
,
Color
::
Yellow
().
full
);
label
->
SetText
(
"你好
\n
轻量级图形 uikit"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestGetFontId_001
()
#if ENABLE_MULTI_FONT
void
UITestFont
::
UIKitFontMultiLanguage001
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Get Font Id"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetFont
(
"HYQiHei-65S"
,
18
);
// 18: means font size
UIFont
::
GetInstance
()
->
GetFontId
(
"HYQiHei-65S"
,
18
);
// 18: means font size
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
container_
->
Add
(
label
);
if
(
container_
==
nullptr
)
{
return
;
}
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
uint8_t
findPath
[]
=
{
UIFont
::
GetInstance
()
->
GetFontId
(
SOURCE_HAN_SANS_SC_REGULAR
)};
UIMultiFontManager
::
GetInstance
()
->
SetSearchFontList
(
UIFont
::
GetInstance
()
->
GetFontId
(
ROBOTO_CONDENSED_REGULAR
),
findPath
,
sizeof
(
findPath
));
#else
uint8_t
findPath
[]
=
{
F_SOURCEHANSANSSC_REGULAR_30_4
};
UIMultiFontManager
::
GetInstance
()
->
SetSearchFontList
(
F_ROBOTOCONDENSED_REGULAR_30_4
,
findPath
,
sizeof
(
findPath
));
#endif
InnerTestTitle
(
" Display multilingual display"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
#if ENABLE_VECTOR_FONT
label
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label
->
SetText
(
"Hello, 鸿蒙轻量级GUI"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
}
void
UITestFont
::
Font_FontEngine_FontConvert_Test_FontTestGetFontHeader_001
()
void
UITestFont
::
UIKitFontMultiLanguage002
()
{
if
(
container_
!=
nullptr
)
{
InnerTestTitle
(
"Test Get Font Header"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
FONT_DEFAULT_SIZE
);
FontHeader
fontHeader
;
UIFont
::
GetInstance
()
->
GetCurrentFontHeader
(
fontHeader
);
char
buf
[
BUF_SIZE
]
=
{
0
};
label
->
SetText
(
reinterpret_cast
<
char
*>
(
buf
));
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
);
positionY_
+=
LABEL_HEIGHT
+
GAP
;
container_
->
Add
(
label
);
if
(
container_
==
nullptr
)
{
return
;
}
#if ENABLE_VECTOR_FONT
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
SOURCE_HAN_SANS_SC_REGULAR
);
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
ROBOTO_CONDENSED_REGULAR
);
uint8_t
findPath
[]
=
{
UIFont
::
GetInstance
()
->
GetFontId
(
SOURCE_HAN_SANS_SC_REGULAR
)};
UIMultiFontManager
::
GetInstance
()
->
SetSearchFontList
(
UIFont
::
GetInstance
()
->
GetFontId
(
ROBOTO_CONDENSED_REGULAR
),
findPath
,
sizeof
(
findPath
));
#else
uint8_t
findPath
[]
=
{
F_SOURCEHANSANSSC_REGULAR_30_4
};
UIMultiFontManager
::
GetInstance
()
->
SetSearchFontList
(
F_ROBOTOCONDENSED_REGULAR_30_4
,
findPath
,
sizeof
(
findPath
));
#endif
InnerTestTitle
(
" Display multilingual display"
);
UILabel
*
label
=
new
UILabel
();
label
->
SetPosition
(
positionX_
,
positionY_
);
label
->
Resize
(
LABEL_WIDTH
,
LABEL_HEIGHT
*
2
);
// 2 : double
#if ENABLE_VECTOR_FONT
label
->
SetFont
(
ROBOTO_CONDENSED_REGULAR
,
FONT_SIZE
);
#else
label
->
SetFontId
(
F_ROBOTOCONDENSED_REGULAR_30_4
);
#endif
label
->
SetText
(
"Hello
\n
鸿蒙轻量级GUI"
);
container_
->
Add
(
label
);
positionY_
+=
LABEL_HEIGHT
*
2
+
GAP
;
// 2 : double
}
}
// namespace OHOS
\ No newline at end of file
#endif // ENABLE_MULTI_FONT
}
// namespace OHOS
test/uitest/test_font/ui_test_font.h
浏览文件 @
7e8c8e03
...
...
@@ -30,45 +30,55 @@ public:
const
UIView
*
GetTestView
()
override
;
/**
* @brief Test
psram
* @brief Test
single line Chinese display
*/
void
Font_FontEngine_FontConvert_Test_FontTestPsram_
001
();
void
UIKitFontTestDispaly
001
();
/**
* @brief Test
Font path
* @brief Test
multiline Chinese display
*/
void
Font_FontEngine_FontConvert_Test_FontTestFontPath_001
();
void
UIKitFontTestDispaly002
();
/**
* @brief Test
Set Font Id
* @brief Test
single line English display
*/
void
Font_FontEngine_FontConvert_Test_FontTestSetFontId_001
();
void
UIKitFontTestDispaly003
();
/**
* @brief Test
Set Font
* @brief Test
multiline English display
*/
void
Font_FontEngine_FontConvert_Test_FontTestSetFont_001
();
void
UIKitFontTestDispaly004
();
/**
* @brief Test
Get Font Height
* @brief Test
single line Chinese and English display
*/
void
Font_FontEngine_FontConvert_Test_FontTestGetFontHeight_001
();
void
UIKitFontTestDispaly005
();
/**
* @brief Test
get font version
* @brief Test
multiline Chinese and English display
*/
void
Font_FontEngine_FontConvert_Test_FontTestGetFontVersion_001
();
void
UIKitFontTestDispaly006
();
/**
* @brief Test
get font Id
* @brief Test
single line text color display
*/
void
Font_FontEngine_FontConvert_Test_FontTestGetFontId_001
();
void
UIKitFontTestDispaly007
();
/**
* @brief Test
get font header
* @brief Test
multiline line text color display
*/
void
Font_FontEngine_FontConvert_Test_FontTestGetFontHeader_001
();
void
UIKitFontTestDispaly008
();
#if ENABLE_MULTI_FONT
/**
* @brief Test multilingual display
*/
void
UIKitFontMultiLanguage001
();
/**
* @brief Test multilingual display
*/
void
UIKitFontMultiLanguage002
();
#endif // ENABLE_MULTI_FONT
private:
UIScrollView
*
container_
=
nullptr
;
void
InnerTestTitle
(
const
char
*
title
);
...
...
test/uitest/test_label/ui_test_label.cpp
浏览文件 @
7e8c8e03
...
...
@@ -99,7 +99,7 @@ void UITestLabel::UIKit_UILabel_Test_Display_001()
uiViewGroupFrame
->
SetStyle
(
STYLE_BACKGROUND_OPA
,
0
);
uiLabel
=
new
UILabel
();
uiLabel
->
SetText
(
"鸿蒙轻量级图形子系统"
);
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
4
);
// 24
: font size
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
6
);
// 26
: font size
uiLabel
->
SetPosition
(
0
,
141
,
280
,
336
);
// 141: y-coordinate; 280: width; 336: height
uiViewGroupFrame
->
Add
(
uiLabel
);
positionX_
+=
336
;
// 336: x-coordinate
...
...
@@ -123,7 +123,7 @@ void UITestLabel::CreateLabels(UIViewGroup* uiViewGroup)
label1
->
SetText
(
"字号"
);
label1
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
FONT_DEFAULT_SIZE
);
labelFontSizeBtn1_
=
SetUpButton
(
"18 "
,
24
,
48
,
uiViewGroup
);
// 24: x-coordinate; 48: y-coordinate
labelFontSizeBtn2_
=
SetUpButton
(
"2
4
"
,
116
,
48
,
uiViewGroup
);
// 116: x-coordinate; 48: y-coordinate
labelFontSizeBtn2_
=
SetUpButton
(
"2
6
"
,
116
,
48
,
uiViewGroup
);
// 116: x-coordinate; 48: y-coordinate
labelFontSizeBtn3_
=
SetUpButton
(
"30"
,
208
,
48
,
uiViewGroup
);
// 208: x-coordinate; 48: y-coordinate
UILabel
*
label2
=
new
UILabel
();
...
...
@@ -210,11 +210,11 @@ void UITestLabel::UIKit_UILabel_Test_Display_003()
bool
UITestLabel
::
OnClick
(
UIView
&
view
,
const
ClickEvent
&
event
)
{
uiLabel
->
Resize
(
288
,
100
);
// 288: width; 100: height
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
4
);
// 24
: font size
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
6
);
// 26
: font size
if
(
&
view
==
labelFontSizeBtn1_
)
{
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
18
);
// 18: font size
}
else
if
(
&
view
==
labelFontSizeBtn2_
)
{
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
4
);
// 24
: font size
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
2
6
);
// 26
: font size
}
else
if
(
&
view
==
labelFontSizeBtn3_
)
{
uiLabel
->
SetFont
(
DEFAULT_VECTOR_FONT_FILENAME
,
30
);
// 30: font size
}
else
if
(
&
view
==
labelHorAlignBtn1_
)
{
...
...
test/unittest/font/ui_font_unit_test.cpp
浏览文件 @
7e8c8e03
...
...
@@ -14,8 +14,11 @@
*/
#include "font/ui_font.h"
#if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h"
#else
#include "font/ui_font_bitmap.h"
#endif
#include <climits>
#include <gtest/gtest.h>
...
...
@@ -23,16 +26,40 @@ using namespace testing::ext;
namespace
OHOS
{
namespace
{
constexpr
uint8_t
FONT_ERROR_RET
=
0xFF
;
constexpr
int8_t
INVALID_RET
=
-
1
;
constexpr
uint8_t
FONT_ID
=
0xFF
;
constexpr
uint8_t
FONT_BPP
=
8
;
}
class
UIFontTest
:
public
testing
::
Test
{
public:
UIFontTest
()
{}
virtual
~
UIFontTest
()
{}
static
void
SetUpTestCase
()
{}
;
static
void
TearDownTestCase
()
{}
;
static
void
SetUpTestCase
();
static
void
TearDownTestCase
()
;
static
BaseFont
*
font_
;
};
BaseFont
*
UIFontTest
::
font_
=
nullptr
;
void
UIFontTest
::
SetUpTestCase
()
{
if
(
font_
==
nullptr
)
{
#if ENABLE_VECTOR_FONT
font_
=
new
UIFontVector
();
#else
font_
=
new
UIFontBitmap
();
#endif
}
}
void
UIFontTest
::
TearDownTestCase
()
{
if
(
font_
!=
nullptr
)
{
delete
font_
;
font_
=
nullptr
;
}
}
/**
* @tc.name: Graphic_Font_Test_GetInstance_001
* @tc.desc: Verify UIFont::GetInstance function, not nullptr.
...
...
@@ -46,16 +73,181 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_001, TestSize.Level0)
}
/**
* @tc.name: Graphic_Font_Test_
GetInstance_002
* @tc.desc: Verify
UIFont::GetInstance
function, equal.
* @tc.name: Graphic_Font_Test_
IsVectorFont_001
* @tc.desc: Verify
IsVectorFont
function, equal.
* @tc.type: FUNC
* @tc.require: SR000F
3PEK
* @tc.require: SR000F
QNFQ
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_
GetInstance_002
,
TestSize
.
Level1
)
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_
IsVectorFont_001
,
TestSize
.
Level1
)
{
UIFont
*
font
=
UIFont
::
GetInstance
();
UIFont
::
GetInstance
()
->
SetFont
(
font_
);
#if ENABLE_VECTOR_FONT
bool
ret
=
UIFont
::
GetInstance
()
->
IsVectorFont
();
EXPECT_EQ
(
ret
,
true
);
#else
bool
ret
=
UIFont
::
GetInstance
()
->
IsVectorFont
();
EXPECT_EQ
(
ret
,
false
);
#endif
}
/**
* @tc.name: Graphic_Font_Test_SetFontPath_001
* @tc.desc: Verify SetFontPath function, nullptr test.
* @tc.type: FUNC
* @tc.require: SR000FQNFQ
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_SetFontPath_001
,
TestSize
.
Level1
)
{
int8_t
ret
=
UIFont
::
GetInstance
()
->
SetFontPath
(
nullptr
,
nullptr
);
EXPECT_EQ
(
ret
,
INVALID_RET
);
}
/**
* @tc.name: Graphic_Font_Test_SetFontPath_002
* @tc.desc: Verify SetFontPath function, empty string test.
* @tc.type: FUNC
* @tc.require: SR000FQNFQ
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_SetFontPath_002
,
TestSize
.
Level1
)
{
int8_t
ret
=
UIFont
::
GetInstance
()
->
SetFontPath
(
""
,
nullptr
);
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
ret
,
0
);
#else
EXPECT_EQ
(
ret
,
INVALID_RET
);
#endif
}
/**
* @tc.name: Graphic_Font_Test_SetCurrentFontId_001
* @tc.desc: Verify SetCurrentFontId function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_SetCurrentFontId_001
,
TestSize
.
Level1
)
{
int8_t
ret
=
UIFont
::
GetInstance
()
->
SetCurrentFontId
(
0
,
0
);
EXPECT_EQ
(
ret
,
INVALID_RET
);
}
/**
* @tc.name: Graphic_Font_Test_GetFontId_001
* @tc.desc: Verify GetFontId function, nullptr test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetFontId_001
,
TestSize
.
Level1
)
{
uint8_t
ret
=
UIFont
::
GetInstance
()
->
GetFontId
(
nullptr
);
EXPECT_EQ
(
ret
,
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
());
}
/**
* @tc.name: Graphic_Font_Test_GetFontId_002
* @tc.desc: Verify GetFontId function, empty string test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetFontId_002
,
TestSize
.
Level1
)
{
uint8_t
id
=
UIFont
::
GetInstance
()
->
GetFontId
(
""
,
0
);
EXPECT_EQ
(
id
,
UIFontBuilder
::
GetInstance
()
->
GetTotalFontId
());
}
/**
* @tc.name: Graphic_Font_Test_GetHeight_001
* @tc.desc: Verify GetHeight function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetHeight_001
,
TestSize
.
Level1
)
{
uint16_t
height
=
UIFont
::
GetInstance
()
->
GetHeight
();
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
height
,
0
);
#else
EXPECT_EQ
(
height
,
static_cast
<
uint16_t
>
(
INVALID_RET
));
#endif
}
/**
* @tc.name: Graphic_Font_Test_GetWidth_001
* @tc.desc: Verify GetWidth function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetWidth_001
,
TestSize
.
Level1
)
{
uint16_t
width
=
UIFont
::
GetInstance
()
->
GetWidth
(
0
,
0
);
EXPECT_EQ
(
width
,
0
);
}
/**
* @tc.name: Graphic_Font_Test_GetBitmap_001
* @tc.desc: Verify GetBitmap function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetBitmap_001
,
TestSize
.
Level1
)
{
GlyphNode
node
;
uint8_t
*
bitmap
=
UIFont
::
GetInstance
()
->
GetBitmap
(
0
,
node
,
0
);
EXPECT_EQ
(
bitmap
,
nullptr
);
}
/**
* @tc.name: Graphic_Font_Test_GetCurrentFontHeader_001
* @tc.desc: Verify GetCurrentFontHeader function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetCurrentFontHeader_001
,
TestSize
.
Level1
)
{
FontHeader
header
;
int8_t
res
=
UIFont
::
GetInstance
()
->
GetCurrentFontHeader
(
header
);
EXPECT_EQ
(
res
,
INVALID_RET
);
}
/**
* @tc.name: Graphic_Font_Test_GetFontWeight_001
* @tc.desc: Verify GetFontWeight function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetFontWeight_001
,
TestSize
.
Level1
)
{
uint8_t
fontWeight
=
UIFont
::
GetInstance
()
->
GetFontWeight
(
FONT_ID
);
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
fontWeight
,
FONT_BPP
);
#else
EXPECT_EQ
(
fontWeight
,
0
);
#endif
}
/**
* @tc.name: Graphic_Font_Test_GetFontInfo_001
* @tc.desc: Verify GetFontInfo function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetFontInfo_001
,
TestSize
.
Level1
)
{
const
UITextLanguageFontParam
*
fontParam
=
UIFont
::
GetInstance
()
->
GetFontInfo
(
FONT_ID
);
EXPECT_EQ
(
fontParam
,
nullptr
);
}
/**
* @tc.name: Graphic_Font_Test_GetShapingFontId_001
* @tc.desc: Verify GetShapingFontId function, abnormal value test.
* @tc.type: FUNC
* @tc.require: AR000FQNFR
*/
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_GetShapingFontId_001
,
TestSize
.
Level1
)
{
uint8_t
ttfId
=
0
;
uint32_t
script
=
0
;
uint8_t
fontId
=
UIFont
::
GetInstance
()
->
GetShapingFontId
(
""
,
ttfId
,
script
,
FONT_ID
,
0
);
EXPECT_EQ
(
fontId
,
0
);
}
/**
...
...
@@ -67,7 +259,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_GetInstance_002, TestSize.Level1)
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_RegisterFontInfo_001
,
TestSize
.
Level1
)
{
uint8_t
ret
=
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
"error"
);
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
ret
,
FONT_ERROR_RET
);
#else
EXPECT_EQ
(
ret
,
0
);
#endif
}
/**
...
...
@@ -79,7 +275,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_001, TestSize.Level1)
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_RegisterFontInfo_002
,
TestSize
.
Level0
)
{
uint8_t
ret
=
UIFont
::
GetInstance
()
->
RegisterFontInfo
(
"ui-font.ttf"
);
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
ret
,
FONT_ERROR_RET
);
#else
EXPECT_EQ
(
ret
,
0
);
#endif
}
/**
...
...
@@ -91,7 +291,11 @@ HWTEST_F(UIFontTest, Graphic_Font_Test_RegisterFontInfo_002, TestSize.Level0)
HWTEST_F
(
UIFontTest
,
Graphic_Font_Test_UnregisterFontInfo_001
,
TestSize
.
Level1
)
{
uint8_t
ret
=
UIFont
::
GetInstance
()
->
UnregisterFontInfo
(
"error font name"
);
#if ENABLE_VECTOR_FONT
EXPECT_EQ
(
ret
,
FONT_ERROR_RET
);
#else
EXPECT_EQ
(
ret
,
0
);
#endif
}
/**
...
...
tools/qt/simulator/drivers/display/monitor.cpp
浏览文件 @
7e8c8e03
...
...
@@ -21,7 +21,12 @@
#include "draw/draw_utils.h"
#include "font/ui_font.h"
#include "font/ui_font_header.h"
#if ENABLE_VECTOR_FONT
#include "font/ui_font_vector.h"
#else
#include "common/ui_text_language.h"
#include "font/ui_font_bitmap.h"
#endif
#include "key_input.h"
#include "mouse_input.h"
#include "mousewheel_input.h"
...
...
@@ -77,8 +82,19 @@ static uint8_t g_icuMemBaseAddr[OHOS::SHAPING_WORD_DICT_LENGTH];
void
Monitor
::
InitFontEngine
()
{
#if ENABLE_VECTOR_FONT
GraphicStartUp
::
InitFontEngine
(
reinterpret_cast
<
uintptr_t
>
(
g_fontMemBaseAddr
),
MIN_FONT_PSRAM_LENGTH
,
VECTOR_FONT_DIR
,
DEFAULT_VECTOR_FONT_FILENAME
);
#else
BitmapFontInit
();
std
::
string
dPath
(
_pgmptr
);
size_t
len
=
dPath
.
size
();
size_t
pos
=
dPath
.
find_last_of
(
'\\'
);
dPath
.
replace
((
pos
+
1
),
(
len
-
pos
),
"..
\\
..
\\
simulator
\\
font
\\
font.bin"
);
GraphicStartUp
::
InitFontEngine
(
reinterpret_cast
<
uintptr_t
>
(
g_fontMemBaseAddr
),
MIN_FONT_PSRAM_LENGTH
,
dPath
.
c_str
(),
nullptr
);
#endif
#if ENABLE_ICU
GraphicStartUp
::
InitLineBreakEngine
(
reinterpret_cast
<
uintptr_t
>
(
g_icuMemBaseAddr
),
SHAPING_WORD_DICT_LENGTH
,
VECTOR_FONT_DIR
,
DEFAULT_LINE_BREAK_RULE_FILENAME
);
...
...
tools/qt/simulator/libui/libui.pro
浏览文件 @
7e8c8e03
...
...
@@ -36,7 +36,6 @@ SOURCES += \
..
/../../../
frameworks
/
common
/
task
.
cpp
\
..
/../../../
frameworks
/
common
/
text
.
cpp
\
..
/../../../
frameworks
/
common
/
typed_text
.
cpp
\
..
/../../../
frameworks
/
common
/
ui_font_header
.
cpp
\
..
/../../../
frameworks
/
components
/
root_view
.
cpp
\
..
/../../../
frameworks
/
components
/
text_adapter
.
cpp
\
..
/../../../
frameworks
/
components
/
ui_abstract_clock
.
cpp
\
...
...
@@ -99,6 +98,8 @@ SOURCES += \
..
/../../../
frameworks
/
font
/
ui_font
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_adaptor
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_allocator
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_bitmap
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_builder
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_cache
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_vector
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_line_break
.
cpp
\
...
...
@@ -155,6 +156,7 @@ HEADERS += \
..
/../../../
interfaces
/
innerkits
/
dock
/
rotate_input_device
.
h
\
..
/../../../
interfaces
/
innerkits
/
engines
/
gfx
/
gfx_engine_manager
.
h
\
..
/../../../
interfaces
/
innerkits
/
dock
/
vibrator_manager
.
h
\
..
/../../../
interfaces
/
innerkits
/
font
/
ui_font_builder
.
h
\
..
/../../../
interfaces
/
kits
/
animator
/
animator
.
h
\
..
/../../../
interfaces
/
kits
/
animator
/
easing_equation
.
h
\
..
/../../../
interfaces
/
kits
/
animator
/
interpolation
.
h
\
...
...
tools/qt/simulator/test/test.pro
浏览文件 @
7e8c8e03
...
...
@@ -11,7 +11,8 @@ CONFIG += c++11
#
deprecated
API
in
order
to
know
how
to
port
your
code
away
from
it
.
DEFINES
+=
QT_DEPRECATED_WARNINGS
\
"ENABLE_ICU=1"
\
"ENABLE_VECTOR_FONT=1"
"ENABLE_VECTOR_FONT=1"
\
"ENABLE_BITMAP_FONT=0"
DEFINES
+=
QT_COMPILER
...
...
@@ -23,6 +24,7 @@ DEFINES += QT_COMPILER
DESTDIR
=
..
/
libs
SOURCES
+=
\
..
/../../../
test
/
framework
/
common
/
ui_text_language
.
cpp
\
..
/../../../
test
/
framework
/
src
/
test_case_list_adapter
.
cpp
\
..
/../../../
test
/
framework
/
src
/
ui_test_group
.
cpp
\
..
/../../../
test
/
framework
/
src
/
test_ability
.
cpp
\
...
...
@@ -77,6 +79,7 @@ SOURCES += \
..
/../../../
test
/
uitest
/
test_render
/
ui_auto_test_render
.
cpp
\
HEADERS
+=
\
..
/../../../
test
/
framework
/
common
/
ui_text_language
.
h
\
..
/../../../
test
/
framework
/
include
/
test_case_list_adapter
.
h
\
..
/../../../
test
/
framework
/
include
/
ui_test_app
.
h
\
..
/../../../
test
/
framework
/
include
/
test_resource_config
.
h
\
...
...
@@ -138,6 +141,7 @@ INCLUDEPATH += \
..
/../../../../
ui
/
interfaces
/
frameworks
\
..
/../../../../
ui
/
interfaces
/
innerkits
\
..
/../../../../
ui
/
interfaces
/
kits
\
..
/../../../
test
/
framework
\
..
/../../../
test
/
framework
/
include
\
..
/../../../
test
/
uitest
\
..
/../../../../../../
third_party
/
bounds_checking_function
/
include
\
...
...
tools/qt/simulator/uitest/UITest.pro
浏览文件 @
7e8c8e03
...
...
@@ -42,7 +42,6 @@ SOURCES += \
..
/../../../
frameworks
/
common
/
task
.
cpp
\
..
/../../../
frameworks
/
common
/
text
.
cpp
\
..
/../../../
frameworks
/
common
/
typed_text
.
cpp
\
..
/../../../
frameworks
/
common
/
ui_font_header
.
cpp
\
..
/../../../
frameworks
/
components
/
root_view
.
cpp
\
..
/../../../
frameworks
/
components
/
text_adapter
.
cpp
\
..
/../../../
frameworks
/
components
/
ui_abstract_clock
.
cpp
\
...
...
@@ -104,6 +103,8 @@ SOURCES += \
..
/../../../
frameworks
/
font
/
ui_font
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_adaptor
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_allocator
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_bitmap
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_builder
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_cache
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_font_vector
.
cpp
\
..
/../../../
frameworks
/
font
/
ui_line_break
.
cpp
\
...
...
@@ -130,6 +131,7 @@ SOURCES += \
..
/../../../../../../
third_party
/
cJSON
/
cJSON
.
c
SOURCES
+=
\
..
/../../../
test
/
framework
/
common
/
ui_text_language
.
cpp
\
..
/../../../
test
/
framework
/
src
/
test_case_list_adapter
.
cpp
\
..
/../../../
test
/
framework
/
src
/
ui_test_group
.
cpp
\
..
/../../../
test
/
framework
/
src
/
test_ability
.
cpp
\
...
...
@@ -223,6 +225,7 @@ HEADERS += \
..
/../../../
interfaces
/
innerkits
/
dock
/
focus_manager
.
h
\
..
/../../../
interfaces
/
innerkits
/
dock
/
rotate_input_device
.
h
\
..
/../../../
interfaces
/
innerkits
/
dock
/
vibrator_manager
.
h
\
..
/../../../
interfaces
/
innerkits
/
font
/
ui_font_builder
.
h
\
..
/../../../
interfaces
/
innerkits
/
engines
/
gfx
/
gfx_engine_manager
.
h
\
..
/../../../
interfaces
/
kits
/
animator
/
animator
.
h
\
..
/../../../
interfaces
/
kits
/
animator
/
easing_equation
.
h
\
...
...
@@ -319,6 +322,7 @@ HEADERS += \
..
/../../../../../../
tools
/
developer_tools_lite
/
graphic_tool
/
iar_project
/
config
/
gpu_2d
/
graphic_config
.
h
HEADERS
+=
\
..
/../../../
test
/
framework
/
common
/
ui_text_language
.
h
\
..
/../../../
test
/
framework
/
include
/
test_case_list_adapter
.
h
\
..
/../../../
test
/
framework
/
include
/
ui_test_app
.
h
\
..
/../../../
test
/
framework
/
include
/
test_resource_config
.
h
\
...
...
@@ -389,6 +393,7 @@ INCLUDEPATH += \
..
/
drivers
/
indev
\
..
/
drivers
\
..
/../../../
frameworks
\
..
/../../../
test
/
framework
\
..
/../../../
test
/
framework
/
include
\
..
/../../../
test
/
uitest
\
..
/../../../../
utils
/
frameworks
/
windows
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录