diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 0cd7d7d65af..50a520ec14e 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -1641,7 +1641,9 @@ class LineMetrics { /// Total height of the line from the top edge to the bottom edge. /// - /// This is equivalent to `ascent + descent` + /// This is equivalent to `round(ascent + descent)`. This value is provided + /// separately due to rounding causing sub-pixel differences from the unrounded + /// values. final double height; /// Width of the line from the left edge of the leftmost glyph to the right @@ -1661,6 +1663,9 @@ class LineMetrics { final double left; /// The y coordinate of the baseline for this line from the top of the paragraph. + /// + /// The bottom edge of the paragraph up to and including this line may be obtained + /// through `baseline + descent`. final double baseline; /// The number of this line in the overall paragraph, with the first line being diff --git a/lib/ui/text/line_metrics.cc b/lib/ui/text/line_metrics.cc index 11c5460764c..a224e9b29b6 100644 --- a/lib/ui/text/line_metrics.cc +++ b/lib/ui/text/line_metrics.cc @@ -31,10 +31,13 @@ Dart_Handle DartConverter::ToDart( Dart_Handle argv[argc] = { tonic::ToDart(*val.hard_break), tonic::ToDart(*val.ascent), - tonic::ToDart(*val.descent), tonic::ToDart(*val.unscaled_ascent), - tonic::ToDart(*val.height), tonic::ToDart(*val.width), - tonic::ToDart(*val.left), tonic::ToDart(*val.baseline), - tonic::ToDart(*val.line_number)}; + tonic::ToDart(*val.descent), tonic::ToDart(*val.unscaled_ascent), + // We add then round to get the height. The + // definition of height here is different + // than the one in LibTxt. + tonic::ToDart(round(*val.ascent + *val.descent)), + tonic::ToDart(*val.width), tonic::ToDart(*val.left), + tonic::ToDart(*val.baseline), tonic::ToDart(*val.line_number)}; return Dart_New(GetLineMetricsType(), tonic::ToDart("_"), argc, argv); } diff --git a/third_party/txt/src/txt/line_metrics.h b/third_party/txt/src/txt/line_metrics.h index 38cecd1dc71..2efd538c710 100644 --- a/third_party/txt/src/txt/line_metrics.h +++ b/third_party/txt/src/txt/line_metrics.h @@ -48,7 +48,9 @@ class LineMetrics { double ascent = 0.0; double descent = 0.0; double unscaled_ascent = 0.0; - // Height of the line. + // Total height of the paragraph including the current line. + // + // The height of the current line is `round(ascent + descent)`. double height = 0.0; // Width of the line. double width = 0.0;