Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
2db93a74
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
未验证
提交
2db93a74
编写于
7月 16, 2021
作者:
H
Harry Terkelsen
提交者:
GitHub
7月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Place Emoji fallback font at the front of the list (#27491)
上级
51104bb2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
56 deletion
+96
-56
lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart
lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart
+34
-17
lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart
lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart
+62
-39
未找到文件。
lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart
浏览文件 @
2db93a74
...
...
@@ -126,7 +126,8 @@ class FontFallbackData {
fonts
.
addAll
(
typefacesForFamily
);
}
}
final
List
<
bool
>
codeUnitsSupported
=
List
<
bool
>.
filled
(
codeUnits
.
length
,
false
);
final
List
<
bool
>
codeUnitsSupported
=
List
<
bool
>.
filled
(
codeUnits
.
length
,
false
);
final
String
testString
=
String
.
fromCharCodes
(
codeUnits
);
for
(
SkFont
font
in
fonts
)
{
final
Uint8List
glyphs
=
font
.
getGlyphIDs
(
testString
);
...
...
@@ -167,11 +168,13 @@ class FontFallbackData {
// fonts. Check them and update the cache.
final
List
<
int
>
codeUnits
=
_codeUnitsToCheckAgainstFallbackFonts
.
toList
();
_codeUnitsToCheckAgainstFallbackFonts
.
clear
();
final
List
<
bool
>
codeUnitsSupported
=
List
<
bool
>.
filled
(
codeUnits
.
length
,
false
);
final
List
<
bool
>
codeUnitsSupported
=
List
<
bool
>.
filled
(
codeUnits
.
length
,
false
);
final
String
testString
=
String
.
fromCharCodes
(
codeUnits
);
for
(
String
font
in
globalFontFallbacks
)
{
final
List
<
SkFont
>?
fontsForFamily
=
skiaFontCollection
.
familyToFontMap
[
font
];
final
List
<
SkFont
>?
fontsForFamily
=
skiaFontCollection
.
familyToFontMap
[
font
];
if
(
fontsForFamily
==
null
)
{
printWarning
(
'A fallback font was registered but we '
'cannot retrieve the typeface for it.'
);
...
...
@@ -227,8 +230,20 @@ class FontFallbackData {
final
int
fontFallbackTag
=
fontFallbackCounts
[
family
]!;
fontFallbackCounts
[
family
]
=
fontFallbackCounts
[
family
]!
+
1
;
final
String
countedFamily
=
'
$family
$fontFallbackTag
'
;
// Insert emoji font before all other fallback fonts so we use the emoji
// whenever it's available.
registeredFallbackFonts
.
add
(
RegisteredFont
(
bytes
,
countedFamily
,
typeface
));
globalFontFallbacks
.
add
(
countedFamily
);
// Insert emoji font before all other fallback fonts so we use the emoji
// whenever it's available.
if
(
family
==
'Noto Color Emoji Compat'
)
{
if
(
globalFontFallbacks
.
first
==
'Roboto'
)
{
globalFontFallbacks
.
insert
(
1
,
countedFamily
);
}
else
{
globalFontFallbacks
.
insert
(
0
,
countedFamily
);
}
}
else
{
globalFontFallbacks
.
add
(
countedFamily
);
}
}
}
...
...
@@ -351,14 +366,16 @@ _ResolvedNotoFont? _makeResolvedNotoFontFromCss(String css, String name) {
if
(
startEnd
.
length
==
1
)
{
final
String
singleRange
=
startEnd
.
single
;
assert
(
singleRange
.
startsWith
(
'U+'
));
final
int
rangeValue
=
int
.
parse
(
singleRange
.
substring
(
2
),
radix:
16
);
final
int
rangeValue
=
int
.
parse
(
singleRange
.
substring
(
2
),
radix:
16
);
fontFaceUnicodeRanges
.
add
(
CodeunitRange
(
rangeValue
,
rangeValue
));
}
else
{
assert
(
startEnd
.
length
==
2
);
final
String
startRange
=
startEnd
[
0
];
final
String
endRange
=
startEnd
[
1
];
assert
(
startRange
.
startsWith
(
'U+'
));
final
int
startValue
=
int
.
parse
(
startRange
.
substring
(
2
),
radix:
16
);
final
int
startValue
=
int
.
parse
(
startRange
.
substring
(
2
),
radix:
16
);
final
int
endValue
=
int
.
parse
(
endRange
,
radix:
16
);
fontFaceUnicodeRanges
.
add
(
CodeunitRange
(
startValue
,
endValue
));
}
...
...
@@ -410,15 +427,15 @@ Future<void> _registerSymbolsAndEmoji() async {
return
;
}
data
.
registeredSymbolsAndEmoji
=
true
;
const
String
symbolsUrl
=
'https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols'
;
const
String
emojiUrl
=
'https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat'
;
const
String
symbolsUrl
=
'https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols'
;
final
String
symbolsCss
=
await
notoDownloadQueue
.
downloader
.
downloadAsString
(
symbolsUrl
);
final
String
emojiCss
=
await
notoDownloadQueue
.
downloader
.
downloadAsString
(
emojiUrl
);
final
String
symbolsCss
=
await
notoDownloadQueue
.
downloader
.
downloadAsString
(
symbolsUrl
);
String
?
extractUrlFromCss
(
String
css
)
{
for
(
final
String
line
in
LineSplitter
.
split
(
css
))
{
...
...
@@ -436,21 +453,21 @@ Future<void> _registerSymbolsAndEmoji() async {
return
null
;
}
final
String
?
symbolsFontUrl
=
extractUrlFromCss
(
symbolsCss
);
final
String
?
emojiFontUrl
=
extractUrlFromCss
(
emojiCss
);
final
String
?
symbolsFontUrl
=
extractUrlFromCss
(
symbolsCss
);
if
(
symbols
FontUrl
!=
null
)
{
if
(
emoji
FontUrl
!=
null
)
{
notoDownloadQueue
.
add
(
_ResolvedNotoSubset
(
symbolsFontUrl
,
'Noto Sans Symbols
'
,
const
<
CodeunitRange
>[]));
emojiFontUrl
,
'Noto Color Emoji Compat
'
,
const
<
CodeunitRange
>[]));
}
else
{
printWarning
(
'Error parsing CSS for Noto
Symbols
font.'
);
printWarning
(
'Error parsing CSS for Noto
Emoji
font.'
);
}
if
(
emoji
FontUrl
!=
null
)
{
if
(
symbols
FontUrl
!=
null
)
{
notoDownloadQueue
.
add
(
_ResolvedNotoSubset
(
emojiFontUrl
,
'Noto Color Emoji Compat
'
,
const
<
CodeunitRange
>[]));
symbolsFontUrl
,
'Noto Sans Symbols
'
,
const
<
CodeunitRange
>[]));
}
else
{
printWarning
(
'Error parsing CSS for Noto
Emoji
font.'
);
printWarning
(
'Error parsing CSS for Noto
Symbols
font.'
);
}
}
...
...
lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart
浏览文件 @
2db93a74
...
...
@@ -56,24 +56,6 @@ void testMain() {
});
test
(
'will download Noto Naskh Arabic if Arabic text is added'
,
()
async
{
final
Completer
<
void
>
fontChangeCompleter
=
Completer
<
void
>();
// Intercept the system font change message.
ui
.
window
.
onPlatformMessage
=
(
String
name
,
ByteData
?
data
,
ui
.
PlatformMessageResponseCallback
?
callback
)
{
if
(
name
==
'flutter/system'
)
{
const
JSONMessageCodec
codec
=
JSONMessageCodec
();
final
dynamic
message
=
codec
.
decodeMessage
(
data
);
if
(
message
is
Map
)
{
if
(
message
[
'type'
]
==
'fontsChange'
)
{
fontChangeCompleter
.
complete
();
}
}
}
if
(
savedCallback
!=
null
)
{
savedCallback
!(
name
,
data
,
callback
);
}
};
TestDownloader
.
mockDownloads
[
'https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic+UI'
]
=
'''
...
...
@@ -98,7 +80,7 @@ void testMain() {
EnginePlatformDispatcher
.
instance
.
rasterizer
!
.
debugRunPostFrameCallbacks
();
await
fontChangeCompleter
.
future
;
await
notoDownloadQueue
.
debugWhenIdle
()
;
expect
(
FontFallbackData
.
instance
.
globalFontFallbacks
,
contains
(
'Noto Naskh Arabic UI 0'
));
...
...
@@ -123,30 +105,71 @@ void testMain() {
// TODO: https://github.com/flutter/flutter/issues/71520
},
skip:
isIosSafari
||
isFirefox
);
test
(
'will
download Noto Emojis and Noto Symbols if no matching Noto Fon
t'
,
test
(
'will
put the Noto Emoji font before other fallback fonts in the lis
t'
,
()
async
{
final
Completer
<
void
>
fontChangeCompleter
=
Completer
<
void
>();
// Intercept the system font change message.
ui
.
window
.
onPlatformMessage
=
(
String
name
,
ByteData
?
data
,
ui
.
PlatformMessageResponseCallback
?
callback
)
{
if
(
name
==
'flutter/system'
)
{
const
JSONMessageCodec
codec
=
JSONMessageCodec
();
final
dynamic
message
=
codec
.
decodeMessage
(
data
);
if
(
message
is
Map
)
{
if
(
message
[
'type'
]
==
'fontsChange'
)
{
fontChangeCompleter
.
complete
();
}
}
}
if
(
savedCallback
!=
null
)
{
savedCallback
!(
name
,
data
,
callback
);
}
};
TestDownloader
.
mockDownloads
[
'https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat'
]
=
'''
@font-face {
font-family: '
Noto
Color
Emoji
';
src: url(packages/ui/assets/NotoColorEmoji.ttf) format('
ttf
');
}
'''
;
TestDownloader
.
mockDownloads
[
'https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic+UI'
]
=
'''
/* arabic */
@font-face {
font-family: '
Noto
Naskh
Arabic
UI
';
font-style: normal;
font-weight: 400;
src: url(packages/ui/assets/NotoNaskhArabic-Regular.ttf) format('
ttf
');
unicode-range: U+0600-06FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE80-FEFC;
}
'''
;
expect
(
FontFallbackData
.
instance
.
globalFontFallbacks
,
<
String
>[
'Roboto'
]);
// Creating this paragraph should cause us to start to download the
// Arabic fallback font.
CkParagraphBuilder
pb
=
CkParagraphBuilder
(
CkParagraphStyle
(),
);
pb
.
addText
(
'مرحبا'
);
EnginePlatformDispatcher
.
instance
.
rasterizer
!
.
debugRunPostFrameCallbacks
();
await
notoDownloadQueue
.
debugWhenIdle
();
expect
(
FontFallbackData
.
instance
.
globalFontFallbacks
,
<
String
>[
'Roboto'
,
'Noto Naskh Arabic UI 0'
]);
pb
=
CkParagraphBuilder
(
CkParagraphStyle
(),
);
pb
.
pushStyle
(
ui
.
TextStyle
(
fontSize:
26
));
pb
.
addText
(
'Hello 😊 مرحبا'
);
pb
.
pop
();
final
CkParagraph
paragraph
=
pb
.
build
();
paragraph
.
layout
(
ui
.
ParagraphConstraints
(
width:
1000
));
EnginePlatformDispatcher
.
instance
.
rasterizer
!
.
debugRunPostFrameCallbacks
();
await
notoDownloadQueue
.
debugWhenIdle
();
expect
(
FontFallbackData
.
instance
.
globalFontFallbacks
,
<
String
>[
'Roboto'
,
'Noto Color Emoji Compat 0'
,
'Noto Naskh Arabic UI 0'
,
]);
});
test
(
'will download Noto Emojis and Noto Symbols if no matching Noto Font'
,
()
async
{
TestDownloader
.
mockDownloads
[
'https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat'
]
=
'''
@font-face {
font-family: '
Noto
Color
Emoji
';
src: url(packages/ui/assets/NotoColorEmoji.ttf) format('
ttf
');
...
...
@@ -164,7 +187,7 @@ void testMain() {
EnginePlatformDispatcher
.
instance
.
rasterizer
!
.
debugRunPostFrameCallbacks
();
await
fontChangeCompleter
.
future
;
await
notoDownloadQueue
.
debugWhenIdle
()
;
expect
(
FontFallbackData
.
instance
.
globalFontFallbacks
,
contains
(
'Noto Color Emoji Compat 0'
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录