From 07eddf7b534e3951eea34c09d90099e2a6542fdc Mon Sep 17 00:00:00 2001 From: Harry Terkelsen Date: Wed, 21 Apr 2021 12:45:51 -0700 Subject: [PATCH] Include paragraph height in the top-level text style. (flutter/engine#25659) * Include paragraph height in the top-level text style. * Update test comment * Update goldens lock --- .../src/flutter/lib/web_ui/dev/goldens_lock.yaml | 2 +- .../lib/web_ui/lib/src/engine/canvaskit/text.dart | 15 ++++++++++++--- .../web_ui/test/canvaskit/canvas_golden_test.dart | 2 -- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml b/engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml index c35deabb24..a6453b378f 100644 --- a/engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml +++ b/engine/src/flutter/lib/web_ui/dev/goldens_lock.yaml @@ -1,2 +1,2 @@ repository: https://github.com/flutter/goldens.git -revision: ca0a1f0b1274f895590fbc31a25c90eee693d914 +revision: 5bef90a33a3a06924de81236ff7902c3e4e64659 diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart index 983155abd3..d656909e44 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart @@ -36,6 +36,7 @@ class CkParagraphStyle implements ui.ParagraphStyle { _textDirection = textDirection ?? ui.TextDirection.ltr, _fontFamily = fontFamily, _fontSize = fontSize, + _height = height, _fontWeight = fontWeight, _fontStyle = fontStyle; @@ -43,12 +44,14 @@ class CkParagraphStyle implements ui.ParagraphStyle { final ui.TextDirection? _textDirection; final String? _fontFamily; final double? _fontSize; + final double? _height; final ui.FontWeight? _fontWeight; final ui.FontStyle? _fontStyle; static SkTextStyleProperties toSkTextStyleProperties( String? fontFamily, double? fontSize, + double? height, ui.FontWeight? fontWeight, ui.FontStyle? fontStyle, ) { @@ -61,6 +64,10 @@ class CkParagraphStyle implements ui.ParagraphStyle { skTextStyle.fontSize = fontSize; } + if (height != null) { + skTextStyle.heightMultiplier = height; + } + skTextStyle.fontFamilies = _getEffectiveFontFamilies(fontFamily); return skTextStyle; @@ -131,8 +138,9 @@ class CkParagraphStyle implements ui.ParagraphStyle { } if (textHeightBehavior != null) { - properties.textHeightBehavior = (textHeightBehavior.applyHeightToFirstAscent ? 0 : 1 << 0) - | (textHeightBehavior.applyHeightToLastDescent ? 0 : 1 << 1); + properties.textHeightBehavior = + (textHeightBehavior.applyHeightToFirstAscent ? 0 : 1 << 0) | + (textHeightBehavior.applyHeightToLastDescent ? 0 : 1 << 1); } if (ellipsis != null) { @@ -144,7 +152,7 @@ class CkParagraphStyle implements ui.ParagraphStyle { } properties.textStyle = - toSkTextStyleProperties(fontFamily, fontSize, fontWeight, fontStyle); + toSkTextStyleProperties(fontFamily, fontSize, height, fontWeight, fontStyle); return canvasKit.ParagraphStyle(properties); } @@ -153,6 +161,7 @@ class CkParagraphStyle implements ui.ParagraphStyle { return CkTextStyle( fontFamily: _fontFamily, fontSize: _fontSize, + height: _height, fontWeight: _fontWeight, fontStyle: _fontStyle, ); diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart index 5869adbaa3..6012e25a97 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/canvas_golden_test.dart @@ -258,8 +258,6 @@ void testMain() { await testTextStyle('paragraph font size', paragraphFontSize: 22); }); - // TODO(yjbanov): paragraphHeight seems to have no effect, but maybe I'm using it wrong. - // https://github.com/flutter/flutter/issues/74337 test('text styles - paragraph height', () async { await testTextStyle('paragraph height', layoutWidth: 50, paragraphHeight: 1.5); });