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 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 # Cannot set the `name` attribute directly # master.name = "Hairline Megawide" master.customParameters['Master Name'] = "Hairline Megawide" # weight master.weight = "Thin" # width master.width = "Wide" # weightValue master.weightValue = 0.01 # widthValue master.widthValue = 0.99 # customValue # customName master.customName = "cuteness" # A value of 0.0 is not written to the file. master.customValue = 0.001 master.customName1 = "color" master.customValue1 = 0.1 master.customName2 = "depth" master.customValue2 = 0.2 master.customName3 = "surealism" 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.GSGuideLine() 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 = cuteness; customValue = 0.001; custom1 = color; customValue1 = 0.1; custom2 = depth; customValue2 = 0.2; custom3 = surealism; customValue3 = 0.3; customParameters = ( { name = "Master Name"; value = "Hairline Megawide"; }, { name = underlinePosition; value = -135; } ); descender = -89.2; guideLines = ( { name = middle; } ); horizontalStems = ( 4, 5, 6 ); id = "MASTER-ID"; italicAngle = 12.2; 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_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)