Пример #1
0
 def test_parseOptions_ttx2font_2nd_time(self):
     file_name = 'TestOTF.ttx'
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     _, _ = ttx.parseOptions([temp_path]) # this is NOT a mistake
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, 'ttCompile')
     self.assertEqual(jobs[0][1:],
                     (os.path.join(self.tempdir, file_name),
                      os.path.join(self.tempdir, file_name.split('.')[0] + '#1.otf')))
Пример #2
0
 def test_parseOptions_ttx2font_2nd_time(self):
     file_name = 'TestOTF.ttx'
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     _, _ = ttx.parseOptions([temp_path]) # this is NOT a mistake
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, 'ttCompile')
     self.assertEqual(jobs[0][1:],
                     (os.path.join(self.tempdir, file_name),
                      os.path.join(self.tempdir, file_name.split('.')[0] + '#1.otf')))
Пример #3
0
 def test_parseOptions_font2ttx_2nd_time(self):
     file_name = "TestTTF.ttf"
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     _, _ = ttx.parseOptions([temp_path])  # this is NOT a mistake
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, "ttDump")
     self.assertEqual(
         jobs[0][1:],
         (
             os.path.join(self.tempdir, file_name),
             os.path.join(self.tempdir, file_name.split(".")[0] + "#1.ttx"),
         ),
     )
Пример #4
0
 def test_parseOptions_font2ttx_2nd_time(self):
     file_name = "TestTTF.ttf"
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     _, _ = ttx.parseOptions([temp_path])  # this is NOT a mistake
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, "ttDump")
     self.assertEqual(
         jobs[0][1:],
         (
             os.path.join(self.tempdir, file_name),
             os.path.join(self.tempdir, file_name.split(".")[0] + "#1.ttx"),
         ),
     )
Пример #5
0
    def test_parseOptions_splitTables(self):
        file_name = "TestTTF.ttf"
        font_path = self.getpath(file_name)
        temp_path = self.temp_font(font_path, file_name)
        args = ["-s", temp_path]

        jobs, options = ttx.parseOptions(args)

        ttx_file_path = jobs[0][2]
        temp_folder = os.path.dirname(ttx_file_path)
        self.assertTrue(options.splitTables)
        self.assertTrue(os.path.exists(ttx_file_path))

        ttx.process(jobs, options)

        # Read the TTX file but strip the first two and the last lines:
        # <?xml version="1.0" encoding="UTF-8"?>
        # <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.22">
        # ...
        # </ttFont>
        parsed_xml = parseXML(self.read_file(ttx_file_path)[2:-1])
        for item in parsed_xml:
            if not isinstance(item, tuple):
                continue
            # the tuple looks like this:
            # (u'head', {u'src': u'TestTTF._h_e_a_d.ttx'}, [])
            table_file_name = item[1].get("src")
            table_file_path = os.path.join(temp_folder, table_file_name)
            self.assertTrue(os.path.exists(table_file_path))
Пример #6
0
    def test_parseOptions_splitTables(self):
        file_name = "TestTTF.ttf"
        font_path = self.getpath(file_name)
        temp_path = self.temp_font(font_path, file_name)
        args = ["-s", temp_path]

        jobs, options = ttx.parseOptions(args)

        ttx_file_path = jobs[0][2]
        temp_folder = os.path.dirname(ttx_file_path)
        self.assertTrue(options.splitTables)
        self.assertTrue(os.path.exists(ttx_file_path))

        ttx.process(jobs, options)

        # Read the TTX file but strip the first two and the last lines:
        # <?xml version="1.0" encoding="UTF-8"?>
        # <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.22">
        # ...
        # </ttFont>
        parsed_xml = parseXML(self.read_file(ttx_file_path)[2:-1])
        for item in parsed_xml:
            if not isinstance(item, tuple):
                continue
            # the tuple looks like this:
            # (u'head', {u'src': u'TestTTF._h_e_a_d.ttx'}, [])
            table_file_name = item[1].get("src")
            table_file_path = os.path.join(temp_folder, table_file_name)
            self.assertTrue(os.path.exists(table_file_path))
