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

Commit 48502a1

Browse files
committed
Move to TextPosition, remove extra fields on LineMetrics (for now)
1 parent 3f534dc commit 48502a1

File tree

6 files changed

+23
-72
lines changed

6 files changed

+23
-72
lines changed

lib/ui/text.dart

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,6 @@ class LineMetrics {
16801680
this.left,
16811681
this.baseline,
16821682
this.lineNumber,
1683-
this.startIndex,
1684-
this.endIndex,
16851683
});
16861684

16871685
@pragma('vm:entry-point')
@@ -1695,8 +1693,6 @@ class LineMetrics {
16951693
this.left,
16961694
this.baseline,
16971695
this.lineNumber,
1698-
this.startIndex,
1699-
this.endIndex,
17001696
);
17011697

17021698
/// True if this line ends with an explicit line break (e.g. '\n') or is the end
@@ -1764,13 +1760,6 @@ class LineMetrics {
17641760
///
17651761
/// For example, the first line is line 0, second line is line 1.
17661762
final int lineNumber;
1767-
1768-
/// The starting text index for this line, in Unicode code points.
1769-
final int startIndex;
1770-
1771-
/// The ending text index, including the newline for this line, in Unicode
1772-
/// code points.
1773-
final int endIndex;
17741763
}
17751764

