def __init__(self, target, test, incremental, emit_config, ignored_cp, only_cp, enabled_tests): self.target = target self.test = test self.incremental = incremental # target is different version of same file self.emit_config = emit_config # generate config lines self.enabled_tests = enabled_tests or FontCompare.test_names self.target_cmap = font_data.get_cmap(target) self.test_cmap = font_data.get_cmap(test) target_chars = set(self.target_cmap.keys()) - _get_excluded_chars() if ignored_cp: target_chars -= ignored_cp if only_cp: target_chars &= only_cp self.target_chars = target_chars # Assume version has two decimal places, which MTI fonts do but Adobe's do not. target_version = font_data.printable_font_revision(target) test_version = font_data.printable_font_revision(test) target_names = font_data.get_name_records(target) test_names = font_data.get_name_records(test) self._log('target name: %s %s, version: %s' % (target_names[1], target_names[2], target_version)) self._log('test name: %s %s, version %s' % (test_names[1], test_names[2], test_version)) if emit_config: font_family = test_names[1] font_subfamily = test_names[2].replace(' ', '') self._config('name like %s; weight like %s; version == %s' % (font_family, font_subfamily, test_version))
def __init__(self, target, test, incremental, emit_config, ignored_cp, only_cp, enabled_tests): self.target = target self.test = test self.incremental = incremental # target is different version of same file self.emit_config = emit_config # generate config lines self.enabled_tests = enabled_tests or FontCompare.test_names self.target_cmap = font_data.get_cmap(target) self.test_cmap = font_data.get_cmap(test) target_chars = set(self.target_cmap.keys()) - _get_excluded_chars() if ignored_cp: target_chars -= ignored_cp if only_cp: target_chars &= only_cp self.target_chars = target_chars # Assume version has two decimal places, which MTI fonts do but Adobe's do not. target_version = font_data.printable_font_revision(target) test_version = font_data.printable_font_revision(test) target_names = font_data.get_name_records(target) test_names = font_data.get_name_records(test) self._log('target name: %s %s, version: %s' % (target_names[1], target_names[2], target_version)) self._log('test name: %s %s, version %s' % (test_names[1], test_names[2], test_version)) if emit_config: font_family = test_names[1] font_subfamily = test_names[2].replace(' ', '') self._config('name like %s; weight like %s; version == %s' % (font_family, font_subfamily, test_version))
def summarize_file(root, path): font = ttLib.TTFont(path) table_info = {} reader = font.reader for tag in reader.keys(): entry = reader.tables[tag] entry_len = entry.length entry_checkSum = int(entry.checkSum) if entry_checkSum < 0: entry_checkSum += 0x100000000 table_info[tag] = (entry_len, entry_checkSum) relpath = path[len(root) + 1:] size = os.path.getsize(path) # Printable_font_revision requires you specify the accuracy of digits. # ttLib apparently reads the fixed values as a float, so it loses the info. # Adobe fonts use 3 digits, so the default from printable_font_revision of 2 # is insufficient. # Assume that the name from the name table is accurate, and use it instead. version_string = noto_lint.font_version(font) match = re.match(r'Version (\d+\.\d+)', version_string) if match: version = match.group(1) else: version = noto_lint.printable_font_revision(font) # default 2 num_glyphs = len(font.getGlyphOrder()) full_name = font_data.get_name_records(font)[4] cmap = set( get_largest_cmap(font).keys()) # copy needed? what's the lifespan? num_chars = len(cmap) font.close() return (relpath, version, full_name, size, num_glyphs, num_chars, cmap, table_info)
def fix_name_table(font): """Fix copyright and reversed values in the 'name' table.""" modified = False name_records = font_data.get_name_records(font) copyright_data = name_records[0] years = re.findall('20[0-9][0-9]', copyright_data) year = min(years) copyright_data = u'Copyright %s Google Inc. All Rights Reserved.' % year if copyright_data != name_records[0]: print 'Updated copyright message to "%s"' % copyright_data font_data.set_name_record(font, 0, copyright_data) modified = True for name_id in [1, 3, 4, 6]: record = name_records[name_id] for source in NAME_CORRECTIONS: if source in record: record = record.replace(source, NAME_CORRECTIONS[source]) if record != name_records[name_id]: font_data.set_name_record(font, name_id, record) print 'Updated name table record #%d to "%s"' % ( name_id, record) modified = True if name_records.has_key(16): font_data.set_name_record(font, 16, None) print 'Name table record #16 dropped' modified = True return modified
def summarize_file(root, path): font = ttLib.TTFont(path) table_info = {} reader = font.reader for tag in reader.keys(): entry = reader.tables[tag] entry_len = entry.length entry_checkSum = int(entry.checkSum) if entry_checkSum < 0: entry_checkSum += 0x100000000 table_info[tag] = (entry_len, entry_checkSum) relpath = path[len(root) + 1:] size = os.path.getsize(path) # Printable_font_revision requires you specify the accuracy of digits. # ttLib apparently reads the fixed values as a float, so it loses the info. # Adobe fonts use 3 digits, so the default from printable_font_revision of 2 # is insufficient. # Assume that the name from the name table is accurate, and use it instead. version_string = noto_lint.font_version(font); match = re.match(r'Version (\d+\.\d+)', version_string) if match: version = match.group(1) else: version = noto_lint.printable_font_revision(font) # default 2 num_glyphs = len(font.getGlyphOrder()) full_name = font_data.get_name_records(font)[4] cmap = set(get_largest_cmap(font).keys()) # copy needed? what's the lifespan? num_chars = len(cmap) font.close() return (relpath, version, full_name, size, num_glyphs, num_chars, cmap, table_info)
def fix_name_table(font): """Fix copyright and reversed values in the 'name' table.""" modified = False name_records = font_data.get_name_records(font) copyright_data = name_records[0] years = re.findall('20[0-9][0-9]', copyright_data) year = min(years) copyright_data = u'Copyright %s Google Inc. All Rights Reserved.' % year if copyright_data != name_records[0]: print 'Updated copyright message to "%s"' % copyright_data font_data.set_name_record(font, 0, copyright_data) modified = True for name_id in [1, 3, 4, 6]: record = name_records[name_id] for source in NAME_CORRECTIONS: if source in record: record = record.replace(source, NAME_CORRECTIONS[source]) if record != name_records[name_id]: font_data.set_name_record(font, name_id, record) print 'Updated name table record #%d to "%s"' % (name_id, record) modified = True if name_records.has_key(16): font_data.set_name_record(font, 16, None) print 'Name table record #16 dropped' modified = True return modified
def get_font_family_name(font_file): font = ttLib.TTFont(font_file) name_record = font_data.get_name_records(font) return name_record[1]
def get_font_family_name(font_file): font = ttLib.TTFont(font_file) name_record = font_data.get_name_records(font) return name_record[1]