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

Commit 6191270

Browse files
Revert "TextStyle level leadingDistribution (#24025)" (#24665)
1 parent 7b80753 commit 6191270

File tree

11 files changed

+173
-938
lines changed

11 files changed

+173
-938
lines changed

lib/ui/text.dart

Lines changed: 50 additions & 133 deletions
Large diffs are not rendered by default.

lib/ui/text/paragraph_builder.cc

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ const int tsTextDecorationStyleIndex = 4;
3939
const int tsFontWeightIndex = 5;
4040
const int tsFontStyleIndex = 6;
4141
const int tsTextBaselineIndex = 7;
42-
const int tsLeadingDistributionIndex = 8;
43-
const int tsTextDecorationThicknessIndex = 9;
44-
const int tsFontFamilyIndex = 10;
45-
const int tsFontSizeIndex = 11;
46-
const int tsLetterSpacingIndex = 12;
47-
const int tsWordSpacingIndex = 13;
48-
const int tsHeightIndex = 14;
49-
const int tsLocaleIndex = 15;
50-
const int tsBackgroundIndex = 16;
51-
const int tsForegroundIndex = 17;
52-
const int tsTextShadowsIndex = 18;
53-
const int tsFontFeaturesIndex = 19;
42+
const int tsTextDecorationThicknessIndex = 8;
43+
const int tsFontFamilyIndex = 9;
44+
const int tsFontSizeIndex = 10;
45+
const int tsLetterSpacingIndex = 11;
46+
const int tsWordSpacingIndex = 12;
47+
const int tsHeightIndex = 13;
48+
const int tsLocaleIndex = 14;
49+
const int tsBackgroundIndex = 15;
50+
const int tsForegroundIndex = 16;
51+
const int tsTextShadowsIndex = 17;
52+
const int tsFontFeaturesIndex = 18;
5453

5554
const int tsColorMask = 1 << tsColorIndex;
5655
const int tsTextDecorationMask = 1 << tsTextDecorationIndex;
@@ -60,7 +59,6 @@ const int tsTextDecorationThicknessMask = 1 << tsTextDecorationThicknessIndex;
6059
const int tsFontWeightMask = 1 << tsFontWeightIndex;
6160
const int tsFontStyleMask = 1 << tsFontStyleIndex;
6261
const int tsTextBaselineMask = 1 << tsTextBaselineIndex;
63-
const int tsLeadingDistributionMask = 1 << tsLeadingDistributionIndex;
6462
const int tsFontFamilyMask = 1 << tsFontFamilyIndex;
6563
const int tsFontSizeMask = 1 << tsFontSizeIndex;
6664
const int tsLetterSpacingMask = 1 << tsLetterSpacingIndex;
@@ -120,16 +118,14 @@ const int sFontStyleIndex = 1;
120118
const int sFontFamilyIndex = 2;
121119
const int sFontSizeIndex = 3;
122120
const int sHeightIndex = 4;
123-
const int sLeadingDistributionIndex = 5;
124-
const int sLeadingIndex = 6;
125-
const int sForceStrutHeightIndex = 7;
121+
const int sLeadingIndex = 5;
122+
const int sForceStrutHeightIndex = 6;
126123

127124
const int sFontWeightMask = 1 << sFontWeightIndex;
128125
const int sFontStyleMask = 1 << sFontStyleIndex;
129126
const int sFontFamilyMask = 1 << sFontFamilyIndex;
130127
const int sFontSizeMask = 1 << sFontSizeIndex;
131128
const int sHeightMask = 1 << sHeightIndex;
132-
const int sLeadingDistributionMask = 1 << sLeadingDistributionIndex;
133129
const int sLeadingMask = 1 << sLeadingIndex;
134130
const int sForceStrutHeightMask = 1 << sForceStrutHeightIndex;
135131

@@ -214,12 +210,6 @@ void decodeStrut(Dart_Handle strut_data,
214210
if (mask & sHeightMask) {
215211
paragraph_style.strut_height = float_data[float_count++];
216212
paragraph_style.strut_has_height_override = true;
217-
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;
222-
}
223213
}
224214
if (mask & sLeadingMask) {
225215
paragraph_style.strut_leading = float_data[float_count++];
@@ -383,7 +373,7 @@ void ParagraphBuilder::pushStyle(tonic::Int32List& encoded,
383373
Dart_Handle foreground_data,
384374
Dart_Handle shadows_data,
385375
Dart_Handle font_features_data) {
386-
FML_DCHECK(encoded.num_elements() == 9);
376+
FML_DCHECK(encoded.num_elements() == 8);
387377

388378
int32_t mask = encoded[0];
389379

@@ -420,11 +410,6 @@ void ParagraphBuilder::pushStyle(tonic::Int32List& encoded,
420410
// property wasn't wired up either.
421411
}
422412

423-
style.has_leading_distribution_override = mask & tsLeadingDistributionMask;
424-
if (mask & tsLeadingDistributionMask) {
425-
style.half_leading = encoded[tsLeadingDistributionIndex];
426-
}
427-
428413
if (mask & (tsFontWeightMask | tsFontStyleMask | tsFontSizeMask |
429414
tsLetterSpacingMask | tsWordSpacingMask)) {
430415
if (mask & tsFontWeightMask) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12111211
List<String>? fontFamilyFallback,
12121212
double? fontSize,
12131213
double? height,
1214-
//TODO(LongCatIsLooong): implement leadingDistribution.
1215-
ui.TextLeadingDistribution? leadingDistribution,
12161214
double? leading,
12171215
ui.FontWeight? fontWeight,
12181216
ui.FontStyle? fontStyle,
@@ -1221,7 +1219,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12211219
_fontFamilyFallback = fontFamilyFallback,
12221220
_fontSize = fontSize,
12231221
_height = height,
1224-
_leadingDistribution = leadingDistribution,
12251222
_leading = leading,
12261223
_fontWeight = fontWeight,
12271224
_fontStyle = fontStyle,
@@ -1235,7 +1232,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12351232
final ui.FontWeight? _fontWeight;
12361233
final ui.FontStyle? _fontStyle;
12371234
final bool? _forceStrutHeight;
1238-
final ui.TextLeadingDistribution? _leadingDistribution;
12391235

12401236
@override
12411237
bool operator ==(Object other) {
@@ -1250,7 +1246,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12501246
&& other._fontSize == _fontSize
12511247
&& other._height == _height
12521248
&& other._leading == _leading
1253-
&& other._leadingDistribution == _leadingDistribution
12541249
&& other._fontWeight == _fontWeight
12551250
&& other._fontStyle == _fontStyle
12561251
&& other._forceStrutHeight == _forceStrutHeight
@@ -1264,7 +1259,6 @@ class EngineStrutStyle implements ui.StrutStyle {
12641259
_fontSize,
12651260
_height,
12661261
_leading,
1267-
_leadingDistribution,
12681262
_fontWeight,
12691263
_fontStyle,
12701264
_forceStrutHeight,

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,18 @@ enum TextDecorationStyle {
204204
wavy
205205
}
206206

207-
enum TextLeadingDistribution {
208-
proportional,
209-
even,
210-
}
211-
212207
class TextHeightBehavior {
213208
const TextHeightBehavior({
214209
this.applyHeightToFirstAscent = true,
215210
this.applyHeightToLastDescent = true,
216-
this.leadingDistribution = TextLeadingDistribution.proportional,
217211
});
218-
TextHeightBehavior.fromEncoded(int encoded)
219-
: applyHeightToFirstAscent = (encoded & 0x1) == 0,
220-
applyHeightToLastDescent = (encoded & 0x2) == 0,
221-
leadingDistribution = TextLeadingDistribution.values[encoded >> 2];
212+
const TextHeightBehavior.fromEncoded(int encoded)
213+
: applyHeightToFirstAscent = (encoded & 0x1) == 0,
214+
applyHeightToLastDescent = (encoded & 0x2) == 0;
222215
final bool applyHeightToFirstAscent;
223216
final bool applyHeightToLastDescent;
224-
final TextLeadingDistribution leadingDistribution;
225-
226217
int encode() {
227-
return (applyHeightToFirstAscent ? 0 : 1 << 0)
228-
| (applyHeightToLastDescent ? 0 : 1 << 1)
229-
| (leadingDistribution.index << 2);
218+
return (applyHeightToFirstAscent ? 0 : 1 << 0) | (applyHeightToLastDescent ? 0 : 1 << 1);
230219
}
231220

232221
@override
@@ -235,8 +224,7 @@ class TextHeightBehavior {
235224
return false;
236225
return other is TextHeightBehavior
237226
&& other.applyHeightToFirstAscent == applyHeightToFirstAscent
238-
&& other.applyHeightToLastDescent == applyHeightToLastDescent
239-
&& other.leadingDistribution == leadingDistribution;
227+
&& other.applyHeightToLastDescent == applyHeightToLastDescent;
240228
}
241229

242230
@override
@@ -251,8 +239,7 @@ class TextHeightBehavior {
251239
String toString() {
252240
return 'TextHeightBehavior('
253241
'applyHeightToFirstAscent: $applyHeightToFirstAscent, '
254-
'applyHeightToLastDescent: $applyHeightToLastDescent, '
255-
'leadingDistribution: $leadingDistribution'
242+
'applyHeightToLastDescent: $applyHeightToLastDescent'
256243
')';
257244
}
258245
}
@@ -273,7 +260,6 @@ abstract class TextStyle {
273260
double? letterSpacing,
274261
double? wordSpacing,
275262
double? height,
276-
TextLeadingDistribution? leadingDistribution,
277263
Locale? locale,
278264
Paint? background,
279265
Paint? foreground,
@@ -384,7 +370,6 @@ abstract class StrutStyle {
384370
List<String>? fontFamilyFallback,
385371
double? fontSize,
386372
double? height,
387-
TextLeadingDistribution? leadingDistribution,
388373
double? leading,
389374
FontWeight? fontWeight,
390375
FontStyle? fontStyle,

testing/dart/text_test.dart

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,6 @@ void main() {
4242
});
4343
});
4444

45-
group('TextStyle', () {
46-
final TextStyle ts0 = TextStyle(fontWeight: FontWeight.w700, fontSize: 12.0, height: 123.0);
47-
final TextStyle ts1 = TextStyle(color: const Color(0xFF00FF00), fontWeight: FontWeight.w800, fontSize: 10.0, height: 100.0);
48-
final TextStyle ts2 = TextStyle(fontFamily: 'test');
49-
final TextStyle ts3 = TextStyle(fontFamily: 'foo', fontFamilyFallback: <String>['Roboto', 'test']);
50-
final TextStyle ts4 = TextStyle(leadingDistribution: TextLeadingDistribution.even);
51-
52-
test('toString works', () {
53-
expect(
54-
ts0.toString(),
55-
equals('TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: FontWeight.w700, fontStyle: unspecified, textBaseline: unspecified, fontFamily: unspecified, fontFamilyFallback: unspecified, fontSize: 12.0, letterSpacing: unspecified, wordSpacing: unspecified, height: 123.0x, leadingDistribution: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
56-
);
57-
expect(
58-
ts1.toString(),
59-
equals('TextStyle(color: Color(0xff00ff00), decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: FontWeight.w800, fontStyle: unspecified, textBaseline: unspecified, fontFamily: unspecified, fontFamilyFallback: unspecified, fontSize: 10.0, letterSpacing: unspecified, wordSpacing: unspecified, height: 100.0x, leadingDistribution: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
60-
);
61-
expect(
62-
ts2.toString(),
63-
equals('TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: test, fontFamilyFallback: unspecified, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, leadingDistribution: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
64-
);
65-
expect(
66-
ts3.toString(),
67-
equals('TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: foo, fontFamilyFallback: [Roboto, test], fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, leadingDistribution: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
68-
);
69-
expect(
70-
ts4.toString(),
71-
equals('TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: unspecified, fontFamilyFallback: unspecified, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, leadingDistribution: TextLeadingDistribution.even, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
72-
);
73-
});
74-
});
75-
7645
group('TextHeightBehavior', () {
7746
const TextHeightBehavior behavior0 = TextHeightBehavior();
7847
const TextHeightBehavior behavior1 = TextHeightBehavior(
@@ -85,10 +54,6 @@ void main() {
8554
const TextHeightBehavior behavior3 = TextHeightBehavior(
8655
applyHeightToLastDescent: false
8756
);
88-
const TextHeightBehavior behavior4 = TextHeightBehavior(
89-
applyHeightToLastDescent: false,
90-
leadingDistribution: TextLeadingDistribution.even,
91-
);
9257

9358
test('default constructor works', () {
9459
expect(behavior0.applyHeightToFirstAscent, equals(true));
@@ -102,33 +67,27 @@ void main() {
10267

10368
expect(behavior3.applyHeightToFirstAscent, equals(true));
10469
expect(behavior3.applyHeightToLastDescent, equals(false));
105-
106-
expect(behavior4.applyHeightToLastDescent, equals(false));
107-
expect(behavior4.leadingDistribution, equals(TextLeadingDistribution.even));
10870
});
10971

11072
test('encode works', () {
11173
expect(behavior0.encode(), equals(0));
11274
expect(behavior1.encode(), equals(3));
11375
expect(behavior2.encode(), equals(1));
11476
expect(behavior3.encode(), equals(2));
115-
expect(behavior4.encode(), equals(6));
11677
});
11778

11879
test('decode works', () {
119-
expect(TextHeightBehavior.fromEncoded(0), equals(behavior0));
120-
expect(TextHeightBehavior.fromEncoded(3), equals(behavior1));
121-
expect(TextHeightBehavior.fromEncoded(1), equals(behavior2));
122-
expect(TextHeightBehavior.fromEncoded(2), equals(behavior3));
123-
expect(TextHeightBehavior.fromEncoded(6), equals(behavior4));
80+
expect(const TextHeightBehavior.fromEncoded(0), equals(behavior0));
81+
expect(const TextHeightBehavior.fromEncoded(3), equals(behavior1));
82+
expect(const TextHeightBehavior.fromEncoded(1), equals(behavior2));
83+
expect(const TextHeightBehavior.fromEncoded(2), equals(behavior3));
12484
});
12585

12686
test('toString works', () {
127-
expect(behavior0.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: true, leadingDistribution: TextLeadingDistribution.proportional)'));
128-
expect(behavior1.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false, leadingDistribution: TextLeadingDistribution.proportional)'));
129-
expect(behavior2.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: true, leadingDistribution: TextLeadingDistribution.proportional)'));
130-
expect(behavior3.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: TextLeadingDistribution.proportional)'));
131-
expect(behavior4.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: TextLeadingDistribution.even)'));
87+
expect(behavior0.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: true)'));
88+
expect(behavior1.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false)'));
89+
expect(behavior2.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: true)'));
90+
expect(behavior3.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false)'));
13291
});
13392
});
13493

third_party/txt/src/txt/paragraph_style.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,10 @@ enum class TextDirection {
4141
ltr,
4242
};
4343

44-
// Adjusts the leading over and under text.
45-
//
46-
// kDisableFirstAscent and kDisableLastDescent allow disabling height
47-
// adjustments to first line's ascent and the last line's descent. If disabled,
48-
// the line will use the default font metric provided ascent/descent and
49-
// ParagraphStyle.height or TextStyle.height will not take effect.
50-
//
51-
// kEvenLeading determines how the leading is distributed over and under the
52-
// text. When true, half of the leading is added to the top of the text and the
53-
// other half is added to the bottom of the text. Otherwise, instead of
54-
// distributing the space evenly, it's distributed proportionally to the font's
55-
// ascent/descent ratio.
44+
// Allows disabling height adjustments to first line's ascent and the
45+
// last line's descent. If disabled, the line will use the default font
46+
// metric provided ascent/descent and ParagraphStyle.height will not take
47+
// effect.
5648
//
5749
// The default behavior is kAll where height adjustments are enabled for all
5850
// lines.
@@ -66,7 +58,6 @@ enum TextHeightBehavior {
6658
kDisableFirstAscent = 0x1,
6759
kDisableLastDescent = 0x2,
6860
kDisableAll = 0x1 | 0x2,
69-
kEvenLeading = 0x1 << 2,
7061
};
7162

7263
class ParagraphStyle {
@@ -78,8 +69,8 @@ class ParagraphStyle {
7869
std::string font_family = "";
7970
double font_size = 14;
8071
double height = 1;
81-
bool has_height_override = false;
8272
size_t text_height_behavior = TextHeightBehavior::kAll;
73+
bool has_height_override = false;
8374

8475
// Strut properties. strut_enabled must be set to true for the rest of the
8576
// properties to take effect.
@@ -91,8 +82,6 @@ class ParagraphStyle {
9182
double strut_font_size = 14;
9283
double strut_height = 1;
9384
bool strut_has_height_override = false;
94-
bool strut_half_leading = false;
95-
bool strut_has_leading_distribution_override = false;
9685
double strut_leading = -1; // Negative to use font's default leading. [0,inf)
9786
// to use custom leading as a ratio of font size.
9887
bool force_strut_height = false;

0 commit comments

Comments
 (0)