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:
Harry Terkelsen
2021-07-23 12:13:26 -07:00
committed by GitHub
parent eab06ef188
commit 397d6c2435
3 changed files with 27 additions and 9 deletions

View File

@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git repository: https://github.com/flutter/goldens.git
revision: 364782e0e6afb9e977524395c4376916340bf176 revision: f1baad46498ce1a754a15d02249827bb042b446b

View File

@@ -19,6 +19,9 @@ import 'font_fallbacks.dart';
const String _robotoUrl = const String _robotoUrl =
'https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Me5WZLCzYlKw.ttf'; '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. /// Manages the fonts used in the Skia-based backend.
class SkiaFontCollection { class SkiaFontCollection {
/// Fonts that have been registered but haven't been loaded yet. /// Fonts that have been registered but haven't been loaded yet.
@@ -47,7 +50,8 @@ class SkiaFontCollection {
.add(SkFont(font.typeface)); .add(SkFont(font.typeface));
} }
for (RegisteredFont font in FontFallbackData.instance.registeredFallbackFonts) { for (RegisteredFont font
in FontFallbackData.instance.registeredFallbackFonts) {
fontProvider!.registerFont(font.bytes, font.family); fontProvider!.registerFont(font.bytes, font.family);
familyToFontMap familyToFontMap
.putIfAbsent(font.family, () => <SkFont>[]) .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 { Future<RegisteredFont?> _registerFont(String url, String family) async {
ByteBuffer buffer; ByteBuffer buffer;
try { try {
@@ -162,7 +171,8 @@ class SkiaFontCollection {
} }
String? _readActualFamilyName(Uint8List bytes) { 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); final String? actualFamily = tmpFontMgr.getFamilyName(0);
tmpFontMgr.delete(); tmpFontMgr.delete();
return actualFamily; return actualFamily;

View File

@@ -7,7 +7,8 @@ part of ui;
Future<void> webOnlyInitializePlatform({ Future<void> webOnlyInitializePlatform({
engine.AssetManager? assetManager, engine.AssetManager? assetManager,
}) { }) {
final Future<void> initializationFuture = _initializePlatform(assetManager: assetManager); final Future<void> initializationFuture =
_initializePlatform(assetManager: assetManager);
scheduleMicrotask(() { scheduleMicrotask(() {
// Access [engine.lineLookup] to force the lazy unpacking of line break data // 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 // now. Removing this line won't break anything. It's just an optimization
@@ -46,7 +47,8 @@ engine.FontCollection? _fontCollection;
bool _webOnlyIsInitialized = false; bool _webOnlyIsInitialized = false;
bool get webOnlyIsInitialized => _webOnlyIsInitialized; bool get webOnlyIsInitialized => _webOnlyIsInitialized;
Future<void> webOnlySetAssetManager(engine.AssetManager assetManager) async { 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) { if (assetManager == _assetManager) {
return; return;
} }
@@ -68,18 +70,24 @@ Future<void> webOnlySetAssetManager(engine.AssetManager assetManager) async {
} }
} }
if (debugEmulateFlutterTesterEnvironment && !engine.useCanvasKit) { if (debugEmulateFlutterTesterEnvironment) {
_fontCollection!.debugRegisterTestFonts(); if (engine.useCanvasKit) {
engine.skiaFontCollection.debugRegisterTestFonts();
} else {
_fontCollection!.debugRegisterTestFonts();
}
} }
} }
bool get debugEmulateFlutterTesterEnvironment => _debugEmulateFlutterTesterEnvironment; bool get debugEmulateFlutterTesterEnvironment =>
_debugEmulateFlutterTesterEnvironment;
set debugEmulateFlutterTesterEnvironment(bool value) { set debugEmulateFlutterTesterEnvironment(bool value) {
_debugEmulateFlutterTesterEnvironment = value; _debugEmulateFlutterTesterEnvironment = value;
if (_debugEmulateFlutterTesterEnvironment) { if (_debugEmulateFlutterTesterEnvironment) {
const Size logicalSize = Size(800.0, 600.0); const Size logicalSize = Size(800.0, 600.0);
engine.window.webOnlyDebugPhysicalSizeOverride = logicalSize * window.devicePixelRatio; engine.window.webOnlyDebugPhysicalSizeOverride =
logicalSize * window.devicePixelRatio;
} }
} }