mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add Ahem as a test font in CanvasKit mode (flutter/engine#27652)
* Add Ahem as a test font in CanvasKit mode * Don't enable `debugEmulateFlutterDriver` by default since tests use platform channels. * Update goldens lock
This commit is contained in:
parent
eab06ef188
commit
397d6c2435
@ -1,2 +1,2 @@
|
||||
repository: https://github.com/flutter/goldens.git
|
||||
revision: 364782e0e6afb9e977524395c4376916340bf176
|
||||
revision: f1baad46498ce1a754a15d02249827bb042b446b
|
||||
|
||||
@ -19,6 +19,9 @@ import 'font_fallbacks.dart';
|
||||
const String _robotoUrl =
|
||||
'https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf';
|
||||
|
||||
// URL for the Ahem font, only used in tests.
|
||||
const String _ahemUrl = 'packages/ui/assets/ahem.ttf';
|
||||
|
||||
/// Manages the fonts used in the Skia-based backend.
|
||||
class SkiaFontCollection {
|
||||
/// Fonts that have been registered but haven't been loaded yet.
|
||||
@ -47,7 +50,8 @@ class SkiaFontCollection {
|
||||
.add(SkFont(font.typeface));
|
||||
}
|
||||
|
||||
for (RegisteredFont font in FontFallbackData.instance.registeredFallbackFonts) {
|
||||
for (RegisteredFont font
|
||||
in FontFallbackData.instance.registeredFallbackFonts) {
|
||||
fontProvider!.registerFont(font.bytes, font.family);
|
||||
familyToFontMap
|
||||
.putIfAbsent(font.family, () => <SkFont>[])
|
||||
@ -139,6 +143,11 @@ class SkiaFontCollection {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> debugRegisterTestFonts() async {
|
||||
_unloadedFonts.add(_registerFont(_ahemUrl, 'Ahem'));
|
||||
FontFallbackData.instance.globalFontFallbacks.add('Ahem');
|
||||
}
|
||||
|
||||
Future<RegisteredFont?> _registerFont(String url, String family) async {
|
||||
ByteBuffer buffer;
|
||||
try {
|
||||
@ -162,7 +171,8 @@ class SkiaFontCollection {
|
||||
}
|
||||
|
||||
String? _readActualFamilyName(Uint8List bytes) {
|
||||
final SkFontMgr tmpFontMgr = canvasKit.FontMgr.FromData(<Uint8List>[bytes])!;
|
||||
final SkFontMgr tmpFontMgr =
|
||||
canvasKit.FontMgr.FromData(<Uint8List>[bytes])!;
|
||||
final String? actualFamily = tmpFontMgr.getFamilyName(0);
|
||||
tmpFontMgr.delete();
|
||||
return actualFamily;
|
||||
|
||||
@ -7,7 +7,8 @@ part of ui;
|
||||
Future<void> webOnlyInitializePlatform({
|
||||
engine.AssetManager? assetManager,
|
||||
}) {
|
||||
final Future<void> initializationFuture = _initializePlatform(assetManager: assetManager);
|
||||
final Future<void> initializationFuture =
|
||||
_initializePlatform(assetManager: assetManager);
|
||||
scheduleMicrotask(() {
|
||||
// Access [engine.lineLookup] to force the lazy unpacking of line break data
|
||||
// now. Removing this line won't break anything. It's just an optimization
|
||||
@ -46,7 +47,8 @@ engine.FontCollection? _fontCollection;
|
||||
bool _webOnlyIsInitialized = false;
|
||||
bool get webOnlyIsInitialized => _webOnlyIsInitialized;
|
||||
Future<void> webOnlySetAssetManager(engine.AssetManager assetManager) async {
|
||||
assert(assetManager != null, 'Cannot set assetManager to null'); // ignore: unnecessary_null_comparison
|
||||
assert(assetManager != null,
|
||||
'Cannot set assetManager to null'); // ignore: unnecessary_null_comparison
|
||||
if (assetManager == _assetManager) {
|
||||
return;
|
||||
}
|
||||
@ -68,18 +70,24 @@ Future<void> webOnlySetAssetManager(engine.AssetManager assetManager) async {
|
||||
}
|
||||
}
|
||||
|
||||
if (debugEmulateFlutterTesterEnvironment && !engine.useCanvasKit) {
|
||||
_fontCollection!.debugRegisterTestFonts();
|
||||
if (debugEmulateFlutterTesterEnvironment) {
|
||||
if (engine.useCanvasKit) {
|
||||
engine.skiaFontCollection.debugRegisterTestFonts();
|
||||
} else {
|
||||
_fontCollection!.debugRegisterTestFonts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool get debugEmulateFlutterTesterEnvironment => _debugEmulateFlutterTesterEnvironment;
|
||||
bool get debugEmulateFlutterTesterEnvironment =>
|
||||
_debugEmulateFlutterTesterEnvironment;
|
||||
|
||||
set debugEmulateFlutterTesterEnvironment(bool value) {
|
||||
_debugEmulateFlutterTesterEnvironment = value;
|
||||
if (_debugEmulateFlutterTesterEnvironment) {
|
||||
const Size logicalSize = Size(800.0, 600.0);
|
||||
engine.window.webOnlyDebugPhysicalSizeOverride = logicalSize * window.devicePixelRatio;
|
||||
engine.window.webOnlyDebugPhysicalSizeOverride =
|
||||
logicalSize * window.devicePixelRatio;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user