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

Commit f3e74f4

Browse files
review
1 parent 45964a1 commit f3e74f4

File tree

7 files changed

+40
-38
lines changed

7 files changed

+40
-38
lines changed

lib/ui/text.dart

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,8 @@ enum TextDecorationStyle {
15651565
wavy
15661566
}
15671567

1568-
/// {@macro dart.ui.leadingDistribution}
1569-
enum LeadingDistribution {
1568+
/// {@macro dart.ui.textLeadingDistribution}
1569+
enum TextLeadingDistribution {
15701570
/// Distributes the [leading](https://en.wikipedia.org/wiki/Leading)
15711571
/// of the text proportionally above and below the text, to the font's
15721572
/// ascent/discent ratio.
@@ -1623,7 +1623,7 @@ class TextHeightBehavior {
16231623
const TextHeightBehavior({
16241624
this.applyHeightToFirstAscent = true,
16251625
this.applyHeightToLastDescent = true,
1626-
this.leadingDistribution = LeadingDistribution.proportional,
1626+
this.leadingDistribution = TextLeadingDistribution.proportional,
16271627
});
16281628

16291629
/// Creates a new TextHeightBehavior object from an encoded form.
@@ -1632,7 +1632,7 @@ class TextHeightBehavior {
16321632
TextHeightBehavior.fromEncoded(int encoded)
16331633
: applyHeightToFirstAscent = (encoded & 0x1) == 0,
16341634
applyHeightToLastDescent = (encoded & 0x2) == 0,
1635-
leadingDistribution = LeadingDistribution.values[encoded >> 2];
1635+
leadingDistribution = TextLeadingDistribution.values[encoded >> 2];
16361636

16371637
/// Whether to apply the [TextStyle.height] modifier to the ascent of the first
16381638
/// line in the paragraph.
@@ -1658,17 +1658,17 @@ class TextHeightBehavior {
16581658
/// Defaults to true (height modifications applied as normal).
16591659
final bool applyHeightToLastDescent;
16601660

1661-
/// {@template dart.ui.leadingDistribution}
1661+
/// {@template dart.ui.textLeadingDistribution}
16621662
/// How the ["leading"](https://en.wikipedia.org/wiki/Leading) is distributed
16631663
/// over and under the text.
16641664
///
16651665
/// Does not affect layout when [TextStyle.height] is not specified. The
1666-
/// leading can become negative, for example, when [LeadingDistribution.even]
1666+
/// leading can become negative, for example, when [TextLeadingDistribution.even]
16671667
/// is used with a [TextStyle.height] much smaller than 1.0.
16681668
/// {@endtemplate}
16691669
///
1670-
/// Defaults to [LeadingDistribution.proportional],
1671-
final LeadingDistribution leadingDistribution;
1670+
/// Defaults to [TextLeadingDistribution.proportional],
1671+
final TextLeadingDistribution leadingDistribution;
16721672

16731673
/// Returns an encoded int representation of this object.
16741674
int encode() {
@@ -1765,7 +1765,7 @@ Int32List _encodeTextStyle(
17651765
double? letterSpacing,
17661766
double? wordSpacing,
17671767
double? height,
1768-
LeadingDistribution? leadingDistribution,
1768+
TextLeadingDistribution? leadingDistribution,
17691769
Locale? locale,
17701770
Paint? background,
17711771
Paint? foreground,
@@ -1903,7 +1903,7 @@ class TextStyle {
19031903
double? letterSpacing,
19041904
double? wordSpacing,
19051905
double? height,
1906-
LeadingDistribution? leadingDistribution,
1906+
TextLeadingDistribution? leadingDistribution,
19071907
Locale? locale,
19081908
Paint? background,
19091909
Paint? foreground,
@@ -2006,7 +2006,7 @@ class TextStyle {
20062006
'letterSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_letterSpacing}x" : "unspecified"}, '
20072007
'wordSpacing: ${ _encoded[0] & 0x02000 == 0x02000 ? "${_wordSpacing}x" : "unspecified"}, '
20082008
'height: ${ _encoded[0] & 0x04000 == 0x04000 ? "${_height}x" : "unspecified"}, '
2009-
'leadingDistribution: ${_encoded[0] & 0x0100 == 0x0100 ? "${LeadingDistribution.values[_encoded[8]]}" : "unspecified"}, '
2009+
'leadingDistribution: ${_encoded[0] & 0x0100 == 0x0100 ? "${TextLeadingDistribution.values[_encoded[8]]}" : "unspecified"}, '
20102010
'locale: ${ _encoded[0] & 0x08000 == 0x08000 ? _locale : "unspecified"}, '
20112011
'background: ${ _encoded[0] & 0x10000 == 0x10000 ? _background : "unspecified"}, '
20122012
'foreground: ${ _encoded[0] & 0x20000 == 0x20000 ? _foreground : "unspecified"}, '
@@ -2259,7 +2259,7 @@ ByteData _encodeStrut(
22592259
List<String>? fontFamilyFallback,
22602260
double? fontSize,
22612261
double? height,
2262-
LeadingDistribution? leadingDistribution,
2262+
TextLeadingDistribution? leadingDistribution,
22632263
double? leading,
22642264
FontWeight? fontWeight,
22652265
FontStyle? fontStyle,
@@ -2350,10 +2350,12 @@ class StrutStyle {
23502350
/// be provided for this property to take effect.
23512351
///
23522352
/// * `leading`: The minimum amount of leading between lines as a multiple of
2353-
/// the font size. `fontSize` must be provided for this property to take effect.
2353+
/// the font size. `fontSize` must be provided for this property to take
2354+
/// effect. The leading added by this property is distributed evenly over
2355+
/// and under the text, regardless of `leadingDistribution`.
23542356
///
2355-
/// * `leadingDistribution`: Specifies how the extra vertical space added by
2356-
/// the `height` multiplier should be distributed over and under the text,
2357+
/// * `leadingDistribution`: how the extra vertical space added by the
2358+
/// `height` multiplier should be distributed over and under the text,
23572359
/// independent of `leading` (which is always distributed evenly over and
23582360
/// under text).
23592361
///
@@ -2375,7 +2377,7 @@ class StrutStyle {
23752377
List<String>? fontFamilyFallback,
23762378
double? fontSize,
23772379
double? height,
2378-
LeadingDistribution? leadingDistribution,
2380+
TextLeadingDistribution? leadingDistribution,
23792381
double? leading,
23802382
FontWeight? fontWeight,
23812383
FontStyle? fontStyle,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ class EngineStrutStyle implements ui.StrutStyle {
12121212
double? fontSize,
12131213
double? height,
12141214
//TODO(LongCatIsLooong): implement leadingDistribution.
1215-
ui.LeadingDistribution? leadingDistribution,
1215+
ui.TextLeadingDistribution? leadingDistribution,
12161216
double? leading,
12171217
ui.FontWeight? fontWeight,
12181218
ui.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.LeadingDistribution? _leadingDistribution;
1238+
final ui.TextLeadingDistribution? _leadingDistribution;
12391239

12401240
@override
12411241
bool operator ==(Object other) {

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

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

207-
enum LeadingDistribution {
207+
enum TextLeadingDistribution {
208208
proportional,
209209
even,
210210
}
@@ -213,15 +213,15 @@ class TextHeightBehavior {
213213
const TextHeightBehavior({
214214
this.applyHeightToFirstAscent = true,
215215
this.applyHeightToLastDescent = true,
216-
this.leadingDistribution = LeadingDistribution.proportional,
216+
this.leadingDistribution = TextLeadingDistribution.proportional,
217217
});
218218
TextHeightBehavior.fromEncoded(int encoded)
219219
: applyHeightToFirstAscent = (encoded & 0x1) == 0,
220220
applyHeightToLastDescent = (encoded & 0x2) == 0,
221-
leadingDistribution = LeadingDistribution.values[encoded >> 2];
221+
leadingDistribution = TextLeadingDistribution.values[encoded >> 2];
222222
final bool applyHeightToFirstAscent;
223223
final bool applyHeightToLastDescent;
224-
final LeadingDistribution leadingDistribution;
224+
final TextLeadingDistribution leadingDistribution;
225225

226226
int encode() {
227227
return (applyHeightToFirstAscent ? 0 : 1 << 0)
@@ -273,7 +273,7 @@ abstract class TextStyle {
273273
double? letterSpacing,
274274
double? wordSpacing,
275275
double? height,
276-
LeadingDistribution? leadingDistribution,
276+
TextLeadingDistribution? leadingDistribution,
277277
Locale? locale,
278278
Paint? background,
279279
Paint? foreground,
@@ -384,7 +384,7 @@ abstract class StrutStyle {
384384
List<String>? fontFamilyFallback,
385385
double? fontSize,
386386
double? height,
387-
LeadingDistribution? leadingDistribution,
387+
TextLeadingDistribution? leadingDistribution,
388388
double? leading,
389389
FontWeight? fontWeight,
390390
FontStyle? fontStyle,

testing/dart/text_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
final TextStyle ts1 = TextStyle(color: const Color(0xFF00FF00), fontWeight: FontWeight.w800, fontSize: 10.0, height: 100.0);
4848
final TextStyle ts2 = TextStyle(fontFamily: 'test');
4949
final TextStyle ts3 = TextStyle(fontFamily: 'foo', fontFamilyFallback: <String>['Roboto', 'test']);
50-
final TextStyle ts4 = TextStyle(leadingDistribution: LeadingDistribution.even);
50+
final TextStyle ts4 = TextStyle(leadingDistribution: TextLeadingDistribution.even);
5151

5252
test('toString works', () {
5353
expect(
@@ -68,7 +68,7 @@ void main() {
6868
);
6969
expect(
7070
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: LeadingDistribution.even, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'),
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)'),
7272
);
7373
});
7474
});
@@ -87,7 +87,7 @@ void main() {
8787
);
8888
const TextHeightBehavior behavior4 = TextHeightBehavior(
8989
applyHeightToLastDescent: false,
90-
leadingDistribution: LeadingDistribution.even,
90+
leadingDistribution: TextLeadingDistribution.even,
9191
);
9292

9393
test('default constructor works', () {
@@ -104,7 +104,7 @@ void main() {
104104
expect(behavior3.applyHeightToLastDescent, equals(false));
105105

106106
expect(behavior4.applyHeightToLastDescent, equals(false));
107-
expect(behavior4.leadingDistribution, equals(LeadingDistribution.even));
107+
expect(behavior4.leadingDistribution, equals(TextLeadingDistribution.even));
108108
});
109109

110110
test('encode works', () {
@@ -124,11 +124,11 @@ void main() {
124124
});
125125

126126
test('toString works', () {
127-
expect(behavior0.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: true, leadingDistribution: LeadingDistribution.proportional)'));
128-
expect(behavior1.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.proportional)'));
129-
expect(behavior2.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: true, leadingDistribution: LeadingDistribution.proportional)'));
130-
expect(behavior3.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.proportional)'));
131-
expect(behavior4.toString(), equals('TextHeightBehavior(applyHeightToFirstAscent: true, applyHeightToLastDescent: false, leadingDistribution: LeadingDistribution.even)'));
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)'));
132132
});
133133
});
134134

third_party/txt/src/txt/paragraph_style.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class TextDirection {
4848
// the line will use the default font metric provided ascent/descent and
4949
// ParagraphStyle.height or TextStyle.height will not take effect.
5050
//
51-
// kHalfLeading determines how the leading is distributed over and under the
51+
// kEvenLeading determines how the leading is distributed over and under the
5252
// text. When true, half of the leading is added to the top of the text and the
5353
// other half is added to the bottom of the text. Otherwise, instead of
5454
// distributing the space evenly, it's distributed proportionally to the font's
@@ -66,7 +66,7 @@ enum TextHeightBehavior {
6666
kDisableFirstAscent = 0x1,
6767
kDisableLastDescent = 0x2,
6868
kDisableAll = 0x1 | 0x2,
69-
kHalfLeading = 0x1 << 2,
69+
kEvenLeading = 0x1 << 2,
7070
};
7171

7272
class ParagraphStyle {

third_party/txt/src/txt/paragraph_txt.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void ParagraphTxt::ComputeStrut(StrutMetrics* strut, SkFont& font) {
570570
paragraph_style_.strut_has_leading_distribution_override
571571
? paragraph_style_.strut_half_leading
572572
: paragraph_style_.text_height_behavior &
573-
TextHeightBehavior::kHalfLeading;
573+
TextHeightBehavior::kEvenLeading;
574574

575575
const double available_height =
576576
half_leading_enabled ? metrics_height : strut_height;
@@ -1215,7 +1215,7 @@ void ParagraphTxt::UpdateLineMetrics(const SkFontMetrics& metrics,
12151215
style.has_leading_distribution_override
12161216
? style.half_leading
12171217
: paragraph_style_.text_height_behavior &
1218-
TextHeightBehavior::kHalfLeading;
1218+
TextHeightBehavior::kEvenLeading;
12191219

12201220
// Scale the ascent and descent such that the sum of ascent and
12211221
// descent is `style.height * style.font_size`.

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(HeightOverrideHalfLeadingParagraph)) {
18921892

18931893
txt::ParagraphStyle paragraph_style;
18941894
paragraph_style.max_lines = 10;
1895-
paragraph_style.text_height_behavior = TextHeightBehavior::kHalfLeading;
1895+
paragraph_style.text_height_behavior = TextHeightBehavior::kEvenLeading;
18961896
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
18971897

18981898
txt::TextStyle text_style;

0 commit comments

Comments
 (0)