[skwasm] Clear font collection cache when font is loaded manually. (#164588)

This addresses https://github.com/flutter/flutter/issues/159375

We just need to clear the font collection's cache if we added a font via
the `loadFontFromList` API.
This commit is contained in:
Jackson Gardner
2025-03-05 10:23:20 -08:00
committed by GitHub
parent 57cddce924
commit 1e9676fc95
2 changed files with 15 additions and 0 deletions

View File

@@ -180,6 +180,7 @@ class SkwasmFontCollection implements FlutterFontCollection {
} else {
fontCollectionRegisterTypeface(handle, typeface.handle, nullptr);
}
fontCollectionClearCaches(handle);
return true;
}

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
@@ -183,6 +184,19 @@ Future<void> testMain() async {
await testTextStyle('non-existent font family', fontFamily: 'DoesNotExist');
});
test('text styles - changes font after font manually loaded', () async {
await testTextStyle('before font load', fontFamily: 'Roboto Slab');
final FlutterFontCollection collection = renderer.fontCollection;
final ByteBuffer robotoSlabData = await httpFetchByteBuffer(
'/assets/fonts/RobotoSlab-VariableFont_wght.ttf',
);
expect(
await collection.loadFontFromList(robotoSlabData.asUint8List(), fontFamily: 'Roboto Slab'),
true,
);
await testTextStyle('after font load', fontFamily: 'Roboto Slab');
});
test('text styles - family fallback', () async {
await testTextStyle(
'family fallback',