def test_to_ufo_draw_paths_open(self):
        layer = GSLayer()
        path = GSPath()
        path.nodes = [
            GSNode(position=(0, 0), nodetype="line"),
            GSNode(position=(1, 1), nodetype="offcurve"),
            GSNode(position=(2, 2), nodetype="offcurve"),
            GSNode(position=(3, 3), nodetype="curve", smooth=True),
        ]
        path.closed = False
        layer.paths.append(path)
        glyph = _Glyph()
        to_ufo_paths(_UFOBuilder(), glyph, layer)

        self.assertEqual(
            glyph.pen.contours,
            [
                [
                    (0, 0, "move", False),
                    (1, 1, None, False),
                    (2, 2, None, False),
                    (3, 3, "curve", True),
                ]
            ],
        )
Beispiel #2
0
 def test_set_disable_last_change(self):
     glyph = GSGlyph()
     glyph.name = "a"
     self.font.glyphs.append(glyph)
     layer = GSLayer()
     layer.layerId = self.font.masters[0].id
     layer.associatedMasterId = self.font.masters[0].id
     layer.width = 100
     glyph.layers.append(layer)
     glyph.lastChange = parse_datetime("2017-10-03 07:35:46 +0000")
     self.font.customParameters["Disable Last Change"] = True
     self.ufo = to_ufos(self.font)[0]
     self.assertEqual(
         True,
         self.ufo.lib[FONT_CUSTOM_PARAM_PREFIX + "disablesLastChange"])
     self.assertNotIn(GLYPHLIB_PREFIX + "lastChange", self.ufo["a"].lib)
Beispiel #3
0
 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_to_ufo_draw_paths_empty_nodes(self):
        layer = GSLayer()
        layer.paths.append(GSPath())

        glyph = _Glyph()
        to_ufo_paths(_UFOBuilder(), glyph, layer)

        self.assertEqual(glyph.pen.contours, [])
 def test_supplementary_layers(self):
     """Test sub layers."""
     font = generate_minimal_font()
     glyph = GSGlyph(name="a")
     font.glyphs.append(glyph)
     layer = GSLayer()
     layer.layerId = font.masters[0].id
     layer.width = 0
     glyph.layers.append(layer)
     sublayer = GSLayer()
     sublayer.associatedMasterId = font.masters[0].id
     sublayer.width = 0
     sublayer.name = "SubLayer"
     glyph.layers.append(sublayer)
     ufo = to_ufos(font)[0]
     self.assertEqual([l.name for l in ufo.layers], ["public.default", "SubLayer"])
    def test_to_ufo_draw_paths_qcurve(self):
        layer = GSLayer()
        path = GSPath()
        path.nodes = [
            GSNode(position=(143, 695), nodetype="offcurve"),
            GSNode(position=(37, 593), nodetype="offcurve"),
            GSNode(position=(37, 434), nodetype="offcurve"),
            GSNode(position=(143, 334), nodetype="offcurve"),
            GSNode(position=(223, 334), nodetype="qcurve", smooth=True),
        ]
        path.closed = True
        layer.paths.append(path)

        glyph = _Glyph()
        to_ufo_paths(_UFOBuilder(), glyph, layer)

        points = glyph.pen.contours[0]

        first_x, first_y = points[0][:2]
        self.assertEqual((first_x, first_y), (223, 334))

        first_segment_type = points[0][2]
        self.assertEqual(first_segment_type, "qcurve")
Beispiel #7
0
    def test_to_ufo_draw_paths_closed(self):
        layer = GSLayer()
        path = GSPath()
        path.nodes = [
            GSNode(position=(0, 0), nodetype='offcurve'),
            GSNode(position=(1, 1), nodetype='offcurve'),
            GSNode(position=(2, 2), nodetype='curve', smooth=True),
            GSNode(position=(3, 3), nodetype='offcurve'),
            GSNode(position=(4, 4), nodetype='offcurve'),
            GSNode(position=(5, 5), nodetype='curve', smooth=True),
        ]
        path.closed = True
        layer.paths.append(path)

        glyph = _Glyph()
        to_ufo_paths(_UFOBuilder(), glyph, layer)

        points = glyph.pen.contours[0]

        first_x, first_y = points[0][:2]
        self.assertEqual((first_x, first_y), (5, 5))

        first_segment_type = points[0][2]
        self.assertEqual(first_segment_type, 'curve')
Beispiel #8
0
 def test_glyph_color(self):
     font = generate_minimal_font()
     glyph = GSGlyph(name='a')
     glyph2 = GSGlyph(name='b')
     glyph3 = GSGlyph(name='c')
     glyph4 = GSGlyph(name='d')
     glyph.color = [244, 0, 138, 1]
     glyph2.color = 3
     glyph3.color = 88
     glyph4.color = [800, 0, 138, 1]
     font.glyphs.append(glyph)
     font.glyphs.append(glyph2)
     font.glyphs.append(glyph3)
     font.glyphs.append(glyph4)
     layer = GSLayer()
     layer2 = GSLayer()
     layer3 = GSLayer()
     layer4 = GSLayer()
     layer.layerId = font.masters[0].id
     layer2.layerId = font.masters[0].id
     layer3.layerId = font.masters[0].id
     layer4.layerId = font.masters[0].id
     glyph.layers.append(layer)
     glyph2.layers.append(layer2)
     glyph3.layers.append(layer3)
     glyph4.layers.append(layer4)
     ufo = to_ufos(font)[0]
     self.assertEqual(ufo['a'].lib.get('public.markColor'),
                      '0.9569,0,0.5412,0.0039')
     self.assertEqual(ufo['b'].lib.get('public.markColor'), '0.97,1,0,1')
     self.assertEqual(ufo['c'].lib.get('public.markColor'), None)
     self.assertEqual(ufo['d'].lib.get('public.markColor'), None)
 def test_glyph_color(self):
     font = generate_minimal_font()
     glyph = GSGlyph(name="a")
     glyph2 = GSGlyph(name="b")
     glyph3 = GSGlyph(name="c")
     glyph4 = GSGlyph(name="d")
     glyph.color = [244, 0, 138, 1]
     glyph2.color = 3
     glyph3.color = 88
     glyph4.color = [800, 0, 138, 255]
     font.glyphs.append(glyph)
     font.glyphs.append(glyph2)
     font.glyphs.append(glyph3)
     font.glyphs.append(glyph4)
     layer = GSLayer()
     layer2 = GSLayer()
     layer3 = GSLayer()
     layer4 = GSLayer()
     layer.layerId = font.masters[0].id
     layer2.layerId = font.masters[0].id
     layer3.layerId = font.masters[0].id
     layer4.layerId = font.masters[0].id
     glyph.layers.append(layer)
     glyph2.layers.append(layer2)
     glyph3.layers.append(layer3)
     glyph4.layers.append(layer4)
     ufo = to_ufos(font)[0]
     self.assertEqual(ufo["a"].lib.get("public.markColor"), "0.957,0,0.541,0.004")
     self.assertEqual(ufo["b"].lib.get("public.markColor"), "0.97,1,0,1")
     self.assertEqual(ufo["c"].lib.get("public.markColor"), None)
     self.assertEqual(ufo["d"].lib.get("public.markColor"), None)