Пример #7
0
 def test_parseOptions_ttx2font_1st_time(self):
     file_name = 'TestTTF.ttx'
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, 'ttCompile')
     self.assertEqual(jobs[0][1:],
                     (os.path.join(self.tempdir, file_name),
                      os.path.join(self.tempdir, file_name.split('.')[0] + '.ttf')))
Пример #8
0
 def test_parseOptions_ttx2font_1st_time(self):
     file_name = 'TestTTF.ttx'
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, 'ttCompile')
     self.assertEqual(jobs[0][1:],
                     (os.path.join(self.tempdir, file_name),
                      os.path.join(self.tempdir, file_name.split('.')[0] + '.ttf')))
Пример #9
0
 def test_parseOptions_multiple_fonts(self):
     file_names = ['TestOTF.otf', 'TestTTF.ttf']
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [self.temp_font(font_path, file_name) \
                   for font_path, file_name in zip(font_paths, file_names)]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, 'ttDump')
         self.assertEqual(jobs[i][1:],
                 (os.path.join(self.tempdir, file_names[i]),
                  os.path.join(self.tempdir, file_names[i].split('.')[0] + '.ttx')))
Пример #10
0
 def test_parseOptions_multiple_fonts(self):
     file_names = ['TestOTF.otf', 'TestTTF.ttf']
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [self.temp_font(font_path, file_name) \
                   for font_path, file_name in zip(font_paths, file_names)]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, 'ttDump')
         self.assertEqual(jobs[i][1:],
                 (os.path.join(self.tempdir, file_names[i]),
                  os.path.join(self.tempdir, file_names[i].split('.')[0] + '.ttx')))
Пример #11
0
 def test_parseOptions_font2ttx_1st_time(self):
     file_name = "TestOTF.otf"
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, "ttDump")
     self.assertEqual(
         jobs[0][1:],
         (
             os.path.join(self.tempdir, file_name),
             os.path.join(self.tempdir, file_name.split(".")[0] + ".ttx"),
         ),
     )
Пример #12
0
 def test_parseOptions_mixed_files(self):
     operations = ['ttDump', 'ttCompile']
     extensions = ['.ttx', '.ttf']
     file_names = ['TestOTF.otf', 'TestTTF.ttx']
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [self.temp_font(font_path, file_name) \
                   for font_path, file_name in zip(font_paths, file_names)]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, operations[i])
         self.assertEqual(jobs[i][1:],
             (os.path.join(self.tempdir, file_names[i]),
              os.path.join(self.tempdir, file_names[i].split('.')[0] + extensions[i])))
Пример #13
0
 def test_parseOptions_mixed_files(self):
     operations = ['ttDump', 'ttCompile']
     extensions = ['.ttx', '.ttf']
     file_names = ['TestOTF.otf', 'TestTTF.ttx']
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [self.temp_font(font_path, file_name) \
                   for font_path, file_name in zip(font_paths, file_names)]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, operations[i])
         self.assertEqual(jobs[i][1:],
             (os.path.join(self.tempdir, file_names[i]),
              os.path.join(self.tempdir, file_names[i].split('.')[0] + extensions[i])))
Пример #14
0
 def test_parseOptions_font2ttx_1st_time(self):
     file_name = "TestOTF.otf"
     font_path = self.getpath(file_name)
     temp_path = self.temp_font(font_path, file_name)
     jobs, _ = ttx.parseOptions([temp_path])
     self.assertEqual(jobs[0][0].__name__, "ttDump")
     self.assertEqual(
         jobs[0][1:],
         (
             os.path.join(self.tempdir, file_name),
             os.path.join(self.tempdir, file_name.split(".")[0] + ".ttx"),
         ),
     )
