Update the ui.LineMetrics.height metric to be more useful to external users (#11456)

This commit is contained in:
Gary Qian 2019-08-28 12:26:42 -07:00 committed by GitHub
parent 6f8565044d
commit 13ece5c7fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -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

View File

@ -31,10 +31,13 @@ Dart_Handle DartConverter<flutter::LineMetrics>::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);
}

View File

@ -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;