Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web_ui/dev/goldens_lock.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repository: https://github.com/flutter/goldens.git
revision: 4a8da9f65353bda26a73e12838797f20cfdedc40
revision: 4d00d1a0f1c0bc123814919a45ef2c2f57ed21ec
2 changes: 2 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ class SkTextStyleProperties {
external set letterSpacing(double? value);
external set wordSpacing(double? value);
external set heightMultiplier(double? value);
external set halfLeading(bool? value);
external set locale(String? value);
external set fontFamilies(List<String>? value);
external set fontStyle(SkFontStyle? value);
Expand All @@ -1688,6 +1689,7 @@ class SkStrutStyleProperties {
external set fontStyle(SkFontStyle? value);
external set fontSize(double? value);
external set heightMultiplier(double? value);
external set halfLeading(bool? value);
external set leading(double? value);
external set strutEnabled(bool? value);
external set forceStrutHeight(bool? value);
Expand Down
35 changes: 33 additions & 2 deletions lib/web_ui/lib/src/engine/canvaskit/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
_fontFamily = fontFamily,
_fontSize = fontSize,
_height = height,
_leadingDistribution = textHeightBehavior?.leadingDistribution,
_fontWeight = fontWeight,
_fontStyle = fontStyle;

Expand All @@ -47,6 +48,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
final double? _height;
final ui.FontWeight? _fontWeight;
final ui.FontStyle? _fontStyle;
final ui.TextLeadingDistribution? _leadingDistribution;

static SkTextStyleProperties toSkTextStyleProperties(
String? fontFamily,
Expand All @@ -73,7 +75,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
return skTextStyle;
}

static SkStrutStyleProperties toSkStrutStyleProperties(ui.StrutStyle value) {
static SkStrutStyleProperties toSkStrutStyleProperties(ui.StrutStyle value, ui.TextHeightBehavior? paragraphHeightBehavior) {
EngineStrutStyle style = value as EngineStrutStyle;
final SkStrutStyleProperties skStrutStyle = SkStrutStyleProperties();
skStrutStyle.fontFamilies =
Expand All @@ -87,6 +89,18 @@ class CkParagraphStyle implements ui.ParagraphStyle {
skStrutStyle.heightMultiplier = style._height;
}

final ui.TextLeadingDistribution? effectiveLeadingDistribution = style._leadingDistribution ?? paragraphHeightBehavior?.leadingDistribution;
switch (effectiveLeadingDistribution) {
case null:
break;
case ui.TextLeadingDistribution.even:
skStrutStyle.halfLeading = true;
break;
case ui.TextLeadingDistribution.proportional:
skStrutStyle.halfLeading = false;
break;
}

if (style._leading != null) {
skStrutStyle.leading = style._leading;
}
Expand Down Expand Up @@ -147,7 +161,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
}

if (strutStyle != null) {
properties.strutStyle = toSkStrutStyleProperties(strutStyle);
properties.strutStyle = toSkStrutStyleProperties(strutStyle, textHeightBehavior);
}

properties.textStyle = toSkTextStyleProperties(
Expand All @@ -161,6 +175,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
fontFamily: _fontFamily,
fontSize: _fontSize,
height: _height,
leadingDistribution: _leadingDistribution,
fontWeight: _fontWeight,
fontStyle: _fontStyle,
);
Expand All @@ -184,6 +199,7 @@ class CkTextStyle implements ui.TextStyle {
double? letterSpacing,
double? wordSpacing,
double? height,
ui.TextLeadingDistribution? leadingDistribution,
ui.Locale? locale,
CkPaint? background,
CkPaint? foreground,
Expand All @@ -205,6 +221,7 @@ class CkTextStyle implements ui.TextStyle {
letterSpacing,
wordSpacing,
height,
leadingDistribution,
locale,
background,
foreground,
Expand All @@ -228,6 +245,7 @@ class CkTextStyle implements ui.TextStyle {
this.letterSpacing,
this.wordSpacing,
this.height,
this.leadingDistribution,
this.locale,
this.background,
this.foreground,
Expand All @@ -249,6 +267,7 @@ class CkTextStyle implements ui.TextStyle {
final double? letterSpacing;
final double? wordSpacing;
final double? height;
final ui.TextLeadingDistribution? leadingDistribution;
final ui.Locale? locale;
final CkPaint? background;
final CkPaint? foreground;
Expand All @@ -275,6 +294,7 @@ class CkTextStyle implements ui.TextStyle {
letterSpacing: other.letterSpacing ?? letterSpacing,
wordSpacing: other.wordSpacing ?? wordSpacing,
height: other.height ?? height,
leadingDistribution: other.leadingDistribution ?? leadingDistribution,
locale: other.locale ?? locale,
background: other.background ?? background,
foreground: other.foreground ?? foreground,
Expand Down Expand Up @@ -367,6 +387,17 @@ class CkTextStyle implements ui.TextStyle {
properties.heightMultiplier = height;
}

switch (leadingDistribution) {
case null:
break;
case ui.TextLeadingDistribution.even:
properties.halfLeading = true;
break;
case ui.TextLeadingDistribution.proportional:
properties.halfLeading = false;
break;
}

if (locale != null) {
properties.locale = locale.toLanguageTag();
}
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/lib/src/engine/text/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ class EngineStrutStyle implements ui.StrutStyle {
List<String>? fontFamilyFallback,
double? fontSize,
double? height,
//TODO(LongCatIsLooong): implement leadingDistribution.
ui.TextLeadingDistribution? leadingDistribution,
double? leading,
ui.FontWeight? fontWeight,
Expand Down
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ abstract class TextStyle {
letterSpacing: letterSpacing,
wordSpacing: wordSpacing,
height: height,
leadingDistribution: leadingDistribution,
locale: locale,
background: background as engine.CkPaint?,
foreground: foreground as engine.CkPaint?,
Expand Down
23 changes: 23 additions & 0 deletions lib/web_ui/test/canvaskit/canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,27 @@ void testMain() {
await testTextStyle('height', height: 2);
});

test('text styles - leading distribution', () async {
await testTextStyle('half leading', height: 20, fontSize: 10, leadingDistribution: ui.TextLeadingDistribution.even);
await testTextStyle(
'half leading inherited from paragraph',
height: 20,
fontSize: 10,
paragraphTextHeightBehavior: ui.TextHeightBehavior(
leadingDistribution: ui.TextLeadingDistribution.even,
),
);
await testTextStyle(
'text style half leading overrides paragraph style half leading',
height: 20,
fontSize: 10,
leadingDistribution: ui.TextLeadingDistribution.proportional,
paragraphTextHeightBehavior: ui.TextHeightBehavior(
leadingDistribution: ui.TextLeadingDistribution.even,
),
);
});

// TODO(yjbanov): locales specified in text styles don't work:
// https://github.com/flutter/flutter/issues/74687
// TODO(yjbanov): spaces are not rendered correctly:
Expand Down Expand Up @@ -1118,6 +1139,7 @@ Future<void> testTextStyle(
double? letterSpacing,
double? wordSpacing,
double? height,
ui.TextLeadingDistribution? leadingDistribution,
ui.Locale? locale,
CkPaint? background,
CkPaint? foreground,
Expand Down Expand Up @@ -1169,6 +1191,7 @@ Future<void> testTextStyle(
letterSpacing: letterSpacing,
wordSpacing: wordSpacing,
height: height,
leadingDistribution: leadingDistribution,
locale: locale,
background: background,
foreground: foreground,
Expand Down
4 changes: 4 additions & 0 deletions lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ void _paragraphTests() {
..letterSpacing = 5
..wordSpacing = 10
..heightMultiplier = 2.5
..halfLeading = true
..locale = 'en_CA'
..fontFamilies = <String>['Roboto', 'serif']
..fontStyle = (SkFontStyle()
Expand All @@ -1310,6 +1311,7 @@ void _paragraphTests() {
..weight = canvasKit.FontWeight.Bold)
..fontSize = 23
..heightMultiplier = 5
..halfLeading = true
..leading = 6
..strutEnabled = true
..forceStrutHeight = false;
Expand Down Expand Up @@ -1338,6 +1340,8 @@ void _paragraphTests() {
SkPaint());
builder.addText('!');
builder.pop();
builder.pushStyle(canvasKit.TextStyle(SkTextStyleProperties()..halfLeading = true));
builder.pop();
final SkParagraph paragraph = builder.build();
paragraph.layout(55);
expect(paragraph.getAlphabeticBaseline(),
Expand Down