Пример #15
0
 def test_parseOptions_multiple_fonts(self):
     file_names = ["TestOTF.otf", "TestTTF.ttf"]
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [
         self.temp_font(font_path, file_name)
         for font_path, file_name in zip(font_paths, file_names)
     ]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, "ttDump")
         self.assertEqual(
             jobs[i][1:],
             (
                 os.path.join(self.tempdir, file_names[i]),
                 os.path.join(self.tempdir,
                              file_names[i].split(".")[0] + ".ttx"),
             ),
         )
Пример #16
0
    def test_parseOptions_splitGlyphs(self):
        file_name = "TestTTF.ttf"
        font_path = self.getpath(file_name)
        temp_path = self.temp_font(font_path, file_name)
        args = ["-g", temp_path]

        jobs, options = ttx.parseOptions(args)

        ttx_file_path = jobs[0][2]
        temp_folder = os.path.dirname(ttx_file_path)
        self.assertTrue(options.splitGlyphs)
        # splitGlyphs also forces splitTables
        self.assertTrue(options.splitTables)
        self.assertTrue(os.path.exists(ttx_file_path))

        ttx.process(jobs, options)

        # Read the TTX file but strip the first two and the last lines:
        # <?xml version="1.0" encoding="UTF-8"?>
        # <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.22">
        # ...
        # </ttFont>
        for item in parseXML(self.read_file(ttx_file_path)[2:-1]):
            if not isinstance(item, tuple):
                continue
            # the tuple looks like this:
            # (u'head', {u'src': u'TestTTF._h_e_a_d.ttx'}, [])
            table_tag = item[0]
            table_file_name = item[1].get("src")
            table_file_path = os.path.join(temp_folder, table_file_name)
            self.assertTrue(os.path.exists(table_file_path))
            if table_tag != "glyf":
                continue
            # also strip the enclosing 'glyf' element
            for item in parseXML(self.read_file(table_file_path)[4:-3]):
                if not isinstance(item, tuple):
                    continue
                # glyphs without outline data only have 'name' attribute
                glyph_file_name = item[1].get("src")
                if glyph_file_name is not None:
                    glyph_file_path = os.path.join(temp_folder,
                                                   glyph_file_name)
                    self.assertTrue(os.path.exists(glyph_file_path))
Пример #17
0
 def test_parseOptions_multiple_fonts(self):
     file_names = ["TestOTF.otf", "TestTTF.ttf"]
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [
         self.temp_font(font_path, file_name)
         for font_path, file_name in zip(font_paths, file_names)
     ]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, "ttDump")
         self.assertEqual(
             jobs[i][1:],
             (
                 os.path.join(self.tempdir, file_names[i]),
                 os.path.join(
                     self.tempdir, file_names[i].split(".")[0] + ".ttx"
                 ),
             ),
         )
Пример #18
0
    def test_parseOptions_splitGlyphs(self):
        file_name = "TestTTF.ttf"
        font_path = self.getpath(file_name)
        temp_path = self.temp_font(font_path, file_name)
        args = ["-g", temp_path]

        jobs, options = ttx.parseOptions(args)

        ttx_file_path = jobs[0][2]
        temp_folder = os.path.dirname(ttx_file_path)
        self.assertTrue(options.splitGlyphs)
        # splitGlyphs also forces splitTables
        self.assertTrue(options.splitTables)
        self.assertTrue(os.path.exists(ttx_file_path))

        ttx.process(jobs, options)

        # Read the TTX file but strip the first two and the last lines:
        # <?xml version="1.0" encoding="UTF-8"?>
        # <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.22">
        # ...
        # </ttFont>
        for item in parseXML(self.read_file(ttx_file_path)[2:-1]):
            if not isinstance(item, tuple):
                continue
            # the tuple looks like this:
            # (u'head', {u'src': u'TestTTF._h_e_a_d.ttx'}, [])
            table_tag = item[0]
            table_file_name = item[1].get("src")
            table_file_path = os.path.join(temp_folder, table_file_name)
            self.assertTrue(os.path.exists(table_file_path))
            if table_tag != "glyf":
                continue
            # also strip the enclosing 'glyf' element
            for item in parseXML(self.read_file(table_file_path)[4:-3]):
                if not isinstance(item, tuple):
                    continue
                # glyphs without outline data only have 'name' attribute
                glyph_file_name = item[1].get("src")
                if glyph_file_name is not None:
                    glyph_file_path = os.path.join(temp_folder, glyph_file_name)
                    self.assertTrue(os.path.exists(glyph_file_path))
