forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose LineMetrics in dart:ui (flutter#10670)
- Loading branch information
Showing
12 changed files
with
347 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/lib/ui/text/line_metrics.h" | ||
|
||
#include "flutter/fml/logging.h" | ||
#include "third_party/tonic/dart_class_library.h" | ||
#include "third_party/tonic/dart_state.h" | ||
#include "third_party/tonic/logging/dart_error.h" | ||
|
||
using namespace flutter; | ||
|
||
namespace tonic { | ||
|
||
namespace { | ||
|
||
Dart_Handle GetLineMetricsType() { | ||
DartClassLibrary& class_library = DartState::Current()->class_library(); | ||
Dart_Handle type = | ||
Dart_HandleFromPersistent(class_library.GetClass("ui", "LineMetrics")); | ||
FML_DCHECK(!LogIfError(type)); | ||
return type; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
Dart_Handle DartConverter<flutter::LineMetrics>::ToDart( | ||
const flutter::LineMetrics& val) { | ||
constexpr int argc = 9; | ||
|
||
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)}; | ||
return Dart_New(GetLineMetricsType(), tonic::ToDart("_"), argc, argv); | ||
} | ||
|
||
Dart_Handle DartListFactory<flutter::LineMetrics>::NewList(intptr_t length) { | ||
return Dart_NewListOfType(GetLineMetricsType(), length); | ||
} | ||
|
||
} // namespace tonic |
This file contains 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_ | ||
#define FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_ | ||
|
||
#include "third_party/dart/runtime/include/dart_api.h" | ||
#include "third_party/tonic/converter/dart_converter.h" | ||
|
||
namespace flutter { | ||
|
||
struct LineMetrics { | ||
const bool* hard_break; | ||
|
||
// The final computed ascent and descent for the line. This can be impacted by | ||
// the strut, height, scaling, as well as outlying runs that are very tall. | ||
// | ||
// The top edge is `baseline - ascent` and the bottom edge is `baseline + | ||
// descent`. Ascent and descent are provided as positive numbers. Raw numbers | ||
// for specific runs of text can be obtained in run_metrics_map. These values | ||
// are the cumulative metrics for the entire line. | ||
const double* ascent; | ||
const double* descent; | ||
const double* unscaled_ascent; | ||
// Height of the line. | ||
const double* height; | ||
// Width of the line. | ||
const double* width; | ||
// The left edge of the line. The right edge can be obtained with `left + | ||
// width` | ||
const double* left; | ||
// The y position of the baseline for this line from the top of the paragraph. | ||
const double* baseline; | ||
// Zero indexed line number. | ||
const size_t* line_number; | ||
|
||
LineMetrics(); | ||
|
||
LineMetrics(const bool* hard_break, | ||
const double* ascent, | ||
const double* descent, | ||
const double* unscaled_ascent, | ||
const double* height, | ||
const double* width, | ||
const double* left, | ||
const double* baseline, | ||
const size_t* line_number) | ||
: hard_break(hard_break), | ||
ascent(ascent), | ||
descent(descent), | ||
unscaled_ascent(unscaled_ascent), | ||
height(height), | ||
width(width), | ||
left(left), | ||
baseline(baseline), | ||
line_number(line_number) {} | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
namespace tonic { | ||
template <> | ||
struct DartConverter<flutter::LineMetrics> { | ||
static Dart_Handle ToDart(const flutter::LineMetrics& val); | ||
}; | ||
|
||
template <> | ||
struct DartListFactory<flutter::LineMetrics> { | ||
static Dart_Handle NewList(intptr_t length); | ||
}; | ||
|
||
} // namespace tonic | ||
|
||
#endif // FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_ |
This file contains 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 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 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 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 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.