Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
f2e7441b
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f2e7441b
编写于
10月 12, 2018
作者:
J
Jason Simmons
提交者:
GitHub
10月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
An API for loading fonts from a buffer provided by the application (#6508)
上级
05aac0f2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
96 addition
and
2 deletion
+96
-2
lib/ui/dart_ui.cc
lib/ui/dart_ui.cc
+2
-0
lib/ui/text.dart
lib/ui/text.dart
+13
-0
lib/ui/text/font_collection.cc
lib/ui/text/font_collection.cc
+50
-1
lib/ui/text/font_collection.h
lib/ui/text/font_collection.h
+11
-0
third_party/txt/src/txt/asset_font_manager.h
third_party/txt/src/txt/asset_font_manager.h
+12
-1
third_party/txt/src/txt/font_collection.cc
third_party/txt/src/txt/font_collection.cc
+6
-0
third_party/txt/src/txt/font_collection.h
third_party/txt/src/txt/font_collection.h
+2
-0
未找到文件。
lib/ui/dart_ui.cc
浏览文件 @
f2e7441b
...
...
@@ -24,6 +24,7 @@
#include "flutter/lib/ui/painting/vertices.h"
#include "flutter/lib/ui/semantics/semantics_update.h"
#include "flutter/lib/ui/semantics/semantics_update_builder.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/text/paragraph.h"
#include "flutter/lib/ui/text/paragraph_builder.h"
#include "flutter/lib/ui/window/window.h"
...
...
@@ -72,6 +73,7 @@ void DartUI::InitForGlobal() {
Codec
::
RegisterNatives
(
g_natives
);
DartRuntimeHooks
::
RegisterNatives
(
g_natives
);
EngineLayer
::
RegisterNatives
(
g_natives
);
FontCollection
::
RegisterNatives
(
g_natives
);
FrameInfo
::
RegisterNatives
(
g_natives
);
ImageFilter
::
RegisterNatives
(
g_natives
);
ImageShader
::
RegisterNatives
(
g_natives
);
...
...
lib/ui/text.dart
浏览文件 @
f2e7441b
...
...
@@ -1087,3 +1087,16 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 {
/// cannot be used further.
Paragraph
build
()
native
'ParagraphBuilder_build'
;
}
/// Loads a font from a buffer and makes it available for rendering text.
///
/// * `list`: A list of bytes containing the font file.
/// * `fontFamily`: The family name used to identify the font in text styles.
/// If this is not provided, then the family name will be extracted from the font file.
Future
<
void
>
loadFontFromList
(
Uint8List
list
,
{
String
fontFamily
})
{
return
_futurize
(
(
_Callback
<
void
>
callback
)
=>
_loadFontFromList
(
list
,
callback
,
fontFamily
)
);
}
String
_loadFontFromList
(
Uint8List
list
,
_Callback
<
void
>
callback
,
String
fontFamily
)
native
'loadFontFromList'
;
lib/ui/text/font_collection.cc
浏览文件 @
f2e7441b
...
...
@@ -7,6 +7,8 @@
#include <mutex>
#include "flutter/lib/ui/text/asset_manager_font_provider.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/runtime/test_font_data.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
...
...
@@ -14,15 +16,40 @@
#include "third_party/skia/include/core/SkGraphics.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/tonic/dart_args.h"
#include "third_party/tonic/dart_library_natives.h"
#include "third_party/tonic/logging/dart_invoke.h"
#include "third_party/tonic/typed_data/uint8_list.h"
#include "txt/asset_font_manager.h"
#include "txt/test_font_manager.h"
#include "txt/typeface_font_asset_provider.h"
namespace
blink
{
namespace
{
void
LoadFontFromList
(
tonic
::
Uint8List
&
font_data
,
Dart_Handle
callback
,
std
::
string
family_name
)
{
FontCollection
&
font_collection
=
UIDartState
::
Current
()
->
window
()
->
client
()
->
GetFontCollection
();
font_collection
.
LoadFontFromList
(
font_data
.
data
(),
font_data
.
num_elements
(),
family_name
);
font_data
.
Release
();
tonic
::
DartInvoke
(
callback
,
{
tonic
::
ToDart
(
0
)});
}
void
_LoadFontFromList
(
Dart_NativeArguments
args
)
{
tonic
::
DartCallStatic
(
LoadFontFromList
,
args
);
}
}
// namespace
FontCollection
::
FontCollection
()
:
collection_
(
std
::
make_shared
<
txt
::
FontCollection
>
())
{
collection_
->
SetDefaultFontManager
(
SkFontMgr
::
RefDefault
());
dynamic_font_manager_
=
sk_make_sp
<
txt
::
DynamicFontManager
>
();
collection_
->
SetDynamicFontManager
(
dynamic_font_manager_
);
}
FontCollection
::~
FontCollection
()
{
...
...
@@ -30,6 +57,12 @@ FontCollection::~FontCollection() {
SkGraphics
::
PurgeFontCache
();
}
void
FontCollection
::
RegisterNatives
(
tonic
::
DartLibraryNatives
*
natives
)
{
natives
->
Register
({
{
"loadFontFromList"
,
_LoadFontFromList
,
3
,
true
},
});
}
std
::
shared_ptr
<
txt
::
FontCollection
>
FontCollection
::
GetFontCollection
()
const
{
return
collection_
;
}
...
...
@@ -110,4 +143,20 @@ void FontCollection::RegisterTestFonts() {
collection_
->
DisableFontFallback
();
}
void
FontCollection
::
LoadFontFromList
(
const
uint8_t
*
font_data
,
int
length
,
std
::
string
family_name
)
{
std
::
unique_ptr
<
SkStreamAsset
>
font_stream
=
std
::
make_unique
<
SkMemoryStream
>
(
font_data
,
length
,
true
);
sk_sp
<
SkTypeface
>
typeface
=
SkTypeface
::
MakeFromStream
(
std
::
move
(
font_stream
));
txt
::
TypefaceFontAssetProvider
&
font_provider
=
dynamic_font_manager_
->
font_provider
();
if
(
family_name
.
empty
())
{
font_provider
.
RegisterTypeface
(
typeface
);
}
else
{
font_provider
.
RegisterTypeface
(
typeface
,
family_name
);
}
}
}
// namespace blink
lib/ui/text/font_collection.h
浏览文件 @
f2e7441b
...
...
@@ -13,6 +13,10 @@
#include "flutter/fml/memory/ref_ptr.h"
#include "txt/font_collection.h"
namespace
tonic
{
class
DartLibraryNatives
;
}
// namespace tonic
namespace
blink
{
class
FontCollection
{
...
...
@@ -21,14 +25,21 @@ class FontCollection {
~
FontCollection
();
static
void
RegisterNatives
(
tonic
::
DartLibraryNatives
*
natives
);
std
::
shared_ptr
<
txt
::
FontCollection
>
GetFontCollection
()
const
;
void
RegisterFonts
(
fml
::
RefPtr
<
AssetManager
>
asset_manager
);
void
RegisterTestFonts
();
void
LoadFontFromList
(
const
uint8_t
*
font_data
,
int
length
,
std
::
string
family_name
);
private:
std
::
shared_ptr
<
txt
::
FontCollection
>
collection_
;
sk_sp
<
txt
::
DynamicFontManager
>
dynamic_font_manager_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
FontCollection
);
};
...
...
third_party/txt/src/txt/asset_font_manager.h
浏览文件 @
f2e7441b
...
...
@@ -22,6 +22,7 @@
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkStream.h"
#include "txt/font_asset_provider.h"
#include "txt/typeface_font_asset_provider.h"
namespace
txt
{
...
...
@@ -35,9 +36,9 @@ class AssetFontManager : public SkFontMgr {
// |SkFontMgr|
SkFontStyleSet
*
onMatchFamily
(
const
char
familyName
[])
const
override
;
private:
std
::
unique_ptr
<
FontAssetProvider
>
font_provider_
;
private:
// |SkFontMgr|
int
onCountFamilies
()
const
override
;
...
...
@@ -84,6 +85,16 @@ class AssetFontManager : public SkFontMgr {
FML_DISALLOW_COPY_AND_ASSIGN
(
AssetFontManager
);
};
class
DynamicFontManager
:
public
AssetFontManager
{
public:
DynamicFontManager
()
:
AssetFontManager
(
std
::
make_unique
<
TypefaceFontAssetProvider
>
())
{}
TypefaceFontAssetProvider
&
font_provider
()
{
return
static_cast
<
TypefaceFontAssetProvider
&>
(
*
font_provider_
);
}
};
}
// namespace txt
#endif // TXT_ASSET_FONT_MANAGER_H_
third_party/txt/src/txt/font_collection.cc
浏览文件 @
f2e7441b
...
...
@@ -84,6 +84,10 @@ void FontCollection::SetAssetFontManager(sk_sp<SkFontMgr> font_manager) {
asset_font_manager_
=
font_manager
;
}
void
FontCollection
::
SetDynamicFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
)
{
dynamic_font_manager_
=
font_manager
;
}
void
FontCollection
::
SetTestFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
)
{
test_font_manager_
=
font_manager
;
}
...
...
@@ -93,6 +97,8 @@ std::vector<sk_sp<SkFontMgr>> FontCollection::GetFontManagerOrder() const {
std
::
vector
<
sk_sp
<
SkFontMgr
>>
order
;
if
(
test_font_manager_
)
order
.
push_back
(
test_font_manager_
);
if
(
dynamic_font_manager_
)
order
.
push_back
(
dynamic_font_manager_
);
if
(
asset_font_manager_
)
order
.
push_back
(
asset_font_manager_
);
if
(
default_font_manager_
)
...
...
third_party/txt/src/txt/font_collection.h
浏览文件 @
f2e7441b
...
...
@@ -42,6 +42,7 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
void
SetDefaultFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
);
void
SetAssetFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
);
void
SetDynamicFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
);
void
SetTestFontManager
(
sk_sp
<
SkFontMgr
>
font_manager
);
std
::
shared_ptr
<
minikin
::
FontCollection
>
GetMinikinFontCollectionForFamily
(
...
...
@@ -73,6 +74,7 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
sk_sp
<
SkFontMgr
>
default_font_manager_
;
sk_sp
<
SkFontMgr
>
asset_font_manager_
;
sk_sp
<
SkFontMgr
>
dynamic_font_manager_
;
sk_sp
<
SkFontMgr
>
test_font_manager_
;
std
::
unordered_map
<
FamilyKey
,
std
::
shared_ptr
<
minikin
::
FontCollection
>
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录