-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathwriter_test.py
1257 lines (1196 loc) · 36.1 KB
/
writer_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
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from io import StringIO
from textwrap import dedent
from collections import OrderedDict
import os
from glyphsLib import classes
from glyphsLib.types import parse_datetime, Point, Rect
from glyphsLib.writer import dump, dumps
from . import test_helpers
class WriterTest(unittest.TestCase, test_helpers.AssertLinesEqual):
def assertWrites(self, glyphs_object, text, format_version=2):
"""Assert that the given object, when given to the writer,
produces the given text.
"""
expected = text.splitlines()
actual = test_helpers.write_to_lines(glyphs_object, format_version)
self.assertLinesEqual(
expected, actual, "The writer has not produced the expected output"
)
def assertWritesValue(self, glyphs_value, text, format_version=2):
"""Assert that the writer produces the given text for the given value."""
expected = (
dedent(
"""\
{{
writtenValue = {0};
}}
"""
)
.format(text)
.splitlines()
)
# We wrap the value in a dict to use the same test helper
actual = test_helpers.write_to_lines(
{"writtenValue": glyphs_value}, format_version
)
self.assertLinesEqual(
expected, actual, "The writer has not produced the expected output"
)
def test_write_font_attributes(self):
"""Test the writer on all GSFont attributes"""
font = classes.GSFont()
# List of properties from https://docu.glyphsapp.com/#gsfont
# parent: not handled because it's internal and read-only
# masters
m1 = classes.GSFontMaster()
m1.id = "M1"
font.masters.insert(0, m1)
m2 = classes.GSFontMaster()
m2.id = "M2"
font.masters.insert(1, m2)
# instances
i1 = classes.GSInstance()
i1.name = "MuchBold"
font.instances.append(i1)
# glyphs
g1 = classes.GSGlyph()
g1.name = "G1"
font.glyphs.append(g1)
# classes
c1 = classes.GSClass()
c1.name = "C1"
font.classes.append(c1)
# features
f1 = classes.GSFeature()
f1.name = "F1"
font.features.append(f1)
# featurePrefixes
fp1 = classes.GSFeaturePrefix()
fp1.name = "FP1"
font.featurePrefixes.append(fp1)
# copyright
font.copyright = "Copyright Bob"
# designer
font.designer = "Bob"
# designerURL
font.designerURL = "bob.me"
# manufacturer
font.manufacturer = "Manu"
# manufacturerURL
font.manufacturerURL = "manu.com"
# versionMajor
font.versionMajor = 2
# versionMinor
font.versionMinor = 104
# date
font.date = parse_datetime("2017-10-03 07:35:46 +0000")
# familyName
font.familyName = "Sans Rien"
# upm
font.upm = 2000
# note
font.note = "Was bored, made this"
# kerning
font.kerning = OrderedDict(
[("M1", OrderedDict([("@MMK_L_G1", OrderedDict([("@MMK_R_G1", 0.1)]))]))]
)
# userData
font.userData = {
"a": "test",
"b": [1, {"c": 2}],
"d": [1, "1"],
"noodleThickness": "106.0",
}
# grid -> gridLength
font.grid = 35
# gridSubDivisions
font.gridSubDivisions = 5
# keyboardIncrement
font.keyboardIncrement = 1.2
# disablesNiceNames
font.disablesNiceNames = True
# customParameters
font.customParameters["ascender"] = 300
# selection: not written
# selectedLayers: not written
# selectedFontMaster: not written
# masterIndex: not written
# currentText: not written
# tabs: not written
# currentTab: not written
# filepath: not written
# tool: not written
# tools: not handled because it is a read-only list of GUI features
# .appVersion (extra property that is not in the docs!)
font.appVersion = "895"
self.assertWrites(
font,
dedent(
"""\
{
.appVersion = "895";
classes = (
{
code = "";
name = C1;
}
);
copyright = "Copyright Bob";
customParameters = (
{
name = note;
value = "Was bored, made this";
},
{
name = ascender;
value = 300;
}
);
date = "2017-10-03 07:35:46 +0000";
designer = Bob;
designerURL = bob.me;
disablesNiceNames = 1;
familyName = "Sans Rien";
featurePrefixes = (
{
code = "";
name = FP1;
}
);
features = (
{
code = "";
name = F1;
}
);
fontMaster = (
{
ascender = 800;
capHeight = 700;
descender = -200;
id = M1;
xHeight = 500;
},
{
ascender = 800;
capHeight = 700;
descender = -200;
id = M2;
xHeight = 500;
}
);
glyphs = (
{
glyphname = G1;
}
);
gridLength = 35;
gridSubDivision = 5;
instances = (
{
name = MuchBold;
}
);
kerning = {
M1 = {
"@MMK_L_G1" = {
"@MMK_R_G1" = 0.1;
};
};
};
keyboardIncrement = 1.2;
manufacturer = Manu;
manufacturerURL = manu.com;
unitsPerEm = 2000;
userData = {
a = test;
b = (
1,
{
c = 2;
}
);
d = (
1,
"1"
);
noodleThickness = "106.0";
};
versionMajor = 2;
versionMinor = 104;
}
"""
),
)
# Don't write the keyboardIncrement if it's 1 (default)
font.keyboardIncrement = 1
written = test_helpers.write_to_lines(font)
self.assertFalse(any("keyboardIncrement" in line for line in written))
# Always write versionMajor and versionMinor, even when 0
font.versionMajor = 0
font.versionMinor = 0
written = test_helpers.write_to_lines(font)
self.assertIn("versionMajor = 0;", written)
self.assertIn("versionMinor = 0;", written)
def test_write_font_master_attributes(self):
"""Test the writer on all GSFontMaster attributes"""
master = classes.GSFontMaster()
# List of properties from https://docu.glyphsapp.com/#gsfontmaster
# id
master.id = "MASTER-ID"
# name
master._name = "Name Hairline Megawide"
master.customParameters["Master Name"] = "Param Hairline Megawide"
# weight
master.weight = "Thin"
# width
master.width = "Wide"
# weightValue
master.weightValue = 0.01
# widthValue
master.widthValue = 0.99
# customValue
# customName
master.customName = "Overextended"
# A value of 0.0 is not written to the file.
master.customValue = 0.001
master.customValue1 = 0.1
master.customValue2 = 0.2
master.customValue3 = 0.3
# ascender
master.ascender = 234.5
# capHeight
master.capHeight = 200.6
# xHeight
master.xHeight = 59.1
# descender
master.descender = -89.2
# italicAngle
master.italicAngle = 12.2
# verticalStems
master.verticalStems = [1, 2, 3]
# horizontalStems
master.horizontalStems = [4, 5, 6]
# alignmentZones
zone = classes.GSAlignmentZone(0, -30)
master.alignmentZones = [zone]
# blueValues: not handled because it is read-only
# otherBlues: not handled because it is read-only
# guides
guide = classes.GSGuide()
guide.name = "middle"
master.guides.append(guide)
# userData
master.userData["rememberToMakeTea"] = True
# customParameters
master.customParameters["underlinePosition"] = -135
self.assertWrites(
master,
dedent(
"""\
{
alignmentZones = (
"{0, -30}"
);
ascender = 234.5;
capHeight = 200.6;
custom = Overextended;
customValue = 0.001;
customValue1 = 0.1;
customValue2 = 0.2;
customValue3 = 0.3;
customParameters = (
{
name = "Master Name";
value = "Param Hairline Megawide";
},
{
name = underlinePosition;
value = -135;
}
);
descender = -89.2;
guideLines = (
{
name = middle;
}
);
horizontalStems = (
4,
5,
6
);
id = "MASTER-ID";
italicAngle = 12.2;
name = "Name Hairline Megawide";
userData = {
rememberToMakeTea = 1;
};
verticalStems = (
1,
2,
3
);
weight = Thin;
weightValue = 0.01;
width = Wide;
widthValue = 0.99;
xHeight = 59.1;
}
"""
),
)
# Write the capHeight and xHeight even if they are "0"
master.xHeight = 0
master.capHeight = 0
written = test_helpers.write_to_lines(master)
self.assertIn("xHeight = 0;", written)
self.assertIn("capHeight = 0;", written)
def test_write_alignment_zone(self):
zone = classes.GSAlignmentZone(23, 40)
self.assertWritesValue(zone, '"{23, 40}"')
def test_write_instance(self):
instance = classes.GSInstance()
# List of properties from https://docu.glyphsapp.com/#gsinstance
# active
instance.active = True
# name
instance.name = "SemiBoldCompressed (name)"
# weight
instance.weight = "SemiBold (weight)"
# width
instance.width = "Compressed (width)"
# weightValue
instance.weightValue = 600
# widthValue
instance.widthValue = 200
# customValue
instance.customValue = 0.4
# isItalic
instance.isItalic = True
# isBold
instance.isBold = True
# linkStyle
instance.linkStyle = "linked style value"
# familyName
instance.familyName = "Sans Rien (familyName)"
# preferredFamily
instance.preferredFamily = "Sans Rien (preferredFamily)"
# preferredSubfamilyName
instance.preferredSubfamilyName = (
"Semi Bold Compressed (preferredSubFamilyName)"
)
# windowsFamily
instance.windowsFamily = "Sans Rien MS (windowsFamily)"
# windowsStyle: read only
# windowsLinkedToStyle: read only
# fontName
instance.fontName = "SansRien (fontName)"
# fullName
instance.fullName = "Sans Rien Semi Bold Compressed (fullName)"
# customParameters
instance.customParameters["hheaLineGap"] = 10
# instanceInterpolations
instance.instanceInterpolations = {"M1": 0.2, "M2": 0.8}
# manualInterpolation
instance.manualInterpolation = True
# interpolatedFont: read only
self.assertWrites(
instance,
dedent(
"""\
{
customParameters = (
{
name = familyName;
value = "Sans Rien (familyName)";
},
{
name = preferredFamily;
value = "Sans Rien (preferredFamily)";
},
{
name = preferredSubfamilyName;
value = "Semi Bold Compressed (preferredSubFamilyName)";
},
{
name = styleMapFamilyName;
value = "Sans Rien MS (windowsFamily)";
},
{
name = postscriptFontName;
value = "SansRien (fontName)";
},
{
name = postscriptFullName;
value = "Sans Rien Semi Bold Compressed (fullName)";
},
{
name = hheaLineGap;
value = 10;
}
);
interpolationCustom = 0.4;
interpolationWeight = 600;
interpolationWidth = 200;
instanceInterpolations = {
M1 = 0.2;
M2 = 0.8;
};
isBold = 1;
isItalic = 1;
linkStyle = "linked style value";
manualInterpolation = 1;
name = "SemiBoldCompressed (name)";
weightClass = "SemiBold (weight)";
widthClass = "Compressed (width)";
}
"""
),
)
def test_write_custom_parameter(self):
# Name without quotes
self.assertWritesValue(
classes.GSCustomParameter("myParam", "myValue"),
"{\nname = myParam;\nvalue = myValue;\n}",
)
# Name with quotes
self.assertWritesValue(
classes.GSCustomParameter("my param", "myValue"),
'{\nname = "my param";\nvalue = myValue;\n}',
)
# Value with quotes
self.assertWritesValue(
classes.GSCustomParameter("myParam", "my value"),
'{\nname = myParam;\nvalue = "my value";\n}',
)
# Int param (ascender): should convert the value to string
self.assertWritesValue(
classes.GSCustomParameter("ascender", 12),
"{\nname = ascender;\nvalue = 12;\n}",
)
# Float param (postscriptBlueScale): should convert the value to string
self.assertWritesValue(
classes.GSCustomParameter("postscriptBlueScale", 0.125),
"{\nname = postscriptBlueScale;\nvalue = 0.125;\n}",
)
# Bool param (isFixedPitch): should convert the boolean value to 0/1
self.assertWritesValue(
classes.GSCustomParameter("isFixedPitch", True),
"{\nname = isFixedPitch;\nvalue = 1;\n}",
)
# Intlist param: should map list of int to list of strings
self.assertWritesValue(
classes.GSCustomParameter("fsType", [1, 2]),
"{\nname = fsType;\nvalue = (\n1,\n2\n);\n}",
)
def test_write_class(self):
class_ = classes.GSClass()
class_.name = "e"
class_.code = "e eacute egrave"
class_.automatic = True
self.assertWrites(
class_,
dedent(
"""\
{
automatic = 1;
code = "e eacute egrave";
name = e;
}
"""
),
)
# When the code is an empty string, write an empty string
class_.code = ""
self.assertWrites(
class_,
dedent(
"""\
{
automatic = 1;
code = "";
name = e;
}
"""
),
)
def test_write_feature_prefix(self):
fp = classes.GSFeaturePrefix()
fp.name = "Languagesystems"
fp.code = "languagesystem DFLT dflt;"
fp.automatic = True
self.assertWrites(
fp,
dedent(
"""\
{
automatic = 1;
code = "languagesystem DFLT dflt;";
name = Languagesystems;
}
"""
),
)
def test_write_feature(self):
feature = classes.GSFeature()
feature.name = "sups"
feature.code = " sub @standard by @sups;"
feature.automatic = True
feature.notes = "notes about sups"
self.assertWrites(
feature,
dedent(
"""\
{
automatic = 1;
code = " sub @standard by @sups;";
name = sups;
notes = "notes about sups";
}
"""
),
)
def test_write_glyph(self):
glyph = classes.GSGlyph()
# https://docu.glyphsapp.com/#gsglyph
# parent: not written
# layers
# Put the glyph in a font with at least one master for the magic in
# `glyph.layers.append()` to work.
font = classes.GSFont()
master = classes.GSFontMaster()
master.id = "MASTER-ID"
font.masters.insert(0, master)
font.glyphs.append(glyph)
layer = classes.GSLayer()
layer.layerId = "LAYER-ID"
layer.name = "L1"
glyph.layers.insert(0, layer)
# name
glyph.name = "Aacute"
# unicode
glyph.unicode = "00C1"
# string: not written
# id: not written
# category
glyph.category = "Letter"
# subCategory
glyph.subCategory = "Uppercase"
# script
glyph.script = "latin"
# productionName
glyph.productionName = "Aacute.prod"
# glyphInfo: not written
# leftKerningGroup
glyph.leftKerningGroup = "A"
# rightKerningGroup
glyph.rightKerningGroup = "A"
# leftKerningKey: not written
# rightKerningKey: not written
# leftMetricsKey
glyph.leftMetricsKey = "A"
# rightMetricsKey
glyph.rightMetricsKey = "A"
# widthMetricsKey
glyph.widthMetricsKey = "A"
# export
glyph.export = False
# color
glyph.color = 11
# colorObject: not written
# note
glyph.note = "Stunning one-bedroom A with renovated acute accent"
# selected: not written
# mastersCompatible: not stored
# userData
glyph.userData["rememberToMakeCoffe"] = True
# Check that empty collections are written
glyph.userData["com.someoneelse.coolsoftware.customdata"] = [
OrderedDict(
[("zero", 0), ("emptyList", []), ("emptyDict", {}), ("emptyString", "")]
),
[],
{},
"",
"hey",
0,
1,
]
# smartComponentAxes
axis = classes.GSSmartComponentAxis()
axis.name = "crotchDepth"
glyph.smartComponentAxes.append(axis)
# lastChange
glyph.lastChange = parse_datetime("2017-10-03 07:35:46 +0000")
self.assertWrites(
glyph,
dedent(
"""\
{
color = 11;
export = 0;
glyphname = Aacute;
lastChange = "2017-10-03 07:35:46 +0000";
layers = (
{
associatedMasterId = "MASTER-ID";
layerId = "LAYER-ID";
name = L1;
width = 600;
}
);
leftKerningGroup = A;
leftMetricsKey = A;
widthMetricsKey = A;
note = "Stunning one-bedroom A with renovated acute accent";
rightKerningGroup = A;
rightMetricsKey = A;
unicode = 00C1;
script = latin;
category = Letter;
subCategory = Uppercase;
userData = {
com.someoneelse.coolsoftware.customdata = (
{
zero = 0;
emptyList = (
);
emptyDict = {
};
emptyString = "";
},
(
),
{
},
"",
hey,
0,
1
);
rememberToMakeCoffe = 1;
};
partsSettings = (
{
name = crotchDepth;
bottomValue = 0;
topValue = 0;
}
);
}
"""
),
)
# Write the script even when it's an empty string
# Same for category and subCategory
glyph.script = ""
glyph.category = ""
glyph.subCategory = ""
written = test_helpers.write_to_lines(glyph)
self.assertIn('script = "";', written)
self.assertIn('category = "";', written)
self.assertIn('subCategory = "";', written)
# Write double unicodes
glyph.unicodes = ["00C1", "E002"]
written = test_helpers.write_to_lines(glyph)
self.assertIn('unicode = "00C1,E002";', written)
def test_write_layer(self):
font = classes.GSFont()
font.format_version = 2
master = classes.GSFontMaster()
master.id = "M1"
font.masters.append(master)
glyph = classes.GSGlyph("A")
font.glyphs.append(glyph)
layer = classes.GSLayer()
glyph.layers.append(layer)
# http://docu.glyphsapp.com/#gslayer
# parent: not written
# name
layer.name = "{125, 100}"
# associatedMasterId
layer.associatedMasterId = "M1"
# layerId
layer.layerId = "L1"
# color
layer.color = (1, 2, 3, 4)
# colorObject: read-only, computed
# components
component = classes.GSComponent(glyph="glyphName")
layer.components.append(component)
# guides
guide = classes.GSGuide()
guide.name = "xheight"
layer.guides.append(guide)
# annotations
annotation = classes.GSAnnotation()
annotation.type = classes.TEXT
annotation.text = "Fuck, this curve is ugly!"
layer.annotations.append(annotation)
# hints
hint = classes.GSHint()
hint.name = "hintName"
layer.hints.append(hint)
# anchors
anchor = classes.GSAnchor()
anchor.name = "top"
layer.anchors["top"] = anchor
# paths
path = classes.GSPath()
layer.paths.append(path)
# selection: read-only
# LSB, RSB, TSB, BSB: not written
# width
layer.width = 890.4
# leftMetricsKey
layer.leftMetricsKey = "A"
# rightMetricsKey
layer.rightMetricsKey = "A"
# widthMetricsKey
layer.widthMetricsKey = "A"
# bounds: read-only, computed
# selectionBounds: read-only, computed
# background
# XXX bg is unused?
bg = layer.background # noqa: F841
# backgroundImage
image = classes.GSBackgroundImage("/path/to/file.jpg")
layer.backgroundImage = image
# bezierPath: read-only, objective-c
# openBezierPath: read-only, objective-c
# completeOpenBezierPath: read-only, objective-c
# isAligned
# FIXME: (jany) is this read-only?
# is this computed from each component's alignment?
# layer.isAligned = False
# userData
layer.userData["rememberToMakeCoffe"] = True
# smartComponentPoleMapping
layer.smartComponentPoleMapping["crotchDepth"] = 2 # Top pole
layer.smartComponentPoleMapping["shoulderWidth"] = 1 # Bottom pole
self.assertWrites(
layer,
dedent(
"""\
{
anchors = (
{
name = top;
position = "{0, 0}";
}
);
annotations = (
{
text = "Fuck, this curve is ugly!";
type = 1;
}
);
associatedMasterId = M1;
background = {
};
backgroundImage = {
crop = "{{0, 0}, {0, 0}}";
imagePath = "/path/to/file.jpg";
};
color = (1, 2, 3, 4);
components = (
{
name = glyphName;
}
);
guideLines = (
{
name = xheight;
}
);
hints = (
{
name = hintName;
}
);
layerId = L1;
leftMetricsKey = A;
widthMetricsKey = A;
rightMetricsKey = A;
name = "{125, 100}";
paths = (
{
closed = 1;
}
);
userData = {
PartSelection = {
crotchDepth = 2;
shoulderWidth = 1;
};
rememberToMakeCoffe = 1;
};
width = 890.4;
}
"""
),
)
# Don't write a blank layer name
layer.name = ""
written = test_helpers.write_to_lines(layer)
self.assertNotIn('name = "";', written)
# Write the width even if 0
layer.width = 0
written = test_helpers.write_to_lines(layer)
self.assertIn("width = 0;", written)
def test_write_anchor(self):
anchor = classes.GSAnchor("top", Point(23, 45.5))
self.assertWrites(
anchor,
dedent(
"""\
{
name = top;
position = "{23, 45.5}";
}
"""
),
)
# Write a position of 0, 0
anchor = classes.GSAnchor("top", Point(0, 0))
self.assertWrites(
anchor,
dedent(
"""\
{
name = top;
position = "{0, 0}";
}
"""
),
)
def test_write_component(self):
component = classes.GSComponent("dieresis")
# http://docu.glyphsapp.com/#gscomponent
# position
component.position = Point(45.5, 250)
# scale
component.scale = 2.0
# rotation
component.rotation = 90
# componentName: already set at init
# component: read-only
# layer: read-only
# transform: already set using scale & position
# bounds: read-only, objective-c
# automaticAlignment
component.automaticAlignment = True
# anchor
component.anchor = "top"
# selected: not written
# smartComponentValues
component.smartComponentValues = {"crotchDepth": -77}
# bezierPath: read-only, objective-c
self.assertWrites(
component,
dedent(
"""\
{
anchor = top;
name = dieresis;
piece = {
crotchDepth = -77;
};
transform = "{0, 2, -2, 0, 45.5, 250}";
}
"""
),
)
def test_write_smart_component_axis(self):
axis = classes.GSSmartComponentAxis()
# http://docu.glyphsapp.com/#gssmartcomponentaxis
axis.name = "crotchDepth"
axis.topName = "High"
axis.topValue = 0
axis.bottomName = "Low"
axis.bottomValue = -100
self.assertWrites(
axis,
dedent(
"""\
{
name = crotchDepth;
bottomName = Low;
bottomValue = -100;
topName = High;
topValue = 0;
}
"""
),
)
def test_write_path(self):
path = classes.GSPath()
# http://docu.glyphsapp.com/#gspath
# parent: not written
# nodes
node = classes.GSNode()
path.nodes.append(node)
# segments: computed, objective-c
# closed
path.closed = True
# direction: computed
# bounds: computed
# selected: not written
# bezierPath: computed
self.assertWrites(
path,
dedent(
"""\
{
closed = 1;
nodes = (
"0 0 LINE"
);
}
"""
),
)
def test_write_node(self):