-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmarkFeatureWriter_test.py
2166 lines (1833 loc) · 74.1 KB
/
markFeatureWriter_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
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
import logging
import os
import re
from textwrap import dedent
import pytest
from ufo2ft.constants import OBJECT_LIBS_KEY
from ufo2ft.featureCompiler import FeatureCompiler, parseLayoutFeatures
from ufo2ft.featureWriters import ast
from ufo2ft.featureWriters.markFeatureWriter import (
MarkFeatureWriter,
NamedAnchor,
parseAnchorName,
)
from . import FeatureWriterTest
@pytest.fixture
def testufo(FontClass):
ufo = FontClass()
ufo.newGlyph("a").appendAnchor({"name": "top", "x": 100, "y": 200})
liga = ufo.newGlyph("f_i")
liga.appendAnchor({"name": "top_1", "x": 100, "y": 500})
liga.appendAnchor({"name": "top_2", "x": 600, "y": 500})
ufo.newGlyph("acutecomb").appendAnchor({"name": "_top", "x": 100, "y": 200})
accent = ufo.newGlyph("tildecomb")
accent.appendAnchor({"name": "_top", "x": 100, "y": 200})
accent.appendAnchor({"name": "top", "x": 100, "y": 300})
return ufo
@pytest.mark.parametrize(
"input_expected",
[
("top", (False, "top", None, False, False)),
("top_", (False, "top_", None, False, False)),
("top1", (False, "top1", None, False, False)),
("_bottom", (True, "bottom", None, False, False)),
("bottom_2", (False, "bottom", 2, False, False)),
("top_right_1", (False, "top_right", 1, False, False)),
],
)
def test_parseAnchorName(input_expected):
anchorName, (isMark, key, number, isContextual, isIgnorable) = input_expected
assert parseAnchorName(anchorName) == (
isMark,
key,
number,
isContextual,
isIgnorable,
)
def test_parseAnchorName_invalid():
with pytest.raises(ValueError, match="mark anchor cannot be numbered"):
parseAnchorName("_top_2")
with pytest.raises(ValueError, match="mark anchor key is nil"):
parseAnchorName("_")
def test_NamedAnchor_invalid():
with pytest.raises(ValueError, match="indexes must start from 1"):
NamedAnchor("top_0", 1, 2)
def test_NamedAnchor_repr():
expected = "NamedAnchor(name='top', x=1.0, y=2.0)"
assert repr(NamedAnchor("top", 1.0, 2.0)) == expected
class MarkFeatureWriterTest(FeatureWriterTest):
FeatureWriter = MarkFeatureWriter
def test__makeMarkClassDefinitions_empty(self, FontClass):
ufo = FontClass()
ufo.newGlyph("a").appendAnchor({"name": "top", "x": 250, "y": 500})
ufo.newGlyph("c").appendAnchor({"name": "bottom", "x": 250, "y": -100})
ufo.newGlyph("grave").appendAnchor({"name": "_top", "x": 100, "y": 200})
ufo.newGlyph("cedilla").appendAnchor({"name": "_bottom", "x": 100, "y": 0})
writer = MarkFeatureWriter()
feaFile = ast.FeatureFile()
writer.setContext(ufo, feaFile)
markClassDefs = writer._makeMarkClassDefinitions()
assert len(feaFile.markClasses) == 2
assert [str(mcd) for mcd in markClassDefs] == [
"markClass cedilla <anchor 100 0> @MC_bottom;",
"markClass grave <anchor 100 200> @MC_top;",
]
def test__makeMarkClassDefinitions_non_empty(self, FontClass):
ufo = FontClass()
ufo.newGlyph("a").appendAnchor({"name": "top", "x": 250, "y": 500})
ufo.newGlyph("c").appendAnchor({"name": "bottom", "x": 250, "y": -100})
ufo.newGlyph("grave").appendAnchor({"name": "_top", "x": 100, "y": 200})
ufo.newGlyph("cedilla").appendAnchor({"name": "_bottom", "x": 100, "y": 0})
ufo.features.text = dedent(
"""\
markClass cedilla <anchor 200 0> @MC_bottom;
markClass grave <anchor 100 200> @MC_top;
"""
)
writer = MarkFeatureWriter()
feaFile = parseLayoutFeatures(ufo)
writer.setContext(ufo, feaFile)
markClassDefs = writer._makeMarkClassDefinitions()
assert len(markClassDefs) == 1
assert len(feaFile.markClasses) == 3
assert "MC_bottom" in feaFile.markClasses
assert "MC_top" in feaFile.markClasses
assert [str(mcd) for mcd in markClassDefs] == [
"markClass cedilla <anchor 100 0> @MC_bottom_1;"
]
def test_skip_empty_feature(self, FontClass):
ufo = FontClass()
assert not self.writeFeatures(ufo)
ufo.newGlyph("a").appendAnchor({"name": "top", "x": 100, "y": 200})
ufo.newGlyph("acutecomb").appendAnchor({"name": "_top", "x": 100, "y": 200})
fea = str(self.writeFeatures(ufo))
assert "feature mark" in fea
assert "feature mkmk" not in fea
def test_skip_unnamed_anchors(self, FontClass, caplog):
caplog.set_level(logging.ERROR)
ufo = FontClass()
ufo.newGlyph("a").appendAnchor({"x": 100, "y": 200})
writer = MarkFeatureWriter()
feaFile = ast.FeatureFile()
logger = "ufo2ft.featureWriters.markFeatureWriter.MarkFeatureWriter"
with caplog.at_level(logging.WARNING, logger=logger):
writer.setContext(ufo, feaFile)
assert len(caplog.records) == 1
assert "unnamed anchor discarded in glyph 'a'" in caplog.text
def test_warn_duplicate_anchor_names(self, FontClass, caplog):
caplog.set_level(logging.ERROR)
ufo = FontClass()
ufo.newGlyph("a").anchors = [
{"name": "top", "x": 100, "y": 200},
{"name": "top", "x": 200, "y": 300},
]
writer = MarkFeatureWriter()
feaFile = ast.FeatureFile()
logger = "ufo2ft.featureWriters.markFeatureWriter.MarkFeatureWriter"
with caplog.at_level(logging.WARNING, logger=logger):
writer.setContext(ufo, feaFile)
assert len(caplog.records) == 1
assert "duplicate anchor 'top' in glyph 'a'" in caplog.text
def test_warn_liga_anchor_in_mark_glyph(self, testufo, caplog):
caplog.set_level(logging.ERROR)
testufo.newGlyph("ogonekcomb").anchors = [
{"name": "_top", "x": 200, "y": -40},
{"name": "top_1", "x": 200, "y": 450}, # should not be there!
]
logger = "ufo2ft.featureWriters.markFeatureWriter.MarkFeatureWriter"
with caplog.at_level(logging.WARNING, logger=logger):
_ = self.writeFeatures(testufo)
assert len(caplog.records) == 1
assert "invalid ligature anchor 'top_1' in mark glyph" in caplog.text
def test_ligature_NULL_anchor(self, testufo):
testufo.newGlyph("f_f_foo").anchors = [
{"name": "top_1", "x": 250, "y": 600},
{"name": "top_2", "x": 500, "y": 600},
{"name": "_3", "x": 0, "y": 0}, # this becomes <anchor NULL>
]
generated = self.writeFeatures(testufo)
assert re.search(r"ligComponent\s+<anchor NULL>", str(generated))
def test_skip_existing_feature(self, testufo):
testufo.features.text = dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
} mark;
"""
)
generated = self.writeFeatures(testufo)
# only mkmk is generated, mark was already present
assert str(generated) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_append_feature(self, testufo):
testufo.features.text = dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
} mark;
"""
)
generated = self.writeFeatures(testufo, mode="append")
assert str(generated) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_insert_comment_before(self, testufo):
writer = MarkFeatureWriter()
testufo.features.text = dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
#
# Automatic Code
#
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
} mark;
"""
)
feaFile = parseLayoutFeatures(testufo)
assert writer.write(testufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mark {
#
#
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
# test append mode ignores insert marker
generated = self.writeFeatures(testufo, mode="append")
assert str(generated) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_insert_comment_after(self, testufo):
writer = MarkFeatureWriter()
testufo.features.text = dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
#
# Automatic Code
#
} mark;
"""
)
feaFile = parseLayoutFeatures(testufo)
assert writer.write(testufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
#
#
} mark;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
# test append mode ignores insert marker
generated = self.writeFeatures(testufo, mode="append")
assert str(generated) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_insert_comment_middle(self, testufo):
writer = MarkFeatureWriter()
testufo.features.text = dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
#
# Automatic Code
#
lookup mark2 {
pos base a
<anchor 150 250> mark @MC_top;
} mark2;
} mark;
"""
)
feaFile = parseLayoutFeatures(testufo)
writer.write(testufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
#
} mark;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mark {
#
lookup mark2 {
pos base a
<anchor 150 250> mark @MC_top;
} mark2;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
# test append mode ignores insert marker
generated = self.writeFeatures(testufo, mode="append")
assert str(generated) == dedent(
"""\
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_insert_comment_outside_block(self, testufo):
writer = MarkFeatureWriter()
testufo.features.text = dedent(
"""\
#
# Automatic Code
#
"""
)
feaFile = parseLayoutFeatures(testufo)
assert writer.write(testufo, feaFile)
testufo.features.text = dedent(
"""\
#
# Automatic Code
#
markClass acutecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark1 {
pos base a
<anchor 100 200> mark @MC_top;
} mark1;
} mark;
"""
)
feaFile = parseLayoutFeatures(testufo)
assert writer.write(testufo, feaFile)
# test append mode
writer = MarkFeatureWriter(mode="append")
assert writer.write(testufo, feaFile)
def test_defs_and_lookups_first(self, testufo):
testufo.newGlyph("circumflexcomb")
writer = MarkFeatureWriter()
testufo.features.text = dedent(
"""\
feature mkmk {
# Automatic Code
# Move acutecomb down and right if preceded by circumflexcomb
lookup move_acutecomb {
lookupflag UseMarkFilteringSet [acutecomb circumflexcomb];
pos circumflexcomb acutecomb' <0 20 0 20>;
} move_acutecomb;
} mkmk;
"""
)
feaFile = parseLayoutFeatures(testufo)
assert writer.write(testufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
feature mkmk {
# Move acutecomb down and right if preceded by circumflexcomb
lookup move_acutecomb {
lookupflag UseMarkFilteringSet [acutecomb circumflexcomb];
pos circumflexcomb acutecomb' <0 20 0 20>;
} move_acutecomb;
} mkmk;
"""
)
def test_mark_mkmk_features(self, testufo):
writer = MarkFeatureWriter() # by default both mark + mkmk are built
feaFile = ast.FeatureFile()
assert writer.write(testufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass acutecomb <anchor 100 200> @MC_top;
markClass tildecomb <anchor 100 200> @MC_top;
feature mark {
lookup mark2base {
pos base a
<anchor 100 200> mark @MC_top;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 100 500> mark @MC_top
ligComponent
<anchor 600 500> mark @MC_top;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_top {
@MFS_mark2mark_top = [acutecomb tildecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark tildecomb
<anchor 100 300> mark @MC_top;
} mark2mark_top;
} mkmk;
"""
)
def test_write_only_one(self, testufo):
writer = MarkFeatureWriter(features=["mkmk"]) # only builds "mkmk"
feaFile = ast.FeatureFile()
assert writer.write(testufo, feaFile)
fea = str(feaFile)
assert "feature mark" not in fea
assert "feature mkmk" in fea
writer = MarkFeatureWriter(features=["mark"]) # only builds "mark"
feaFile = ast.FeatureFile()
assert writer.write(testufo, feaFile)
fea = str(feaFile)
assert "feature mark" in fea
assert "feature mkmk" not in fea
def test_predefined_anchor_lists(self, FontClass):
"""Roboto uses some weird anchor naming scheme, see:
https://github.com/google/roboto/blob/
5700de83856781fa0c097a349e46dbaae5792cb0/
scripts/lib/fontbuild/markFeature.py#L41-L47
"""
class RobotoMarkFeatureWriter(MarkFeatureWriter):
class NamedAnchor(NamedAnchor):
markPrefix = "_mark"
ignoreRE = "(^mkmk|_acc$)"
ufo = FontClass()
a = ufo.newGlyph("a")
a.anchors = [
{"name": "top", "x": 250, "y": 600},
{"name": "bottom", "x": 250, "y": -100},
]
f_i = ufo.newGlyph("f_i")
f_i.anchors = [
{"name": "top_1", "x": 200, "y": 700},
{"name": "top_2", "x": 500, "y": 700},
]
gravecomb = ufo.newGlyph("gravecomb")
gravecomb.anchors = [
{"name": "_marktop", "x": 160, "y": 780},
{"name": "mkmktop", "x": 150, "y": 800},
{"name": "mkmkbottom_acc", "x": 150, "y": 600},
]
ufo.newGlyph("cedillacomb").appendAnchor(
{"name": "_markbottom", "x": 200, "y": 0}
)
ufo.newGlyph("ogonekcomb").appendAnchor({"name": "_bottom", "x": 180, "y": -10})
writer = RobotoMarkFeatureWriter(groupMarkClasses=True)
feaFile = ast.FeatureFile()
writer.write(ufo, feaFile)
assert str(feaFile) == dedent(
"""\
markClass cedillacomb <anchor 200 0> @MC_markbottom;
markClass gravecomb <anchor 160 780> @MC_marktop;
feature mark {
lookup mark2base {
pos base a
<anchor 250 -100> mark @MC_markbottom
<anchor 250 600> mark @MC_marktop;
} mark2base;
lookup mark2liga {
pos ligature f_i
<anchor 200 700> mark @MC_marktop
ligComponent
<anchor 500 700> mark @MC_marktop;
} mark2liga;
} mark;
feature mkmk {
lookup mark2mark_bottom {
@MFS_mark2mark_bottom = [cedillacomb gravecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_bottom;
pos mark gravecomb
<anchor 150 600> mark @MC_markbottom;
} mark2mark_bottom;
lookup mark2mark_top {
@MFS_mark2mark_top = [gravecomb];
lookupflag UseMarkFilteringSet @MFS_mark2mark_top;
pos mark gravecomb
<anchor 150 800> mark @MC_marktop;
} mark2mark_top;
} mkmk;
""" # noqa: B950
)
@pytest.mark.parametrize(
"groupMarkClasses, expected",
[
(
True,
dedent(
"""\
markClass nukta-kannada <anchor 0 0> @MC_bottom;
markClass candrabindu-kannada <anchor 0 547> @MC_top;
markClass halant-kannada <anchor -456 460> @MC_topright;
feature abvm {
lookup abvm_mark2base {
pos base ka-kannada.base
<anchor 291 547> mark @MC_top
<anchor 391 460> mark @MC_topright;
} abvm_mark2base;
} abvm;
feature blwm {
lookup blwm_mark2base {
pos base ka-kannada
<anchor 290 0> mark @MC_bottom;
pos base ka-kannada.base
<anchor 290 0> mark @MC_bottom;
} blwm_mark2base;
} blwm;
feature mark {
lookup mark2base {
pos base dottedCircle
<anchor 297 0> mark @MC_bottom
<anchor 297 552> mark @MC_top
<anchor 491 458> mark @MC_topright;
} mark2base;
} mark;
""" # noqa: B950
),
),
(
False,
dedent(
"""\
markClass nukta-kannada <anchor 0 0> @MC_bottom;
markClass candrabindu-kannada <anchor 0 547> @MC_top;
markClass halant-kannada <anchor -456 460> @MC_topright;
feature abvm {
lookup abvm_mark2base {
pos base ka-kannada.base
<anchor 291 547> mark @MC_top;
} abvm_mark2base;
lookup abvm_mark2base_1 {
pos base ka-kannada.base
<anchor 391 460> mark @MC_topright;
} abvm_mark2base_1;
} abvm;
feature blwm {
lookup blwm_mark2base {
pos base ka-kannada
<anchor 290 0> mark @MC_bottom;
pos base ka-kannada.base
<anchor 290 0> mark @MC_bottom;
} blwm_mark2base;
} blwm;
feature mark {
lookup mark2base {
pos base dottedCircle
<anchor 297 0> mark @MC_bottom;
} mark2base;
lookup mark2base_1 {
pos base dottedCircle
<anchor 297 552> mark @MC_top;
} mark2base_1;
lookup mark2base_2 {
pos base dottedCircle
<anchor 491 458> mark @MC_topright;
} mark2base_2;
} mark;
""" # noqa: B950
),
),
],
)
def test_abvm_blwm_features(self, FontClass, groupMarkClasses, expected):
ufo = FontClass()
ufo.info.unitsPerEm = 1000
dottedCircle = ufo.newGlyph("dottedCircle")
dottedCircle.unicode = 0x25CC
dottedCircle.anchors = [
{"name": "top", "x": 297, "y": 552},
{"name": "topright", "x": 491, "y": 458},
{"name": "bottom", "x": 297, "y": 0},
]
nukta = ufo.newGlyph("nukta-kannada")
nukta.unicode = 0x0CBC
nukta.appendAnchor({"name": "_bottom", "x": 0, "y": 0})
nukta = ufo.newGlyph("candrabindu-kannada")
nukta.unicode = 0x0C81
nukta.appendAnchor({"name": "_top", "x": 0, "y": 547})
halant = ufo.newGlyph("halant-kannada")
halant.unicode = 0x0CCD
halant.appendAnchor({"name": "_topright", "x": -456, "y": 460})
ka = ufo.newGlyph("ka-kannada")
ka.unicode = 0x0C95
ka.appendAnchor({"name": "bottom", "x": 290, "y": 0})
ka_base = ufo.newGlyph("ka-kannada.base")
ka_base.appendAnchor({"name": "top", "x": 291, "y": 547})
ka_base.appendAnchor({"name": "topright", "x": 391, "y": 460})
ka_base.appendAnchor({"name": "bottom", "x": 290, "y": 0})
ufo.features.text = dedent(
"""\
languagesystem DFLT dflt;
languagesystem knda dflt;
languagesystem knd2 dflt;
feature psts {
sub ka-kannada' halant-kannada by ka-kannada.base;
} psts;
"""
)
generated = self.writeFeatures(ufo, groupMarkClasses=groupMarkClasses)
assert str(generated) == expected
def test_shared_script_char(self, FontClass):
ufo = FontClass()
ufo.info.unitsPerEm = 1000
dottedCircle = ufo.newGlyph("kashida-ar")
dottedCircle.unicode = 0x0640
dottedCircle.anchors = [
{"name": "top", "x": 100, "y": 100},
{"name": "bottom", "x": 100, "y": -100},
]
nukta = ufo.newGlyph("fatha-ar")
nukta.unicode = 0x064E
nukta.appendAnchor({"name": "_top", "x": 0, "y": 0})
nukta = ufo.newGlyph("kasra-ar")
nukta.unicode = 0x0650
nukta.appendAnchor({"name": "_bottom", "x": 0, "y": 547})
ufo.features.text = dedent(
"""\
languagesystem DFLT dflt;
languagesystem arab dflt;
"""
)
generated = self.writeFeatures(ufo, groupMarkClasses=True)
assert str(generated) == dedent(
"""\
markClass kasra-ar <anchor 0 547> @MC_bottom;
markClass fatha-ar <anchor 0 0> @MC_top;
feature mark {
lookup mark2base {
pos base kashida-ar
<anchor 100 -100> mark @MC_bottom
<anchor 100 100> mark @MC_top;
} mark2base;
} mark;
""" # noqa: B950
)
expected = dedent(
"""\
markClass kasra-ar <anchor 0 547> @MC_bottom;
markClass fatha-ar <anchor 0 0> @MC_top;
feature abvm {
lookup abvm_mark2base {
pos base kashida-ar
<anchor 100 100> mark @MC_top;
} abvm_mark2base;
} abvm;
feature blwm {
lookup blwm_mark2base {
pos base kashida-ar
<anchor 100 -100> mark @MC_bottom;
} blwm_mark2base;
} blwm;
feature mark {