Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
8d6fa7e8
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,发现更多精彩内容 >>
未验证
提交
8d6fa7e8
编写于
11月 27, 2019
作者:
H
Harry Terkelsen
提交者:
GitHub
11月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fallback to Roboto if no suitable font is found (#14061)
上级
6c605f8a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
8 deletion
+22
-8
lib/web_ui/lib/src/engine/compositor/fonts.dart
lib/web_ui/lib/src/engine/compositor/fonts.dart
+17
-0
lib/web_ui/lib/src/engine/compositor/text.dart
lib/web_ui/lib/src/engine/compositor/text.dart
+5
-8
未找到文件。
lib/web_ui/lib/src/engine/compositor/fonts.dart
浏览文件 @
8d6fa7e8
...
...
@@ -4,9 +4,14 @@
part of
engine
;
const
String
_robotoUrl
=
'http://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf'
;
class
SkiaFontCollection
{
final
List
<
Future
<
ByteBuffer
>>
_loadingFontBuffers
=
<
Future
<
ByteBuffer
>>[];
final
Set
<
String
>
registeredFamilies
=
<
String
>{};
Future
<
void
>
ensureFontsLoaded
()
async
{
final
List
<
Uint8List
>
fontBuffers
=
(
await
Future
.
wait
<
ByteBuffer
>(
_loadingFontBuffers
))
...
...
@@ -46,6 +51,8 @@ class SkiaFontCollection {
final
String
family
=
fontFamily
[
'family'
];
final
List
<
dynamic
>
fontAssets
=
fontFamily
[
'fonts'
];
registeredFamilies
.
add
(
family
);
for
(
dynamic
fontAssetItem
in
fontAssets
)
{
final
Map
<
String
,
dynamic
>
fontAsset
=
fontAssetItem
;
final
String
asset
=
fontAsset
[
'asset'
];
...
...
@@ -54,6 +61,16 @@ class SkiaFontCollection {
.
then
((
dynamic
fetchResult
)
=>
fetchResult
.
arrayBuffer
()));
}
}
/// We need a default fallback font for CanvasKit, in order to
/// avoid crashing while laying out text with an unregistered font. We chose
/// Roboto to match Android.
if
(!
registeredFamilies
.
contains
(
'Roboto'
))
{
// Download Roboto and add it to the font buffers.
_loadingFontBuffers
.
add
(
html
.
window
.
fetch
(
_robotoUrl
)
.
then
((
dynamic
fetchResult
)
=>
fetchResult
.
arrayBuffer
()));
}
}
js
.
JsObject
skFontMgr
;
...
...
lib/web_ui/lib/src/engine/compositor/text.dart
浏览文件 @
8d6fa7e8
...
...
@@ -9,17 +9,12 @@ part of engine;
/// fonts. CanvasKit reads the font name from the font's bytes. So, we map
/// some common family names to how they are registered in the Gallery app.
const
Map
<
String
,
String
>
_fontFamilyOverrides
=
<
String
,
String
>{
'Roboto'
:
'Google Sans'
,
'GoogleSans'
:
'Google Sans'
,
'GoogleSansDisplay'
:
'Google Sans Display'
,
'MaterialIcons'
:
'Material Icons'
,
'LibreFranklin'
:
'LibreFranklin'
,
'LibreFranklin'
:
'Libre
Franklin'
,
'AbrilFatface'
:
'Abril Fatface'
,
'packages/cupertino_icons/CupertinoIcons'
:
'CupertinoIcons'
,
'.SF Pro Text'
:
'Google Sans'
,
'.SF Pro Display'
:
'Google Sans'
,
'.SF UI Text'
:
'Google Sans'
,
'.SF UI Display'
:
'Google Sans'
,
};
class
SkParagraphStyle
implements
ui
.
ParagraphStyle
{
...
...
@@ -71,7 +66,8 @@ class SkParagraphStyle implements ui.ParagraphStyle {
skTextStyle
[
'fontSize'
]
=
fontSize
;
}
if
(
fontFamily
==
null
)
{
if
(
fontFamily
==
null
||
!
skiaFontCollection
.
registeredFamilies
.
contains
(
fontFamily
))
{
fontFamily
=
'Roboto'
;
}
if
(
_fontFamilyOverrides
.
containsKey
(
fontFamily
))
{
...
...
@@ -205,7 +201,8 @@ class SkTextStyle implements ui.TextStyle {
style
[
'fontSize'
]
=
fontSize
;
}
if
(
fontFamily
==
null
)
{
if
(
fontFamily
==
null
||
!
skiaFontCollection
.
registeredFamilies
.
contains
(
fontFamily
))
{
fontFamily
=
'Roboto'
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录