-
Notifications
You must be signed in to change notification settings - Fork 169
/
makeotfexe_test.py
776 lines (682 loc) · 31.7 KB
/
makeotfexe_test.py
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
import glob
import os
import pytest
import subprocess
from runner import main as runner
from differ import main as differ, SPLIT_MARKER
from test_utils import (get_input_path, get_expected_path, get_temp_file_path,
generate_ttx_dump, generate_spot_dumptables)
TOOL = 'makeotfexe'
CMD = ['-t', TOOL]
# -----
# Tests
# -----
def test_exit_no_option():
# It's valid to run 'makeotfexe' without using any options,
# but if a default-named font file ('font.ps') is NOT found
# in the current directory, the tool exits with an error
with pytest.raises(subprocess.CalledProcessError) as err:
subprocess.check_call([TOOL])
assert err.value.returncode == 1
@pytest.mark.parametrize('arg', ['-h', '-u'])
def test_exit_known_option(arg):
assert subprocess.call([TOOL, arg]) == 0
@pytest.mark.parametrize('arg', ['-j', '--bogus'])
def test_exit_unknown_option(arg):
assert subprocess.call([TOOL, arg]) == 1
@pytest.mark.parametrize('args, ttx_fname', [
([], 'font_dev'),
(['r'], 'font_rel'),
])
def test_build_font_and_check_messages(args, ttx_fname):
actual_path = get_temp_file_path()
expected_msg_path = get_expected_path(f'{ttx_fname}_output.txt')
ttx_filename = f'{ttx_fname}.ttx'
stderr_path = runner(CMD + [
'-s', '-e', '-o', 'f', f'_{get_input_path("font.pfa")}',
'o', f'_{actual_path}'] + args)
actual_ttx = generate_ttx_dump(actual_path)
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value=',
'-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
assert differ([expected_msg_path, stderr_path])
@pytest.mark.parametrize('caret_format', [
'bypos', 'byindex', 'mixed', 'mixed2', 'double', 'double2'])
def test_GDEF_LigatureCaret_bug155(caret_format):
input_filename = 'bug155/font.pfa'
feat_filename = f'bug155/caret-{caret_format}.fea'
ttx_filename = f'bug155/caret-{caret_format}.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GDEF'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-l', '2'])
def test_useMarkFilteringSet_flag_bug196():
input_filename = "bug196/font.pfa"
feat_filename = "bug196/feat.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug196.ttx"
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GSUB'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_useException_bug321():
input_filename = "bug321/font.pfa"
feat_filename = "bug321/feat.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug321.ttx"
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GSUB', 'GPOS'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_mark_refer_diff_classes_bug416():
input_filename = "bug416/font.pfa"
feat_filename = "bug416/feat.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug416.ttx"
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GPOS'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_DFLT_script_with_any_lang_bug438():
""" The feature file bug438/feat.fea contains languagesystem
statements for a language other than 'dflt' with the 'DFLT' script
tag. With the fix, makeotfexe will build an OTF which is identical to
'bug438.ttx'. Without the fix, it will fail to build an OTF."""
input_filename = 'bug438/font.pfa'
feat_filename = 'bug438/feat.fea'
ttx_filename = 'bug438.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path)
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value=',
'-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
def test_glyph_not_in_font_bug492():
input_filename = 'bug492/font.pfa'
feat_filename = 'bug492/features.fea'
otf_path = get_temp_file_path()
stderr_path = runner(
CMD + ['-s', '-e', '-o',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b'Glyph "glyph_not_found" not in font.') in output
assert (b'syntax error at "a" [') not in output
def test_version_warning_bug610():
input_filename = 'bug610/font.pfa'
feat_filename = 'bug610/v0005.fea'
otf_path = get_temp_file_path()
stderr_path = runner(
CMD + ['-s', '-e', '-o',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b"[WARNING] <SourceSans-Test> Major version number not in "
b"range 1 .. 255") not in output
@pytest.mark.parametrize('feat_name, error_msg', [
('test_named_lookup',
b"In feature 'last' positioning rules "
b"cause an offset overflow (0x10020) to a lookup subtable"),
('test_singlepos_subtable_overflow',
b"In feature 'sps1' lookup 'lkup40' "
b"positioning rules cause an offset overflow (0x10188) to a "
b"lookup subtable"),
('test_class_pair_subtable_overflow',
b"In feature 'last' positioning rules "
b"cause an offset overflow (0x10020) to a lookup subtable"),
('test_class_pair_class_def_overflow',
b"In feature 'krn1' lookup 'l1' pair "
b"positioning rules cause an offset overflow (0x1001a) to a "
b"class 2 definition table"),
('test_contextual_overflow',
b"In feature 'krn0' lookup 'lkup40' "
b"chain contextual positioning rules cause an offset overflow "
b"(0x10002) to a lookup subtable"),
('test_cursive_subtable_overflow',
b"In feature 'curs' lookup 'lk20' "
b"cursive positioning rules cause an offset overflow "
b"(0x1006e) to a cursive attach table"),
('test_mark_to_base_coverage_overflow',
b"In feature 'mrk1' mark to base "
b"positioning rules cause an offset overflow (0x1002c) to a "
b"base coverage table"),
('test_mark_to_base_subtable_overflow',
b"In feature 'mrk1' mark to base "
b"positioning rules cause an offset overflow (0x10230) to a "
b"lookup subtable"),
('test_mark_to_ligature_subtable_overflow',
b"In feature 'lig1' lookup 'lk0' mark "
b"to ligature positioning rules cause an offset overflow (0x1053e) "
b"to a lookup subtable"),
('test_singlesub1_subtable_overflow',
b"In feature 'tss2' lookup 'lkup258' "
b"substitution rules cause an offset overflow (0x10002) to a "
b"lookup subtable"),
('test_singlesub2_subtable_overflow',
b"In feature 'tss1' lookup 'lkup237' "
b"substitution rules cause an offset overflow (0x10098) to a "
b"lookup subtable"),
('test_multiplesub_subtable_overflow',
b"In feature 'mts1' lookup 'lkup238' "
b"substitution rules cause an offset overflow (0x10056) to a "
b"lookup subtable"),
('test_alternatesub_subtable_overflow',
b"In feature 'ats1' lookup 'lkup238' "
b"substitution rules cause an offset overflow (0x1009c) to a "
b"lookup subtable"),
('test_ligaturesub_subtable_overflow',
b"In feature 'lts1' lookup 'lkup238' "
b"substitution rules cause an offset overflow (0x10016) to a "
b"lookup subtable"),
('test_chaincontextualsub_subtable_overflow',
b"In feature 'cts1' substitution rules "
b"cause an offset overflow (0x100ac) to a lookup subtable"),
('test_reversechaincontextualsub_subtable_overflow',
b"In feature 'rts1' lookup 'lkup238' "
b"reverse chain contextual substitution rules cause an offset "
b"overflow (0x100a0) to a lookup subtable"),
('test_duplicate_single_sub',
b"Removing duplicate single substitution "
b"in standalone lookup 'test2': glyph1, glyph1"),
('test_conflicting_single_sub',
b"Duplicate target glyph for single "
b"substitution in standalone lookup 'test2': glyph1"),
('test_duplicate_alternate_sub',
b"Duplicate target glyph for alternate "
b"substitution in standalone lookup 'test2': glyph1"),
('test_duplicate_multiple_sub',
b"Duplicate target glyph for multiple "
b"substitution in standalone lookup 'test2': glyph1"),
('test_duplicate_ligature_sub',
b"Removing duplicate ligature substitution "
b"in standalone lookup 'test2'"),
('test_conflicting_ligature_sub',
b"Duplicate target sequence but different "
b"replacement glyphs in ligature substitutions in standalone "
b"lookup 'test2'"),
('test_duplicate_single_pos',
b"Removing duplicate single positioning "
b"in standalone lookup 'test2'"),
('test_conflicting_single_pos',
b"Duplicate single positioning glyph "
b"with different values in standalone lookup 'test2'"),
('test_features_name_missing_win_dflt_sub',
b"Missing Windows default name for "
b"'featureNames' nameid 256 in feature 'ss01'"),
('test_cv_params_not_in_cvxx_sub',
b"A 'cvParameters' block is only allowed "
b"in Character Variant (cvXX) features; it is being used in "
b"feature 'tst1'"),
('test_cv_params_missing_win_dflt_sub',
b"Missing Windows default name for "
b"'cvParameters' nameid 256 in feature 'cv01'"),
('test_size_withfamilyID_0_pos',
b"'size' feature must have 4 parameters if "
b"sub family ID code is non-zero!"),
('test_size_withfamilyID_3_pos',
b"'size' feature must have 4 or 2 "
b"parameters if sub family code is zero!"),
('test_sizemenuname_missing_win_dflt_pos',
b"Missing Windows default name for "
b"'sizemenuname' nameid 256 in 'size' feature"),
('test_kernpair_warnings_pos',
b"Single kern pair occurring after class "
b"kern pair in feature 'tst1'"),
('test_kernpair_warnings_pos',
b"Start of new pair positioning subtable "
b"forced by overlapping glyph classes in feature 'tst1'; some pairs "
b"may never be accessed"),
('test_kernpair_warnings_pos',
b"Removing duplicate pair positioning in "
b"feature 'tst1': glyph3 glyph3"),
('test_kernpair_warnings_pos',
b"Pair positioning has conflicting "
b"statements in feature 'tst1'"),
('test_base_glyph_conflict_pos',
b"MarkToBase or MarkToMark error in "
b"feature 'tst1'. Another statement has already defined the anchors "
b"and marks on glyph 'glyph5'."),
('test_base_glyph_conflict_pos',
b"MarkToBase or MarkToMark error in "
b"feature 'tst1'. Glyph 'glyph5' does not have an anchor point "
b"for a mark class that was used in a previous statement in the "
b"same lookup table. Setting the anchor point offset to 0."),
('test_mark_ligature_conflict_pos',
b"MarkToLigature error in feature 'tst1'. "
b"Two different statements referencing the ligature glyph 'glyph6' "
b"have assigned the same mark class to the same ligature component."),
('test_mark_ligature_conflict_pos',
b"MarkToLigature statement error in feature "
b"'tst1'. Glyph 'glyph6' contains a duplicate mark class assignment "
b"for one of the ligature components."),
('test_mark_class_glyph_conflict',
b"In feature 'tst1', glyph 'glyph2' "
b"is repeated in the current class definition. Mark class: "
b"@TOP_MARKS."),
('test_mark_class_glyph_conflict',
b"In feature 'tst1', glyph 'glyph1' "
b"occurs in two different mark classes. Previous mark class: "
b"@TOP_MARKS. Current mark class: @BOTTOM_MARKS."),
('test_base_anchor_errors_pos',
b"MarkToBase or MarkToMark error in "
b"feature 'tst1'. Another statement has already assigned the current "
b"mark class to another anchor point on glyph 'glyph7'"),
('test_base_anchor_errors_pos',
b"MarkToBase or MarkToMark error in "
b"feature 'tst1'. Glyph 'glyph5' does not have an anchor point "
b"for a mark class that was used in a previous statement in the "
b"same lookup table"),
('test_cursive_duplicate_glyph_pos',
b"Cursive statement error in feature "
b"'tst1'. A previous statement has already referenced glyph "
b"'glyph1'."),
])
def test_overflow_report_bug313(feat_name, error_msg):
input_filename = 'bug313/font.pfa'
feat_filename = f'bug313/{feat_name}.fea'
otf_path = get_temp_file_path()
stderr_path = runner(
CMD + ['-s', '-e', '-o', 'shw',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
with open(stderr_path, 'rb') as f:
output = f.read()
assert error_msg in output
def test_feature_recursion_bug628():
input_filename = 'bug628/font.pfa'
feat_filename = 'bug628/feat.fea'
otf_path = get_temp_file_path()
stderr_path = runner(
CMD + ['-s', '-e', '-o', 'shw',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b"Can't include [feat.fea]; maximum "
b"include levels <50> reached") in output
@pytest.mark.parametrize('arg', [[], ['gs']])
def test_recalculate_bbox_bug617(arg):
input_filename = "bug617/font.pfa"
goadb_filename = "bug617/goadb.txt"
ttx_filename = f"bug617/{'no_' if not arg else ''}gs_opt.ttx"
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'gf', f'_{get_input_path(goadb_filename)}',
'o', f'_{actual_path}', 'r'] + arg)
actual_ttx = generate_ttx_dump(actual_path, ['head', 'CFF '])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value='])
def test_contextual_multiple_substitutions_bug725():
input_filename = "bug725/font.pfa"
feat_filename = "bug725/feat.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug725.ttx"
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GSUB'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_notdef_in_glyph_class_bug726():
input_filename = "bug726/font.pfa"
feat_filename = "bug726/feat.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug726.ttx"
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GDEF'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_overflow_bug731():
input_filename = 'bug731/font.pfa'
feat_filename = 'bug731/feat.fea'
otf_path = get_temp_file_path()
stderr_path = runner(
CMD + ['-s', '-e', '-o', 'shw',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b"subtable offset too large (1003c) in "
b"lookup 0 type 3") in output
def test_base_anchor_bug811():
input_filename = 'bug811/font.pfa'
feat_filename = 'bug811/feat.fea'
ttx_filename = 'bug811.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GPOS'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion'])
def test_max_revision_bug876():
input_filename = 'bug876/font.pfa'
feat_filename = 'bug876/feat.fea'
ttx_filename = 'bug876.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['head'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value='])
def test_infinite_loop_with_dflt_lookups_bug965():
input_filename = 'bug965/font.pfa'
feat_filename = 'bug965/feat.fea'
ttx_filename = 'bug965.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GSUB'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value='])
def test_bug993():
input_filename = 'fealib/font.pfa'
feat_filename = 'bug993/feat.fea'
ttx_filename = 'bug993.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GPOS'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value='])
def test_bug1006():
input_filename = 'fealib/font.pfa'
feat_filename = 'bug1006/feat.fea'
ttx_filename = 'bug1006.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['GPOS'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value='])
@pytest.mark.parametrize(
'cmap_filename, cs, expectedOS2',
[('UniCN-UTF32-H', '25', 'expected_OS2_SC.ttx'),
('UniJP-UTF32-H', '1', 'expected_OS2_JP.ttx'),
('UniKR-UTF32-H', '3', 'expected_OS2_KR.ttx'),
('UniTW-UTF32-H', '2', 'expected_OS2_TC.ttx')])
def test_bug1040(cmap_filename, cs, expectedOS2):
out_path = get_temp_file_path()
cmd = CMD + ['-o', 'f', f'_{get_input_path("bug1040/cidfont.ps")}',
'cs', f'_{cs}',
'o', f'_{out_path}',
'ch', f'_{get_input_path("bug1040/" + cmap_filename)}']
runner(cmd)
actual_ttx = generate_ttx_dump(out_path, ["OS/2"])
expected_ttx = get_expected_path("bug1040/" + expectedOS2)
assert differ([expected_ttx, actual_ttx, '-l', '2'])
def test_parameter_offset_overflow_bug1017():
# Since the fix for issue 1017, it is not practical to actually cause
# this overflow, which used to be tested as bug746. What we do
# instead is to verify that the FeatParams blocks are written right
# after the FeatureList, and before the LookupList, by comparing with
# the expected low level spot GSUB dump.
input_filename = 'bug1017/font.pfa'
feat_filename = 'bug1017/feat.fea'
txt_filename = 'bug1017.GSUB.txt'
otf_path = get_temp_file_path()
runner(
CMD + ['-s', '-e', '-o', 'shw',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{otf_path}'])
actual_txt = generate_spot_dumptables(otf_path, ['GSUB'])
expected_txt = get_expected_path(txt_filename)
assert differ([expected_txt, actual_txt])
def test_bug1178():
input_filename = 'fealib/font.pfa'
feat_filename = 'fealib/bug1178.fea'
ttx_filename = 'fealib/bug1178.ttx'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['name', 'STAT'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx,
'-s',
'<ttFont sfntVersion' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value=',
'-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
TEST_FEATURE_FILES = [
"Attach", "enum", "markClass", "language_required", "GlyphClassDef",
"LigatureCaretByIndex", "LigatureCaretByPos", "lookup", "lookupflag",
"feature_aalt", "ignore_pos", "GPOS_1", "GPOS_1_zero", "GPOS_2", "GPOS_2b",
"GPOS_3", "GPOS_4", "GPOS_5", "GPOS_6", "GPOS_8", "GSUB_2", "GSUB_3",
"GSUB_6", "GSUB_8", "spec4h1", "spec4h2", "spec5d1", "spec5d2", "spec5fi1",
"spec5fi2", "spec5fi3", "spec5fi4", "spec5f_ii_1", "spec5f_ii_2",
"spec5f_ii_3", "spec5f_ii_4", "spec5h1", "spec6b_ii", "spec6d2", "spec6e",
"spec6f", "spec6h_ii", "spec6h_iii_1", "spec6h_iii_3d", "spec8a", "spec8b",
"spec8c", "spec8d", "spec9a", "spec9b", "spec9c1", "spec9c2", "spec9c3",
"spec9d", "spec9e", "spec9f", "spec9g", "spec10", "bug453", "bug457",
"bug463", "bug501", "bug502", "bug504", "bug505", "bug506", "bug509",
"bug512", "bug514", "bug568", "bug633", "bug1307", "bug1459", "name",
"size", "size2", "multiple_feature_blocks", "omitted_GlyphClassDef",
"ZeroValue_SinglePos_horizontal", "ZeroValue_SinglePos_vertical",
"ZeroValue_PairPos_horizontal", "ZeroValue_PairPos_vertical",
"ZeroValue_ChainSinglePos_horizontal", "ZeroValue_ChainSinglePos_vertical",
"PairPosSubtable", "MultipleLookupsPerGlyph", "MultipleLookupsPerGlyph2",
"name_after_STAT.bad", "incomplete_glyph_range.bad",
]
TEST_FEATURE_FILES_XFAIL = [
"GPOS_1", # <device>
"GSUB_6", # Contextual alternate rule not yet supported
"bug1459", # <NULL>
"language_required", # required
"PairPosSubtable", # https://github.com/adobe-type-tools/afdko/issues/971
"bug1307", # https://github.com/adobe-type-tools/afdko/issues/966
"name_after_STAT.bad",
"incomplete_glyph_range.bad",
]
TEST_FEATURE_FILES_TABLES = {
"name": ["name"],
"spec8b": ["name", "GPOS"],
"spec8c": ["name", "GSUB"],
"spec8d": ["name", "GSUB"],
"spec9c1": ["head"],
"spec9c2": ["head"],
"spec9c3": ["head"],
"spec9d": ["hhea"],
"spec9e": ["name"],
"spec9f": ["OS/2"],
"spec9g": ["vhea"],
}
TEST_TABLES = ['BASE', 'GDEF', 'GSUB', 'GPOS']
@pytest.mark.parametrize('name', TEST_FEATURE_FILES)
def test_feature_file(name):
try:
input_filename = "fealib/font.pfa"
feat_filename = f"fealib/{name}.fea"
ttx_filename = f"fealib/{name}.ttx"
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
tables = TEST_FEATURE_FILES_TABLES.get(name, TEST_TABLES)
actual_ttx = generate_ttx_dump(actual_path, tables)
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-l', '2',
'-s',
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value=',
'-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
except Exception:
if name in TEST_FEATURE_FILES_XFAIL:
pytest.xfail()
raise
@pytest.mark.parametrize('path', glob.glob(get_input_path("spec/*.fea")))
def test_spec(path):
name = os.path.splitext(os.path.basename(path))[0]
if ".cid" in name:
input_filename = "spec/fontcid.ps"
else:
input_filename = "spec/font.pfa"
feat_filename = f"spec/{name}.fea"
ttx_filename = f"spec/{name}.ttx"
cmap_filename = "spec/Identity-H"
actual_path = get_temp_file_path()
cmd = CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}',
'ch', f'_{get_input_path(cmap_filename)}']
if name.endswith(".bad"):
with pytest.raises(subprocess.CalledProcessError):
runner(cmd)
return
runner(cmd)
tables = TEST_TABLES
with open(get_input_path(feat_filename)) as fp:
line = fp.readline()
if line.startswith("#") and "TABLES" in line:
tables = line.split("# TABLES:")[1].strip().split(",")
actual_ttx = generate_ttx_dump(actual_path, tables)
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-l', '2',
'-s',
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <checkSumAdjustment value=' + SPLIT_MARKER +
' <created value=' + SPLIT_MARKER +
' <modified value=',
'-r', r'^\s+Version.*;hotconv.*;makeotfexe'])
def test_negative_internal_leading_bug1227():
input_filename = "font.pfa"
feat_filename = "bug1227/bug1227.fea"
actual_path = get_temp_file_path()
ttx_filename = "bug1227.ttx"
stderr_path = runner(
CMD + ['-s', '-e', '-o',
'f', f'_{get_input_path(input_filename)}',
'ff', f'_{get_input_path(feat_filename)}',
'o', f'_{actual_path}'])
actual_ttx = generate_ttx_dump(actual_path, ['OS/2'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion='])
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b'Negative internal leading: '
b'win.ascent + win.descent < unitsPerEm') in output
def test_goadb_multiple_unicodes_bug1273():
input_filename = "bug1273/font.pfa"
ttx_filename = "bug1273.ttx"
goadb_filename = 'bug1273/GlyphOrderAndAliasDB'
actual_path = get_temp_file_path()
runner(CMD + ['-o', 'f', f'_{get_input_path(input_filename)}',
'gf', f'_{get_input_path(goadb_filename)}',
'o', f'_{actual_path}', 'r'])
actual_ttx = generate_ttx_dump(actual_path, ['cmap'])
expected_ttx = get_expected_path(ttx_filename)
assert differ([expected_ttx, actual_ttx, '-s', '<ttFont sfntVersion='])
@pytest.mark.parametrize(
'goadb_filename, expected',
[('bug1310/longUVGOADB.txt', False),
('bug1310/longGnameGOADB.txt', True)])
def test_glyph_alias_name_limits(goadb_filename, expected):
"""
- 'longUVGOADB' has a 3rd column (UV names) with length > 63. This should
is expected to be allowed (up to MAX_UV_CHAR_NAME_LEN in cb.c)
- 'longGnameGOADB' has 2nd column (glyph name) with a length > 63. This
is expected to raise a warning.
"""
input_filename = "font.pfa"
actual_path = get_temp_file_path()
cmd = CMD + ['-s', '-e', '-o',
'r',
'f', f'_{get_input_path(input_filename)}',
'o', f'_{actual_path}',
'gf', f'_{get_input_path(goadb_filename)}']
stderr_path = runner(cmd)
with open(stderr_path, 'rb') as f:
output = f.read()
assert (b'(record skipped)(gnameError)' in output) is expected
def test_heap_after_free_bug1349():
"""
Heap used after free because of stale pointer
after realloc. This wiped out some values
in name table.
"""
folder = "bug1349/"
input_filename = get_input_path(folder + "cidfont.subset")
output_filename = get_temp_file_path()
features_filename = get_input_path(folder + "features.VF.HW.J")
db_filename = get_input_path(folder + "FontMenuNameDB.VF.Mono")
cmap_filename = get_input_path(folder + "UniSourceHanSansHWJP-UTF32-H")
lic_name = "ADOBE"
cmd = CMD + ['-o',
'f', f'_{input_filename}',
'o', f'_{output_filename}',
'shw', 'omitMacNames',
'ff', f'_{features_filename}',
'mf', f'_{db_filename}',
'r', 'nS', 'cs', '1',
'ch', f'_{cmap_filename}',
'lic', f'_{lic_name}']
runner(cmd)
output_dump = generate_ttx_dump(output_filename, ['name'])
assert differ([output_dump, get_expected_path("bug1349.ttx"),
'-s', '<ttFont sfntVersion='])