-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathfont_feature.dart
505 lines (448 loc) · 12.7 KB
/
font_feature.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
import 'diagram_step.dart';
// When adding a new font here, add it to:
// /packages/diagram_generator/pubspec.yaml
// ...and put the binary and license file in:
// /packages/diagram_generator/fonts
const double _margin = 5.0;
const double _gap = _margin * 5;
abstract class FontFeatureDiagram<T> extends StatelessWidget
with DiagramMetadata {
const FontFeatureDiagram({super.key});
Iterable<T> get entries;
Widget buildEntry(BuildContext context, T entry);
String describe(T entry);
TextStyle get textStyle =>
const TextStyle(color: Colors.black, fontSize: 32.0);
Widget buildRow(BuildContext context, T entry) {
return Stack(
children: <Widget>[
Positioned.fill(
top: _margin,
left: _margin,
child: buildEntry(context, entry),
),
Positioned(
left: 0.0,
top: 0.0,
child: buildDescription(context, entry),
),
],
);
}
Widget buildDescription(BuildContext context, T entry) {
return Text(describe(entry), style: const TextStyle(fontSize: 10.0));
}
@override
Widget build(BuildContext context) {
return SizedBox(
key: UniqueKey(),
width: 600.0,
height:
(textStyle.fontSize! * 1.2 + _margin + _gap) * entries.length +
_margin * 3.0 -
_gap,
child: Container(
padding: const EdgeInsets.all(_margin),
color: Colors.white,
child: OverflowBox(
alignment: Alignment.topLeft,
minWidth: 600.0,
maxWidth: 600.0,
minHeight: 0.0,
maxHeight: double.infinity,
child: Column(
children:
entries
.map(
(T entry) => SizedBox(
height: _margin + textStyle.fontSize! * 1.2 + _gap,
child: buildRow(context, entry),
),
)
.toList(),
),
),
),
);
}
}
class FontFeatureValueDiagram extends FontFeatureDiagram<int> {
const FontFeatureValueDiagram(
this.feature,
this.values,
this.font, {
this.sampleText = 'The infamous Tuna Torture.', // from s03e09, of course
this.style,
this.additionalFontFeatures,
super.key,
});
@override
String get name => 'font_feature_$feature';
final String feature;
final List<int> values;
final String font;
final String sampleText;
final TextStyle? style;
final List<FontFeature>? additionalFontFeatures;
@override
Iterable<int> get entries => values;
@override
Widget buildEntry(BuildContext context, int entry) => Text(
sampleText,
style: textStyle
.copyWith(
fontFamily: font,
package: 'diagrams',
fontFeatures: <FontFeature>[
FontFeature(feature, entry),
...?additionalFontFeatures,
],
)
.merge(style),
textAlign: TextAlign.left,
);
@override
String describe(int entry) => '$feature $entry';
}
class HistoricalFontFeatureDiagram
extends FontFeatureDiagram<List<FontFeature>> {
const HistoricalFontFeatureDiagram(
this.font, {
required this.sampleText,
super.key,
});
@override
String get name => 'font_feature_historical';
final String font;
final String sampleText;
@override
Iterable<List<FontFeature>> get entries => const <List<FontFeature>>[
<FontFeature>[FontFeature('hist', 0), FontFeature('hlig', 0)],
<FontFeature>[FontFeature('hist'), FontFeature('hlig', 0)],
<FontFeature>[FontFeature('hist', 0), FontFeature('hlig')],
<FontFeature>[FontFeature('hist'), FontFeature('hlig')],
];
@override
Widget buildEntry(BuildContext context, List<FontFeature> entry) => Text(
sampleText,
style: textStyle.copyWith(
fontFamily: font,
package: 'diagrams',
fontFeatures: entry,
),
textAlign: TextAlign.left,
);
@override
String describe(List<FontFeature> entry) => entry
.map<String>(
(FontFeature feature) => '${feature.feature} ${feature.value}',
)
.join(', ');
}
class LocalizedFontFeatureDiagram extends FontFeatureDiagram<Locale> {
const LocalizedFontFeatureDiagram({super.key});
@override
String get name => 'font_feature_locl';
@override
Iterable<Locale> get entries => const <Locale>[
Locale('ja'),
Locale('ko'),
Locale('zh', 'CN'),
Locale('zh', 'TW'),
]; // alphabetical order
@override
Widget buildEntry(BuildContext context, Locale entry) => Text(
'次 化 刃 直 入 令',
style: textStyle.copyWith(
fontFamily: 'Noto Sans',
package: 'diagrams',
fontFeatures: <FontFeature>[
const FontFeature('locl'), // redundant, this is the default anyway
],
),
textAlign: TextAlign.left,
locale: entry,
);
@override
String describe(Locale entry) => 'Locale: ${entry.toLanguageTag()}';
}
abstract class SideBySideFontFeatureDiagram<T> extends FontFeatureDiagram<T> {
const SideBySideFontFeatureDiagram({super.key});
String get font;
@override
Widget buildRow(BuildContext context, T entry) {
return Row(
children: <Widget>[
buildSubEntry(context, entry, enable: false),
buildSubEntry(context, entry),
],
);
}
Widget buildSubEntry(BuildContext context, T entry, {bool enable = true}) =>
Expanded(
child: Stack(
children: <Widget>[
Positioned.fill(
top: _margin,
left: _margin,
child: buildEntry(context, entry, enable: enable),
),
Positioned(
left: 0.0,
top: 0.0,
child: buildDescription(context, entry, enable: enable),
),
],
),
);
@override
Widget buildDescription(BuildContext context, T entry, {bool enable = true}) {
return Text(
describe(entry, enable: enable),
style: const TextStyle(fontSize: 10.0),
);
}
@override
Widget buildEntry(BuildContext context, T entry, {bool enable = true}) {
return Text(
describe(entry, enable: enable),
style: const TextStyle(fontSize: 10.0),
);
}
@override
String describe(T entry, {bool enable = true});
}
class CharacterVariantsFontFeatureDiagram
extends SideBySideFontFeatureDiagram<String> {
const CharacterVariantsFontFeatureDiagram({super.key});
@override
String get name => 'font_feature_cvXX';
@override
String get font => 'Source Code Pro';
@override
Iterable<String> get entries => const <String>['cv01', 'cv02', 'cv04'];
static const Map<String, String> demos = <String, String>{
'cv01': 'aáâ β',
'cv02': 'gǵĝ θб',
'cv04': 'Iiíî Ll',
'cv06': 'Ŋ',
'cv07': 'β',
'cv08': 'θ',
'cv09': 'φ',
'cv10': 'б',
'cv12': '0',
'cv17': '1',
'cv16': r'$',
'cv15': '*',
};
@override
Widget buildEntry(BuildContext context, String entry, {bool enable = true}) =>
Text(
demos[entry]!,
style: textStyle.copyWith(
fontFamily: font,
package: 'diagrams',
fontFeatures: enable ? <FontFeature>[FontFeature(entry)] : null,
),
textAlign: TextAlign.left,
);
@override
String describe(String entry, {bool enable = true}) {
return 'with $entry ${enable ? "enabled" : "disabled"}';
}
}
class StylisticSetsFontFeatureDiagram1
extends SideBySideFontFeatureDiagram<String> {
const StylisticSetsFontFeatureDiagram1({super.key});
@override
String get name => 'font_feature_ssXX_1';
@override
String get font => 'Source Code Pro';
@override
Iterable<String> get entries => const <String>['ss02', 'ss03', 'ss04'];
static const Map<String, String> demos = <String, String>{
'ss02': 'aáâ β',
'ss03': 'gǵĝ θб',
'ss04': 'Iiíî Ll',
};
@override
Widget buildEntry(BuildContext context, String entry, {bool enable = true}) =>
Text(
demos[entry]!,
style: textStyle.copyWith(
fontFamily: font,
package: 'diagrams',
fontFeatures: enable ? <FontFeature>[FontFeature(entry)] : null,
),
textAlign: TextAlign.left,
);
@override
String describe(String entry, {bool enable = true}) {
return 'with $entry ${enable ? "enabled" : "disabled"}';
}
}
class StylisticSetsFontFeatureDiagram2 extends FontFeatureDiagram<int> {
const StylisticSetsFontFeatureDiagram2({super.key});
@override
String get name => 'font_feature_ssXX_2';
@override
Iterable<int> get entries => const <int>[0x00, 0x01, 0x02, 0x03];
String get font => 'Piazzolla';
@override
Widget buildEntry(BuildContext context, int entry) => Text(
'-> MCMXCVII <-', // the year SG-1 started
style: textStyle.copyWith(
fontFamily: font,
package: 'diagrams',
fontFeatures: <FontFeature>[
if (0x01 & entry > 0) const FontFeature('ss01'),
if (0x02 & entry > 0) const FontFeature('ss02', 2),
],
),
textAlign: TextAlign.left,
);
@override
String describe(int entry) {
switch (entry) {
case 0x00:
return 'no stylistic sets enabled';
case 0x01:
return 'only ss01 enabled';
case 0x02:
return 'only ss02 enabled';
case 0x03:
return 'ss01 and ss02 enabled';
}
throw UnsupportedError('$entry not recognized');
}
}
class FontFeatureDiagramStep extends DiagramStep {
@override
final String category = 'dart-ui';
@override
Future<List<FontFeatureDiagram<Object>>>
get diagrams async => <FontFeatureDiagram<Object>>[
const FontFeatureValueDiagram('aalt', <int>[0, 1, 2], 'Raleway'),
const FontFeatureValueDiagram(
'afrc',
<int>[0, 1],
'Ubuntu Mono',
sampleText: 'Fractions: 1/2 2/3 3/4 4/5',
),
const FontFeatureValueDiagram(
'calt',
<int>[0, 1],
'Barriecito',
sampleText: "Ooohh, we weren't going to tell him that.",
),
const FontFeatureValueDiagram(
'case',
<int>[0, 1],
'Piazzolla',
sampleText: '(A) [A] {A} «A» A/B A•B',
),
const CharacterVariantsFontFeatureDiagram(), // cvXX, uses 'Source Code Pro'
const FontFeatureValueDiagram(
'dnom',
<int>[0, 1],
'Piazzolla',
sampleText: 'Fractions: 1/2 2/3 3/4 4/5',
),
const FontFeatureValueDiagram(
'frac',
<int>[0, 1],
'Ubuntu Mono',
sampleText: 'Fractions: 1/2 2/3 3/4 4/5',
),
const HistoricalFontFeatureDiagram(
'Cardo',
sampleText: 'VIBRANT fish assisted his business.',
),
const FontFeatureValueDiagram(
'lnum',
<int>[0, 1],
'Sorts Mill Goudy',
sampleText: 'CALL 311-555-2368 NOW!',
),
const LocalizedFontFeatureDiagram(), // locl, uses 'Noto Sans'
const FontFeatureValueDiagram(
'nalt',
<int>[0, 1, 2, 3, 4, 5, 7],
'Gothic A1',
sampleText: 'abc 123',
),
const FontFeatureValueDiagram(
'numr',
<int>[0, 1],
'Piazzolla',
sampleText: 'Fractions: 1/2 2/3 3/4 4/5',
),
const FontFeatureValueDiagram(
'onum',
<int>[0, 1],
'Piazzolla',
sampleText: 'Call 311-555-2368 now!',
),
const FontFeatureValueDiagram(
'ordn',
<int>[0, 1],
'Piazzolla',
sampleText: '1st, 2nd, 3rd, 4th...',
),
const FontFeatureValueDiagram(
'pnum',
<int>[0, 1],
'Kufam',
sampleText: 'Call 311-555-2368 now!',
),
const FontFeatureValueDiagram(
'salt',
<int>[0, 1],
'Source Code Pro',
sampleText: r'Agile Game - $100 initial bet',
),
const FontFeatureValueDiagram(
'sinf',
<int>[0, 1],
'Piazzolla',
sampleText: 'C8H10N4O2',
),
const StylisticSetsFontFeatureDiagram1(), // ssXX, uses 'Source Code Pro'
const StylisticSetsFontFeatureDiagram2(), // ssXX, uses 'Piazzolla'
const FontFeatureValueDiagram(
'subs',
<int>[0, 1],
'Piazzolla',
sampleText: 'Line from x1,y1 to x2,y2',
),
const FontFeatureValueDiagram(
'sups',
<int>[0, 1],
'Sorts Mill Goudy',
sampleText: 'The isotope 238U decays to 206Pb',
),
const FontFeatureValueDiagram(
'swsh',
<int>[0, 1],
'BioRhyme Expanded',
sampleText: 'Queer & Romantic',
),
const FontFeatureValueDiagram(
'tnum',
<int>[0, 1],
'Piazzolla',
sampleText: 'Call 311-555-2368 now!',
),
const FontFeatureValueDiagram(
'zero',
<int>[0, 1],
'Source Code Pro',
sampleText: 'One million is: 1,000,000.00',
),
];
}