Skip to content

Commit

Permalink
Fix copying/applying font fallback with package (#118393)
Browse files Browse the repository at this point in the history
* Add test to check that package prefix of font fallback is not duplicated

* Fix duplicate package prefix of font family fallback

* Add test to check that package prefix of font fallback is not duplicated

* Fix duplicate package prefix of font family fallback
  • Loading branch information
IchordeDionysos authored Jan 13, 2023
1 parent b896066 commit ddad6f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/painting/text_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ class TextStyle with Diagnosticable {
decorationThickness: decorationThickness ?? this.decorationThickness,
debugLabel: newDebugLabel,
fontFamily: fontFamily ?? _fontFamily,
fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback,
package: package ?? _package,
overflow: overflow ?? this.overflow,
);
Expand Down Expand Up @@ -991,7 +991,7 @@ class TextStyle with Diagnosticable {
color: foreground == null ? color ?? this.color : null,
backgroundColor: background == null ? backgroundColor ?? this.backgroundColor : null,
fontFamily: fontFamily ?? _fontFamily,
fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback,
fontSize: fontSize == null ? null : fontSize! * fontSizeFactor + fontSizeDelta,
fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight!.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1)], // ignore_clamp_double_lint
fontStyle: fontStyle ?? this.fontStyle,
Expand Down
14 changes: 14 additions & 0 deletions packages/flutter/test/painting/text_style_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ void main() {

const TextStyle s10 = TextStyle(fontFamilyFallback: <String>[], package: 'p');
expect(s10.fontFamilyFallback, <String>[]);

// Ensure that package prefix is not duplicated after copying.
final TextStyle s11 = s8.copyWith();
expect(s11.fontFamilyFallback![0], 'packages/p/test');
expect(s11.fontFamilyFallback![1], 'packages/p/test2');
expect(s11.fontFamilyFallback!.length, 2);
expect(s8, s11);

// Ensure that package prefix is not duplicated after applying.
final TextStyle s12 = s8.apply();
expect(s12.fontFamilyFallback![0], 'packages/p/test');
expect(s12.fontFamilyFallback![1], 'packages/p/test2');
expect(s12.fontFamilyFallback!.length, 2);
expect(s8, s12);
});

test('TextStyle package font merge', () {
Expand Down

0 comments on commit ddad6f1

Please sign in to comment.