mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
add TextLeadingDistribution to webui TextStyle (flutter/engine#25777)
This commit is contained in:
parent
2043d0839a
commit
177d73babf
@ -1,2 +1,2 @@
|
||||
repository: https://github.com/flutter/goldens.git
|
||||
revision: 4a8da9f65353bda26a73e12838797f20cfdedc40
|
||||
revision: 4d00d1a0f1c0bc123814919a45ef2c2f57ed21ec
|
||||
|
||||
@ -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);
|
||||
@ -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);
|
||||
|
||||
@ -37,6 +37,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
_fontFamily = fontFamily,
|
||||
_fontSize = fontSize,
|
||||
_height = height,
|
||||
_leadingDistribution = textHeightBehavior?.leadingDistribution,
|
||||
_fontWeight = fontWeight,
|
||||
_fontStyle = fontStyle;
|
||||
|
||||
@ -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,
|
||||
@ -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 =
|
||||
@ -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;
|
||||
}
|
||||
@ -147,7 +161,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
}
|
||||
|
||||
if (strutStyle != null) {
|
||||
properties.strutStyle = toSkStrutStyleProperties(strutStyle);
|
||||
properties.strutStyle = toSkStrutStyleProperties(strutStyle, textHeightBehavior);
|
||||
}
|
||||
|
||||
properties.textStyle = toSkTextStyleProperties(
|
||||
@ -161,6 +175,7 @@ class CkParagraphStyle implements ui.ParagraphStyle {
|
||||
fontFamily: _fontFamily,
|
||||
fontSize: _fontSize,
|
||||
height: _height,
|
||||
leadingDistribution: _leadingDistribution,
|
||||
fontWeight: _fontWeight,
|
||||
fontStyle: _fontStyle,
|
||||
);
|
||||
@ -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,
|
||||
@ -205,6 +221,7 @@ class CkTextStyle implements ui.TextStyle {
|
||||
letterSpacing,
|
||||
wordSpacing,
|
||||
height,
|
||||
leadingDistribution,
|
||||
locale,
|
||||
background,
|
||||
foreground,
|
||||
@ -228,6 +245,7 @@ class CkTextStyle implements ui.TextStyle {
|
||||
this.letterSpacing,
|
||||
this.wordSpacing,
|
||||
this.height,
|
||||
this.leadingDistribution,
|
||||
this.locale,
|
||||
this.background,
|
||||
this.foreground,
|
||||
@ -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;
|
||||
@ -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,
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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?,
|
||||
|
||||
@ -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:
|
||||
@ -1118,6 +1139,7 @@ Future<void> testTextStyle(
|
||||
double? letterSpacing,
|
||||
double? wordSpacing,
|
||||
double? height,
|
||||
ui.TextLeadingDistribution? leadingDistribution,
|
||||
ui.Locale? locale,
|
||||
CkPaint? background,
|
||||
CkPaint? foreground,
|
||||
@ -1169,6 +1191,7 @@ Future<void> testTextStyle(
|
||||
letterSpacing: letterSpacing,
|
||||
wordSpacing: wordSpacing,
|
||||
height: height,
|
||||
leadingDistribution: leadingDistribution,
|
||||
locale: locale,
|
||||
background: background,
|
||||
foreground: foreground,
|
||||
|
||||
@ -1289,6 +1289,7 @@ void _paragraphTests() {
|
||||
..letterSpacing = 5
|
||||
..wordSpacing = 10
|
||||
..heightMultiplier = 2.5
|
||||
..halfLeading = true
|
||||
..locale = 'en_CA'
|
||||
..fontFamilies = <String>['Roboto', 'serif']
|
||||
..fontStyle = (SkFontStyle()
|
||||
@ -1310,6 +1311,7 @@ void _paragraphTests() {
|
||||
..weight = canvasKit.FontWeight.Bold)
|
||||
..fontSize = 23
|
||||
..heightMultiplier = 5
|
||||
..halfLeading = true
|
||||
..leading = 6
|
||||
..strutEnabled = true
|
||||
..forceStrutHeight = false;
|
||||
@ -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(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user