def test_collide(self): prefix = "TEST_PREFIX" suffix = "TEST_SUFFIX" name = "NAME" name_file = "N_A_M_E_" collision_avoidance1 = "000000000000001" collision_avoidance2 = "000000000000002" exist = set() generated = userNameToFileName(name, exist, prefix=prefix, suffix=suffix) exist.add(generated.lower()) self.assertEqual(generated, prefix + name_file + suffix) generated = userNameToFileName(name, exist, prefix=prefix, suffix=suffix) exist.add(generated.lower()) self.assertEqual(generated, prefix + name_file + collision_avoidance1 + suffix) generated = userNameToFileName(name, exist, prefix=prefix, suffix=suffix) self.assertEqual(generated, prefix + name_file + collision_avoidance2 + suffix)
def toXML(self, writer, ttFont, splitGlyphs=False): notice = ( "The xMin, yMin, xMax and yMax values\n" "will be recalculated by the compiler.") glyphNames = ttFont.getGlyphNames() if not splitGlyphs: writer.newline() writer.comment(notice) writer.newline() writer.newline() numGlyphs = len(glyphNames) if splitGlyphs: path, ext = os.path.splitext(writer.file.name) existingGlyphFiles = set() for glyphName in glyphNames: glyph = self[glyphName] if glyph.numberOfContours: if splitGlyphs: glyphPath = userNameToFileName( tounicode(glyphName, 'utf-8'), existingGlyphFiles, prefix=path + ".", suffix=ext) existingGlyphFiles.add(glyphPath.lower()) glyphWriter = xmlWriter.XMLWriter( glyphPath, idlefunc=writer.idlefunc, newlinestr=writer.newlinestr) glyphWriter.begintag("ttFont", ttLibVersion=version) glyphWriter.newline() glyphWriter.begintag("glyf") glyphWriter.newline() glyphWriter.comment(notice) glyphWriter.newline() writer.simpletag("TTGlyph", src=os.path.basename(glyphPath)) else: glyphWriter = writer glyphWriter.begintag('TTGlyph', [ ("name", glyphName), ("xMin", glyph.xMin), ("yMin", glyph.yMin), ("xMax", glyph.xMax), ("yMax", glyph.yMax), ]) glyphWriter.newline() glyph.toXML(glyphWriter, ttFont) glyphWriter.endtag('TTGlyph') glyphWriter.newline() if splitGlyphs: glyphWriter.endtag("glyf") glyphWriter.newline() glyphWriter.endtag("ttFont") glyphWriter.newline() glyphWriter.close() else: writer.simpletag('TTGlyph', name=glyphName) writer.comment("contains no outline data") if not splitGlyphs: writer.newline() writer.newline()
def test_prefix_suffix(self): prefix = "TEST_PREFIX" suffix = "TEST_SUFFIX" name = "NAME" name_file = "N_A_M_E_" self.assertEqual( userNameToFileName(name, prefix=prefix, suffix=suffix), prefix + name_file + suffix)
def test_collide(self): prefix = "TEST_PREFIX" suffix = "TEST_SUFFIX" name = "NAME" name_file = "N_A_M_E_" collision_avoidance1 = "000000000000001" collision_avoidance2 = "000000000000002" exist = set() generated = userNameToFileName( name, exist, prefix=prefix, suffix=suffix) exist.add(generated.lower()) self.assertEqual(generated, prefix + name_file + suffix) generated = userNameToFileName( name, exist, prefix=prefix, suffix=suffix) exist.add(generated.lower()) self.assertEqual( generated, prefix + name_file + collision_avoidance1 + suffix) generated = userNameToFileName( name, exist, prefix=prefix, suffix=suffix) self.assertEqual( generated, prefix + name_file + collision_avoidance2+ suffix)
def test_names(self): self.assertEqual(userNameToFileName("a"), "a") self.assertEqual(userNameToFileName("A"), "A_") self.assertEqual(userNameToFileName("AE"), "A_E_") self.assertEqual(userNameToFileName("Ae"), "A_e") self.assertEqual(userNameToFileName("ae"), "ae") self.assertEqual(userNameToFileName("aE"), "aE_") self.assertEqual(userNameToFileName("a.alt"), "a.alt") self.assertEqual(userNameToFileName("A.alt"), "A_.alt") self.assertEqual(userNameToFileName("A.Alt"), "A_.A_lt") self.assertEqual(userNameToFileName("A.aLt"), "A_.aL_t") self.assertEqual(userNameToFileName(u"A.alT"), "A_.alT_") self.assertEqual(userNameToFileName("T_H"), "T__H_") self.assertEqual(userNameToFileName("T_h"), "T__h") self.assertEqual(userNameToFileName("t_h"), "t_h") self.assertEqual(userNameToFileName("F_F_I"), "F__F__I_") self.assertEqual(userNameToFileName("f_f_i"), "f_f_i") self.assertEqual(userNameToFileName("Aacute_V.swash"), "A_acute_V_.swash") self.assertEqual(userNameToFileName(".notdef"), "_notdef") self.assertEqual(userNameToFileName("con"), "_con") self.assertEqual(userNameToFileName("CON"), "C_O_N_") self.assertEqual(userNameToFileName("con.alt"), "_con.alt") self.assertEqual(userNameToFileName("alt.con"), "alt._con")
def test_ValueError(self): with self.assertRaises(ValueError): userNameToFileName(b"a") with self.assertRaises(ValueError): userNameToFileName({"a"}) with self.assertRaises(ValueError): userNameToFileName(("a", )) with self.assertRaises(ValueError): userNameToFileName(["a"]) with self.assertRaises(ValueError): userNameToFileName(["a"]) with self.assertRaises(ValueError): userNameToFileName(b"\xd8\x00")
def test_names(self): self.assertEqual(userNameToFileName("a"),"a") self.assertEqual(userNameToFileName("A"), "A_") self.assertEqual(userNameToFileName("AE"), "A_E_") self.assertEqual(userNameToFileName("Ae"), "A_e") self.assertEqual(userNameToFileName("ae"), "ae") self.assertEqual(userNameToFileName("aE"), "aE_") self.assertEqual(userNameToFileName("a.alt"), "a.alt") self.assertEqual(userNameToFileName("A.alt"), "A_.alt") self.assertEqual(userNameToFileName("A.Alt"), "A_.A_lt") self.assertEqual(userNameToFileName("A.aLt"), "A_.aL_t") self.assertEqual(userNameToFileName(u"A.alT"), "A_.alT_") self.assertEqual(userNameToFileName("T_H"), "T__H_") self.assertEqual(userNameToFileName("T_h"), "T__h") self.assertEqual(userNameToFileName("t_h"), "t_h") self.assertEqual(userNameToFileName("F_F_I"), "F__F__I_") self.assertEqual(userNameToFileName("f_f_i"), "f_f_i") self.assertEqual( userNameToFileName("Aacute_V.swash"), "A_acute_V_.swash") self.assertEqual(userNameToFileName(".notdef"), "_notdef") self.assertEqual(userNameToFileName("con"), "_con") self.assertEqual(userNameToFileName("CON"), "C_O_N_") self.assertEqual(userNameToFileName("con.alt"), "_con.alt") self.assertEqual(userNameToFileName("alt.con"), "alt._con")
def test_ValueError(self): with self.assertRaises(ValueError): userNameToFileName(b"a") with self.assertRaises(ValueError): userNameToFileName({"a"}) with self.assertRaises(ValueError): userNameToFileName(("a",)) with self.assertRaises(ValueError): userNameToFileName(["a"]) with self.assertRaises(ValueError): userNameToFileName(["a"]) with self.assertRaises(ValueError): userNameToFileName(b"\xd8\x00")