예제 #1
0
    def write(self, glyphSet: GlyphSet, saveAs: bool = True) -> None:
        """Write Layer to a :class:`fontTools.ufoLib.glifLib.GlyphSet`.

        Args:
            glyphSet: The GlyphSet object to write to.
            saveAs: If True, tells the writer to save out-of-place. If False, tells the
                writer to save in-place. This affects how resources are cleaned before
                writing.
        """
        glyphs = self._glyphs
        if not saveAs:
            for name in set(glyphSet.contents).difference(glyphs):
                glyphSet.deleteGlyph(name)
        for name, glyph in glyphs.items():
            if glyph is _GLYPH_NOT_LOADED:
                if saveAs:
                    glyph = self.loadGlyph(name)
                else:
                    continue
            _prune_object_libs(glyph.lib, _fetch_glyph_identifiers(glyph))
            glyphSet.writeGlyph(name,
                                glyphObject=glyph,
                                drawPointsFunc=glyph.drawPoints)
        glyphSet.writeContents()
        glyphSet.writeLayerInfo(self)
        if saveAs:
            # all glyphs are loaded by now, no need to keep ref to glyphSet
            self._glyphSet = None
예제 #2
0
 def testReverseContents2(self):
     src = GlyphSet(GLYPHSETDIR, validateRead=True, validateWrite=True)
     dst = GlyphSet(self.dstDir, validateRead=True, validateWrite=True)
     dstMap = dst.getReverseContents()
     self.assertEqual(dstMap, {})
     for glyphName in src.keys():
         g = src[glyphName]
         g.drawPoints(None)  # load attrs
         dst.writeGlyph(glyphName, g, g.drawPoints)
     self.assertNotEqual(dstMap, {})
     srcMap = dict(src.getReverseContents())  # copy
     self.assertEqual(dstMap, srcMap)
     del srcMap["a.glif"]
     dst.deleteGlyph("a")
     self.assertEqual(dstMap, srcMap)
예제 #3
0
	def test_conflicting_case_insensitive_file_names(self, tmp_path):
		src = GlyphSet(GLYPHSETDIR)
		dst = GlyphSet(tmp_path)
		glyph = src["a"]

		dst.writeGlyph("a", glyph)
		dst.writeGlyph("A", glyph)
		dst.writeGlyph("a_", glyph)
		dst.deleteGlyph("a_")
		dst.writeGlyph("a_", glyph)
		dst.writeGlyph("A_", glyph)
		dst.writeGlyph("i_j", glyph)

		assert dst.contents == {
			'a': 'a.glif',
			'A': 'A_.glif',
			'a_': 'a_000000000000001.glif',
			'A_': 'A__.glif',
			'i_j': 'i_j.glif',
		}

		# make sure filenames are unique even on case-insensitive filesystems
		assert len({fileName.lower() for fileName in dst.contents.values()}) == 5