Skip to content

Commit

Permalink
Make FontWeight an enum, Remove unused text classes (#44960)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong authored Aug 22, 2023
1 parent 1f65e1a commit 2c4ada8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 136 deletions.
4 changes: 0 additions & 4 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1869,12 +1869,10 @@ ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc + ../../../f
ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/font_collection.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/font_collection.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/line_metrics.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/text_box.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui_benchmarks.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui_dart_state.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4598,12 +4596,10 @@ FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
FILE: ../../../flutter/lib/ui/text/font_collection.cc
FILE: ../../../flutter/lib/ui/text/font_collection.h
FILE: ../../../flutter/lib/ui/text/line_metrics.h
FILE: ../../../flutter/lib/ui/text/paragraph.cc
FILE: ../../../flutter/lib/ui/text/paragraph.h
FILE: ../../../flutter/lib/ui/text/paragraph_builder.cc
FILE: ../../../flutter/lib/ui/text/paragraph_builder.h
FILE: ../../../flutter/lib/ui/text/text_box.h
FILE: ../../../flutter/lib/ui/ui.dart
FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
FILE: ../../../flutter/lib/ui/ui_dart_state.cc
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ source_set("ui") {
"text/asset_manager_font_provider.h",
"text/font_collection.cc",
"text/font_collection.h",
"text/line_metrics.h",
"text/paragraph.cc",
"text/paragraph.h",
"text/paragraph_builder.cc",
"text/paragraph_builder.h",
"text/text_box.h",
"ui_dart_state.cc",
"ui_dart_state.h",
"volatile_path_tracker.cc",
Expand Down
53 changes: 15 additions & 38 deletions lib/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,45 @@ enum FontStyle {
}

/// The thickness of the glyphs used to draw the text
class FontWeight {
const FontWeight._(this.index, this.value);

/// The encoded integer value of this font weight.
final int index;

/// The thickness value of this font weight.
final int value;

enum FontWeight {
/// Thin, the least thick
static const FontWeight w100 = FontWeight._(0, 100);
w100._(100),

/// Extra-light
static const FontWeight w200 = FontWeight._(1, 200);
w200._(200),

/// Light
static const FontWeight w300 = FontWeight._(2, 300);
w300._(300),

/// Normal / regular / plain
static const FontWeight w400 = FontWeight._(3, 400);
w400._(400),

/// Medium
static const FontWeight w500 = FontWeight._(4, 500);
w500._(500),

/// Semi-bold
static const FontWeight w600 = FontWeight._(5, 600);
w600._(600),

/// Bold
static const FontWeight w700 = FontWeight._(6, 700);
w700._(700),

/// Extra-bold
static const FontWeight w800 = FontWeight._(7, 800);
w800._(800),

/// Black, the most thick
static const FontWeight w900 = FontWeight._(8, 900);
w900._(900);

const FontWeight._(this.value);

/// The thickness value of this font weight.
final int value;

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

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

/// A list of all the font weights.
static const List<FontWeight> values = <FontWeight>[
w100, w200, w300, w400, w500, w600, w700, w800, w900
];

/// Linearly interpolates between two font weights.
///
/// Rather than using fractional weights, the interpolation rounds to the
Expand Down Expand Up @@ -87,21 +79,6 @@ class FontWeight {
}
return values[_lerpInt((a ?? normal).index, (b ?? normal).index, t).round().clamp(0, 8)];
}

@override
String toString() {
return const <int, String>{
0: 'FontWeight.w100',
1: 'FontWeight.w200',
2: 'FontWeight.w300',
3: 'FontWeight.w400',
4: 'FontWeight.w500',
5: 'FontWeight.w600',
6: 'FontWeight.w700',
7: 'FontWeight.w800',
8: 'FontWeight.w900',
}[index]!;
}
}

/// A feature tag and value that affect the selection of glyphs in a font.
Expand Down
62 changes: 0 additions & 62 deletions lib/ui/text/line_metrics.h

This file was deleted.

2 changes: 0 additions & 2 deletions lib/ui/text/paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "flutter/fml/message_loop.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/lib/ui/text/line_metrics.h"
#include "flutter/lib/ui/text/text_box.h"
#include "flutter/third_party/txt/src/txt/paragraph.h"

namespace flutter {
Expand Down
28 changes: 0 additions & 28 deletions lib/ui/text/text_box.h

This file was deleted.

0 comments on commit 2c4ada8

Please sign in to comment.