Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e396b6f

Browse files
TextStyle.textHeightBehavior -> TextStyle.leadingDistribution
1 parent 0982171 commit e396b6f

File tree

10 files changed

+184
-139
lines changed

10 files changed

+184
-139
lines changed

lib/ui/text.dart

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ bool _listEquals<T>(List<T>? a, List<T>? b) {
17481748
//
17491749
// - Element 7: The enum index of the |textBaseline|.
17501750
//
1751-
// - Element 8: The encoded value of the |textHeightBehavior|.
1751+
// - Element 8: The encoded value of the |leadingDistribution|.
17521752
//
17531753
Int32List _encodeTextStyle(
17541754
Color? color,
@@ -1765,7 +1765,7 @@ Int32List _encodeTextStyle(
17651765
double? letterSpacing,
17661766
double? wordSpacing,
17671767
double? height,
1768-
TextHeightBehavior? textHeightBehavior,
1768+
LeadingDistribution? leadingDistribution,
17691769
Locale? locale,
17701770
Paint? background,
17711771
Paint? foreground,
@@ -1801,9 +1801,9 @@ Int32List _encodeTextStyle(
18011801
result[0] |= 1 << 7;
18021802
result[7] = textBaseline.index;
18031803
}
1804-
if (textHeightBehavior != null) {
1804+
if (leadingDistribution != null) {
18051805
result[0] |= 1 << 8;
1806-
result[8] = textHeightBehavior.encode();
1806+
result[8] = leadingDistribution.index;
18071807
}
18081808
if (decorationThickness != null) {
18091809
result[0] |= 1 << 9;
@@ -1883,7 +1883,7 @@ class TextStyle {
18831883
/// * `textBaseline`: The common baseline that should be aligned between this text span and its parent text span, or, for the root text spans, with the line box.
18841884
/// * `height`: The height of this text span, as a multiplier of the font size. Omitting `height` will allow the line height
18851885
/// to take the height as defined by the font, which may not be exactly the height of the fontSize.
1886-
/// * `textHeightBehavior`: When `height` is specified, how the extra vertical space should be distributed over and under the text.
1886+
/// * `leadingDistribution`: When `height` is specified, how the extra vertical space should be distributed over and under the text.
18871887
/// * `locale`: The locale used to select region-specific glyphs.
18881888
/// * `background`: The paint drawn as a background for the text.
18891889
/// * `foreground`: The paint used to draw the text. If this is specified, `color` must be null.
@@ -1903,7 +1903,7 @@ class TextStyle {
19031903
double? letterSpacing,
19041904
double? wordSpacing,
19051905
double? height,
1906-
TextHeightBehavior? textHeightBehavior,
1906+
LeadingDistribution? leadingDistribution,
19071907
Locale? locale,
19081908
Paint? background,
19091909
Paint? foreground,
@@ -1928,7 +1928,7 @@ class TextStyle {
19281928
letterSpacing,
19291929
wordSpacing,
19301930
height,
1931-
textHeightBehavior,
1931+
leadingDistribution,
19321932
locale,
19331933
background,
19341934
foreground,
@@ -1988,30 +1988,30 @@ class TextStyle {
19881988
@override
19891989
String toString() {
19901990
return 'TextStyle('
1991-
'color: ${ _encoded[0] & 0x00002 == 0x00002 ? Color(_encoded[1]) : "unspecified"}, '
1992-
'decoration: ${ _encoded[0] & 0x00004 == 0x00004 ? TextDecoration._(_encoded[2]) : "unspecified"}, '
1993-
'decorationColor: ${ _encoded[0] & 0x00008 == 0x00008 ? Color(_encoded[3]) : "unspecified"}, '
1994-
'decorationStyle: ${ _encoded[0] & 0x00010 == 0x00010 ? TextDecorationStyle.values[_encoded[4]] : "unspecified"}, '
1991+
'color: ${ _encoded[0] & 0x00002 == 0x00002 ? Color(_encoded[1]) : "unspecified"}, '
1992+
'decoration: ${ _encoded[0] & 0x00004 == 0x00004 ? TextDecoration._(_encoded[2]) : "unspecified"}, '
1993+
'decorationColor: ${ _encoded[0] & 0x00008 == 0x00008 ? Color(_encoded[3]) : "unspecified"}, '
1994+
'decorationStyle: ${ _encoded[0] & 0x00010 == 0x00010 ? TextDecorationStyle.values[_encoded[4]] : "unspecified"}, '
19951995
// The decorationThickness is not in encoded order in order to keep it near the other decoration properties.
1996-
'decorationThickness: ${_encoded[0] & 0x00200 == 0x00200 ? _decorationThickness : "unspecified"}, '
1997-
'fontWeight: ${ _encoded[0] & 0x00020 == 0x00020 ? FontWeight.values[_encoded[5]] : "unspecified"}, '
1998-
'fontStyle: ${ _encoded[0] & 0x00040 == 0x00040 ? FontStyle.values[_encoded[6]] : "unspecified"}, '
1999-
'textBaseline: ${ _encoded[0] & 0x00080 == 0x00080 ? TextBaseline.values[_encoded[7]] : "unspecified"}, '
1996+
'decorationThickness: ${_encoded[0] & 0x00200 == 0x00200 ? _decorationThickness : "unspecified"}, '
1997+
'fontWeight: ${ _encoded[0] & 0x00020 == 0x00020 ? FontWeight.values[_encoded[5]] : "unspecified"}, '
1998+
'fontStyle: ${ _encoded[0] & 0x00040 == 0x00040 ? FontStyle.values[_encoded[6]] : "unspecified"}, '
1999+
'textBaseline: ${ _encoded[0] & 0x00080 == 0x00080 ? TextBaseline.values[_encoded[7]] : "unspecified"}, '
20002000
'fontFamily: ${ _encoded[0] & 0x00400 == 0x00400
2001-
&& _fontFamily != '' ? _fontFamily : "unspecified"}, '
2001+
&& _fontFamily != '' ? _fontFamily : "unspecified"}, '
20022002
'fontFamilyFallback: ${ _encoded[0] & 0x00400 == 0x00400
20032003
&& _fontFamilyFallback != null
2004-
&& _fontFamilyFallback!.isNotEmpty ? _fontFamilyFallback : "unspecified"}, '
2005-
'fontSize: ${ _encoded[0] & 0x00800 == 0x00800 ? _fontSize : "unspecified"}, '
2006-
'letterSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_letterSpacing}x" : "unspecified"}, '
2007-
'wordSpacing: ${ _encoded[0] & 0x02000 == 0x02000 ? "${_wordSpacing}x" : "unspecified"}, '
2008-
'height: ${ _encoded[0] & 0x04000 == 0x04000 ? "${_height}x" : "unspecified"}, '
2009-
'textHeightBehavior: ${ _encoded[0] & 0x0100 == 0x0100 ? "${TextHeightBehavior.fromEncoded(_encoded[8])}" : "unspecified"}, '
2010-
'locale: ${ _encoded[0] & 0x08000 == 0x08000 ? _locale : "unspecified"}, '
2011-
'background: ${ _encoded[0] & 0x10000 == 0x10000 ? _background : "unspecified"}, '
2012-
'foreground: ${ _encoded[0] & 0x20000 == 0x20000 ? _foreground : "unspecified"}, '
2013-
'shadows: ${ _encoded[0] & 0x40000 == 0x40000 ? _shadows : "unspecified"}, '
2014-
'fontFeatures: ${ _encoded[0] & 0x80000 == 0x80000 ? _fontFeatures : "unspecified"}'
2004+
&& _fontFamilyFallback!.isNotEmpty ? _fontFamilyFallback : "unspecified"}, '
2005+
'fontSize: ${ _encoded[0] & 0x00800 == 0x00800 ? _fontSize : "unspecified"}, '
2006+
'letterSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_letterSpacing}x" : "unspecified"}, '
2007+
'wordSpacing: ${ _encoded[0] & 0x02000 == 0x02000 ? "${_wordSpacing}x" : "unspecified"}, '
2008+
'height: ${ _encoded[0] & 0x04000 == 0x04000 ? "${_height}x" : "unspecified"}, '
2009+
'leadingDistribution: ${_encoded[0] & 0x0100 == 0x0100 ? "${LeadingDistribution.values[_encoded[8]]}" : "unspecified"}, '
2010+
'locale: ${ _encoded[0] & 0x08000 == 0x08000 ? _locale : "unspecified"}, '
2011+
'background: ${ _encoded[0] & 0x10000 == 0x10000 ? _background : "unspecified"}, '
2012+
'foreground: ${ _encoded[0] & 0x20000 == 0x20000 ? _foreground : "unspecified"}, '
2013+
'shadows: ${ _encoded[0] & 0x40000 == 0x40000 ? _shadows : "unspecified"}, '
2014+
'fontFeatures: ${ _encoded[0] & 0x80000 == 0x80000 ? _fontFeatures : "unspecified"}'
20152015
')';
20162016
}
20172017
}
@@ -2139,7 +2139,10 @@ class ParagraphStyle {
21392139
/// be exactly the height of the `fontSize`.
21402140
///
21412141
/// * `textHeightBehavior`: Specifies how the `height` multiplier is
2142-
/// applied to ascent and the descent of the text.
2142+
/// applied to ascent of the first line and the descent of the last line.
2143+
///
2144+
/// * `leadingDistribution`: Specifies how the extra vertical space added by
2145+
/// the `height` multiplier should be distributed over and under the text.
21432146
///
21442147
/// * `fontWeight`: The typeface thickness to use when painting the text
21452148
/// (e.g., bold).
@@ -2256,15 +2259,15 @@ ByteData _encodeStrut(
22562259
List<String>? fontFamilyFallback,
22572260
double? fontSize,
22582261
double? height,
2259-
TextHeightBehavior? textHeightBehavior,
2262+
LeadingDistribution? leadingDistribution,
22602263
double? leading,
22612264
FontWeight? fontWeight,
22622265
FontStyle? fontStyle,
22632266
bool? forceStrutHeight) {
22642267
if (fontFamily == null &&
22652268
fontSize == null &&
22662269
height == null &&
2267-
textHeightBehavior == null &&
2270+
leadingDistribution == null &&
22682271
leading == null &&
22692272
fontWeight == null &&
22702273
fontStyle == null &&
@@ -2297,9 +2300,9 @@ ByteData _encodeStrut(
22972300
bitmask |= 1 << 4;
22982301
data.setFloat32(byteCount, height, _kFakeHostEndian);
22992302
byteCount += 4;
2300-
if (textHeightBehavior != null) {
2303+
if (leadingDistribution != null) {
23012304
bitmask |= 1 << 5;
2302-
data.setInt8(byteCount, textHeightBehavior.encode());
2305+
data.setInt8(byteCount, leadingDistribution.index);
23032306
byteCount += 4;
23042307
}
23052308
}
@@ -2349,6 +2352,11 @@ class StrutStyle {
23492352
/// * `leading`: The minimum amount of leading between lines as a multiple of
23502353
/// the font size. `fontSize` must be provided for this property to take effect.
23512354
///
2355+
/// * `leadingDistribution`: Specifies how the extra vertical space added by
2356+
/// the `height` multiplier should be distributed over and under the text,
2357+
/// independent of `leading` (which is always distributed evenly over and
2358+
/// under text).
2359+
///
23522360
/// * `fontWeight`: The typeface thickness to use when painting the text
23532361
/// (e.g., bold).
23542362
///
@@ -2367,7 +2375,7 @@ class StrutStyle {
23672375
List<String>? fontFamilyFallback,
23682376
double? fontSize,
23692377
double? height,
2370-
TextHeightBehavior? textHeightBehavior,
2378+
LeadingDistribution? leadingDistribution,
23712379
double? leading,
23722380
FontWeight? fontWeight,
23732381
FontStyle? fontStyle,
@@ -2377,7 +2385,7 @@ class StrutStyle {
23772385
fontFamilyFallback,
23782386
fontSize,
23792387
height,
2380-
textHeightBehavior,
2388+
leadingDistribution,
23812389
leading,
23822390
fontWeight,
23832391
fontStyle,

lib/ui/text/paragraph_builder.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const int tsTextDecorationStyleIndex = 4;
3939
const int tsFontWeightIndex = 5;
4040
const int tsFontStyleIndex = 6;
4141
const int tsTextBaselineIndex = 7;
42-
const int tsTextHeightBehaviorIndex = 8;
42+
const int tsLeadingDistributionIndex = 8;
4343
const int tsTextDecorationThicknessIndex = 9;
4444
const int tsFontFamilyIndex = 10;
4545
const int tsFontSizeIndex = 11;
@@ -60,7 +60,7 @@ const int tsTextDecorationThicknessMask = 1 << tsTextDecorationThicknessIndex;
6060
const int tsFontWeightMask = 1 << tsFontWeightIndex;
6161
const int tsFontStyleMask = 1 << tsFontStyleIndex;
6262
const int tsTextBaselineMask = 1 << tsTextBaselineIndex;
63-
const int tsTextHeightBehaviorMask = 1 << tsTextHeightBehaviorIndex;
63+
const int tsLeadingDistributionMask = 1 << tsLeadingDistributionIndex;
6464
const int tsFontFamilyMask = 1 << tsFontFamilyIndex;
6565
const int tsFontSizeMask = 1 << tsFontSizeIndex;
6666
const int tsLetterSpacingMask = 1 << tsLetterSpacingIndex;
@@ -120,7 +120,7 @@ const int sFontStyleIndex = 1;
120120
const int sFontFamilyIndex = 2;
121121
const int sFontSizeIndex = 3;
122122
const int sHeightIndex = 4;
123-
const int sTextHeightBehaviorIndex = 5;
123+
const int sLeadingDistributionIndex = 5;
124124
const int sLeadingIndex = 6;
125125
const int sForceStrutHeightIndex = 7;
126126

@@ -129,7 +129,7 @@ const int sFontStyleMask = 1 << sFontStyleIndex;
129129
const int sFontFamilyMask = 1 << sFontFamilyIndex;
130130
const int sFontSizeMask = 1 << sFontSizeIndex;
131131
const int sHeightMask = 1 << sHeightIndex;
132-
const int sTextHeightBehaviorMask = 1 << sTextHeightBehaviorIndex;
132+
const int sLeadingDistributionMask = 1 << sLeadingDistributionIndex;
133133
const int sLeadingMask = 1 << sLeadingIndex;
134134
const int sForceStrutHeightMask = 1 << sForceStrutHeightIndex;
135135

@@ -215,9 +215,10 @@ void decodeStrut(Dart_Handle strut_data,
215215
paragraph_style.strut_height = float_data[float_count++];
216216
paragraph_style.strut_has_height_override = true;
217217

218-
// TextHeightBehavior does not affect layout if height is not set.
219-
if (mask & sTextHeightBehaviorMask) {
220-
paragraph_style.strut_text_height_behavior = uint8_data[byte_count];
218+
// LeadingDistribution does not affect layout if height is not set.
219+
if (mask & sLeadingDistributionMask) {
220+
paragraph_style.strut_half_leading = uint8_data[byte_count];
221+
paragraph_style.strut_has_leading_distribution_override = true;
221222
}
222223
}
223224
if (mask & sLeadingMask) {
@@ -419,9 +420,9 @@ void ParagraphBuilder::pushStyle(tonic::Int32List& encoded,
419420
// property wasn't wired up either.
420421
}
421422

422-
style.has_text_height_behavior_override = mask & tsTextHeightBehaviorMask;
423-
if (mask & tsTextHeightBehaviorMask) {
424-
style.text_height_behavior = encoded[tsTextHeightBehaviorIndex];
423+
style.has_leading_distribution_override = mask & tsLeadingDistributionMask;
424+
if (mask & tsLeadingDistributionMask) {
425+
style.half_leading = encoded[tsLeadingDistributionIndex];
425426
}
426427

427428
if (mask & (tsFontWeightMask | tsFontStyleMask | tsFontSizeMask |

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,8 @@ class EngineStrutStyle implements ui.StrutStyle {
12111211
List<String>? fontFamilyFallback,
12121212
double? fontSize,
12131213
double? height,
1214-
//TODO(LongCatIsLooong): implement textHeightBehavior.
1215-
ui.TextHeightBehavior? textHeightBehavior,
1214+
//TODO(LongCatIsLooong): implement leadingDistribution.
1215+
ui.LeadingDistribution? leadingDistribution,
12161216
double? leading,
12171217
ui.FontWeight? fontWeight,
12181218
ui.FontStyle? fontStyle,
@@ -1221,7 +1221,7 @@ class EngineStrutStyle implements ui.StrutStyle {
12211221
_fontFamilyFallback = fontFamilyFallback,
12221222
_fontSize = fontSize,
12231223
_height = height,
1224-
_textHeightBehavior = textHeightBehavior,
1224+
_leadingDistribution = leadingDistribution,
12251225
_leading = leading,
12261226
_fontWeight = fontWeight,
12271227
_fontStyle = fontStyle,
@@ -1235,7 +1235,7 @@ class EngineStrutStyle implements ui.StrutStyle {
12351235
final ui.FontWeight? _fontWeight;
12361236
final ui.FontStyle? _fontStyle;
12371237
final bool? _forceStrutHeight;
1238-
final ui.TextHeightBehavior? _textHeightBehavior;
1238+
final ui.LeadingDistribution? _leadingDistribution;
12391239

12401240
@override
12411241
bool operator ==(Object other) {
@@ -1249,7 +1249,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12491249
&& other._fontFamily == _fontFamily
12501250
&& other._fontSize == _fontSize
12511251
&& other._height == _height
1252-
&& other._textHeightBehavior == _textHeightBehavior
12531252
&& other._leading == _leading
12541253
&& other._fontWeight == _fontWeight
12551254
&& other._fontStyle == _fontStyle
@@ -1263,7 +1262,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12631262
_fontFamilyFallback,
12641263
_fontSize,
12651264
_height,
1266-
_textHeightBehavior,
12671265
_leading,
12681266
_fontWeight,
12691267
_fontStyle,

lib/web_ui/lib/src/ui/text.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,13 @@ class TextHeightBehavior {
213213
const TextHeightBehavior({
214214
this.applyHeightToFirstAscent = true,
215215
this.applyHeightToLastDescent = true,
216-
this.leadingDistribution = LeadingDistribution.proportional,
217216
});
218-
TextHeightBehavior.fromEncoded(int encoded)
217+
const TextHeightBehavior.fromEncoded(int encoded)
219218
: applyHeightToFirstAscent = (encoded & 0x1) == 0,
220-
applyHeightToLastDescent = (encoded & 0x2) == 0,
221-
leadingDistribution = LeadingDistribution.values[encoded >> 2];
219+
applyHeightToLastDescent = (encoded & 0x2) == 0;
222220
final bool applyHeightToFirstAscent;
223221
final bool applyHeightToLastDescent;
224-
final LeadingDistribution leadingDistribution;
222+
225223
int encode() {
226224
return (applyHeightToFirstAscent ? 0 : 1 << 0) | (applyHeightToLastDescent ? 0 : 1 << 1);
227225
}
@@ -247,8 +245,7 @@ class TextHeightBehavior {
247245
String toString() {
248246
return 'TextHeightBehavior('
249247
'applyHeightToFirstAscent: $applyHeightToFirstAscent, '
250-
'applyHeightToLastDescent: $applyHeightToLastDescent, '
251-
'leadingDistribution: $leadingDistribution'
248+
'applyHeightToLastDescent: $applyHeightToLastDescent'
252249
')';
253250
}
254251
}
@@ -269,7 +266,7 @@ abstract class TextStyle {
269266
double? letterSpacing,
270267
double? wordSpacing,
271268
double? height,
272-
TextHeightBehavior? textHeightBehavior,
269+
LeadingDistribution? leadingDistribution,
273270
Locale? locale,
274271
Paint? background,
275272
Paint? foreground,
@@ -380,7 +377,7 @@ abstract class StrutStyle {
380377
List<String>? fontFamilyFallback,
381378
double? fontSize,
382379
double? height,
383-
TextHeightBehavior? textHeightBehavior,
380+
LeadingDistribution? leadingDistribution,
384381
double? leading,
385382
FontWeight? fontWeight,
386383
FontStyle? fontStyle,

0 commit comments

Comments
 (0)