-
Notifications
You must be signed in to change notification settings - Fork 28
/
fonts.js
1933 lines (1870 loc) · 76.9 KB
/
fonts.js
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
let fntCodePoints = {
// ToDo: create OS specific lists
// ToDo: update codepoints to be gecko specifc and cover unicode changes since fifield et al
"test": [ // sorted
//*
'0x007F','0x0218','0x058F','0x05C6','0x061C','0x0700','0x08E4','0x097F','0x09B3',
'0x0B82','0x0D02','0x10A0','0x115A','0x17DD','0x1950','0x1C50','0x1CDA','0x1D790',
'0x1E9E','0x20B0','0x20B8','0x20B9','0x20BA','0x20BD','0x20E3','0x21E4','0x23AE',
'0x2425','0x2581','0x2619','0x2B06','0x2C7B','0x302E','0x3095','0x532D','0xA73D',
'0xA830','0xF003','0xF810','0xFBEE','0xFFF9',
// '0xFFFD', // problematic
// replacement character: https://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character
// https://thorin-oakenpants.github.io/testing/FFFD.html
// win FF: always Segoe UI
// win MB: always Malgun Gothic
// win TB102
// on first document tab/run (and reloading the same tab) = tahoma
// on subsequent tabs = Malgun Gothic
//*/
],
"tofu": ['0xFFFF'],
"tbwindows": ["0x0374"], // or "0x0375": +1 more size: not worth it
}
let fntCodes = [],
fntData = {},
fntSize = "512px",
fntString = "Mōá?-"+ get_fntCodes("tofu"),
fntBtn = "",
fntDocEnabled = false,
fntBases = {}
let fntMaster = {
// android core noto fonts
'android': {
'notoboth': [
// sans: 5+ except CJK JP + Gujarati + Gurmukhi + Tibetan 9+
// serifs: 9+ except tibetan 12+
'Armenian','Bengali','CJK JP','Devanagari','Ethiopic','Georgian','Gujarati','Gurmukhi','Hebrew','Kannada',
'Khmer','Lao','Malayalam','Myanmar','Sinhala','Tamil','Telugu','Thai','Tibetan',
],
'notosans': [
// 5+
'Bengali UI','Devanagari UI','Khmer UI','Lao UI','Malayalam UI','Myanmar UI','Symbols','Tamil UI','Telugu UI','Thai UI',
// 9+
'Adlam','Ahom','Anatolian Hieroglyphs','Avestan','Balinese','Bamum','Bassa Vah','Batak','Bhaiksuki','Brahmi','Buginese','Buhid',
'Canadian Aboriginal','Carian','Chakma','Cham','Cherokee','Coptic','Cuneiform','Cypriot','Deseret','Egyptian Hieroglyphs',
'Elbasan','Glagolitic','Gothic','Gujarati UI','Gurmukhi UI','Hanunoo','Hatran','Imperial Aramaic','Inscriptional Pahlavi',
'Inscriptional Parthian','Javanese','Kaithi','Kayah Li','Kharoshthi','Lepcha','Limbu','Linear A','Linear B','Lisu','Lycian',
'Lydian','Mandaic','Manichaean','Marchen','Meetei Mayek','Meroitic','Miao','Mongolian','Mro','Multani','Nabataean','Newa',
'New Tai Lue','NKo','Ogham','Ol Chiki','Old Italic','Old North Arabian','Old Permic','Old Persian','Old South Arabian',
'Old Turkic','Oriya','Oriya UI','Osage','Osmanya','Pahawh Hmong','Palmyrene','Pau Cin Hau','Phags Pa','Phoenician','Rejang',
'Runic','Samaritan','Saurashtra','Sharada','Shavian','Sinhala UI','Sora Sompeng','Sundanese','Syloti Nagri','Syriac Eastern',
'Syriac Estrangela','Syriac Western','Tagalog','Tagbanwa','Tai Le','Tai Tham','Tai Viet','Thaana','Tifinagh','Ugaritic','Vai','Yi',
// 12+
'Grantha','Gunjala Gondi','Hanifi Rohingya','Khojki','Masaram Gondi','Medefaidrin','Modi','Soyombo','Takri','Wancho','Warang Citi',
],
'notoserif': [
'Dogra','Nyiakeng Puachue Hmong','Yezidi', // 12+
],
},
// TB13 bundled: reuse for android/linux
'bundled': {
// all: win/mac/linux: 80sans-only 4serif-only 17both: total 118, sorted hash: 8949a424
'notoboth': [
'Balinese','Bengali','Devanagari','Ethiopic','Georgian','Grantha','Gujarati','Gurmukhi','Kannada','Khmer',
'Khojki','Lao','Malayalam','Myanmar','Sinhala','Tamil','Telugu',
],
'notosans': [
'Adlam','Bamum','Bassa Vah','Batak','Buginese','Buhid','Canadian Aboriginal','Chakma','Cham','Cherokee',
'Coptic','Deseret','Elbasan','Gunjala Gondi','Hanifi Rohingya','Hanunoo','Javanese','Kayah Li','Khudawadi',
'Lepcha','Limbu','Lisu','Mahajani','Mandaic','Masaram Gondi','Medefaidrin','Meetei Mayek','Mende Kikakui',
'Miao','Modi','Mongolian','Mro','Multani','NKo','New Tai Lue','Newa','Ol Chiki','Oriya','Osage','Osmanya',
'Pahawh Hmong','Pau Cin Hau','Rejang','Runic','Samaritan','Saurashtra','Sharada','Shavian','Sora Sompeng',
'Soyombo','Sundanese','Syloti Nagri','Symbols','Symbols 2','Syriac','Tagalog','Tagbanwa','Tai Le','Tai Tham',
'Tai Viet','Takri','Thaana','Tifinagh','Tifinagh APT','Tifinagh Adrar','Tifinagh Agraw Imazighen',
'Tifinagh Ahaggar','Tifinagh Air','Tifinagh Azawagh','Tifinagh Ghat','Tifinagh Hawad','Tifinagh Rhissa Ixa',
'Tifinagh SIL','Tifinagh Tawellemmet','Tirhuta','Vai','Wancho','Warang Citi','Yi','Zanabazar Square',
],
'notoserif': ['Dogra','NP Hmong','Tibetan','Yezidi',],
'android': [],
// notos then linux +16, mac +5, win +4
'linux': [
'Arimo','Cousine','Noto Naskh Arabic','Noto Sans Armenian','Noto Sans Hebrew','Noto Sans JP','Noto Sans KR',
'Noto Sans SC','Noto Sans TC','Noto Sans Thai','Noto Serif Armenian','Noto Serif Hebrew','Noto Serif Thai',
'STIX Two Math','Tinos','Twemoji Mozilla',
],
'mac': ['Noto Sans Armenian','Noto Sans Hebrew','Noto Serif Armenian','Noto Serif Hebrew','STIX Two Math',],
'windows': ['Noto Naskh Arabic','Noto Sans','Noto Serif','Twemoji Mozilla',],
},
// TB whitelist system
'allowlist': {
'android': [],
'linux': [],
'mac': [
'AppleGothic','Apple Color Emoji','Arial','Courier','Courier New',
'Geneva','Georgia','Heiti TC','Helvetica','Helvetica Neue','Hiragino Kaku Gothic ProN',
'Kailasa','Lucida Grande','Menlo','Monaco','PingFang HK','PingFang SC','PingFang TC','Songti SC',
'Songti TC','Tahoma','Thonburi','Times','Times New Roman','Verdana',
// always
'-apple-system',
/* variants
'Hiragino Kaku Gothic ProN W3','Hiragino Kaku Gothic ProN W6',
*/
],
'windows': [
// 7
'Arial','Cambria Math','Consolas','Courier New','Georgia','Lucida Console','MS Gothic','MS PGothic','MV Boli',
'Malgun Gothic','Microsoft Himalaya','Microsoft JhengHei','Microsoft YaHei','Segoe UI','SimSun','Sylfaen',
'Tahoma','Times New Roman','Verdana',
// localized
'微软雅黑','MS ゴシック','MS Pゴシック','宋体', // Microsoft YaHei, MS Gothic, MS PGothic, SimSun
// system aliases
// https://searchfox.org/mozilla-central/source/gfx/thebes/gfxDWriteFontList.cpp#1990
// should always be the same but lets test everything in TB
'MS Serif','Courier','Small Fonts','Roman', // TNR, Courier New, Arial, TNR
// isPlatformFont
'MS Shell Dlg \\32',
// FontSubstitutes
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
// TB FontSubstitutes -> whitelisted
'Arabic Transparent','Arial (Arabic)','Arial (Hebrew)','Arial Baltic','Arial CE','Arial CYR',
'Arial Greek','Arial TUR','Courier New (Hebrew)','Courier New Baltic','Courier New CE',
'Courier New CYR','Courier New Greek','Courier New TUR','Helvetica','MS Shell Dlg 2','Tahoma Armenian',
'Times','Times New Roman (Hebrew)','Times New Roman Baltic','Times New Roman CE','Times New Roman CYR',
'Times New Roman Greek','Times New Roman TUR','Tms Rmn','MS Serif Greek','Small Fonts Greek',
'標準ゴシック','ゴシック','ゴシック', // MS ゴシック -> MS Gothic
'ヘルベチカ','タイムズロマン','クーリエ', // Arial, TNR, Courier - >Courier New
/* ignore
// variants
'Arial Black','Arial Narrow','Segoe UI Light','Segoe UI Semibold', // 7
'Segoe UI Semilight', // 8
'Microsoft JhengHei Light','Microsoft YaHei Light','Segoe UI Black', // 8.1
'Malgun Gothic Semilight', // 10
*/
],
},
// TB unexpected
'blocklist': {
'android': [],
'linux': [
'Arial','Courier New','Times New Roman', // aliases
'Courier','Noto Color Emoji','Noto Emoji','Noto Mono','Noto Sans','Noto Serif', // notos
'Cantarell','DejaVu Sans','DejaVu Serif','Droid Sans','STIX', // fedora
'Dingbats','FreeMono','Ubuntu', // ubuntu
'Liberation Mono','Liberation Sans','Liberation Serif', // popular
'Noto Serif Hmong Nyiakeng','Noto Sans Symbols2','STIX Math', // TB12 fontnames
],
'mac': [
'Apple Symbols','Avenir','Charter','Impact','Palatino','Rockwell', // system
'Noto Serif Hmong Nyiakeng','Noto Sans Symbols2','STIX Math', // TB12 fontnames
'.Helvetica Neue DeskInterface', // dot-prefixed font families on mac = hidden // tb#42377
// not detected: we may whitelist these
'Arial Black','Arial Narrow',
],
'windows': [
'Calibri', //'Impact','Candara','Corbel','Ebrima','Gabriola', // system
'MS Dlg Shell', // system that should point to Microsoft Sans Serif
'Gill Sans','Gill Sans MT', // MS bundled
'Noto Serif Hmong Nyiakeng', //'Noto Sans Symbols2', // TB12 fontnames
],
},
// kBaseFonts: https://searchfox.org/mozilla-central/search?path=StandardFonts*.inc
'base': {
'android': [],
'linux': [],
'mac': [
// always
'-apple-system',
//kBaseFonts
'Al Bayan','Al Nile','Al Tarikh','American Typewriter','Andale Mono','Apple Braille','Apple Chancery',
'Apple Color Emoji','Apple SD Gothic Neo','Apple Symbols','AppleGothic','AppleMyungjo','Arial',
'Arial Black','Arial Hebrew','Arial Hebrew Scholar','Arial Narrow','Arial Rounded MT Bold',
'Arial Unicode MS','Avenir','Avenir Next','Ayuthaya',
'Baghdad','Bangla MN','Bangla Sangam MN','Baskerville','Beirut','Big Caslon','Bodoni 72',
'Bodoni 72 Oldstyle','Bodoni 72 Smallcaps','Bodoni Ornaments','Bradley Hand','Brush Script MT',
'Chalkboard','Chalkboard SE','Chalkduster','Charter','Cochin','Comic Sans MS','Copperplate',
'Corsiva Hebrew','Courier','Courier New',
'DIN Alternate','DIN Condensed','Damascus','DecoType Naskh','Devanagari MT','Devanagari Sangam MN',
'Didot','Diwan Kufi','Diwan Thuluth',
'Euphemia UCAS',
'Farah','Farisi','Futura',
'GB18030 Bitmap','Galvji','Geeza Pro','Geneva','Georgia','Gill Sans','Gujarati MT','Gujarati Sangam MN',
'Gurmukhi MN','Gurmukhi MT','Gurmukhi Sangam MN',
'Heiti SC','Heiti TC','Helvetica','Helvetica Neue','Hoefler Text','Hiragino Maru Gothic ProN',
'Hiragino Mincho ProN','Hiragino Sans','Hiragino Sans GB',
'ITF Devanagari','ITF Devanagari Marathi','Impact','InaiMathi',
'Kailasa','Kannada MN','Kannada Sangam MN','Kefa','Khmer MN','Khmer Sangam MN','Kohinoor Bangla',
'Kohinoor Devanagari','Kohinoor Gujarati','Kohinoor Telugu','Kokonor','Krungthep','KufiStandardGK',
'Lao MN','Lao Sangam MN','Lucida Grande','Luminari',
'Malayalam MN','Malayalam Sangam MN','Marker Felt','Menlo','Microsoft Sans Serif','Mishafi','Mishafi Gold',
'Monaco','Mshtakan','Mukta Mahee','Muna','Myanmar MN','Myanmar Sangam MN',
'Nadeem','New Peninim MT','Noteworthy',
'Noto Nastaliq Urdu',
'Noto Sans Adlam','Noto Sans Armenian','Noto Sans Avestan','Noto Sans Bamum','Noto Sans Bassa Vah',
'Noto Sans Batak','Noto Sans Bhaiksuki','Noto Sans Brahmi','Noto Sans Buginese','Noto Sans Buhid',
'Noto Sans Canadian Aboriginal','Noto Sans Carian','Noto Sans Caucasian Albanian','Noto Sans Chakma',
'Noto Sans Cham','Noto Sans Coptic','Noto Sans Cuneiform','Noto Sans Cypriot','Noto Sans Duployan',
'Noto Sans Egyptian Hieroglyphs','Noto Sans Elbasan','Noto Sans Glagolitic','Noto Sans Gothic',
'Noto Sans Gunjala Gondi','Noto Sans Hanifi Rohingya','Noto Sans Hanunoo','Noto Sans Hatran',
'Noto Sans Imperial Aramaic','Noto Sans Inscriptional Pahlavi','Noto Sans Inscriptional Parthian',
'Noto Sans Javanese','Noto Sans Kaithi','Noto Sans Kannada','Noto Sans Kayah Li','Noto Sans Kharoshthi',
'Noto Sans Khojki','Noto Sans Khudawadi','Noto Sans Lepcha','Noto Sans Limbu','Noto Sans Linear A',
'Noto Sans Linear B','Noto Sans Lisu','Noto Sans Lycian','Noto Sans Lydian','Noto Sans Mahajani',
'Noto Sans Mandaic','Noto Sans Manichaean','Noto Sans Marchen','Noto Sans Masaram Gondi',
'Noto Sans Meetei Mayek','Noto Sans Mende Kikakui','Noto Sans Meroitic','Noto Sans Miao','Noto Sans Modi',
'Noto Sans Mongolian','Noto Sans Mro','Noto Sans Multani','Noto Sans Myanmar','Noto Sans Nabataean',
'Noto Sans New Tai Lue','Noto Sans Newa','Noto Sans NKo','Noto Sans Ol Chiki','Noto Sans Old Hungarian',
'Noto Sans Old Italic','Noto Sans Old North Arabian','Noto Sans Old Permic','Noto Sans Old Persian',
'Noto Sans Old South Arabian','Noto Sans Old Turkic','Noto Sans Oriya','Noto Sans Osage','Noto Sans Osmanya',
'Noto Sans Pahawh Hmong','Noto Sans Palmyrene','Noto Sans Pau Cin Hau','Noto Sans PhagsPa','Noto Sans Phoenician',
'Noto Sans Psalter Pahlavi','Noto Sans Rejang','Noto Sans Samaritan','Noto Sans Saurashtra','Noto Sans Sharada',
'Noto Sans Siddham','Noto Sans Sora Sompeng','Noto Sans Sundanese','Noto Sans Syloti Nagri','Noto Sans Syriac',
'Noto Sans Tagalog','Noto Sans Tagbanwa','Noto Sans Tai Le','Noto Sans Tai Tham','Noto Sans Tai Viet',
'Noto Sans Takri','Noto Sans Thaana','Noto Sans Tifinagh','Noto Sans Tirhuta','Noto Sans Ugaritic',
'Noto Sans Vai','Noto Sans Wancho','Noto Sans Warang Citi','Noto Sans Yi','Noto Sans Zawgyi',
'Noto Serif Ahom','Noto Serif Balinese','Noto Serif Hmong Nyiakeng','Noto Serif Myanmar','Noto Serif Yezidi',
'Optima','Oriya MN','Oriya Sangam MN',
'PT Mono','PT Sans','PT Sans Caption','PT Sans Narrow','PT Serif','PT Serif Caption','Palatino','Papyrus',
'Phosphate','PingFang HK','PingFang SC','PingFang TC','Plantagenet Cherokee',
'Raanana','Rockwell',
'STIXGeneral','STIXIntegralsD','STIXIntegralsSm','STIXIntegralsUp','STIXIntegralsUpD','STIXIntegralsUpSm',
'STIXNonUnicode','STIXSizeFiveSym','STIXSizeFourSym','STIXSizeOneSym','STIXSizeThreeSym','STIXSizeTwoSym',
'STIXVariants','STSong','Sana','Sathu','Savoye LET','Shree Devanagari 714','SignPainter','Silom','Sinhala MN',
'Sinhala Sangam MN','Skia','Snell Roundhand','Songti SC','Songti TC','Sukhumvit Set','Symbol',
'Tahoma','Tamil MN','Tamil Sangam MN','Telugu MN','Telugu Sangam MN','Thonburi','Times','Times New Roman',
'Trattatello','Trebuchet MS',
'Verdana',
'Waseem','Webdings','Wingdings','Wingdings 2','Wingdings 3',
'Zapf Dingbats','Zapfino',
],
'windows': [
'AlternateGothic2 BT', // ?
// 7
'Arial','Calibri','Cambria','Cambria Math','Candara','Comic Sans MS','Consolas','Constantia','Corbel','Courier New','Ebrima',
'Gabriola','Georgia','Impact','Lucida Console','Lucida Sans Unicode','MS Gothic','MS PGothic','MS UI Gothic','MV Boli',
'Malgun Gothic','Marlett','Microsoft Himalaya','Microsoft JhengHei','Microsoft New Tai Lue','Microsoft PhagsPa',
'Microsoft Sans Serif','Microsoft Tai Le','Microsoft YaHei','Microsoft Yi Baiti','MingLiU-ExtB','MingLiU_HKSCS-ExtB',
'Mongolian Baiti','NSimSun','PMingLiU-ExtB','Palatino Linotype','Segoe Print','Segoe Script','Segoe UI','Segoe UI Symbol',
'SimSun','SimSun-ExtB','Sylfaen','Symbol','Tahoma','Times New Roman','Trebuchet MS','Verdana','Webdings','Wingdings',
// 7 but not detected if font-vis < 3: 1720408
'Franklin Gothic Medium',
// 8
'Gadugi','Nirmala UI','Microsoft JhengHei UI','Microsoft YaHei UI','Myanmar Text',
// 8.1
'Javanese Text','Leelawadee UI','Segoe UI Emoji','Sitka Banner','Sitka Display',
'Sitka Heading','Sitka Small','Sitka Subheading','Sitka Text','Yu Gothic',
// 10
'Bahnschrift','HoloLens MDL2 Assets','Segoe MDL2 Assets','Segoe UI Historic','Yu Gothic UI',
// localized: kBase: detected FF119+: 1850672
'微软雅黑','MS ゴシック','MS Pゴシック','宋体','游ゴシック', // Microsoft YaHei, MS Gothic, MS PGothic, SimSun, Yu Gothic
// isPlatformFont
'MS Shell Dlg \\32',
// common FontSubstitutes that point to kBase fonts
'MS Shell Dlg','MS Shell Dlg 2', // can differ
// non-common FontSubstitutes
'Arial (Arabic)','Arial (Hebrew)','MS Serif Greek','ヘルベチカ', // ja = arial
/* ignore
// common subs
'Arabic Transparent','Arial Baltic','Arial CE','Arial CYR','Arial Greek','Arial TUR',
'Courier New Baltic','Courier New CE','Courier New CYR','Courier New Greek','Courier New TUR',
'Helv','Helvetica','Tahoma Armenian','Times','Times New Roman Baltic','Times New Roman CE',
'Times New Roman CYR','Times New Roman Greek','Times New Roman TUR','Tms Rmn',
// non-common subs: redundant
'Courier New (Hebrew)','Times New Roman (Hebrew)','Small Fonts Greek',
'標準ゴシック','ゴシック','ゴシック', // MS ゴシック -> MS Gothic
'タイムズロマン','クーリエ', // TNR, Courier -> Courier New
// system aliases: should always be the same AFAICT
// https://searchfox.org/mozilla-central/source/gfx/thebes/gfxDWriteFontList.cpp#1990
'MS Sans Serif','MS Serif','Courier','Small Fonts','Roman', // Microsoft Sans Serif, TNR, Courier New, Arial, TNR
// variants
'Arial Black','Arial Narrow','Segoe UI Light','Segoe UI Semibold', // 7
'Calibri Light','Calibri Light Italic','Segoe UI Semilight', // 8
// 8.1
'Leelawadee UI Semilight','Microsoft JhengHei Light','Microsoft JhengHei UI Light',
'Microsoft YaHei Light','Microsoft YaHei UI Light','Nirmala UI Semilight','Segoe UI Black','Yu Gothic Light',
// 10
'Bahnschrift Light','Bahnschrift SemiBold','Bahnschrift SemiLight','Candara Light','Corbel Light',
'Malgun Gothic Semilight','Yu Gothic Medium','Yu Gothic UI Light','Yu Gothic UI Semilight','Yu Gothic UI Semibold',
*/
],
},
'system': {
'android': [
// all
'AndroidClock Regular','Carrois Gothic SC','Cutive Mono','Dancing Script','Droid Sans Mono',
'Noto Color Emoji','Noto Naskh Arabic', // ignore 'Coming Soon Regular', see 'Coming Soon'
// 9+
'Coming Soon','Noto Naskh Arabic UI','Roboto',
// 12+
'Noto Color Emoji Flags','Source Sans Pro Regular',
// + common + self
'Droid Sans','Droid Serif','Noto Sans','Noto Serif','Roboto Condensed',
// + vendor: ToDo: SamsungOneUI*, SamsungNeo*, vendor specific
'SamsungKorean_v2.0', // 1674683
'SamsungKorean_v3.0',
'SamsungColorEmoji', // 1872510
'One UI Sans KR VF', // 1865238
// + me
'Noto Serif CJK KR','Noto Serif CJK SC','Noto Serif CJK TC',
// + defaults
'SEC CJK JP','SEC CJK KR','SEC CJK SC','SEC CJK TC','SEC Mono CJK JP','SEC Mono CJK KR','SEC Mono CJK SC',
'SEC Mono CJK TC',
/* defaults
// https://searchfox.org/mozilla-central/source/modules/libpref/init/all.js#3041
// ToDo: check names are correct
'HYSerif','MotoyaLCedar','MotoyaLMaru','NanumGothic','SmartGothic',
// ToDo: possibles: but I don't have them (Android 11), they seem out of date
'Arial','Asana Math','Cambria Math','Charis SIL Compact','DejaVu Math TeX Gyre','DejaVu Sans',
'DejaVu Serif','Droid Sans Fallback','Droid Sans Hebrew','Droid Sans Japanese','Droid Sans Thai',
'Google Sans','Latin Modern Math','Libertinus Math','Noto Sans Mono CJK JP','Noto Sans Mono CJK KR',
'Noto Sans Mono CJK SC','Noto Sans Mono CJK TC','STIX Math','STIX Two Math','STIXGeneral',
'TeX Gyre Bonum Math','TeX Gyre Pagella Math','TeX Gyre Schola','TeX Gyre Termes Math','XITS Math',
*/
],
'linux': [
// self
'Noto Sans','Noto Serif',
// + always
'Arial','Courier','Courier New',
// + common notos
'Noto Emoji','Noto Sans Tibetan',
// + some selective kBase ubuntu or fedora
// notos
'Noto Color Emoji','Noto Mono','Noto Serif CJK JP','Noto Serif CJK KR','Noto Serif CJK SC','Noto Serif CJK TC',
// western/symbols
'Cantarell','DejaVu Sans','DejaVu Serif','Droid Sans','STIX','STIX Two Text','Symbola', // fedora
'Dingbats','FreeMono','Jamrul','Kinnari','Ubuntu', // ubuntu
// scripts
// ubuntu
'KacstNaskh','PakType Naskh Basic', // arabic
'Likhan','Mitra Mono','Mukti Narrow', // bengali
'Chandas','Gargi','Kalimati','Nakula','Rachana','Sahadeva','Samanata','Sarai', // devangari
'Rekha','Saab','Samyak Gujarati', // gujarati
'Lohit Gurmukhi', // gurmukhi
'Gubbi','Navilu', // kannada
'Phetsarath OT', // lao
'Chilanka','Dyuthi','Gayathri','Karumbi','Keraleeyam','Manjari','Suruma','Uroob', // malayalam
'ori1Uni','utkal', // oriya
'LKLUG','padmaa', // sinhala
'Samyak Tamil', // tamil
'Pothana2000','Vemana2000', // telugu
'Laksaman','Norasi','Purisa','Tlwg Mono','Umpush', // thai
'Jomolhari', // tibetan, also chrome os
'Pagul','Rasa','Yrsa', // multiscript
// fedora
'Droid Arabic Kufi', // arabic
'Droid Sans Devanagari', // devangari
'Droid Sans Ethiopic', // ethiopic
'Droid Sans Hebrew', // hebrew
'Droid Sans Japanese', // jap
'Khmer OS', // khmer
'Droid Sans Tamil', // tamil
'Droid Sans Thai', // thai
'Nuosu SIL', // yi
// other
'Liberation Mono','Liberation Sans','Liberation Serif',
'OpenSymbol', // openoffice
'Amiri', // libreoffice
// ToDo: expand
],
'mac': [
'Academy Engraved LET','Adelle Sans Devanagari','AkayaKanadaka','AkayaTelivigala','Annai MN','Apple LiGothic',
'Apple LiSung','Arima Koshi','Arima Madurai','Athelas','Avenir Next Condensed',
'Bai Jamjuree','Baloo 2','Baloo Bhai 2','Baloo Bhaijaan','Baloo Bhaina 2','Baloo Chettan 2','Baloo Da 2','Baloo Paaji 2',
'Baloo Tamma 2','Baloo Tammudu 2','Baloo Thambi 2','Baoli SC','Baoli TC','BiauKaiHK','BiauKaiTC','BIZ UDGothic',
'BIZ UDMincho','BM Dohyeon','BM Hanna 11yrs Old','BM Hanna Air','BM Hanna Pro','BM Jua','BM Kirang Haerang','BM Yeonsung','Brill',
'Cambay Devanagari','Canela','Canela Deck','Canela Text','Chakra Petch','Charm','Charmonman',
'Domaine Display',
'Fahkwang','Founders Grotesk','Founders Grotesk Condensed','Founders Grotesk Text',
'Gotu','Grantha Sangam MN','Graphik','Graphik Compact','GungSeo',
'Hannotate SC','Hannotate TC','HanziPen SC','HanziPen TC','HeadLineA','Hei','Herculanum','Hiragino Kaku Gothic ProN','Hiragino Sans CNS','Hubballi',
'Jaini','Jaini Purva',
'Iowan Old Style',
'K2D','Kai','Kaiti SC','Kaiti TC','Katari','Kavivanar','Kigelia','Kigelia Arabic','Klee','Kodchasan','KoHo','Krub',
'Lahore Gurmukhi','Lantinghei SC','Lantinghei TC','Lava Devanagari','Lava Kannada','Lava Telugu',
'LiHei Pro','LiSong Pro','Libian SC','Libian TC','LingWai SC','LingWai TC',
'Maku','Mali','Marion','Modak','Mukta','Mukta Malar','Mukta Vaani','Myriad Arabic',
'Nanum Brush Script','Nanum Gothic','Nanum Myeongjo','Nanum Pen Script','Niramit','Noto Serif Kannada',
'October Compressed Devanagari','October Compressed Gujarati','October Compressed Gurmukhi','October Compressed Kannada',
'October Compressed Meetei Mayek','October Compressed Odia','October Compressed Ol Chiki','October Compressed Tamil','October Compressed Telugu',
'October Condensed Devanagari','October Condensed Gujarati','October Condensed Gurmukhi','October Condensed Kannada',
'October Condensed Meetei Mayek','October Condensed Odia','October Condensed Ol Chiki','October Condensed Tamil','October Condensed Telugu',
'October Devanagari','October Gujarati','October Gurmukhi','October Kannada',
'October Meetei Mayek','October Odia','October Ol Chiki','October Tamil','October Telugu',
'Osaka','Osaka-Mono',
'Padyakke Expanded One','Party LET','PCMyungjo','PilGi','Produkt','Proxima Nova','PSL Ornanong Pro','Publico Headline','Publico Text',
'Quotes Caps','Quotes Script',
'Sama Devanagari','Sama Gujarati','Sama Gurmukhi','Sama Kannada','Sama Malayalam','Sama Tamil','Sarabun','Sauber Script','Seravek',
'Shobhika','SimSong','Spot Mono','Srisakdi','STFangsong','STHeiti','STIX Two Math','STIX Two Text','STKaiti','Superclarendon',
'Tiro Bangla','Tiro Devanagari Hindi','Tiro Devanagari Marathi','Tiro Devanagari Sanskrit','Tiro Gurmukhi',
'Tiro Kannada','Tiro Tamil','Tiro Telugu','Toppan Bunkyu Gothic','Toppan Bunkyu Midashi Gothic',
'Toppan Bunkyu Midashi Mincho','Toppan Bunkyu Mincho','Tsukushi A Round Gothic','Tsukushi B Round Gothic',
'Wawati SC','Wawati TC','Weibei SC','Weibei TC',
'Xingkai SC','Xingkai TC',
'Yuanti SC','Yuanti TC','YuGothic','YuKyokasho','YuKyokasho Yoko','YuMincho','YuMincho +36p Kana','Yuppy SC','Yuppy TC',
],
'windows': [
'Aharoni','Aldhabi','Andalus','Angsana New','AngsanaUPC','Aparajita','Arabic Typesetting','Arial Nova',
'BIZ UDGothic','BIZ UDPGothic','Batang','BatangChe','Browallia New','BrowalliaUPC','Cordia New','DFKai-SB',
'CordiaUPC','DaunPenh','David','DengXian','DilleniaUPC','DokChampa','Dotum','DotumChe','Estrangelo Edessa',
'EucrosiaUPC','Euphemia','FangSong','FrankRuehl','FreesiaUPC','Gautami','Georgia Pro','Gill Sans Nova',
'Gisha','Gulim','GulimChe','Gungsuh','GungsuhChe','Ink Free','IrisUPC','Iskoola Pota','JasmineUPC','KaiTi',
'Kalinga','Kartika','Khmer UI','KodchiangUPC','Kokila','Lao UI','Latha','Leelawadee','Levenim MT','LilyUPC',
'MS Mincho','MS PMincho','Mangal','Meiryo','Meiryo UI','Microsoft Uighur','MingLiU','MingLiU_HKSCS','Miriam',
'Miriam Fixed','MoolBoran','Narkisim','Neue Haas Grotesk Text Pro','Nyala','PMingLiU','Plantagenet Cherokee',
'Raavi','Rockwell Nova','Rod','Sakkal Majalla','Sanskrit Text','Segoe Fluent Icons','Segoe UI Variable Display',
'Segoe UI Variable Small','Segoe UI Variable Text','Shonar Bangla','Shruti','SimHei','Simplified Arabic',
'Simplified Arabic Fixed','Traditional Arabic','Tunga','UD Digi Kyokasho N-B','UD Digi Kyokasho N-R',
'UD Digi Kyokasho NK-B','UD Digi Kyokasho NK-R','UD Digi Kyokasho NP-B','UD Digi Kyokasho NP-R','Urdu Typesetting',
'Utsaah','Vani','Verdana Pro','Vijaya','Vrinda','Yu Mincho',
// win11
'Sans Serif Collection',
// localized ^
'바탕', // Batang
'BIZ UDPゴシック', // BIZ UDPGothic
'굴림', // Gulim
'굴림체', // GulimChe
'細明體', // MingLiU
'細明體_HKSCS', // MingLiU_HKSCS
'MS 明朝', // MS Mincho
'MS P明朝', // MS PMincho
'新細明體', // PMingLiU
// fontSubs
'KaiTi_GB2312', // simplified chinese
// fontSubs redundant
// '標準明朝', // MS 明朝 -> MS Mincho
// 'FangSong_GB2312',
// MS products
'Arial Unicode MS','MS Reference Specialty','MS Outlook','Gill Sans','Gill Sans MT',
// MS downloads
'Cascadia Code','Cascadia Mono', // 11
],
},
// help determine OS
"mini": [
//'Dancing Script','Roboto', // also help determine isPlatformFont for android
'-apple-system',
'MS Shell Dlg \\32',
],
}
function get_fntCodes(name) {
let list = fntCodePoints[name], str = ""
list.forEach(function(code) {str += String.fromCodePoint(code)})
return str
}
function set_fntList(os = isOS) {
let fntListBaseName = isTB ? "allowlist" : "kBaseFonts"
let build = (gLoad || isFontSizesMore !== isFontSizesPrevious)
if (build) {
isFontSizesPrevious = isFontSizesMore
fntData = {
"system": [], "bundled": [], "base": [], "unexpected": [], "full": [],
"control": [], "control_name": [], "generic": [],
}
// baseSize: add fallback for misconfigured/missing
// isPlatformFont: expected + can't be blocked + differs vs most fonts
// no entropy loss: size collisions of expected system fonts e.g. Tahoma
// means not detected/recorded - but we _know_ it should be there
let isPlatformFont
let baseSize = ['monospace','sans-serif','serif']
let tofu = get_fntCodes("tofu")
if ("windows" === os) {
// Mō = 124 +"á" = 125 +"Ω" = 127 (win7)
// Mō - 141 +"á" = 142 +"Ω" = 144 | Mō - 141 +tofu = 154 | (win11: have 182/186 fonts
fntString = isTB ? "?-"+ tofu : "Mō"+ tofu
if (!isFontSizesMore) {isPlatformFont = "MS Shell Dlg \\32"}
if (isTB) {isPlatformFont = undefined} // detect all fonts: cost 188->226 measurements taken
baseSize = [
'monospace, Consolas, Courier, \"Courier New\", \"Lucida Console\"',
'sans-serif, Arial',
'serif, Times, Roman'
]
} else if ("mac" === os) {
if (!isFontSizesMore) {isPlatformFont = "-apple-system"}
baseSize = ['monospace, Menlo, Courier, \"Courier New\", Monaco',
'sans-serif',
'serif'
]
} else if ("android" == os) {
// see android list notes: Roboto is not guaranteed unless Android 9+
// ToDo: we should test a mini set of android fonts and use a detected one
if (!isFontSizesMore) {isPlatformFont = "Dancing Script"}
fntString = '?-'+ tofu
}
// baseCtrl: 1-pass or 3-pass
// baseCtrlNames: remove fallback e.g. "serif, X" -> "serif"
let baseCtrl = isPlatformFont === undefined ? baseSize : [isPlatformFont]
fntData["control"] = baseCtrl
let baseCtrlNames = []
baseCtrl.forEach(function(name) {
baseCtrlNames.push(name.split(",")[0])
})
fntData["control_name"] = baseCtrlNames
// generic: expand baseSize
//'ui-monospace','ui-rounded','ui-serif','math','emoji','none' // redundant
baseSize = baseSize.concat(['cursive','fantasy','fangsong','system-ui'])
baseSize = baseSize.concat(isSystemFont)
if (isPlatformFont !== undefined) {baseSize.push(isPlatformFont)}
fntData["generic"] = baseSize.sort()
// lists
if (os !== undefined) {
let fntFake = "--00"+ rnd_string()
let array = []
if (os == "android") {
// android
// build notos
fntMaster.android.notoboth.forEach(function(fnt) {array.push("Noto Sans "+ fnt, "Noto Serif "+ fnt)})
fntMaster.android.notosans.forEach(function(fnt) {array.push("Noto Sans "+ fnt)})
fntMaster.android.notoserif.forEach(function(fnt) {array.push("Noto Serif "+ fnt)})
// add extras
array = array.concat(fntMaster["system"][os])
fntData["full"] = array
fntData["full"].push(fntFake)
} else if (isTB) {
// desktop TB
let aBundled = []
fntMaster.bundled.notoboth.forEach(function(fnt) {aBundled.push("Noto Sans "+ fnt, "Noto Serif "+ fnt)})
fntMaster.bundled.notosans.forEach(function(fnt) {aBundled.push("Noto Sans "+ fnt)})
fntMaster.bundled.notoserif.forEach(function(fnt) {aBundled.push("Noto Serif "+ fnt)})
aBundled = aBundled.concat(fntMaster["bundled"][os])
array = array.concat(aBundled)
fntData["bundled"] = array
fntData["system"] = fntMaster["allowlist"][os]
array = array.concat(fntMaster["allowlist"][os])
fntData["base"] = array
fntMaster["blocklist"][os].push(fntFake)
fntData["unexpected"] = fntMaster["blocklist"][os]
array = array.concat(fntMaster["blocklist"][os])
fntData["full"] = array
} else {
// desktop FF
array = fntMaster["base"][os]
fntData["base"] = array
array = array.concat(fntMaster["system"][os])
fntData["full"] = array
fntData["full"].push(fntFake)
}
// -control from lists
if (isPlatformFont !== undefined) {
let fntKeys = ["base","full","system","bundled"]
fntKeys.forEach(function(key) {
if (fntData[key] !== undefined) {
let array = fntData[key]
fntData[key] = array.filter(x => ![isPlatformFont].includes(x))
}
})
}
// dupes
let aCheck = fntData["full"]
aCheck = aCheck.filter(function(item, position) {return aCheck.indexOf(item) === position})
if (aCheck.length !== fntData["full"].length) {
log_alert(SECT12, "dupes in "+ os +" font list")
fntData["full"] = aCheck
}
// sort
fntData["bundled"].sort()
fntData["system"].sort()
fntData["unexpected"].sort()
fntData["base"].sort()
fntData["full"].sort()
// fntBtns
let str = "fonts_"+ os, fntBtnBundled, fntBtnSystem, fntBtnBase, fntBtnUnexpected, fntBtnAll
fntBtnBundled = addButton(12, str +"_bundled", fntData["bundled"].length, "btnc", "lists")
fntBtnSystem = addButton(12, str +"_system", fntData["system"].length, "btnc", "lists")
fntBtnUnexpected = addButton(12, str +"_unexpected", fntData["unexpected"].length, "btnc", "lists")
fntBtnBase = addButton(12, str +"_"+ fntListBaseName, fntData["base"].length, "btnc", "lists")
fntBtnAll = addButton(12, str, fntData["full"].length, "btnc", "lists")
// fntBtn
if (os == "android") {
fntBtn = fntBtnAll
} else if (isTB) {
if (os == "linux") {
fntBtn = fntBtnBundled +" + "+ fntBtnUnexpected +" = "+ fntBtnAll
} else {
fntBtn = fntBtnSystem +" + "+ fntBtnBundled +" = "+ fntBtnBase +" + "+ fntBtnUnexpected + " = "+ fntBtnAll
}
} else {
fntBtn = (os !== "linux" ? fntBtnBase : "") + fntBtnAll
}
}
}
// bail
if (os === undefined) {return}
// fnt*Btn data
if (gRun || build) {
let str = "fonts_"+ os
addDetail(str +"_system", fntData["system"], "lists")
addDetail(str +"_bundled", fntData["bundled"], "lists")
addDetail(str +"_"+ fntListBaseName, fntData["base"], "lists")
addDetail(str +"_unexpected", fntData["unexpected"], "lists")
addDetail(str, fntData["full"], "lists")
}
}
const get_document_fonts = () => new Promise(resolve => {
fntDocEnabled = false // reset global
const METRIC = "document_fonts", fntTest = "\"Arial Black\""
let res, fpvalue
try {
if (runSE) {foo++}
let font = getComputedStyle(dom.divDocFont).getPropertyValue("font-family")
fntDocEnabled = (font == fntTest ? true : false)
if (!fntDocEnabled) {
if (font.slice(0,11) == "Arial Black") {fntDocEnabled = true} // ext may strip quotes marks
}
res = (fntDocEnabled ? zE : zD) + " | " + font
fpvalue = res
} catch(e) {
res = log_error(SECT12, METRIC, e)
fpvalue = zErr
}
log_display(12, METRIC, res)
return resolve([METRIC, fpvalue])
})
const get_font_sizes = (isMain = true) => new Promise(resolve => {
/* https://github.com/abrahamjuliot/creepjs */
try {
fntBases = {} // reset
if (runSE) {foo++}
const doc = document // or iframe.contentWindow.document
const id = `font-fingerprint`
const div = doc.createElement('div')
div.setAttribute('id', id)
doc.body.appendChild(div)
doc.getElementById(id).innerHTML = `
<style>
#${id}-detector {
--font: '';
position: absolute !important;
left: -9999px!important;
font-size: ` + fntSize + ` !important;
font-style: normal !important;
font-weight: normal !important;
font-stretch: normal !important;
letter-spacing: normal !important;
line-break: auto !important;
line-height: normal !important;
text-transform: none !important;
text-align: left !important;
text-decoration: none !important;
text-shadow: none !important;
white-space: normal !important;
word-break: normal !important;
word-spacing: normal !important;
/* in order to test scrollWidth, clientWidth, etc. */
padding: 0 !important;
margin: 0 !important;
/* in order to test inlineSize and blockSize */
writing-mode: horizontal-tb !important;
/* for transform and perspective */
transform-origin: unset !important;
perspective-origin: unset !important;
}
#${id}-detector::after {
font-family: var(--font);
content: '`+ fntString +`';
}
</style>
<span id="${id}-detector"></span>`
const span = doc.getElementById(`${id}-detector`)
const pixelsToInt = pixels => Math.round(+pixels.replace('px',''))
const pixelsToNumber = pixels => +pixels.replace('px','')
const originPixelsToInt = pixels => Math.round(2*pixels.replace('px', ''))
const originPixelsToNumber = pixels => 2*pixels.replace('px', '')
const detectedViaPixel = new Set()
const detectedViaPixelNumber = new Set()
const detectedViaPixelSize = new Set()
const detectedViaPixelSizeNumber = new Set()
const detectedViaScroll = new Set()
const detectedViaOffset = new Set()
const detectedViaClient = new Set()
const detectedViaTransform = new Set()
const detectedViaTransformNumber = new Set()
const detectedViaPerspective = new Set()
const detectedViaPerspectiveNumber = new Set()
const detectedViaDomRectBounding = new Set()
const detectedViaDomRectBoundingRange = new Set()
const detectedViaDomRectClient = new Set()
const detectedViaDomRectClientRange = new Set()
const style = getComputedStyle(span)
const range = document.createRange()
range.selectNode(span)
let getDimensions = (span, style) => {
const transform = style.transformOrigin.split(' ')
const perspective = style.perspectiveOrigin.split(' ')
const dimensions = {
// keep in sorted order for base objects
// + Math.floor(Math.random() * 10), //
clientHeight: span.clientHeight,
clientWidth: span.clientWidth,
domrectboundingHeight: span.getBoundingClientRect().height,
domrectboundingWidth: span.getBoundingClientRect().width,
domrectboundingrangeHeight: range.getBoundingClientRect().height,
domrectboundingrangeWidth: range.getBoundingClientRect().width,
domrectclientHeight: span.getClientRects()[0].height,
domrectclientWidth: span.getClientRects()[0].width,
domrectclientrangeHeight: range.getClientRects()[0].height,
domrectclientrangeWidth: range.getClientRects()[0].width,
nperspectiveHeight: originPixelsToNumber(perspective[1]),
nperspectiveWidth: originPixelsToNumber(perspective[0]),
npixelHeight: pixelsToNumber(style.height),
npixelWidth: pixelsToNumber(style.width),
npixelsizeHeight: pixelsToNumber(style.blockSize),
npixelsizeWidth: pixelsToNumber(style.inlineSize),
ntransformHeight: originPixelsToNumber(transform[1]),
ntransformWidth: originPixelsToNumber(transform[0]),
offsetHeight: span.offsetHeight,
offsetWidth: span.offsetWidth,
perspectiveHeight: originPixelsToInt(perspective[1]),
perspectiveWidth: originPixelsToInt(perspective[0]),
pixelHeight: pixelsToInt(style.height),
pixelWidth: pixelsToInt(style.width),
pixelsizeHeight: pixelsToInt(style.blockSize),
pixelsizeWidth: pixelsToInt(style.inlineSize),
scrollHeight: span.scrollHeight,
scrollWidth: span.scrollWidth,
transformHeight: originPixelsToInt(transform[1]),
transformWidth: originPixelsToInt(transform[0]),
}
return dimensions
}
if (runST) {
getDimensions = (span, style) => {
const transform = style.transformOrigin.split(' ')
const perspective = style.perspectiveOrigin.split(' ')
const dimensions = {
clientHeight: NaN,
clientWidth: NaN,
domrectboundingHeight: '',
domrectboundingWidth: ' ',
domrectboundingrangeHeight: 0, // zero detected
domrectboundingrangeWidth: 0,
domrectclientHeight: [1],
domrectclientWidth: [],
domrectclientrangeHeight: range.getClientRects()[0].height, // so we fiddle with isDomRect
domrectclientrangeWidth: range.getClientRects()[0].width,
nperspectiveHeight: '1',
nperspectiveWidth: [1],
npixelHeight: {},
npixelWidth: {1:1},
npixelsizeHeight: pixelsToNumber(style.blockSize), // 1 size: we set this later
npixelsizeWidth: pixelsToNumber(style.inlineSize),
ntransformHeight: true,
ntransformWidth: null,
offsetHeight: span.offsetHeight, // a real one
offsetWidth: span.offsetWidth,
perspectiveHeight: undefined,
perspectiveWidth: Infinity,
pixelHeight: true,
pixelWidth: null,
pixelsizeHeight: 100, // none: everything matches
pixelsizeWidth: 100,
scrollHeight: span.scrollHeight, // all: we set this later
scrollWidth: span.scrollWidth,
transformHeight: undefined,
transformWidth: -Infinity,
}
return dimensions
}
}
let fntGeneric = [], fntTest = [], fntControl = []
let aTests = [], aTestsValid = [], aRemove = []
if (isMain) {
fntControl = fntData["control"]
fntGeneric = fntData["generic"]
fntTest = fntData["full"]
aTests = [
["client", detectedViaClient],
["domrectbounding", detectedViaDomRectBounding],
["domrectboundingrange", detectedViaDomRectBoundingRange],
["domrectclient", detectedViaDomRectClient],
["domrectclientrange", detectedViaDomRectClientRange],
["offset", detectedViaOffset],
["npixel", detectedViaPixelNumber],
["npixelsize", detectedViaPixelSizeNumber],
["nperspective", detectedViaPerspectiveNumber],
["ntransform", detectedViaTransformNumber],
["pixel", detectedViaPixel],
["pixelsize", detectedViaPixelSize],
["perspective", detectedViaPerspective],
["scroll", detectedViaScroll],
["transform", detectedViaTransform],
]
} else {
fntControl = ['monospace, Consolas, Menlo, "Courier New\"','sans-serif, Arial','serif, "Times New Roman\"']
fntGeneric = fntControl
fntTest = ["--00"+ rnd_string()]
fntTest = fntTest.concat(fntMaster["mini"])
aTests = [
["nperspective", detectedViaPerspectiveNumber],
]
}
// base sizes
let base = fntGeneric.reduce((acc, font) => {
if (isSystemFont.includes(font)) { // not a family
span.style.setProperty('--font', "")
span.style.font = font
} else {
span.style.font = ""
span.style.setProperty('--font', font)
}
const dimensions = getDimensions(span, style)
acc[font.split(",")[0]] = dimensions // use only first name, i.e w/o fallback
return acc
}, {})
span.style.font = "" // reset
// copy base into new object, regroup by hashs
let baseObj = {}, oTempBase = {}
if (isMain) {
for (const k of Object.keys(base)) {
baseObj[k] = {}
for (const j of Object.keys(base[k])) {baseObj[k][j] = base[k][j]}
}
for (const k of Object.keys(baseObj)) {
let tmpHash = mini(baseObj[k])
if (oTempBase[tmpHash] == undefined) {
oTempBase[tmpHash] = {"bases": [k], "metrics": baseObj[k]}
} else {
oTempBase[tmpHash]["bases"].push(k)
}
}
}
//console.log(base)
//console.log(oTempBase)
// test validity
let baseStyle = "monospace" // we need a base style: we'll always have monospace
aTests.forEach(function(pair) {
let wName = pair[0] +"Width", hName = pair[0] +"Height"
let wValue = base[baseStyle][wName], hValue = base[baseStyle][hName]
let wType = typeFn(wValue)
let hType = typeFn(hValue)
if ("number" == wType && "number" == hType) {
if (wValue < 1 || hValue < 1) {
pair[1].clear()
pair[1].add("invalid size")
aRemove.push(wName, hName)
} else {
aTestsValid.push(pair)
}
} else {
pair[1].clear()
pair[1].add("mismatch:"+ zErrType + (wType == hType ? wType : wType +" x "+ hType ))
aRemove.push(wName, hName)
}
})
if (isMain) {
// expand removals, take out the garbage + stash in fntBases
if (aDomRect[0] == false) {aRemove.push('domrectboundingHeight','domrectboundingWidth')}
if (aDomRect[1] == false) {aRemove.push('domrectclientHeight','domrectclientWidth')}
if (aDomRect[2] == false) {aRemove.push('domrectboundingrangeHeight','domrectboundingrangeWidth')}
if (aDomRect[3] == false) {aRemove.push('domrectclientrangeHeight','domrectclientrangeWidth')}
aRemove = aRemove.filter(function(item, position) {return aRemove.indexOf(item) === position})
aRemove.forEach(function(m) {
for (const k of Object.keys(oTempBase)) {delete oTempBase[k]["metrics"][m]}
})
fntBases = oTempBase
// return if not doing font sizes
if (!fntTest.length || fntDocEnabled == false) {
return resolve("baseonly")
}
}
// measure
//let counter = 0
if (aTestsValid.length) {
let isDetected = false, intDetected = 0, intDetectedMax = aTestsValid.length
fntTest.forEach(font => {
isDetected = false // have we found it
intDetected = 0 // in all valid methods
fntControl.forEach(basefont => {
if (isDetected) {return}
//counter++
intDetected = 0 // reset per control
const family = "'"+ font +"', "+ basefont
span.style.setProperty('--font', family)
const style = getComputedStyle(span)
const dimensions = getDimensions(span, style)
basefont = basefont.split(",")[0] // switch to short generic name
aTestsValid.forEach(function(pair) {
let wName = pair[0] +"Width", hName = pair[0] +"Height"
if (dimensions[wName] != base[basefont][wName] || dimensions[hName] != base[basefont][hName]) {
pair[1].add(font +":"+ basefont +":"+ dimensions[wName] +" x "+ dimensions[hName])
intDetected++
}
})
if (intDetected == intDetectedMax && !isFontSizesMore) {isDetected = true}
//isDetected = false // force max passes per font
return
})
})
}
//console.log(counter)
// tidy lies: none/all in Sets
if (isMain) {
aTests.forEach(function(pair) {
if (pair[1].size == 0) {
pair[1].clear()
pair[1].add("none")
} else if (pair[1].size == fntData["full"].length) {
pair[1].clear()
pair[1].add("all") // includes fake font
}
})
}
const fontsScroll = [...detectedViaScroll]
const fontsOffset = [...detectedViaOffset]
const fontsClient = [...detectedViaClient]
const fontsPixel = [...detectedViaPixel]
const fontsPixelSize = [...detectedViaPixelSize]
const fontsPerspective = [...detectedViaPerspective]
const fontsTransform = [...detectedViaTransform]
const fontsPixelNumber = [...detectedViaPixelNumber]
const fontsPixelSizeNumber = [...detectedViaPixelSizeNumber]
const fontsPerspectiveNumber = [...detectedViaPerspectiveNumber]
const fontsTransformNumber = [...detectedViaTransformNumber]
const fontsDomRectBounding = [...detectedViaDomRectBounding]
const fontsDomRectBoundingRange = [...detectedViaDomRectBoundingRange]
const fontsDomRectClient = [...detectedViaDomRectClient]
const fontsDomRectClientRange = [...detectedViaDomRectClientRange]
if (isMain) {
return resolve({
// match display order so we output detail links for the first of each hash
fontsClient,
fontsOffset,
fontsPerspective,
fontsPixel,
fontsPixelSize,
fontsScroll,
fontsTransform,
fontsPixelNumber,
fontsPixelSizeNumber,
fontsPerspectiveNumber,
fontsTransformNumber,
fontsDomRectBounding,
fontsDomRectBoundingRange,
fontsDomRectClient,
fontsDomRectClientRange,
})
} else {
return resolve({fontsPerspectiveNumber})
}
} catch(e) {
log_error(SECT12, "fontsizes", e)
return resolve(zErr)
}
})
const get_fonts = () => new Promise(resolve => {
let t0 = nowFn()
const METRIC = "fontsizes"
const METRICG = METRIC +"_groups"
const METRICB = METRIC +"_base"
const METRICN = "fontnames"
let badnotation = (isSmart ? (isTB ? tb_red : rfp_red) : "")
let goodnotation = (isSmart ? (isTB ? tb_green : rfp_green) : "")
let aRemove = []
// functions
function exit(value) {
addDataDisplay(12, METRIC, value)
addData(12, METRICN, value)
log_display(12, METRICN, value + badnotation)
addData(12, METRICG, value)
log_display(12, METRICG, value + badnotation)
if (value == zNA) {
let baseReturn = get_baseHash()
} else {
log_display(12, METRICB, value)
addData(12, METRICB, value)
}
log_perf(SECT12, METRIC, t0)
return resolve()
}
function get_baseHash() {
let display = "", baseBtn = ""
try {
let bType = typeFn(fntBases)