def test_check_names_same_across_platforms(self):
        """ Font names are same across specific-platforms """
        font = Font.get_ttfont(self.path)

        for name in font.names:
            for name2 in font.names:
                if name.nameID != name2.nameID:
                    continue

                if self.diff_platform(name, name2) or self.diff_platform(name2, name):
                    _name = Font.bin2unistring(name)
                    _name2 = Font.bin2unistring(name2)
                    if _name != _name2:
                        msg = ('Names in "name" table are not the same'
                               ' across specific-platforms')
                        self.fail(msg)
    def test_check_names_are_ascii_only(self):
        """ NAME and CFF tables must not contain non-ascii characters """
        font = Font.get_ttfont(self.path)

        for name_record in font.names:
            string = Font.bin2unistring(name_record)
            try:
                string.encode('ascii')
            except UnicodeEncodeError:
                self.fail("%s contain non-ascii chars" % name_record.nameID)
    def test_check_full_font_name_begins_with_family_name(self):
        """ Check if full font name begins with the font family name """
        font = Font.get_ttfont(self.path)
        for entry in font.names:
            if entry.nameID != 1:
                continue
            for entry2 in font.names:
                if entry2.nameID != 4:
                    continue
                if (entry.platformID == entry2.platformID
                        and entry.platEncID == entry2.platEncID
                        and entry.langID == entry2.langID):

                    entry2value = Font.bin2unistring(entry2)
                    entryvalue = Font.bin2unistring(entry)
                    if not entry2value.startswith(entryvalue):
                        _ = ('Full font name does not begin with family'
                             ' name: FontFamilyName = "%s";'
                             ' FullFontName = "%s"')
                        self.fail(_ % (entryvalue, entry2value))
예제 #4
0
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
import os
import sys

from fontTools.ttLib import TTLibError


def fix_name_table(fontfile):
    from cli.ttfont import Font
    try:
        font = Font(fontfile)
    except TTLibError, ex:
        print >> sys.stderr, "ERROR: %s" % ex
        return
    for name_record in font['name'].names:
        name_record.string = Font.bin2unistring(name_record.string)
    font.save(fontfile + '.fix')


if __name__ == '__main__':
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('filename', help="Font file in TTF format")

    args = parser.parse_args()
    assert os.path.exists(args.filename)
    fix_name_table(args.filename)
 def find_italic_in_name_table(self, ttfont):
     for entry in ttfont.names:
         if 'italic' in Font.bin2unistring(entry).lower():
             return True