mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Continue filling in the list of FontFeatures (#23730)
This commit is contained in:
parent
5693b4d578
commit
0540bc876d
1339
lib/ui/text.dart
1339
lib/ui/text.dart
File diff suppressed because it is too large
Load Diff
@ -68,44 +68,56 @@ class FontWeight {
|
||||
}
|
||||
|
||||
class FontFeature {
|
||||
const FontFeature(this.feature, [this.value = 1])
|
||||
: assert(feature != null), // ignore: unnecessary_null_comparison
|
||||
assert(feature.length == 4),
|
||||
assert(value != null), // ignore: unnecessary_null_comparison
|
||||
assert(value >= 0);
|
||||
const FontFeature(
|
||||
this.feature,
|
||||
[ this.value = 1 ]
|
||||
) : assert(feature != null), // ignore: unnecessary_null_comparison
|
||||
assert(feature.length == 4, 'Feature tag must be exactly four characters long.'),
|
||||
assert(value != null), // ignore: unnecessary_null_comparison
|
||||
assert(value >= 0, 'Feature value must be zero or a positive integer.');
|
||||
const FontFeature.enable(String feature) : this(feature, 1);
|
||||
const FontFeature.disable(String feature) : this(feature, 0);
|
||||
const FontFeature.randomize()
|
||||
: feature = 'rand',
|
||||
value = 1;
|
||||
const FontFeature.alternative(this.value) : feature = 'aalt';
|
||||
const FontFeature.alternativeFractions() : feature = 'afrc', value = 1;
|
||||
const FontFeature.contextualAlternates() : feature = 'calt', value = 1;
|
||||
const FontFeature.caseSensitiveForms() : feature = 'case', value = 1;
|
||||
factory FontFeature.characterVariant(int value) {
|
||||
assert(value >= 1);
|
||||
assert(value <= 20);
|
||||
return FontFeature('cv${value.toString().padLeft(2, "0")}');
|
||||
}
|
||||
const FontFeature.denominator() : feature = 'dnom', value = 1;
|
||||
const FontFeature.fractions() : feature = 'frac', value = 1;
|
||||
const FontFeature.historicalForms() : feature = 'hist', value = 1;
|
||||
const FontFeature.historicalLigatures() : feature = 'hlig', value = 1;
|
||||
const FontFeature.liningFigures() : feature = 'lnum', value = 1;
|
||||
const FontFeature.localeAware({ bool enable = true }) : feature = 'locl', value = enable ? 1 : 0;
|
||||
const FontFeature.notationalForms([this.value = 1]) : feature = 'nalt', assert(value >= 0);
|
||||
const FontFeature.numerators() : feature = 'numr', value = 1;
|
||||
const FontFeature.oldstyleFigures() : feature = 'onum', value = 1;
|
||||
const FontFeature.ordinalForms() : feature = 'ordn', value = 1;
|
||||
const FontFeature.proportionalFigures() : feature = 'pnum', value = 1;
|
||||
const FontFeature.randomize() : feature = 'rand', value = 1;
|
||||
const FontFeature.stylisticAlternates() : feature = 'salt', value = 1;
|
||||
const FontFeature.scientificInferiors() : feature = 'sinf', value = 1;
|
||||
factory FontFeature.stylisticSet(int value) {
|
||||
assert(value >= 1);
|
||||
assert(value <= 20);
|
||||
return FontFeature('ss${value.toString().padLeft(2, "0")}');
|
||||
}
|
||||
const FontFeature.slashedZero()
|
||||
: feature = 'zero',
|
||||
value = 1;
|
||||
const FontFeature.oldstyleFigures()
|
||||
: feature = 'onum',
|
||||
value = 1;
|
||||
const FontFeature.proportionalFigures()
|
||||
: feature = 'pnum',
|
||||
value = 1;
|
||||
const FontFeature.tabularFigures()
|
||||
: feature = 'tnum',
|
||||
value = 1;
|
||||
const FontFeature.subscripts() : feature = 'subs', value = 1;
|
||||
const FontFeature.superscripts() : feature = 'sups', value = 1;
|
||||
const FontFeature.swash([this.value = 1]) : feature = 'swsh', assert(value >= 0);
|
||||
const FontFeature.tabularFigures() : feature = 'tnum', value = 1;
|
||||
const FontFeature.slashedZero() : feature = 'zero', value = 1;
|
||||
|
||||
final String feature;
|
||||
final int value;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) {
|
||||
return true;
|
||||
}
|
||||
if (other.runtimeType != runtimeType) {
|
||||
if (other.runtimeType != runtimeType)
|
||||
return false;
|
||||
}
|
||||
return other is FontFeature
|
||||
&& other.feature == feature
|
||||
&& other.value == value;
|
||||
@ -115,7 +127,7 @@ class FontFeature {
|
||||
int get hashCode => hashValues(feature, value);
|
||||
|
||||
@override
|
||||
String toString() => 'FontFeature($feature, $value)';
|
||||
String toString() => "FontFeature('$feature', $value)";
|
||||
}
|
||||
|
||||
// The order of this enum must match the order of the values in RenderStyleConstants.h's ETextAlign.
|
||||
|
||||
@ -164,4 +164,45 @@ void main() {
|
||||
expect(message, '{"type":"fontsChange"}');
|
||||
});
|
||||
});
|
||||
|
||||
test('FontFeature class', () {
|
||||
expect(const FontFeature.alternative(1), const FontFeature('aalt', 1));
|
||||
expect(const FontFeature.alternative(5), const FontFeature('aalt', 5));
|
||||
expect(const FontFeature.alternativeFractions(), const FontFeature('afrc', 1));
|
||||
expect(const FontFeature.contextualAlternates(), const FontFeature('calt', 1));
|
||||
expect(const FontFeature.caseSensitiveForms(), const FontFeature('case', 1));
|
||||
expect( FontFeature.characterVariant(1), const FontFeature('cv01', 1));
|
||||
expect( FontFeature.characterVariant(18), const FontFeature('cv18', 1));
|
||||
expect(const FontFeature.denominator(), const FontFeature('dnom', 1));
|
||||
expect(const FontFeature.fractions(), const FontFeature('frac', 1));
|
||||
expect(const FontFeature.historicalForms(), const FontFeature('hist', 1));
|
||||
expect(const FontFeature.historicalLigatures(), const FontFeature('hlig', 1));
|
||||
expect(const FontFeature.liningFigures(), const FontFeature('lnum', 1));
|
||||
expect(const FontFeature.localeAware(), const FontFeature('locl', 1));
|
||||
expect(const FontFeature.localeAware(enable: true), const FontFeature('locl', 1));
|
||||
expect(const FontFeature.localeAware(enable: false), const FontFeature('locl', 0));
|
||||
expect(const FontFeature.notationalForms(), const FontFeature('nalt', 1));
|
||||
expect(const FontFeature.notationalForms(5), const FontFeature('nalt', 5));
|
||||
expect(const FontFeature.numerators(), const FontFeature('numr', 1));
|
||||
expect(const FontFeature.oldstyleFigures(), const FontFeature('onum', 1));
|
||||
expect(const FontFeature.ordinalForms(), const FontFeature('ordn', 1));
|
||||
expect(const FontFeature.proportionalFigures(), const FontFeature('pnum', 1));
|
||||
expect(const FontFeature.randomize(), const FontFeature('rand', 1));
|
||||
expect(const FontFeature.stylisticAlternates(), const FontFeature('salt', 1));
|
||||
expect(const FontFeature.scientificInferiors(), const FontFeature('sinf', 1));
|
||||
expect( FontFeature.stylisticSet(1), const FontFeature('ss01', 1));
|
||||
expect( FontFeature.stylisticSet(18), const FontFeature('ss18', 1));
|
||||
expect(const FontFeature.subscripts(), const FontFeature('subs', 1));
|
||||
expect(const FontFeature.superscripts(), const FontFeature('sups', 1));
|
||||
expect(const FontFeature.swash(), const FontFeature('swsh', 1));
|
||||
expect(const FontFeature.swash(0), const FontFeature('swsh', 0));
|
||||
expect(const FontFeature.swash(5), const FontFeature('swsh', 5));
|
||||
expect(const FontFeature.tabularFigures(), const FontFeature('tnum', 1));
|
||||
expect(const FontFeature.slashedZero(), const FontFeature('zero', 1));
|
||||
expect(const FontFeature.enable('TEST'), const FontFeature('TEST', 1));
|
||||
expect(const FontFeature.disable('TEST'), const FontFeature('TEST', 0));
|
||||
expect(const FontFeature('FEAT', 1000).feature, 'FEAT');
|
||||
expect(const FontFeature('FEAT', 1000).value, 1000);
|
||||
expect(const FontFeature('FEAT', 1000).toString(), "FontFeature('FEAT', 1000)");
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user