mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[skwasm] Use test fonts while in debugEmulateFlutterTesterEnvironment mode (flutter/engine#51630)
This brings the behavior in line with the other renderers. The framework sets this bit to make sure we render only using the Ahem font.
This commit is contained in:
parent
8bb8f16804
commit
047ea1efd4
@ -9,10 +9,18 @@ import 'dart:js_interop';
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/src/engine/skwasm/skwasm_impl.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||
|
||||
const int _kSoftLineBreak = 0;
|
||||
const int _kHardLineBreak = 100;
|
||||
|
||||
final List<String> _testFonts = <String>['FlutterTest', 'Ahem'];
|
||||
String _computeEffectiveFontFamily(String fontFamily) {
|
||||
return ui_web.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)
|
||||
? _testFonts.first
|
||||
: fontFamily;
|
||||
}
|
||||
|
||||
class SkwasmLineMetrics extends SkwasmObjectWrapper<RawLineMetrics> implements ui.LineMetrics {
|
||||
factory SkwasmLineMetrics({
|
||||
required bool hardBreak,
|
||||
@ -430,8 +438,8 @@ class SkwasmTextStyle implements ui.TextStyle {
|
||||
}
|
||||
|
||||
List<String> get fontFamilies => <String>[
|
||||
if (fontFamily != null) fontFamily!,
|
||||
if (fontFamilyFallback != null) ...fontFamilyFallback!,
|
||||
if (fontFamily != null) _computeEffectiveFontFamily(fontFamily!),
|
||||
if (fontFamilyFallback != null) ...fontFamilyFallback!.map(_computeEffectiveFontFamily),
|
||||
];
|
||||
|
||||
final ui.Color? color;
|
||||
|
||||
@ -116,4 +116,23 @@ Future<void> testMain() async {
|
||||
expect(metrics, hasLength(1));
|
||||
}
|
||||
}, skip: isHtml); // The rounding hack doesn't apply to the html renderer
|
||||
|
||||
test('uses flutter test fonts when debugEmulateFlutterTesterEnvironment is enabled', () {
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle());
|
||||
builder.pushStyle(ui.TextStyle(
|
||||
fontSize: 10.0,
|
||||
fontFamily: 'SomeOtherFontFamily',
|
||||
));
|
||||
builder.addText('XXXX');
|
||||
final ui.Paragraph paragraph = builder.build();
|
||||
paragraph.layout(const ui.ParagraphConstraints(width: 400));
|
||||
|
||||
expect(paragraph.numberOfLines, 1);
|
||||
|
||||
final ui.LineMetrics? metrics = paragraph.getLineMetricsAt(0);
|
||||
expect(metrics, isNotNull);
|
||||
|
||||
// FlutterTest font's 'X' character is a square, so it's the font size (10.0) * 4 characters.
|
||||
expect(metrics!.width, 40.0);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user