This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Engine/LibTxt/dart:ui impl of TextHeightBehavior #15087
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7be0036
Begin adding API for boundary line height behavior
GaryQian 82f9361
Add enum
GaryQian 882397b
LibTxt begin impl
GaryQian 5a92bbb
Add docs/comments
GaryQian 3125514
add tests
GaryQian 2757cf1
boundaryLineHeight class
GaryQian 86bf1f2
Caps
GaryQian 5ec5618
Add BoundaryLineHeightBehavior to web_ui
GaryQian 3e7e846
More web_ui impl
GaryQian b8e6f03
toString
GaryQian 338516d
COmments
GaryQian d683d82
Add info on defaults
GaryQian 6882081
Rename first/last to be more descriptive
GaryQian ba29ea3
Rename BoundaryLineHeightBehavior -> HeightBehavior, address comments
GaryQian 8423170
Add unit tests for HeightBehavior
GaryQian 0c4c3ab
simpler property naming
GaryQian 8f2b9eb
Fix tests, feed linter
GaryQian bb7cf30
Sync changes with web_ui
GaryQian fa18e73
Fix typo/bug
GaryQian c531373
Add const to contructors
GaryQian d9829fa
Fix wording issues
GaryQian 5764a36
Fix analyzer
GaryQian 9cdc51a
Analyzer part 2
GaryQian 889b95d
REname HeightBehavior -> TextHeighBehavior
GaryQian 2b46f70
Fix indentation
GaryQian ddda7e6
Invert enum bits, fix namiming change
GaryQian ba9f09a
Fix tests:
GaryQian 24dbc56
Formatting
GaryQian 8a0d421
Rename to TextHeightBehavior in Web_ui
GaryQian 5668145
Address nets
GaryQian 5ff8cf7
MOre missed renaming
GaryQian 30bfb54
Apply naming changes to comments
GaryQian abbaafb
Fix dart unittests
GaryQian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,94 @@ enum TextDecorationStyle { | |
wavy | ||
} | ||
|
||
/// {@template flutter.dart:ui.textHeightBehavior} | ||
/// Defines how the paragraph will apply [TextStyle.height] to the ascent of the | ||
/// first line and descent of the last line. | ||
/// | ||
/// Each boolean value represents whether the [TextStyle.height] modifier will | ||
/// be applied to the corresponding metric. By default, all properties are true, | ||
/// and [TextStyle.height] is applied as normal. When set to false, the font's | ||
/// default ascent will be used. | ||
/// {@endtemplate} | ||
class TextHeightBehavior { | ||
|
||
/// Creates a new TextHeightBehavior object. | ||
/// | ||
/// * applyHeightToFirstAscent: When true, the [TextStyle.height] modifier | ||
/// will be applied to the ascent of the first line. When false, the font's | ||
/// default ascent will be used. | ||
/// * applyHeightToLastDescent: When true, the [TextStyle.height] modifier | ||
/// will be applied to the descent of the last line. When false, the font's | ||
/// default descent will be used. | ||
/// | ||
/// All properties default to true (height modifications applied as normal). | ||
const TextHeightBehavior({ | ||
this.applyHeightToFirstAscent = true, | ||
this.applyHeightToLastDescent = true, | ||
}); | ||
|
||
/// Creates a new TextHeightBehavior object from an encoded form. | ||
/// | ||
/// See [encode] for the creation of the encoded form. | ||
const TextHeightBehavior.fromEncoded(int encoded) : applyHeightToFirstAscent = (encoded & 0x1) == 0, | ||
applyHeightToLastDescent = (encoded & 0x2) == 0; | ||
|
||
|
||
/// Whether to apply the [TextStyle.height] modifier to the ascent of the first | ||
/// line in the paragraph. | ||
/// | ||
/// When true, the [TextStyle.height] modifier will be applied to to the ascent | ||
/// of the first line. When false, the font's default ascent will be used and | ||
/// the [TextStyle.height] will have no effect on the ascent of the first line. | ||
/// | ||
/// This property only has effect if a non-null [TextStyle.height] is specified. | ||
/// | ||
/// Defaults to true (height modifications applied as normal). | ||
final bool applyHeightToFirstAscent; | ||
|
||
/// Whether to apply the [TextStyle.height] modifier to the descent of the last | ||
/// line in the paragraph. | ||
/// | ||
/// When true, the [TextStyle.height] modifier will be applied to to the descent | ||
/// of the last line. When false, the font's default descent will be used and | ||
/// the [TextStyle.height] will have no effect on the descent of the last line. | ||
/// | ||
/// This property only has effect if a non-null [TextStyle.height] is specified. | ||
/// | ||
/// Defaults to true (height modifications applied as normal). | ||
final bool applyHeightToLastDescent; | ||
|
||
/// Returns an encoded int representation of this object. | ||
int encode() { | ||
return (applyHeightToFirstAscent ? 0 : 1 << 0) | (applyHeightToLastDescent ? 0 : 1 << 1); | ||
} | ||
|
||
@override | ||
bool operator ==(dynamic other) { | ||
if (other.runtimeType != runtimeType) | ||
return false; | ||
return other is TextHeightBehavior | ||
&& other.applyHeightToFirstAscent == applyHeightToFirstAscent | ||
&& other.applyHeightToLastDescent == applyHeightToLastDescent; | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
return hashValues( | ||
applyHeightToFirstAscent, | ||
applyHeightToLastDescent, | ||
); | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'TextHeightBehavior(' | ||
'applyHeightToFirstAscent: $applyHeightToFirstAscent, ' | ||
'applyHeightToLastDescent: $applyHeightToLastDescent' | ||
')'; | ||
} | ||
} | ||
|
||
/// Determines if lists [a] and [b] are deep equivalent. | ||
/// | ||
/// Returns true if the lists are both null, or if they are both non-null, have | ||
|
@@ -746,20 +834,23 @@ class TextStyle { | |
// | ||
// - Element 5: The value of |maxLines|. | ||
// | ||
// - Element 6: The encoded value of |textHeightBehavior|. | ||
// | ||
Int32List _encodeParagraphStyle( | ||
TextAlign textAlign, | ||
TextDirection textDirection, | ||
int maxLines, | ||
String fontFamily, | ||
double fontSize, | ||
double height, | ||
TextHeightBehavior textHeightBehavior, | ||
FontWeight fontWeight, | ||
FontStyle fontStyle, | ||
StrutStyle strutStyle, | ||
String ellipsis, | ||
Locale locale, | ||
) { | ||
final Int32List result = Int32List(6); // also update paragraph_builder.cc | ||
final Int32List result = Int32List(7); // also update paragraph_builder.cc | ||
if (textAlign != null) { | ||
result[0] |= 1 << 1; | ||
result[1] = textAlign.index; | ||
|
@@ -780,28 +871,32 @@ Int32List _encodeParagraphStyle( | |
result[0] |= 1 << 5; | ||
result[5] = maxLines; | ||
} | ||
if (fontFamily != null) { | ||
if (textHeightBehavior != null) { | ||
result[0] |= 1 << 6; | ||
result[6] = textHeightBehavior.encode(); | ||
} | ||
if (fontFamily != null) { | ||
result[0] |= 1 << 7; | ||
// Passed separately to native. | ||
} | ||
if (fontSize != null) { | ||
result[0] |= 1 << 7; | ||
result[0] |= 1 << 8; | ||
// Passed separately to native. | ||
} | ||
if (height != null) { | ||
result[0] |= 1 << 8; | ||
result[0] |= 1 << 9; | ||
// Passed separately to native. | ||
} | ||
if (strutStyle != null) { | ||
result[0] |= 1 << 9; | ||
result[0] |= 1 << 10; | ||
// Passed separately to native. | ||
} | ||
if (ellipsis != null) { | ||
result[0] |= 1 << 10; | ||
result[0] |= 1 << 11; | ||
// Passed separately to native. | ||
} | ||
if (locale != null) { | ||
result[0] |= 1 << 11; | ||
result[0] |= 1 << 12; | ||
// Passed separately to native. | ||
} | ||
return result; | ||
|
@@ -842,6 +937,9 @@ class ParagraphStyle { | |
/// the line height to take the height as defined by the font, which may not | ||
/// be exactly the height of the `fontSize`. | ||
/// | ||
/// * `textHeightBehavior`: Specifies how the `height` multiplier is | ||
/// applied to ascent of the first line and the descent of the last line. | ||
/// | ||
/// * `fontWeight`: The typeface thickness to use when painting the text | ||
/// (e.g., bold). | ||
/// | ||
|
@@ -869,6 +967,7 @@ class ParagraphStyle { | |
String fontFamily, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs on this constructor are out of date |
||
double fontSize, | ||
double height, | ||
TextHeightBehavior textHeightBehavior, | ||
FontWeight fontWeight, | ||
FontStyle fontStyle, | ||
StrutStyle strutStyle, | ||
|
@@ -881,6 +980,7 @@ class ParagraphStyle { | |
fontFamily, | ||
fontSize, | ||
height, | ||
textHeightBehavior, | ||
fontWeight, | ||
fontStyle, | ||
strutStyle, | ||
|
@@ -929,11 +1029,14 @@ class ParagraphStyle { | |
'fontWeight: ${ _encoded[0] & 0x008 == 0x008 ? FontWeight.values[_encoded[3]] : "unspecified"}, ' | ||
'fontStyle: ${ _encoded[0] & 0x010 == 0x010 ? FontStyle.values[_encoded[4]] : "unspecified"}, ' | ||
'maxLines: ${ _encoded[0] & 0x020 == 0x020 ? _encoded[5] : "unspecified"}, ' | ||
'fontFamily: ${ _encoded[0] & 0x040 == 0x040 ? _fontFamily : "unspecified"}, ' | ||
'fontSize: ${ _encoded[0] & 0x080 == 0x080 ? _fontSize : "unspecified"}, ' | ||
'height: ${ _encoded[0] & 0x100 == 0x100 ? "${_height}x" : "unspecified"}, ' | ||
'ellipsis: ${ _encoded[0] & 0x200 == 0x200 ? "\"$_ellipsis\"" : "unspecified"}, ' | ||
'locale: ${ _encoded[0] & 0x400 == 0x400 ? _locale : "unspecified"}' | ||
'textHeightBehavior: ${ | ||
_encoded[0] & 0x040 == 0x040 ? | ||
TextHeightBehavior.fromEncoded(_encoded[6]).toString() : "unspecified"}, ' | ||
'fontFamily: ${ _encoded[0] & 0x080 == 0x080 ? _fontFamily : "unspecified"}, ' | ||
'fontSize: ${ _encoded[0] & 0x100 == 0x100 ? _fontSize : "unspecified"}, ' | ||
'height: ${ _encoded[0] & 0x200 == 0x200 ? "${_height}x" : "unspecified"}, ' | ||
'ellipsis: ${ _encoded[0] & 0x400 == 0x400 ? "\"$_ellipsis\"" : "unspecified"}, ' | ||
'locale: ${ _encoded[0] & 0x800 == 0x800 ? _locale : "unspecified"}' | ||
')'; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment on this method is out of date