17761765
/// A paragraph of text.
@@ -1882,16 +1871,8 @@ class Paragraph extends NativeFieldWrapperClass2 {
18821871
/// on both sides. In such cases, this method will return [offset, offset+1].
18831872
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
18841873
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1885-
TextRange getWordBoundary(dynamic position) {
1886-
// TODO(gspencergoog): have this take only a TextPosition once the framework
1887-
// code is calling it with that.
1888-
List<int> boundary;
1889-
if (position is TextPosition) {
1890-
boundary = _getWordBoundary(position.offset);
1891-
} else {
1892-
final int offset = position;
1893-
boundary = _getWordBoundary(offset);
1894-
}
1874+
TextRange getWordBoundary(TextPosition position) {
1875+
final List<int> boundary = _getWordBoundary(position.offset);
18951876
return TextRange(start: boundary[0], end: boundary[1]);
18961877
}
18971878
List<int> _getWordBoundary(int offset) native 'Paragraph_getWordBoundary';
@@ -1901,10 +1882,12 @@ class Paragraph extends NativeFieldWrapperClass2 {
19011882
/// The newline (if any) is returned as part of the range.
19021883
///
19031884
/// This can potentially be expensive, since it needs to compute the line
1904-
/// metrics, so use it sparingly. If higher performance is needed, caching the
1905-
/// results of [computeLineMetrics] is recommended (which also contains the
1906-
/// start and end of each line).
1907-
List<int> getLineBoundary(int offset) native 'Paragraph_getLineBoundary';
1885+
/// metrics, so use it sparingly.
1886+
TextRange getLineBoundary(TextPosition position) {
1887+
final List<int> boundary = _getLineBoundary(position.offset);
1888+
return TextRange(start: boundary[0], end: boundary[1]);
1889+
}
1890+
List<int> _getLineBoundary(int offset) native 'Paragraph_getLineBoundary';
19081891

19091892
// Redirecting the paint function in this way solves some dependency problems
19101893
// in the C++ code. If we straighten out the C++ dependencies, we can remove

lib/ui/text/line_metrics.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Dart_Handle GetLineMetricsType() {
2727

2828
Dart_Handle DartConverter<flutter::LineMetrics>::ToDart(
2929
const flutter::LineMetrics& val) {
30-
constexpr int argc = 11;
30+
constexpr int argc = 9;
3131

3232
Dart_Handle argv[argc] = {
3333
tonic::ToDart(*val.hard_break), tonic::ToDart(*val.ascent),
@@ -37,8 +37,7 @@ Dart_Handle DartConverter<flutter::LineMetrics>::ToDart(
3737
// than the one in LibTxt.
3838
tonic::ToDart(round(*val.ascent + *val.descent)),
3939
tonic::ToDart(*val.width), tonic::ToDart(*val.left),
40-
tonic::ToDart(*val.baseline), tonic::ToDart(*val.line_number),
41-
tonic::ToDart(*val.start_index), tonic::ToDart(*val.end_index)};
40+
tonic::ToDart(*val.baseline), tonic::ToDart(*val.line_number)};
4241
return Dart_New(GetLineMetricsType(), tonic::ToDart("_"), argc, argv);
4342
}
4443

lib/ui/text/line_metrics.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ struct LineMetrics {
3434
const double* baseline;
3535
// Zero indexed line number.
3636
const size_t* line_number;
37-
// The starting text index for this line.
38-
const size_t* start_index;
39-
// The ending index for this line, including the newline, if any.
40-
const size_t* end_index;
4137

4238
LineMetrics();
4339

@@ -49,9 +45,7 @@ struct LineMetrics {
4945
const double* width,
5046
const double* left,
5147
const double* baseline,
52-
const size_t* line_number,
53-
const size_t* start_index,
54-
const size_t* end_index)
48+
const size_t* line_number)
5549
: hard_break(hard_break),
5650
ascent(ascent),
5751
descent(descent),
@@ -60,9 +54,7 @@ struct LineMetrics {
6054
width(width),
6155
left(left),
6256
baseline(baseline),
63-
line_number(line_number),
64-
start_index(start_index),
65-
end_index(end_index) {}
57+
line_number(line_number) {}
6658
};
6759

6860
} // namespace flutter

lib/ui/text/paragraph.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ std::vector<LineMetrics> Paragraph::computeLineMetrics() {
158158
for (txt::LineMetrics& line : metrics) {
159159
result.emplace_back(&line.hard_break, &line.ascent, &line.descent,
160160
&line.unscaled_ascent, &line.height, &line.width,
161-
&line.left, &line.baseline, &line.line_number,
162-
&line.start_index, &line.end_index);
161+
&line.left, &line.baseline, &line.line_number);
163162
}
164163
return result;
165164
}

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -281,31 +281,19 @@ class EngineParagraph implements ui.Paragraph {
281281
}
282282

283283
@override
284-
ui.TextRange getWordBoundary(dynamic position) {
285-
// TODO(gspencergoog): have this take only a TextPosition once the framework
286-
// code is calling it with that.
287-
if (position is ui.TextPosition) {
288-
ui.TextPosition textPosition = position;
289-
if (_plainText == null) {
290-
return ui.TextRange(start: textPosition.offset, end: textPosition.offset);
291-
}
292-
293-
final int start = WordBreaker.prevBreakIndex(_plainText, textPosition.offset);
294-
final int end = WordBreaker.nextBreakIndex(_plainText, textPosition.offset);
295-
return ui.TextRange(start: start, end: end);
296-
}
297-
284+
ui.TextRange getWordBoundary(ui.TextPosition position) {
285+
ui.TextPosition textPosition = position;
298286
if (_plainText == null) {
299-
return ui.TextRange(start: position, end: position);
287+
return ui.TextRange(start: textPosition.offset, end: textPosition.offset);
300288
}
301289

302-
final int start = WordBreaker.prevBreakIndex(_plainText, position);
303-
final int end = WordBreaker.nextBreakIndex(_plainText, position);
290+
final int start = WordBreaker.prevBreakIndex(_plainText, textPosition.offset);
291+
final int end = WordBreaker.nextBreakIndex(_plainText, textPosition.offset);
304292
return ui.TextRange(start: start, end: end);
305293
}
306294

307295
@override
308-
List<int> getLineBoundary(int offset) {
296+
ui.TextRange getLineBoundary(ui.TextPosition position) {
309297
// TODO(flutter_web): https://github.com/flutter/flutter/issues/39537
310298
// Depends upon LineMetrics measurement.
311299
return null;

lib/web_ui/lib/src/ui/text.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,6 @@ class LineMetrics {
11111111
this.left,
11121112
this.baseline,
11131113
this.lineNumber,
1114-
this.startIndex,
1115-
this.endIndex,
11161114
});
11171115

11181116
@pragma('vm:entry-point')
@@ -1126,8 +1124,6 @@ class LineMetrics {
11261124
this.left,
11271125
this.baseline,
11281126
this.lineNumber,
1129-
this.startIndex,
1130-
this.endIndex,
11311127
);
11321128

11331129
final bool hardBreak;
@@ -1147,10 +1143,6 @@ class LineMetrics {
11471143
final double baseline;
11481144

11491145
final int lineNumber;
1150-
1151-
final int startIndex;
1152-
1153-
final int endIndex;
11541146
}
11551147

11561148
/// A paragraph of text.
@@ -1250,17 +1242,15 @@ abstract class Paragraph {
12501242
/// on both sides. In such cases, this method will return [offset, offset+1].
12511243
/// Word boundaries are defined more precisely in Unicode Standard Annex #29
12521244
/// http://www.unicode.org/reports/tr29/#Word_Boundaries
1253-
TextRange getWordBoundary(dynamic position);
1245+
TextRange getWordBoundary(TextPosition position);
12541246

1255-
/// Returns the [start, end] of the line at the given offset.
1247+
/// Returns the [TextRange] of the line at the given offset.
12561248
///
12571249
/// The newline (if any) is returned as part of the range.
12581250
///
12591251
/// This can potentially be expensive, since it needs to compute the line
1260-
/// metrics, so use it sparingly. If higher performance is needed, caching the
1261-
/// results of [computeLineMetrics] is recommended (which also contains the
1262-
/// start and end of each line).
1263-
List<int> getLineBoundary(int offset);
1252+
/// metrics, so use it sparingly.
1253+
TextRange getLineBoundary(TextPosition position);
12641254

12651255
/// Returns a list of text boxes that enclose all placeholders in the paragraph.
12661256
///

0 commit comments

Comments
 (0)