mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make it possible to obtain FontWeight integer value (flutter/engine#35183)
This commit is contained in:
parent
4a3850f484
commit
bbcfc5c06f
@ -14,37 +14,40 @@ enum FontStyle {
|
||||
|
||||
/// The thickness of the glyphs used to draw the text
|
||||
class FontWeight {
|
||||
const FontWeight._(this.index);
|
||||
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;
|
||||
|
||||
/// Thin, the least thick
|
||||
static const FontWeight w100 = FontWeight._(0);
|
||||
static const FontWeight w100 = FontWeight._(0, 100);
|
||||
|
||||
/// Extra-light
|
||||
static const FontWeight w200 = FontWeight._(1);
|
||||
static const FontWeight w200 = FontWeight._(1, 200);
|
||||
|
||||
/// Light
|
||||
static const FontWeight w300 = FontWeight._(2);
|
||||
static const FontWeight w300 = FontWeight._(2, 300);
|
||||
|
||||
/// Normal / regular / plain
|
||||
static const FontWeight w400 = FontWeight._(3);
|
||||
static const FontWeight w400 = FontWeight._(3, 400);
|
||||
|
||||
/// Medium
|
||||
static const FontWeight w500 = FontWeight._(4);
|
||||
static const FontWeight w500 = FontWeight._(4, 500);
|
||||
|
||||
/// Semi-bold
|
||||
static const FontWeight w600 = FontWeight._(5);
|
||||
static const FontWeight w600 = FontWeight._(5, 600);
|
||||
|
||||
/// Bold
|
||||
static const FontWeight w700 = FontWeight._(6);
|
||||
static const FontWeight w700 = FontWeight._(6, 700);
|
||||
|
||||
/// Extra-bold
|
||||
static const FontWeight w800 = FontWeight._(7);
|
||||
static const FontWeight w800 = FontWeight._(7, 800);
|
||||
|
||||
/// Black, the most thick
|
||||
static const FontWeight w900 = FontWeight._(8);
|
||||
static const FontWeight w900 = FontWeight._(8, 900);
|
||||
|
||||
/// The default font weight.
|
||||
static const FontWeight normal = w400;
|
||||
|
||||
@ -19,17 +19,18 @@ enum PlaceholderAlignment {
|
||||
}
|
||||
|
||||
class FontWeight {
|
||||
const FontWeight._(this.index);
|
||||
const FontWeight._(this.index, this.value);
|
||||
final int index;
|
||||
static const FontWeight w100 = FontWeight._(0);
|
||||
static const FontWeight w200 = FontWeight._(1);
|
||||
static const FontWeight w300 = FontWeight._(2);
|
||||
static const FontWeight w400 = FontWeight._(3);
|
||||
static const FontWeight w500 = FontWeight._(4);
|
||||
static const FontWeight w600 = FontWeight._(5);
|
||||
static const FontWeight w700 = FontWeight._(6);
|
||||
static const FontWeight w800 = FontWeight._(7);
|
||||
static const FontWeight w900 = FontWeight._(8);
|
||||
final int value;
|
||||
static const FontWeight w100 = FontWeight._(0, 100);
|
||||
static const FontWeight w200 = FontWeight._(1, 200);
|
||||
static const FontWeight w300 = FontWeight._(2, 300);
|
||||
static const FontWeight w400 = FontWeight._(3, 400);
|
||||
static const FontWeight w500 = FontWeight._(4, 500);
|
||||
static const FontWeight w600 = FontWeight._(5, 600);
|
||||
static const FontWeight w700 = FontWeight._(6, 700);
|
||||
static const FontWeight w800 = FontWeight._(7, 800);
|
||||
static const FontWeight w900 = FontWeight._(8, 900);
|
||||
static const FontWeight normal = w400;
|
||||
static const FontWeight bold = w700;
|
||||
static const List<FontWeight> values = <FontWeight>[
|
||||
|
||||
@ -352,4 +352,16 @@ Future<void> testMain() async {
|
||||
equals('hello'));
|
||||
});
|
||||
});
|
||||
|
||||
test('FontWeights have the correct value', () {
|
||||
expect(FontWeight.w100.value, 100);
|
||||
expect(FontWeight.w200.value, 200);
|
||||
expect(FontWeight.w300.value, 300);
|
||||
expect(FontWeight.w400.value, 400);
|
||||
expect(FontWeight.w500.value, 500);
|
||||
expect(FontWeight.w600.value, 600);
|
||||
expect(FontWeight.w700.value, 700);
|
||||
expect(FontWeight.w800.value, 800);
|
||||
expect(FontWeight.w900.value, 900);
|
||||
});
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ Future<Uint8List> readFile(String fileName) async {
|
||||
return file.readAsBytes();
|
||||
}
|
||||
|
||||
void testFontWeightLerp() {
|
||||
void testFontWeight() {
|
||||
test('FontWeight.lerp works with non-null values', () {
|
||||
expect(FontWeight.lerp(FontWeight.w400, FontWeight.w600, .5), equals(FontWeight.w500));
|
||||
});
|
||||
@ -35,6 +35,18 @@ void testFontWeightLerp() {
|
||||
test('FontWeight.lerp returns FontWeight.w400 if b is null', () {
|
||||
expect(FontWeight.lerp(FontWeight.w400, null, 1), equals(FontWeight.w400));
|
||||
});
|
||||
|
||||
test('FontWeights have the correct value', () {
|
||||
expect(FontWeight.w100.value, 100);
|
||||
expect(FontWeight.w200.value, 200);
|
||||
expect(FontWeight.w300.value, 300);
|
||||
expect(FontWeight.w400.value, 400);
|
||||
expect(FontWeight.w500.value, 500);
|
||||
expect(FontWeight.w600.value, 600);
|
||||
expect(FontWeight.w700.value, 700);
|
||||
expect(FontWeight.w800.value, 800);
|
||||
expect(FontWeight.w900.value, 900);
|
||||
});
|
||||
}
|
||||
|
||||
void testParagraphStyle() {
|
||||
@ -277,7 +289,7 @@ void testFontVariation() {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testFontWeightLerp();
|
||||
testFontWeight();
|
||||
testParagraphStyle();
|
||||
testTextStyle();
|
||||
testTextHeightBehavior();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user