Пример #19
0
 def test_parseOptions_mixed_files(self):
     operations = ["ttDump", "ttCompile"]
     extensions = [".ttx", ".ttf"]
     file_names = ["TestOTF.otf", "TestTTF.ttx"]
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [
         self.temp_font(font_path, file_name)
         for font_path, file_name in zip(font_paths, file_names)
     ]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, operations[i])
         self.assertEqual(
             jobs[i][1:],
             (
                 os.path.join(self.tempdir, file_names[i]),
                 os.path.join(
                     self.tempdir,
                     file_names[i].split(".")[0] + extensions[i],
                 ),
             ),
         )
Пример #20
0
 def test_parseOptions_mixed_files(self):
     operations = ["ttDump", "ttCompile"]
     extensions = [".ttx", ".ttf"]
     file_names = ["TestOTF.otf", "TestTTF.ttx"]
     font_paths = [self.getpath(file_name) for file_name in file_names]
     temp_paths = [
         self.temp_font(font_path, file_name)
         for font_path, file_name in zip(font_paths, file_names)
     ]
     jobs, _ = ttx.parseOptions(temp_paths)
     for i in range(len(jobs)):
         self.assertEqual(jobs[i][0].__name__, operations[i])
         self.assertEqual(
             jobs[i][1:],
             (
                 os.path.join(self.tempdir, file_names[i]),
                 os.path.join(
                     self.tempdir,
                     file_names[i].split(".")[0] + extensions[i],
                 ),
             ),
         )
Пример #21
0
 def test_parseOptions_no_args(self):
     with self.assertRaises(getopt.GetoptError) as cm:
         ttx.parseOptions([])
     self.assertTrue('Must specify at least one input file' in str(cm.exception))
Пример #22
0
 def test_parseOptions_invalid_path(self):
     file_path = "invalid_font_path"
     with self.assertRaises(getopt.GetoptError) as cm:
         ttx.parseOptions([file_path])
     self.assertTrue('File not found: "%s"' % file_path in str(cm.exception))
Пример #23
0
 def test_parseOptions_no_args(self):
     with self.assertRaises(getopt.GetoptError) as cm:
         ttx.parseOptions([])
     self.assertTrue(
         "Must specify at least one input file" in str(cm.exception)
     )
Пример #24
0
    for theme in THEMES:
        external_font_file = get_font_file(theme['font_family'])
        local_font_file = theme['name'] + os.path.splitext(
            urlparse(external_font_file).path)[1]
        font_files[theme['name']] = local_font_file
        open(local_font_file, 'wb').write(urlopen(external_font_file).read())

    print('Extracting font glyphs...')

    icons = {}
    theme_icons_mapping = {}

    for theme in THEMES:
        ttx.process(
            *ttx.parseOptions(['-f', '-t', 'GSUB', font_files[theme['name']]]))

        tree = etree.parse('{}.ttx'.format(theme['name']))
        theme_icons = []

        for ligature_set in tree.findall(
                '/GSUB/LookupList/Lookup/LigatureSubst/LigatureSet'):
            for ligature in ligature_set.findall('Ligature'):
                icon_name = fix_ligature_name(ligature_set.attrib['glyph']) \
                    + fix_ligature_name(ligature.attrib['components'])
                icon_codepoint = convert_glyph_unicode(
                    ligature.attrib['glyph'])

                if icon_name not in icons:
                    icons[icon_name] = icon_codepoint
Пример #25
0
 def test_parseOptions_invalid_path(self):
     file_path = 'invalid_font_path'
     with self.assertRaises(getopt.GetoptError) as cm:
         ttx.parseOptions([file_path])
     self.assertTrue('File not found: "%s"' % file_path in str(cm.exception))