def test_write_background_image(self): image = classes.GSBackgroundImage('/tmp/img.jpg') # http://docu.glyphsapp.com/#gsbackgroundimage # path: already set # image: read-only, objective-c image.crop = rect(point(0, 10), point(500, 510)) image.locked = True image.alpha = 70 image.position = point(40, 90) image.scale = (1.1, 1.2) image.rotation = 0.3 # transform: Already set with scale/rotation self.assertWrites(image, dedent("""\ { alpha = 70; crop = "{{0, 10}, {500, 510}}"; imagePath = "/tmp/img.jpg"; locked = 1; transform = ( 1.09998, 0.00576, -0.00628, 1.19998, 40, 90 ); } """))
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_anchor(self): anchor = classes.GSAnchor('top', point(23, 45.5)) self.assertWrites(anchor, dedent("""\ { name = top; position = "{23, 45.5}"; } """))
def test_write_hint(self): hint = classes.GSHint() # http://docu.glyphsapp.com/#gshint layer = classes.GSLayer() path1 = classes.GSPath() layer.paths.append(path1) node1 = classes.GSNode(point(100, 100)) path1.nodes.append(node1) hint.originNode = node1 node2 = classes.GSNode(point(200, 200)) path1.nodes.append(node2) hint.targetNode = node2 node3 = classes.GSNode(point(300, 300)) path1.nodes.append(node3) hint.otherNode1 = node3 path2 = classes.GSPath() layer.paths.append(path2) node4 = classes.GSNode(point(400, 400)) path2.nodes.append(node4) hint.otherNode2 = node4 hint.type = classes.CORNER hint.options = classes.TTROUND | classes.TRIPLE hint.horizontal = True # selected: not written hint.name = "My favourite hint" self.assertWrites( hint, dedent("""\ { horizontal = 1; origin = "{0, 0}"; target = "{0, 1}"; other1 = "{0, 2}"; other2 = "{1, 0}"; type = 16; name = "My favourite hint"; options = 128; } """))
def test_write_node(self): node = classes.GSNode(point(10, 30), classes.GSNode.CURVE) # http://docu.glyphsapp.com/#gsnode # position: already set # type: already set # smooth node.smooth = True # connection: deprecated # selected: not written # index, nextNode, prevNode: computed # name node.name = "top-left corner" # userData node.userData["rememberToDownloadARealRemindersApp"] = True self.assertWritesValue( node, '"10 30 CURVE SMOOTH {name = \\"top-left corner\\";\\n\ rememberToDownloadARealRemindersApp = 1;}"' ) # Write floating point coordinates node = classes.GSNode(point(499.99, 512.01), classes.GSNode.OFFCURVE) self.assertWritesValue( node, '"499.99 512.01 OFFCURVE"' ) # Write userData with special characters test_user_data = { '\nkey"\';\n\n\n': '"\'value\nseveral lines\n;\n', ';': ';\n', 'escapeception': '\\"\\\'\\n\\\\n', } node = classes.GSNode(point(130, 431), classes.GSNode.LINE) for key, value in test_user_data.items(): node.userData[key] = value # This is the output of Glyphs 1089 expected_output = '"130 431 LINE {\\"\\012key\\\\"\';\\012\\012\\012\\" = \\"\\\\"\'value\\012several lines\\012;\\012\\";\\n\\";\\" = \\";\\012\\";\\nescapeception = \\"\\\\\\\\"\\\\\'\\\\n\\\\\\\\n\\";}"' self.assertWritesValue(node, expected_output) # Check that we can read the userData back node = Parser(classes.GSNode).parse(expected_output) self.assertEqual(test_user_data, dict(node.userData))
def test_write_node(self): node = classes.GSNode(point(10, 30), classes.GSNode.CURVE) # http://docu.glyphsapp.com/#gsnode # position: already set # type: already set # smooth node.smooth = True # connection: deprecated # selected: not written # index, nextNode, prevNode: computed # name node.name = "top-left corner" # userData node.userData["rememberToDownloadARealRemindersApp"] = True self.assertWritesValue( node, '"10 30 CURVE SMOOTH {\\nname = \\"top-left corner\\";\\n\ rememberToDownloadARealRemindersApp = 1;\\n}"') # Write floating point coordinates node = classes.GSNode(point(499.99, 512.01), classes.GSNode.OFFCURVE) self.assertWritesValue(node, '"499.99 512.01 OFFCURVE"')
def test_write_guideline(self): line = classes.GSGuideLine() # http://docu.glyphsapp.com/#GSGuideLine line.position = point(56, 45) line.angle = 11.0 line.name = "italic angle" # selected: not written self.assertWrites(line, dedent("""\ { angle = 11; name = "italic angle"; position = "{56, 45}"; } """))
def _run_guideline_test(self, data_in, expected): font = generate_minimal_font() glyph = GSGlyph(name='a') font.glyphs.append(glyph) layer = GSLayer() layer.layerId = font.masters[0].id layer.width = 0 for guide_data in data_in: pt = point(value=guide_data['position'][0], value2=guide_data['position'][1]) guide = GSGuideLine() guide.position = pt guide.angle = guide_data['angle'] layer.guides.append(guide) glyph.layers.append(layer) ufo = to_ufos(font)[0] self.assertEqual(ufo['a'].guidelines, expected)
def test_write_annotation(self): annotation = classes.GSAnnotation() # http://docu.glyphsapp.com/#gsannotation annotation.position = point(12, 34) annotation.type = classes.TEXT annotation.text = "Look here" annotation.angle = 123.5 annotation.width = 135 self.assertWrites(annotation, dedent("""\ { angle = 123.5; position = "{12, 34}"; text = "Look here"; type = 1; width = 135; } """))