From 4d8e840ae9058490aed68aa7687cc9c73469ac3f Mon Sep 17 00:00:00 2001 From: Pierre-Louis <6655696+guidezpl@users.noreply.github.com> Date: Fri, 5 Aug 2022 10:15:04 -0400 Subject: [PATCH 1/3] Make it possible to obtain `FontWeight` value --- lib/ui/text.dart | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 4b329608da900..739ecd16005f1 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -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; From 6b5c42add1995bc671071d728ce6c191fd03075d Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guidez Date: Fri, 5 Aug 2022 17:40:49 +0200 Subject: [PATCH 2/3] x --- lib/web_ui/lib/text.dart | 21 +++++++++++---------- lib/web_ui/test/text_test.dart | 12 ++++++++++++ testing/dart/text_test.dart | 16 ++++++++++++++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/web_ui/lib/text.dart b/lib/web_ui/lib/text.dart index e1c2a56fd1eb2..30e0ed35de273 100644 --- a/lib/web_ui/lib/text.dart +++ b/lib/web_ui/lib/text.dart @@ -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 values = [ diff --git a/lib/web_ui/test/text_test.dart b/lib/web_ui/test/text_test.dart index d1f8f3fbf6130..442e44bf1b630 100644 --- a/lib/web_ui/test/text_test.dart +++ b/lib/web_ui/test/text_test.dart @@ -352,4 +352,16 @@ Future 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); + }); } diff --git a/testing/dart/text_test.dart b/testing/dart/text_test.dart index b845b654b41f7..13bb1645bb433 100644 --- a/testing/dart/text_test.dart +++ b/testing/dart/text_test.dart @@ -19,7 +19,7 @@ Future 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(); From 632ab45095cfd90bbb0b1922dd9a7b585f945515 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guidez Date: Fri, 5 Aug 2022 17:41:25 +0200 Subject: [PATCH 3/3] Update text.dart --- lib/ui/text.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 739ecd16005f1..3627aa28ac367 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -18,7 +18,7 @@ class FontWeight { /// The encoded integer value of this font weight. final int index; - + /// The thickness value of this font weight. final int value;