From 1e9676fc95278abb8669687e3bdac15b1fad7842 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Wed, 5 Mar 2025 10:23:20 -0800 Subject: [PATCH] [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. --- .../engine/skwasm/skwasm_impl/font_collection.dart | 1 + .../lib/web_ui/test/ui/text_golden_test.dart | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart index 24af20555e..5ee33c9824 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/font_collection.dart @@ -180,6 +180,7 @@ class SkwasmFontCollection implements FlutterFontCollection { } else { fontCollectionRegisterTypeface(handle, typeface.handle, nullptr); } + fontCollectionClearCaches(handle); return true; } diff --git a/engine/src/flutter/lib/web_ui/test/ui/text_golden_test.dart b/engine/src/flutter/lib/web_ui/test/ui/text_golden_test.dart index f0d2c0acad..2b7f736761 100644 --- a/engine/src/flutter/lib/web_ui/test/ui/text_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/ui/text_golden_test.dart @@ -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 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',