Skip to content

Commit 2391d28

Browse files
zandersogaaclarke
authored andcommitted
Revert "Make FontWeight an enum, Remove unused text classes" (flutter#44987)
Reverts flutter#44960 Failing on customer_testing: https://ci.chromium.org/ui/p/flutter/builders/try/Mac%20customer_testing/59576/overview
1 parent a2c4cb8 commit 2391d28

6 files changed

Lines changed: 136 additions & 15 deletions

File tree

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,12 @@ ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc + ../../../f
18691869
ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.h + ../../../flutter/LICENSE
18701870
ORIGIN: ../../../flutter/lib/ui/text/font_collection.cc + ../../../flutter/LICENSE
18711871
ORIGIN: ../../../flutter/lib/ui/text/font_collection.h + ../../../flutter/LICENSE
1872+
ORIGIN: ../../../flutter/lib/ui/text/line_metrics.h + ../../../flutter/LICENSE
18721873
ORIGIN: ../../../flutter/lib/ui/text/paragraph.cc + ../../../flutter/LICENSE
18731874
ORIGIN: ../../../flutter/lib/ui/text/paragraph.h + ../../../flutter/LICENSE
18741875
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.cc + ../../../flutter/LICENSE
18751876
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.h + ../../../flutter/LICENSE
1877+
ORIGIN: ../../../flutter/lib/ui/text/text_box.h + ../../../flutter/LICENSE
18761878
ORIGIN: ../../../flutter/lib/ui/ui.dart + ../../../flutter/LICENSE
18771879
ORIGIN: ../../../flutter/lib/ui/ui_benchmarks.cc + ../../../flutter/LICENSE
18781880
ORIGIN: ../../../flutter/lib/ui/ui_dart_state.cc + ../../../flutter/LICENSE
@@ -4596,10 +4598,12 @@ FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
45964598
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
45974599
FILE: ../../../flutter/lib/ui/text/font_collection.cc
45984600
FILE: ../../../flutter/lib/ui/text/font_collection.h
4601+
FILE: ../../../flutter/lib/ui/text/line_metrics.h
45994602
FILE: ../../../flutter/lib/ui/text/paragraph.cc
46004603
FILE: ../../../flutter/lib/ui/text/paragraph.h
46014604
FILE: ../../../flutter/lib/ui/text/paragraph_builder.cc
46024605
FILE: ../../../flutter/lib/ui/text/paragraph_builder.h
4606+
FILE: ../../../flutter/lib/ui/text/text_box.h
46034607
FILE: ../../../flutter/lib/ui/ui.dart
46044608
FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
46054609
FILE: ../../../flutter/lib/ui/ui_dart_state.cc

lib/ui/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ source_set("ui") {
123123
"text/asset_manager_font_provider.h",
124124
"text/font_collection.cc",
125125
"text/font_collection.h",
126+
"text/line_metrics.h",
126127
"text/paragraph.cc",
127128
"text/paragraph.h",
128129
"text/paragraph_builder.cc",
129130
"text/paragraph_builder.h",
131+
"text/text_box.h",
130132
"ui_dart_state.cc",
131133
"ui_dart_state.h",
132134
"volatile_path_tracker.cc",

lib/ui/text.dart

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,53 @@ enum FontStyle {
1313
}
1414

1515
/// The thickness of the glyphs used to draw the text
16-
enum FontWeight {
16+
class FontWeight {
17+
const FontWeight._(this.index, this.value);
18+
19+
/// The encoded integer value of this font weight.
20+
final int index;
21+
22+
/// The thickness value of this font weight.
23+
final int value;
24+
1725
/// Thin, the least thick
18-
w100._(100),
26+
static const FontWeight w100 = FontWeight._(0, 100);
1927

2028
/// Extra-light
21-
w200._(200),
29+
static const FontWeight w200 = FontWeight._(1, 200);
2230

2331
/// Light
24-
w300._(300),
32+
static const FontWeight w300 = FontWeight._(2, 300);
2533

2634
/// Normal / regular / plain
27-
w400._(400),
35+
static const FontWeight w400 = FontWeight._(3, 400);
2836

2937
/// Medium
30-
w500._(500),
38+
static const FontWeight w500 = FontWeight._(4, 500);
3139

3240
/// Semi-bold
33-
w600._(600),
41+
static const FontWeight w600 = FontWeight._(5, 600);
3442

3543
/// Bold
36-
w700._(700),
44+
static const FontWeight w700 = FontWeight._(6, 700);
3745

3846
/// Extra-bold
39-
w800._(800),
47+
static const FontWeight w800 = FontWeight._(7, 800);
4048

4149
/// Black, the most thick
42-
w900._(900);
43-
44-
const FontWeight._(this.value);
45-
46-
/// The thickness value of this font weight.
47-
final int value;
50+
static const FontWeight w900 = FontWeight._(8, 900);
4851

4952
/// The default font weight.
5053
static const FontWeight normal = w400;
5154

5255
/// A commonly used font weight that is heavier than normal.
5356
static const FontWeight bold = w700;
5457

58+
/// A list of all the font weights.
59+
static const List<FontWeight> values = <FontWeight>[
60+
w100, w200, w300, w400, w500, w600, w700, w800, w900
61+
];
62+
5563
/// Linearly interpolates between two font weights.
5664
///
5765
/// Rather than using fractional weights, the interpolation rounds to the
@@ -79,6 +87,21 @@ enum FontWeight {
7987
}
8088
return values[_lerpInt((a ?? normal).index, (b ?? normal).index, t).round().clamp(0, 8)];
8189
}
90+
91+
@override
92+
String toString() {
93+
return const <int, String>{
94+
0: 'FontWeight.w100',
95+
1: 'FontWeight.w200',
96+
2: 'FontWeight.w300',
97+
3: 'FontWeight.w400',
98+
4: 'FontWeight.w500',
99+
5: 'FontWeight.w600',
100+
6: 'FontWeight.w700',
101+
7: 'FontWeight.w800',
102+
8: 'FontWeight.w900',
103+
}[index]!;
104+
}
82105
}
83106

84107
/// A feature tag and value that affect the selection of glyphs in a font.

lib/ui/text/line_metrics.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
6+
#define FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
7+
8+
#include "third_party/dart/runtime/include/dart_api.h"
9+
#include "third_party/tonic/converter/dart_converter.h"
10+
11+
namespace flutter {
12+
13+
struct LineMetrics {
14+
const bool* hard_break;
15+
16+
// The final computed ascent and descent for the line. This can be impacted by
17+
// the strut, height, scaling, as well as outlying runs that are very tall.
18+
//
19+
// The top edge is `baseline - ascent` and the bottom edge is `baseline +
20+
// descent`. Ascent and descent are provided as positive numbers. Raw numbers
21+
// for specific runs of text can be obtained in run_metrics_map. These values
22+
// are the cumulative metrics for the entire line.
23+
const double* ascent;
24+
const double* descent;
25+
const double* unscaled_ascent;
26+
// Height of the line.
27+
const double* height;
28+
// Width of the line.
29+
const double* width;
30+
// The left edge of the line. The right edge can be obtained with `left +
31+
// width`
32+
const double* left;
33+
// The y position of the baseline for this line from the top of the paragraph.
34+
const double* baseline;
35+
// Zero indexed line number.
36+
const size_t* line_number;
37+
38+
LineMetrics();
39+
40+
LineMetrics(const bool* hard_break,
41+
const double* ascent,
42+
const double* descent,
43+
const double* unscaled_ascent,
44+
const double* height,
45+
const double* width,
46+
const double* left,
47+
const double* baseline,
48+
const size_t* line_number)
49+
: hard_break(hard_break),
50+
ascent(ascent),
51+
descent(descent),
52+
unscaled_ascent(unscaled_ascent),
53+
height(height),
54+
width(width),
55+
left(left),
56+
baseline(baseline),
57+
line_number(line_number) {}
58+
};
59+
60+
} // namespace flutter
61+
62+
#endif // FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_

lib/ui/text/paragraph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "flutter/fml/message_loop.h"
99
#include "flutter/lib/ui/dart_wrapper.h"
1010
#include "flutter/lib/ui/painting/canvas.h"
11+
#include "flutter/lib/ui/text/line_metrics.h"
12+
#include "flutter/lib/ui/text/text_box.h"
1113
#include "flutter/third_party/txt/src/txt/paragraph.h"
1214

1315
namespace flutter {

lib/ui/text/text_box.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_
6+
#define FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_
7+
8+
#include "third_party/dart/runtime/include/dart_api.h"
9+
#include "third_party/skia/include/core/SkRect.h"
10+
#include "third_party/tonic/converter/dart_converter.h"
11+
12+
namespace flutter {
13+
14+
enum class TextDirection {
15+
rtl,
16+
ltr,
17+
};
18+
19+
struct TextBox {
20+
SkRect rect;
21+
TextDirection direction;
22+
23+
TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {}
24+
};
25+
26+
} // namespace flutter
27+
28+
#endif // FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_

0 commit comments

Comments
 (0)