Beispiel #1
0
 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;
         }
     """))
Beispiel #2
0
    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)
Beispiel #3
0
    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)