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

Commit 47d6148

Browse files
add test
1 parent 1519006 commit 47d6148

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

lib/ui/text.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ part of dart.ui;
66
/// A [TextStyle.height] value that indicates the text span should take
77
/// the height defined by the font, which may not be exactly the height of
88
/// [TextStyle.fontSize].
9+
// To change the sentinel value, search for "kTextHeightNone" in the source code.
910
const double kTextHeightNone = 0.0;
1011

1112
/// Whether to use the italic type variation of glyphs in the font.
@@ -1830,6 +1831,7 @@ class TextStyle {
18301831
@override
18311832
String toString() {
18321833
final List<String>? fontFamilyFallback = _fontFamilyFallback;
1834+
final String heightText = _encoded[0] & 0x02000 == 0x02000 ? (_height == kTextHeightNone ? 'kTextHeightNone' : '${_height}x') : 'unspecified'
18331835
return 'TextStyle('
18341836
'color: ${ _encoded[0] & 0x00002 == 0x00002 ? Color(_encoded[1]) : "unspecified"}, '
18351837
'decoration: ${ _encoded[0] & 0x00004 == 0x00004 ? TextDecoration._(_encoded[2]) : "unspecified"}, '
@@ -1848,7 +1850,7 @@ class TextStyle {
18481850
'fontSize: ${ _encoded[0] & 0x00400 == 0x00400 ? _fontSize : "unspecified"}, '
18491851
'letterSpacing: ${ _encoded[0] & 0x00800 == 0x00800 ? "${_letterSpacing}x" : "unspecified"}, '
18501852
'wordSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_wordSpacing}x" : "unspecified"}, '
1851-
'height: ${ _encoded[0] & 0x02000 == 0x02000 ? "${_height}x" : "unspecified"}, '
1853+
'height: $heightText, '
18521854
'leadingDistribution: ${_leadingDistribution ?? "unspecified"}, '
18531855
'locale: ${ _encoded[0] & 0x04000 == 0x04000 ? _locale : "unspecified"}, '
18541856
'background: ${ _encoded[0] & 0x08000 == 0x08000 ? _background : "unspecified"}, '

lib/ui/text/paragraph_builder.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
namespace flutter {
3131
namespace {
3232

33+
const double kTextHeightNone = 0.0;
34+
3335
// TextStyle
3436

3537
const int kTSLeadingDistributionIndex = 0;
@@ -445,7 +447,7 @@ void ParagraphBuilder::pushStyle(const tonic::Int32List& encoded,
445447

446448
if (mask & kTSHeightMask) {
447449
style.height = height;
448-
style.has_height_override = style.height != 0;
450+
style.has_height_override = style.height != kTextHeightNone;
449451
}
450452

451453
if (mask & kTSLocaleMask) {

lib/web_ui/lib/text.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ part of ui;
66

77
// This constant must be consistent with `kTextHeightNone` defined in
88
// flutter/lib/ui/text.dart.
9+
// To change the sentinel value, search for "kTextHeightNone" in the source code.
910
const double kTextHeightNone = 0.0;
1011

1112
enum FontStyle {

lib/web_ui/skwasm/text/text_style.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../wrappers.h"
77
#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
88

9+
const double kTextHeightNone = 0.0;
10+
911
using namespace skia::textlayout;
1012
using namespace Skwasm;
1113

@@ -96,7 +98,7 @@ SKWASM_EXPORT void textStyle_setWordSpacing(TextStyle* style,
9698

9799
SKWASM_EXPORT void textStyle_setHeight(TextStyle* style, SkScalar height) {
98100
style->setHeight(height);
99-
style->setHeightOverride(height != 0.0);
101+
style->setHeightOverride(height != kTextHeightNone);
100102
}
101103

102104
SKWASM_EXPORT void textStyle_setHalfLeading(TextStyle* style,

testing/dart/paragraph_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,15 @@ void main() {
349349
expect(metrics, hasLength(1));
350350
}
351351
});
352+
353+
test('kTextHeightNone unsets the height multiplier', () {
354+
const double fontSize = 10;
355+
const String text = 'A';
356+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontSize: fontSize, height: 10));
357+
builder.pushStyle(TextStyle(height: kTextHeightNone));
358+
builder.addText(text);
359+
final Paragraph paragraph = builder.build()
360+
..layout(const ParagraphConstraints(width: 1000));
361+
paragraph.height = fontSize;
362+
});
352363
}

testing/dart/text_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ void testParagraphStyle() {
5454
final ParagraphStyle ps1 = ParagraphStyle(textDirection: TextDirection.rtl, fontSize: 14.0);
5555
final ParagraphStyle ps2 = ParagraphStyle(textAlign: TextAlign.center, fontWeight: FontWeight.w800, fontSize: 10.0, height: 100.0);
5656
final ParagraphStyle ps3 = ParagraphStyle(fontWeight: FontWeight.w700, fontSize: 12.0, height: 123.0);
57+
final ParagraphStyle ps3 = ParagraphStyle(fontWeight: FontWeight.w700, fontSize: 12.0, height: kTextHeightNone);
5758

5859
test('ParagraphStyle toString works', () {
5960
expect(ps0.toString(), equals('ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.ltr, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, textHeightBehavior: unspecified, fontFamily: unspecified, fontSize: 14.0, height: unspecified, strutStyle: unspecified, ellipsis: unspecified, locale: unspecified)'));
6061
expect(ps1.toString(), equals('ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.rtl, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, textHeightBehavior: unspecified, fontFamily: unspecified, fontSize: 14.0, height: unspecified, strutStyle: unspecified, ellipsis: unspecified, locale: unspecified)'));
6162
expect(ps2.toString(), equals('ParagraphStyle(textAlign: TextAlign.center, textDirection: unspecified, fontWeight: FontWeight.w800, fontStyle: unspecified, maxLines: unspecified, textHeightBehavior: unspecified, fontFamily: unspecified, fontSize: 10.0, height: 100.0x, strutStyle: unspecified, ellipsis: unspecified, locale: unspecified)'));
6263
expect(ps3.toString(), equals('ParagraphStyle(textAlign: unspecified, textDirection: unspecified, fontWeight: FontWeight.w700, fontStyle: unspecified, maxLines: unspecified, textHeightBehavior: unspecified, fontFamily: unspecified, fontSize: 12.0, height: 123.0x, strutStyle: unspecified, ellipsis: unspecified, locale: unspecified)'));
64+
expect(ps4.toString(), equals('ParagraphStyle(textAlign: unspecified, textDirection: unspecified, fontWeight: FontWeight.w700, fontStyle: unspecified, maxLines: unspecified, textHeightBehavior: unspecified, fontFamily: unspecified, fontSize: 12.0, height: unspecified, strutStyle: unspecified, ellipsis: unspecified, locale: unspecified)'));
6365
});
6466
}
6567

@@ -69,6 +71,7 @@ void testTextStyle() {
6971
final TextStyle ts2 = TextStyle(fontFamily: 'test');
7072
final TextStyle ts3 = TextStyle(fontFamily: 'foo', fontFamilyFallback: <String>['Roboto', 'test']);
7173
final TextStyle ts4 = TextStyle(leadingDistribution: TextLeadingDistribution.even);
74+
final TextStyle ts5 = TextStyle(height: kTextHeightNone);
7275

7376
test('TextStyle toString works', () {
7477
expect(
@@ -91,6 +94,10 @@ void testTextStyle() {
9194
ts4.toString(),
9295
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, fontVariations: unspecified)'),
9396
);
97+
expect(
98+
ts5.toString(),
99+
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: kTextHeightNone, leadingDistribution: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified, fontVariations: unspecified)'),
100+
);
94101
});
95102
}
96103

0 commit comments

Comments
 (0)