|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 |
| -import 'dart:ui' as ui show ParagraphStyle, TextStyle, StrutStyle, lerpDouble, Shadow, FontFeature, TextHeightBehavior, TextLeadingDistribution; |
| 5 | +import 'dart:ui' as ui show ParagraphStyle, TextStyle, StrutStyle, lerpDouble, Shadow, FontFeature, FontVariation, TextHeightBehavior, TextLeadingDistribution; |
6 | 6 |
|
7 | 7 | import 'package:flutter/foundation.dart';
|
8 | 8 |
|
@@ -482,6 +482,7 @@ class TextStyle with Diagnosticable {
|
482 | 482 | this.background,
|
483 | 483 | this.shadows,
|
484 | 484 | this.fontFeatures,
|
| 485 | + this.fontVariations, |
485 | 486 | this.decoration,
|
486 | 487 | this.decorationColor,
|
487 | 488 | this.decorationStyle,
|
@@ -769,6 +770,23 @@ class TextStyle with Diagnosticable {
|
769 | 770 | /// these variants will be used for rendering.
|
770 | 771 | final List<ui.FontFeature>? fontFeatures;
|
771 | 772 |
|
| 773 | + /// A list of [FontVariation]s that affect how a variable font is rendered. |
| 774 | + /// |
| 775 | + /// Some fonts are variable fonts that can generate multiple font faces based |
| 776 | + /// on the values of customizable attributes. For example, a variable font |
| 777 | + /// may have a weight axis that can be set to a value between 1 and 1000. |
| 778 | + /// [FontVariation]s can be used to select the values of these design axes. |
| 779 | + /// |
| 780 | + /// For example, to control the weight axis of the Roboto Slab variable font |
| 781 | + /// (https://fonts.google.com/specimen/Roboto+Slab): |
| 782 | + /// ```dart |
| 783 | + /// TextStyle( |
| 784 | + /// fontFamily: 'RobotoSlab', |
| 785 | + /// fontVariations: <FontVariation>[FontVariation('wght', 900.0)] |
| 786 | + /// ) |
| 787 | + /// ``` |
| 788 | + final List<ui.FontVariation>? fontVariations; |
| 789 | + |
772 | 790 | /// How visual text overflow should be handled.
|
773 | 791 | final TextOverflow? overflow;
|
774 | 792 |
|
@@ -809,6 +827,7 @@ class TextStyle with Diagnosticable {
|
809 | 827 | Paint? background,
|
810 | 828 | List<ui.Shadow>? shadows,
|
811 | 829 | List<ui.FontFeature>? fontFeatures,
|
| 830 | + List<ui.FontVariation>? fontVariations, |
812 | 831 | TextDecoration? decoration,
|
813 | 832 | Color? decorationColor,
|
814 | 833 | TextDecorationStyle? decorationStyle,
|
@@ -845,6 +864,7 @@ class TextStyle with Diagnosticable {
|
845 | 864 | background: background ?? this.background,
|
846 | 865 | shadows: shadows ?? this.shadows,
|
847 | 866 | fontFeatures: fontFeatures ?? this.fontFeatures,
|
| 867 | + fontVariations: fontVariations ?? this.fontVariations, |
848 | 868 | decoration: decoration ?? this.decoration,
|
849 | 869 | decorationColor: decorationColor ?? this.decorationColor,
|
850 | 870 | decorationStyle: decorationStyle ?? this.decorationStyle,
|
@@ -911,6 +931,7 @@ class TextStyle with Diagnosticable {
|
911 | 931 | Locale? locale,
|
912 | 932 | List<ui.Shadow>? shadows,
|
913 | 933 | List<ui.FontFeature>? fontFeatures,
|
| 934 | + List<ui.FontVariation>? fontVariations, |
914 | 935 | String? package,
|
915 | 936 | TextOverflow? overflow,
|
916 | 937 | }) {
|
@@ -957,6 +978,7 @@ class TextStyle with Diagnosticable {
|
957 | 978 | background: background,
|
958 | 979 | shadows: shadows ?? this.shadows,
|
959 | 980 | fontFeatures: fontFeatures ?? this.fontFeatures,
|
| 981 | + fontVariations: fontVariations ?? this.fontVariations, |
960 | 982 | decoration: decoration ?? this.decoration,
|
961 | 983 | decorationColor: decorationColor ?? this.decorationColor,
|
962 | 984 | decorationStyle: decorationStyle ?? this.decorationStyle,
|
@@ -1017,6 +1039,7 @@ class TextStyle with Diagnosticable {
|
1017 | 1039 | background: other.background,
|
1018 | 1040 | shadows: other.shadows,
|
1019 | 1041 | fontFeatures: other.fontFeatures,
|
| 1042 | + fontVariations: other.fontVariations, |
1020 | 1043 | decoration: other.decoration,
|
1021 | 1044 | decorationColor: other.decorationColor,
|
1022 | 1045 | decorationStyle: other.decorationStyle,
|
@@ -1073,6 +1096,7 @@ class TextStyle with Diagnosticable {
|
1073 | 1096 | background: t < 0.5 ? null : b.background,
|
1074 | 1097 | shadows: t < 0.5 ? null : b.shadows,
|
1075 | 1098 | fontFeatures: t < 0.5 ? null : b.fontFeatures,
|
| 1099 | + fontVariations: t < 0.5 ? null : b.fontVariations, |
1076 | 1100 | decoration: t < 0.5 ? null : b.decoration,
|
1077 | 1101 | decorationColor: Color.lerp(null, b.decorationColor, t),
|
1078 | 1102 | decorationStyle: t < 0.5 ? null : b.decorationStyle,
|
@@ -1103,6 +1127,7 @@ class TextStyle with Diagnosticable {
|
1103 | 1127 | background: t < 0.5 ? a.background : null,
|
1104 | 1128 | shadows: t < 0.5 ? a.shadows : null,
|
1105 | 1129 | fontFeatures: t < 0.5 ? a.fontFeatures : null,
|
| 1130 | + fontVariations: t < 0.5 ? a.fontVariations : null, |
1106 | 1131 | decoration: t < 0.5 ? a.decoration : null,
|
1107 | 1132 | decorationColor: Color.lerp(a.decorationColor, null, t),
|
1108 | 1133 | decorationStyle: t < 0.5 ? a.decorationStyle : null,
|
@@ -1140,6 +1165,7 @@ class TextStyle with Diagnosticable {
|
1140 | 1165 | : null,
|
1141 | 1166 | shadows: t < 0.5 ? a.shadows : b.shadows,
|
1142 | 1167 | fontFeatures: t < 0.5 ? a.fontFeatures : b.fontFeatures,
|
| 1168 | + fontVariations: t < 0.5 ? a.fontVariations : b.fontVariations, |
1143 | 1169 | decoration: t < 0.5 ? a.decoration : b.decoration,
|
1144 | 1170 | decorationColor: Color.lerp(a.decorationColor, b.decorationColor, t),
|
1145 | 1171 | decorationStyle: t < 0.5 ? a.decorationStyle : b.decorationStyle,
|
@@ -1178,6 +1204,7 @@ class TextStyle with Diagnosticable {
|
1178 | 1204 | ),
|
1179 | 1205 | shadows: shadows,
|
1180 | 1206 | fontFeatures: fontFeatures,
|
| 1207 | + fontVariations: fontVariations, |
1181 | 1208 | );
|
1182 | 1209 | }
|
1183 | 1210 |
|
@@ -1260,6 +1287,7 @@ class TextStyle with Diagnosticable {
|
1260 | 1287 | background != other.background ||
|
1261 | 1288 | !listEquals(shadows, other.shadows) ||
|
1262 | 1289 | !listEquals(fontFeatures, other.fontFeatures) ||
|
| 1290 | + !listEquals(fontVariations, other.fontVariations) || |
1263 | 1291 | !listEquals(fontFamilyFallback, other.fontFamilyFallback) ||
|
1264 | 1292 | overflow != other.overflow)
|
1265 | 1293 | return RenderComparison.layout;
|
@@ -1296,6 +1324,7 @@ class TextStyle with Diagnosticable {
|
1296 | 1324 | && other.background == background
|
1297 | 1325 | && listEquals(other.shadows, shadows)
|
1298 | 1326 | && listEquals(other.fontFeatures, fontFeatures)
|
| 1327 | + && listEquals(other.fontVariations, fontVariations) |
1299 | 1328 | && other.decoration == decoration
|
1300 | 1329 | && other.decorationColor == decorationColor
|
1301 | 1330 | && other.decorationStyle == decorationStyle
|
@@ -1324,10 +1353,11 @@ class TextStyle with Diagnosticable {
|
1324 | 1353 | background,
|
1325 | 1354 | shadows == null ? null : Object.hashAll(shadows!),
|
1326 | 1355 | fontFeatures == null ? null : Object.hashAll(fontFeatures!),
|
| 1356 | + fontVariations == null ? null : Object.hashAll(fontVariations!), |
1327 | 1357 | decoration,
|
1328 | 1358 | decorationColor,
|
1329 |
| - decorationStyle, |
1330 | 1359 | Object.hash(
|
| 1360 | + decorationStyle, |
1331 | 1361 | decorationThickness,
|
1332 | 1362 | fontFamily,
|
1333 | 1363 | fontFamilyFallback == null ? null : Object.hashAll(fontFamilyFallback!),
|
|
0 commit comments