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_layer(self): layer = classes.GSLayer() # http://docu.glyphsapp.com/#gslayer # parent: not written # name layer.name = '{125, 100}' # associatedMasterId layer.associatedMasterId = 'M1' # layerId layer.layerId = 'L1' # color layer.color = 2 # brown # colorObject: read-only, computed # components component = classes.GSComponent(glyph='glyphName') layer.components.append(component) # guides guide = classes.GSGuideLine() guide.name = 'xheight' layer.guides.append(guide) # annotations annotation = classes.GSAnnotation() annotation.type = classes.TEXT annotation.text = 'F**k, 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 # FIXME: (jany) why not use a GSLayer like the official doc suggests? background_layer = classes.GSBackgroundLayer() layer.background = background_layer # 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; } ); annotations = ( { position = ; text = "F**k, this curve is ugly!"; type = 1; } ); associatedMasterId = M1; background = { }; backgroundImage = { crop = "{{0, 0}, {0, 0}}"; imagePath = "/path/to/file.jpg"; }; color = 2; components = ( { name = glyphName; } ); guideLines = ( { name = xheight; } ); hints = ( { name = hintName; } ); layerId = L1; leftMetricsKey = A; widthMetricsKey = A; rightMetricsKey = A; name = "{125, 100}"; paths = ( { } ); 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)
def test_write_layer(self): layer = classes.GSLayer() # 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.GSGuideLine() guide.name = "xheight" layer.guides.append(guide) # annotations annotation = classes.GSAnnotation() annotation.type = classes.TEXT annotation.text = "F**k, 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 = "F**k, 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)