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

Commit 5a0eda4

Browse files
committed
boundaryLineHeight class
1 parent d911ece commit 5a0eda4

1 file changed

Lines changed: 51 additions & 5 deletions

File tree

lib/ui/text.dart

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,52 @@ enum TextDecorationStyle {
431431
wavy
432432
}
433433

434+
/// Defines how the paragraph will handle the ascent of the first line and
435+
/// descent of the last line. These lines are referred to as "Boundary" lines.
436+
class BoundaryLineHeightBehavior {
437+
438+
/// Creates a new BoundaryLineHeightBehavior object.
439+
///
440+
/// * first: When true, the [TextStyle.height] modifier will be applied to
441+
/// to the ascent of the first line. When false, the font's default ascent
442+
/// will be used.
443+
/// * last: When true, the [TextStyle.height] modifier will be applied to
444+
/// to the descent of the last line. When false, the font's default descent
445+
/// will be used.
446+
BoundaryLineHeightBehavior({
447+
this.first = true,
448+
this.last = true,
449+
});
450+
451+
/// Creates a new BoundaryLineHeightBehavior object from an encoded form.
452+
///
453+
/// See [encode] for the creation of the encoded form.
454+
BoundaryLineHeightBehavior.fromEncoded(int encoded) : first = (encoded & 0x1) > 0,
455+
last = (encoded & 0x2) > 0;
456+
457+
458+
/// Whether to apply the [TextStyle.height] modifier or not to the ascent of
459+
/// the first line in the paragraph.
460+
///
461+
/// When true, the [TextStyle.height] modifier will be applied to to the ascent
462+
/// of the first line. When false, the font's default ascent will be used and
463+
/// the [TextStyle.height] will have no effect on the ascent of the first line.
464+
final bool first;
465+
466+
/// Whether to apply the [TextStyle.height] modifier or not to the descent of
467+
/// the last line in the paragraph.
468+
///
469+
/// When true, the [TextStyle.height] modifier will be applied to to the descent
470+
/// of the last line. When false, the font's default descent will be used and
471+
/// the [TextStyle.height] will have no effect on the descent of the last line.
472+
final bool last;
473+
474+
/// Returns an encoded int representation of this object.
475+
int encode() {
476+
return 0 + (first ? 1 << 0 : 0) + (last ? 1 << 1 : 0);
477+
}
478+
}
479+
434480
/// Determines if lists [a] and [b] are deep equivalent.
435481
///
436482
/// Returns true if the lists are both null, or if they are both non-null, have
@@ -765,7 +811,7 @@ Int32List _encodeParagraphStyle(
765811
String fontFamily,
766812
double fontSize,
767813
double height,
768-
int boundingLineHeightBehavior,
814+
BoundaryLineHeightBehavior boundaryLineHeightBehavior,
769815
FontWeight fontWeight,
770816
FontStyle fontStyle,
771817
StrutStyle strutStyle,
@@ -793,9 +839,9 @@ Int32List _encodeParagraphStyle(
793839
result[0] |= 1 << 5;
794840
result[5] = maxLines;
795841
}
796-
if (boundingLineHeightBehavior != null) {
842+
if (boundaryLineHeightBehavior != null) {
797843
result[0] |= 1 << 6;
798-
result[6] = boundingLineHeightBehavior;
844+
result[6] = boundaryLineHeightBehavior.encode();
799845
}
800846
if (fontFamily != null) {
801847
result[0] |= 1 << 7;
@@ -886,7 +932,7 @@ class ParagraphStyle {
886932
String fontFamily,
887933
double fontSize,
888934
double height,
889-
int boundingLineHeightBehavior,
935+
BoundaryLineHeightBehavior boundaryLineHeightBehavior,
890936
FontWeight fontWeight,
891937
FontStyle fontStyle,
892938
StrutStyle strutStyle,
@@ -899,7 +945,7 @@ class ParagraphStyle {
899945
fontFamily,
900946
fontSize,
901947
height,
902-
boundingLineHeightBehavior,
948+
boundaryLineHeightBehavior,
903949
fontWeight,
904950
fontStyle,
905951
strutStyle,

0 commit comments

Comments
 (0)