def generate_table(filename): with codecs.open(filename, "w", "utf-8") as f: script_to_samples = _get_script_to_samples() f.write(_HTML_HEADER) f.write("<table>\n") f.write("<tr><th>Script<br/>BCP<th>name<th>type<th>text\n") for script, samples in sorted(script_to_samples.items()): script_en = cldr_data.get_english_script_name(script) f.write("<tr><th colspan=4>%s\n" % script_en) for bcp, sample_type, sample_text in samples: try: lsrv = cldr_data.loc_tag_to_lsrv(bcp) lsrv = (lsrv[0], None, lsrv[2], lsrv[3]) bcp_no_script = cldr_data.lsrv_to_loc_tag(lsrv) bcp_en = cldr_data.get_english_language_name(bcp_no_script) if not bcp_en: bcp_en = "No name" if bcp_en == "Unknown Language" and sample_type == "chars": bcp_en = "(characters)" except: print("could not get english name for %s" % bcp) bcp_en = bcp cols = ["<tr>"] cols.append(bcp_no_script) cols.append(bcp_en) cols.append(sample_type) cols.append(sample_text) f.write("<td>".join(cols) + "\n") f.write("<tr><td colspan=4> \n") f.write("</table>\n") f.write(_HTML_FOOTER + "\n")
def _create_lang_script_to_names(lang_script_data): """Generate a map from lang-script to English (and possibly native) names. Whether the script is included in the name depends on the number of used and unused scripts. If there's one used script, that script is omitted. Else if there's no used script and one unused script, that script is omitted. Else the script is included. If there's no English name for the lang_script, it is excluded.""" lang_to_names = {} for lang in lang_script_data: used, unused = lang_script_data[lang] if len(used) == 1: exclude_script = iter(used).next() elif not used and len(unused) == 1: exclude_script = iter(unused).next() else: exclude_script = '' for script in (used | unused): lang_script = lang + '-' + script target = lang if script == exclude_script else lang_script # special case, not generally useful if target.startswith('und-'): en_name = cldr_data.get_english_script_name(target[4:]) + ' script' else: en_name = cldr_data.get_english_language_name(target) if not en_name: print '!No english name for %s' % lang_script continue native_name = cldr_data.get_native_language_name(lang_script, exclude_script) if native_name == en_name: native_name = None lang_to_names[lang_script] = [en_name, native_name] if native_name else [en_name] return lang_to_names
def generate_table(filename): with codecs.open(filename, 'w', 'utf-8') as f: script_to_samples = _get_script_to_samples() print >> f, _HTML_HEADER print >> f, '<table>' print >> f, '<tr><th>Script<br/>BCP<th>name<th>type<th>text' for script, samples in sorted(script_to_samples.iteritems()): script_en = cldr_data.get_english_script_name(script) print >> f, '<tr><th colspan=4>%s' % script_en for bcp, sample_type, sample_text in samples: try: lsrv = cldr_data.loc_tag_to_lsrv(bcp) lsrv = (lsrv[0], None, lsrv[2], lsrv[3]) bcp_no_script = cldr_data.lsrv_to_loc_tag(lsrv) bcp_en = cldr_data.get_english_language_name(bcp_no_script) if not bcp_en: bcp_en = 'No name' if bcp_en == 'Unknown Language' and sample_type == 'chars': bcp_en = '(characters)' except: print 'could not get english name for %s' % bcp bcp_en = bcp cols = ['<tr>'] cols.append(bcp_no_script) cols.append(bcp_en) cols.append(sample_type) cols.append(sample_text) print >> f, '<td>'.join(cols) print >> f, '<tr><td colspan=4> ' print >> f, '</table>' print >> f, _HTML_FOOTER
def _create_lang_script_to_names(lang_script_data): """Generate a map from lang-script to English (and possibly native) names. Whether the script is included in the name depends on the number of used and unused scripts. If there's one used script, that script is omitted. Else if there's no used script and one unused script, that script is omitted. Else the script is included. If there's no English name for the lang_script, it is excluded. """ lang_to_names = {} for lang in lang_script_data: used, unused = lang_script_data[lang] if len(used) == 1: exclude_script = iter(used).next() elif not used and len(unused) == 1: exclude_script = iter(unused).next() else: exclude_script = '' for script in (used | unused): lang_script = lang + '-' + script target = lang if script == exclude_script else lang_script # special case, not generally useful if target.startswith('und-'): en_name = cldr_data.get_english_script_name( target[4:]) + ' script' else: en_name = cldr_data.get_english_language_name(target) if not en_name: # Easier than patching the cldr_data, not sure I want to go there. if lang_script == 'tlh-Piqd': en_name = u'Klingon' else: _log('No english name for %s' % lang_script) continue native_name = cldr_data.get_native_language_name( lang_script, exclude_script) if native_name == en_name: native_name = None lang_to_names[lang_script] = ([en_name, native_name] if native_name else [en_name]) return lang_to_names
def preferred_script_name(script_key): # Returns the script_key if we have nothing else. try: return unicode_data.human_readable_script_name(script_key) except: return cldr_data.get_english_script_name(script_key)
def preferred_script_name(script_key): try: return unicode_data.human_readable_script_name(script_key) except: return cldr_data.get_english_script_name(script_key)
def script_key(script): return (_SCRIPT_KEYS.get(script, None) or cldr_data.get_english_script_name(script))
def _swat_font(noto_font, dst_root, dry_run): filepath = noto_font.filepath basename = path.basename(filepath) if noto_font.is_cjk: print '# Skipping cjk font %s' % basename return if noto_font.fmt == 'ttc': print '# Deferring ttc font %s' % basename _ttc_fonts[noto_font] = ttc_utils.ttcfile_filenames(filepath) return ttfont = ttLib.TTFont(filepath, fontNumber=0) names = font_data.get_name_records(ttfont) # create relative root path rel_filepath = _noto_relative_path(filepath) if not rel_filepath: raise ValueError('Could not identify noto root of %s' % filepath) print '-----\nUpdating %s' % rel_filepath dst_file = path.join(dst_root, rel_filepath) version = names[_VERSION_ID] m = re.match(r'Version (\d{1,5})\.(\d{1,5})(.*)', version) if not m: print '! Could not match version string (%s)' % version return major_version = m.group(1) minor_version = m.group(2) version_remainder = m.group(3) accuracy = len(minor_version) print_revision = font_data.printable_font_revision(ttfont, accuracy) # sanity check expected_revision = major_version + '.' + minor_version if expected_revision != print_revision: print '! Expected revision \'%s\' but got revision \'%s\'' % ( expected_revision, print_revision) return # bump the minor version keeping significant digits: new_minor_version = str(int(minor_version) + 1).zfill(accuracy) new_revision = major_version + '.' + new_minor_version print 'Update revision from \'%s\' to \'%s\'' % (expected_revision, new_revision) # double check we are going to properly round-trip this value float_revision = float(new_revision) fixed_revision = misc.fixedTools.floatToFixed(float_revision, 16) rt_float_rev = misc.fixedTools.fixedToFloat(fixed_revision, 16) rt_float_rev_int = int(rt_float_rev) rt_float_rev_frac = int( round((rt_float_rev - rt_float_rev_int) * 10**accuracy)) rt_new_revision = (str(rt_float_rev_int) + '.' + str(rt_float_rev_frac).zfill(accuracy)) if new_revision != rt_new_revision: print '! Could not update new revision, expected \'%s\' but got \'%s\'' % ( new_revision, rt_new_revision) return new_version_string = 'Version ' + new_revision if not noto_font.is_hinted: new_version_string += ' uh' print '%s: %s' % ('Would write' if dry_run else 'Writing', dst_file) new_trademark = "%s is a trademark of Google Inc." % noto_font.family # description field should be set. # Roozbeh has note, make sure design field has information # on whether the font is hinted. # Missing in Lao and Khmer, default in Cham. if (cldr_data.get_english_script_name(noto_font.script) in ['Lao', 'Khmer', 'Cham']): new_description = 'Data %shinted.' % ('' if noto_font.is_hinted else 'un') # elif noto_font.vendor is 'Monotype': elif not noto_font.is_cjk and noto_font.family == 'Noto': new_description = ('Data %shinted. Designed by Monotype design team.' % ('' if noto_font.is_hinted else 'un')) else: new_description = None if re.match(r'^Copyright 201\d Google Inc. All Rights Reserved\.$', names[_COPYRIGHT_ID]): new_copyright = None else: new_copyright = '!!' if names.get(_DESIGNER_ID) in [ 'Steve Matteson', 'Monotype Design Team', 'Danh Hong', ]: new_designer = None elif names.get(_DESIGNER_ID) == 'Monotype Design team': new_designer = 'Monotype Design Team' elif (_DESIGNER_ID not in names and cldr_data.get_english_script_name(noto_font.script) == 'Khmer'): new_designer = 'Danh Hong' else: new_designer = '!!' if names.get(_DESIGNER_URL_ID) in [ 'http://www.monotype.com/studio', 'http://www.khmertype.org', ]: new_designer_url = None elif names.get(_DESIGNER_URL_ID) in [ 'http://www.monotypeimaging.com/ProductsServices/TypeDesignerShowcase', ]: new_designer_url = 'http://www.monotype.com/studio' elif names.get(_DESIGNER_URL_ID) in [ 'http://www.khmertype.blogspot.com', 'http://www.khmertype.blogspot.com/', 'http://khmertype.blogspot.com/', 'http://wwwkhmertype.blogspot.com.com/', ]: new_designer_url = 'http://www.khmertype.org' else: new_designer_url = '!!!' if names.get(_MANUFACTURER_ID) in [ 'Monotype Imaging Inc.', 'Danh Hong', ]: new_manufacturer = None else: new_manufacturer = '!!!' def update(name_id, new, newText=None): old = names.get(name_id) if new and (new != old): if not dry_run and not '!!!' in new: font_data.set_name_record(ttfont, name_id, new, addIfMissing='win') label = _NAME_ID_LABELS[name_id] oldText = '\'%s\'' % old if old else 'None' newText = newText or ('\'%s\'' % new) print '%s:\n old: %s\n new: %s' % (label, oldText, newText or new) label_change = _changes.get(label) if not label_change: label_change = {} _changes[label] = label_change new_val_change = label_change.get(new) if not new_val_change: new_val_change = {} label_change[new] = new_val_change old_val_fonts = new_val_change.get(old) if not old_val_fonts: old_val_fonts = [] new_val_change[old] = old_val_fonts old_val_fonts.append(noto_font.filepath) update(_COPYRIGHT_ID, new_copyright) update(_VERSION_ID, new_version_string) update(_TRADEMARK_ID, new_trademark) update(_MANUFACTURER_ID, new_manufacturer) update(_DESIGNER_ID, new_designer) update(_DESCRIPTION_ID, new_description) update(_VENDOR_URL_ID, _NOTO_URL) update(_DESIGNER_URL_ID, new_designer_url) update(_LICENSE_ID, _SIL_LICENSE, newText='(OFL)') update(_LICENSE_URL_ID, _SIL_LICENSE_URL) if autofix_for_release.fix_fstype(ttfont): _autofix['fstype'].append(noto_font.filepath) if autofix_for_release.fix_vendor_id(ttfont): _autofix['vendor_id'].append(noto_font.filepath) if autofix_for_release.fix_attachlist(ttfont): _autofix['attachlist'].append(noto_font.filepath) if noto_font.is_hinted: tables_to_drop = _HINTED_TABLES_TO_DROP else: tables_to_drop = _UNHINTED_TABLES_TO_DROP if autofix_for_release.drop_hints(ttfont): _autofix['drop_hints'].append(noto_font.filepath) if autofix_for_release.drop_tables(ttfont, tables_to_drop): _autofix['drop_tables'].append(noto_font.filepath) if noto_font.family == 'Noto': if autofix_for_release.fix_linegap(ttfont): _autofix['linegap'].append(noto_font.filepath) if autofix_for_release.fix_os2_unicoderange(ttfont): _autofix['os2_unicoderange'].append(noto_font.filepath) if dry_run: return ttfont['head'].fontRevision = float_revision dst_dir = path.dirname(dst_file) if not path.isdir(dst_dir): os.makedirs(dst_dir) ttfont.save(dst_file) print 'Wrote file.'
def preferred_script_name(script_key): try: return unicode_data.human_readable_script_name(script_key) except KeyError: return cldr_data.get_english_script_name(script_key)
def _swat_font(noto_font, dst_root, dry_run): filepath = noto_font.filepath basename = path.basename(filepath) if noto_font.is_cjk: print '# Skipping cjk font %s' % basename return if noto_font.fmt == 'ttc': print '# Deferring ttc font %s' % basename _ttc_fonts[noto_font] = ttc_utils.ttcfile_filenames(filepath) return ttfont = ttLib.TTFont(filepath, fontNumber=0) names = font_data.get_name_records(ttfont) # create relative root path rel_filepath = _noto_relative_path(filepath) if not rel_filepath: raise ValueError('Could not identify noto root of %s' % filepath) print '-----\nUpdating %s' % rel_filepath dst_file = path.join(dst_root, rel_filepath) version = names[_VERSION_ID] m = re.match(r'Version (\d{1,5})\.(\d{1,5})(.*)', version) if not m: print '! Could not match version string (%s)' % version return major_version = m.group(1) minor_version = m.group(2) version_remainder = m.group(3) accuracy = len(minor_version) print_revision = font_data.printable_font_revision(ttfont, accuracy) # sanity check expected_revision = major_version + '.' + minor_version if expected_revision != print_revision: print '! Expected revision \'%s\' but got revision \'%s\'' % ( expected_revision, print_revision) return # bump the minor version keeping significant digits: new_minor_version = str(int(minor_version) + 1).zfill(accuracy) new_revision = major_version + '.' + new_minor_version print 'Update revision from \'%s\' to \'%s\'' % ( expected_revision, new_revision) # double check we are going to properly round-trip this value float_revision = float(new_revision) fixed_revision = misc.fixedTools.floatToFixed(float_revision, 16) rt_float_rev = misc.fixedTools.fixedToFloat(fixed_revision, 16) rt_float_rev_int = int(rt_float_rev) rt_float_rev_frac = int(round((rt_float_rev - rt_float_rev_int) * 10 ** accuracy)) rt_new_revision = (str(rt_float_rev_int) + '.' + str(rt_float_rev_frac).zfill(accuracy)) if new_revision != rt_new_revision: print '! Could not update new revision, expected \'%s\' but got \'%s\'' % ( new_revision, rt_new_revision) return new_version_string = 'Version ' + new_revision if not noto_font.is_hinted: new_version_string += ' uh' print '%s: %s' % ('Would write' if dry_run else 'Writing', dst_file) new_trademark = "%s is a trademark of Google Inc." % noto_font.family # description field should be set. # Roozbeh has note, make sure design field has information # on whether the font is hinted. # Missing in Lao and Khmer, default in Cham. if (cldr_data.get_english_script_name(noto_font.script) in ['Lao', 'Khmer', 'Cham']): new_description = 'Data %shinted.' % ('' if noto_font.is_hinted else 'un') # elif noto_font.vendor is 'Monotype': elif not noto_font.is_cjk and noto_font.family == 'Noto': new_description = ( 'Data %shinted. Designed by Monotype design team.' % ('' if noto_font.is_hinted else 'un')) else: new_description = None if re.match(r'^Copyright 201\d Google Inc. All Rights Reserved\.$', names[_COPYRIGHT_ID]): new_copyright = None else: new_copyright = '!!' if names.get(_DESIGNER_ID) in [ 'Steve Matteson', 'Monotype Design Team', 'Danh Hong', ]: new_designer = None elif names.get(_DESIGNER_ID) == 'Monotype Design team': new_designer = 'Monotype Design Team' elif (_DESIGNER_ID not in names and cldr_data.get_english_script_name(noto_font.script) == 'Khmer'): new_designer = 'Danh Hong' else: new_designer = '!!' if names.get(_DESIGNER_URL_ID) in [ 'http://www.monotype.com/studio', 'http://www.khmertype.org', ]: new_designer_url = None elif names.get(_DESIGNER_URL_ID) in [ 'http://www.monotypeimaging.com/ProductsServices/TypeDesignerShowcase', ]: new_designer_url = 'http://www.monotype.com/studio' elif names.get(_DESIGNER_URL_ID) in [ 'http://www.khmertype.blogspot.com', 'http://www.khmertype.blogspot.com/', 'http://khmertype.blogspot.com/', 'http://wwwkhmertype.blogspot.com.com/', ]: new_designer_url = 'http://www.khmertype.org' else: new_designer_url = '!!!' if names.get(_MANUFACTURER_ID) in [ 'Monotype Imaging Inc.', 'Danh Hong', ]: new_manufacturer = None else: new_manufacturer = '!!!' def update(name_id, new, newText=None): old = names.get(name_id) if new and (new != old): if not dry_run and not '!!!' in new: font_data.set_name_record(ttfont, name_id, new, addIfMissing='win') label = _NAME_ID_LABELS[name_id] oldText = '\'%s\'' % old if old else 'None' newText = newText or ('\'%s\'' % new) print '%s:\n old: %s\n new: %s' % (label, oldText, newText or new) label_change = _changes.get(label) if not label_change: label_change = {} _changes[label] = label_change new_val_change = label_change.get(new) if not new_val_change: new_val_change = {} label_change[new] = new_val_change old_val_fonts = new_val_change.get(old) if not old_val_fonts: old_val_fonts = [] new_val_change[old] = old_val_fonts old_val_fonts.append(noto_font.filepath) update(_COPYRIGHT_ID, new_copyright) update(_VERSION_ID, new_version_string) update(_TRADEMARK_ID, new_trademark) update(_MANUFACTURER_ID, new_manufacturer) update(_DESIGNER_ID, new_designer) update(_DESCRIPTION_ID, new_description) update(_VENDOR_URL_ID, _NOTO_URL) update(_DESIGNER_URL_ID, new_designer_url) update(_LICENSE_ID, _SIL_LICENSE, newText='(OFL)') update(_LICENSE_URL_ID, _SIL_LICENSE_URL) if autofix_for_release.fix_fstype(ttfont): _autofix['fstype'].append(noto_font.filepath) if autofix_for_release.fix_vendor_id(ttfont): _autofix['vendor_id'].append(noto_font.filepath) if autofix_for_release.fix_attachlist(ttfont): _autofix['attachlist'].append(noto_font.filepath) if noto_font.is_hinted: tables_to_drop = _HINTED_TABLES_TO_DROP else: tables_to_drop = _UNHINTED_TABLES_TO_DROP if autofix_for_release.drop_hints(ttfont): _autofix['drop_hints'].append(noto_font.filepath) if autofix_for_release.drop_tables(ttfont, tables_to_drop): _autofix['drop_tables'].append(noto_font.filepath) if noto_font.family == 'Noto': if autofix_for_release.fix_linegap(ttfont): _autofix['linegap'].append(noto_font.filepath) if autofix_for_release.fix_os2_unicoderange(ttfont): _autofix['os2_unicoderange'].append(noto_font.filepath) if dry_run: return ttfont['head'].fontRevision = float_revision dst_dir = path.dirname(dst_file) if not path.isdir(dst_dir): os.makedirs(dst_dir) ttfont.save(dst_file) print 'Wrote file.'
def _swat_font(noto_font, dst_root, dry_run): filepath = noto_font.filepath basename = path.basename(filepath) if noto_font.is_cjk: print('# Skipping cjk font %s' % basename) return if noto_font.fmt == 'ttc': print('# Deferring ttc font %s' % basename) _ttc_fonts[noto_font] = ttc_utils.ttcfile_filenames(filepath) return ttfont = ttLib.TTFont(filepath, fontNumber=0) names = font_data.get_name_records(ttfont) # create relative root path rel_filepath = _noto_relative_path(filepath) if not rel_filepath: raise ValueError('Could not identify noto root of %s' % filepath) print('-----\nUpdating %s' % rel_filepath) dst_file = path.join(dst_root, rel_filepath) try: new_revision, new_version_string = get_bumped_version( ttfont, noto_font.is_hinted) except ValueError as e: print(e) return print('%s: %s' % ('Would write' if dry_run else 'Writing', dst_file)) new_trademark = "%s is a trademark of Google Inc." % noto_font.family # description field should be set. # Roozbeh has note, make sure design field has information # on whether the font is hinted. # Missing in Lao and Khmer, default in Cham. if (cldr_data.get_english_script_name(noto_font.script) in ['Lao', 'Khmer', 'Cham']): new_description = 'Data %shinted.' % ('' if noto_font.is_hinted else 'un') # elif noto_font.vendor is 'Monotype': elif not noto_font.is_cjk and noto_font.family == 'Noto': new_description = ('Data %shinted. Designed by Monotype design team.' % ('' if noto_font.is_hinted else 'un')) else: new_description = None if re.match(r'^Copyright 201\d Google Inc. All Rights Reserved\.$', names[_COPYRIGHT_ID]): new_copyright = None else: new_copyright = '!!' if names.get(_DESIGNER_ID) in [ 'Steve Matteson', 'Monotype Design Team', 'Danh Hong', ]: new_designer = None elif names.get(_DESIGNER_ID) == 'Monotype Design team': new_designer = 'Monotype Design Team' elif (_DESIGNER_ID not in names and cldr_data.get_english_script_name(noto_font.script) == 'Khmer'): new_designer = 'Danh Hong' else: new_designer = '!!' if names.get(_DESIGNER_URL_ID) in [ 'http://www.monotype.com/studio', 'http://www.khmertype.org', ]: new_designer_url = None elif names.get(_DESIGNER_URL_ID) in [ 'http://www.monotypeimaging.com/ProductsServices/TypeDesignerShowcase', ]: new_designer_url = 'http://www.monotype.com/studio' elif names.get(_DESIGNER_URL_ID) in [ 'http://www.khmertype.blogspot.com', 'http://www.khmertype.blogspot.com/', 'http://khmertype.blogspot.com/', 'http://wwwkhmertype.blogspot.com.com/', ]: new_designer_url = 'http://www.khmertype.org' else: new_designer_url = '!!!' if names.get(_MANUFACTURER_ID) in [ 'Monotype Imaging Inc.', 'Danh Hong', ]: new_manufacturer = None else: new_manufacturer = '!!!' def update(name_id, new, newText=None): old = names.get(name_id) if new and (new != old): if not dry_run and not '!!!' in new: font_data.set_name_record(ttfont, name_id, new, addIfMissing='win') label = _NAME_ID_LABELS[name_id] oldText = '\'%s\'' % old if old else 'None' newText = newText or ('\'%s\'' % new) print('%s:\n old: %s\n new: %s' % (label, oldText, newText or new)) label_change = _changes.get(label) if not label_change: label_change = {} _changes[label] = label_change new_val_change = label_change.get(new) if not new_val_change: new_val_change = {} label_change[new] = new_val_change old_val_fonts = new_val_change.get(old) if not old_val_fonts: old_val_fonts = [] new_val_change[old] = old_val_fonts old_val_fonts.append(noto_font.filepath) update(_COPYRIGHT_ID, new_copyright) update(_VERSION_ID, new_version_string) update(_TRADEMARK_ID, new_trademark) update(_MANUFACTURER_ID, new_manufacturer) update(_DESIGNER_ID, new_designer) update(_DESCRIPTION_ID, new_description) update(_VENDOR_URL_ID, _NOTO_URL) update(_DESIGNER_URL_ID, new_designer_url) update(_LICENSE_ID, _SIL_LICENSE, newText='(OFL)') update(_LICENSE_URL_ID, _SIL_LICENSE_URL) if autofix_for_release.fix_fstype(ttfont): _autofix['fstype'].append(noto_font.filepath) if autofix_for_release.fix_vendor_id(ttfont): _autofix['vendor_id'].append(noto_font.filepath) if autofix_for_release.fix_attachlist(ttfont): _autofix['attachlist'].append(noto_font.filepath) if noto_font.is_hinted: tables_to_drop = _HINTED_TABLES_TO_DROP else: tables_to_drop = _UNHINTED_TABLES_TO_DROP if autofix_for_release.drop_hints(ttfont): _autofix['drop_hints'].append(noto_font.filepath) if autofix_for_release.drop_tables(ttfont, tables_to_drop): _autofix['drop_tables'].append(noto_font.filepath) if noto_font.family == 'Noto': if autofix_for_release.fix_linegap(ttfont): _autofix['linegap'].append(noto_font.filepath) if autofix_for_release.fix_os2_unicoderange(ttfont): _autofix['os2_unicoderange'].append(noto_font.filepath) if dry_run: return ttfont['head'].fontRevision = float_revision dst_dir = path.dirname(dst_file) if not path.isdir(dst_dir): os.makedirs(dst_dir) ttfont.save(dst_file) print('Wrote file.')
def _swat_font(noto_font, dst_root, dry_run): filepath = noto_font.filepath basename = path.basename(filepath) if noto_font.is_cjk: print '# Skipping cjk font %s' % basename return if noto_font.fmt == 'ttc': print '# Deferring ttc font %s' % basename _ttc_fonts[noto_font] = ttc_utils.ttcfile_filenames(filepath) return ttfont = ttLib.TTFont(filepath, fontNumber=0) names = font_data.get_name_records(ttfont) # create relative root path rel_filepath = _noto_relative_path(filepath) if not rel_filepath: raise ValueError('Could not identify noto root of %s' % filepath) print '-----\nUpdating %s' % rel_filepath dst_file = path.join(dst_root, rel_filepath) try: new_revision, new_version_string = get_bumped_version( ttfont, noto_font.is_hinted) except ValueError as e: print e return print '%s: %s' % ('Would write' if dry_run else 'Writing', dst_file) new_trademark = "%s is a trademark of Google Inc." % noto_font.family # description field should be set. # Roozbeh has note, make sure design field has information # on whether the font is hinted. # Missing in Lao and Khmer, default in Cham. if (cldr_data.get_english_script_name(noto_font.script) in ['Lao', 'Khmer', 'Cham']): new_description = 'Data %shinted.' % ('' if noto_font.is_hinted else 'un') # elif noto_font.vendor is 'Monotype': elif not noto_font.is_cjk and noto_font.family == 'Noto': new_description = ( 'Data %shinted. Designed by Monotype design team.' % ('' if noto_font.is_hinted else 'un')) else: new_description = None if re.match(r'^Copyright 201\d Google Inc. All Rights Reserved\.$', names[_COPYRIGHT_ID]): new_copyright = None else: new_copyright = '!!' if names.get(_DESIGNER_ID) in [ 'Steve Matteson', 'Monotype Design Team', 'Danh Hong', ]: new_designer = None elif names.get(_DESIGNER_ID) == 'Monotype Design team': new_designer = 'Monotype Design Team' elif (_DESIGNER_ID not in names and cldr_data.get_english_script_name(noto_font.script) == 'Khmer'): new_designer = 'Danh Hong' else: new_designer = '!!' if names.get(_DESIGNER_URL_ID) in [ 'http://www.monotype.com/studio', 'http://www.khmertype.org', ]: new_designer_url = None elif names.get(_DESIGNER_URL_ID) in [ 'http://www.monotypeimaging.com/ProductsServices/TypeDesignerShowcase', ]: new_designer_url = 'http://www.monotype.com/studio' elif names.get(_DESIGNER_URL_ID) in [ 'http://www.khmertype.blogspot.com', 'http://www.khmertype.blogspot.com/', 'http://khmertype.blogspot.com/', 'http://wwwkhmertype.blogspot.com.com/', ]: new_designer_url = 'http://www.khmertype.org' else: new_designer_url = '!!!' if names.get(_MANUFACTURER_ID) in [ 'Monotype Imaging Inc.', 'Danh Hong', ]: new_manufacturer = None else: new_manufacturer = '!!!' def update(name_id, new, newText=None): old = names.get(name_id) if new and (new != old): if not dry_run and not '!!!' in new: font_data.set_name_record(ttfont, name_id, new, addIfMissing='win') label = _NAME_ID_LABELS[name_id] oldText = '\'%s\'' % old if old else 'None' newText = newText or ('\'%s\'' % new) print '%s:\n old: %s\n new: %s' % (label, oldText, newText or new) label_change = _changes.get(label) if not label_change: label_change = {} _changes[label] = label_change new_val_change = label_change.get(new) if not new_val_change: new_val_change = {} label_change[new] = new_val_change old_val_fonts = new_val_change.get(old) if not old_val_fonts: old_val_fonts = [] new_val_change[old] = old_val_fonts old_val_fonts.append(noto_font.filepath) update(_COPYRIGHT_ID, new_copyright) update(_VERSION_ID, new_version_string) update(_TRADEMARK_ID, new_trademark) update(_MANUFACTURER_ID, new_manufacturer) update(_DESIGNER_ID, new_designer) update(_DESCRIPTION_ID, new_description) update(_VENDOR_URL_ID, _NOTO_URL) update(_DESIGNER_URL_ID, new_designer_url) update(_LICENSE_ID, _SIL_LICENSE, newText='(OFL)') update(_LICENSE_URL_ID, _SIL_LICENSE_URL) if autofix_for_release.fix_fstype(ttfont): _autofix['fstype'].append(noto_font.filepath) if autofix_for_release.fix_vendor_id(ttfont): _autofix['vendor_id'].append(noto_font.filepath) if autofix_for_release.fix_attachlist(ttfont): _autofix['attachlist'].append(noto_font.filepath) if noto_font.is_hinted: tables_to_drop = _HINTED_TABLES_TO_DROP else: tables_to_drop = _UNHINTED_TABLES_TO_DROP if autofix_for_release.drop_hints(ttfont): _autofix['drop_hints'].append(noto_font.filepath) if autofix_for_release.drop_tables(ttfont, tables_to_drop): _autofix['drop_tables'].append(noto_font.filepath) if noto_font.family == 'Noto': if autofix_for_release.fix_linegap(ttfont): _autofix['linegap'].append(noto_font.filepath) if autofix_for_release.fix_os2_unicoderange(ttfont): _autofix['os2_unicoderange'].append(noto_font.filepath) if dry_run: return ttfont['head'].fontRevision = float_revision dst_dir = path.dirname(dst_file) if not path.isdir(dst_dir): os.makedirs(dst_dir) ttfont.save(dst_file) print 'Wrote file.'
def _swat_font(noto_font, dst_root, dry_run): filepath = noto_font.filepath basename = path.basename(filepath) if noto_font.is_cjk: print("# Skipping cjk font %s" % basename) return if noto_font.fmt == "ttc": print("# Deferring ttc font %s" % basename) _ttc_fonts[noto_font] = ttc_utils.ttcfile_filenames(filepath) return ttfont = ttLib.TTFont(filepath, fontNumber=0) names = font_data.get_name_records(ttfont) # create relative root path rel_filepath = _noto_relative_path(filepath) if not rel_filepath: raise ValueError("Could not identify noto root of %s" % filepath) print("-----\nUpdating %s" % rel_filepath) dst_file = path.join(dst_root, rel_filepath) try: new_revision, new_version_string = get_bumped_version( ttfont, noto_font.is_hinted) except ValueError as e: print(e) return print("%s: %s" % ("Would write" if dry_run else "Writing", dst_file)) new_trademark = "%s is a trademark of Google Inc." % noto_font.family # description field should be set. # Roozbeh has note, make sure design field has information # on whether the font is hinted. # Missing in Lao and Khmer, default in Cham. if cldr_data.get_english_script_name( noto_font.script) in ["Lao", "Khmer", "Cham"]: new_description = "Data %shinted." % ("" if noto_font.is_hinted else "un") # elif noto_font.vendor is 'Monotype': elif not noto_font.is_cjk and noto_font.family == "Noto": new_description = "Data %shinted. Designed by Monotype design team." % ( "" if noto_font.is_hinted else "un") else: new_description = None if re.match(r"^Copyright 201\d Google Inc. All Rights Reserved\.$", names[_COPYRIGHT_ID]): new_copyright = None else: new_copyright = "!!" if names.get(_DESIGNER_ID) in [ "Steve Matteson", "Monotype Design Team", "Danh Hong", ]: new_designer = None elif names.get(_DESIGNER_ID) == "Monotype Design team": new_designer = "Monotype Design Team" elif (_DESIGNER_ID not in names and cldr_data.get_english_script_name(noto_font.script) == "Khmer"): new_designer = "Danh Hong" else: new_designer = "!!" if names.get(_DESIGNER_URL_ID) in [ "http://www.monotype.com/studio", "http://www.khmertype.org", ]: new_designer_url = None elif names.get(_DESIGNER_URL_ID) in [ "http://www.monotypeimaging.com/ProductsServices/TypeDesignerShowcase", ]: new_designer_url = "http://www.monotype.com/studio" elif names.get(_DESIGNER_URL_ID) in [ "http://www.khmertype.blogspot.com", "http://www.khmertype.blogspot.com/", "http://khmertype.blogspot.com/", "http://wwwkhmertype.blogspot.com.com/", ]: new_designer_url = "http://www.khmertype.org" else: new_designer_url = "!!!" if names.get(_MANUFACTURER_ID) in [ "Monotype Imaging Inc.", "Danh Hong", ]: new_manufacturer = None else: new_manufacturer = "!!!" def update(name_id, new, newText=None): old = names.get(name_id) if new and (new != old): if not dry_run and not "!!!" in new: font_data.set_name_record(ttfont, name_id, new, addIfMissing="win") label = _NAME_ID_LABELS[name_id] oldText = "'%s'" % old if old else "None" newText = newText or ("'%s'" % new) print("%s:\n old: %s\n new: %s" % (label, oldText, newText or new)) label_change = _changes.get(label) if not label_change: label_change = {} _changes[label] = label_change new_val_change = label_change.get(new) if not new_val_change: new_val_change = {} label_change[new] = new_val_change old_val_fonts = new_val_change.get(old) if not old_val_fonts: old_val_fonts = [] new_val_change[old] = old_val_fonts old_val_fonts.append(noto_font.filepath) update(_COPYRIGHT_ID, new_copyright) update(_VERSION_ID, new_version_string) update(_TRADEMARK_ID, new_trademark) update(_MANUFACTURER_ID, new_manufacturer) update(_DESIGNER_ID, new_designer) update(_DESCRIPTION_ID, new_description) update(_VENDOR_URL_ID, _NOTO_URL) update(_DESIGNER_URL_ID, new_designer_url) update(_LICENSE_ID, _SIL_LICENSE, newText="(OFL)") update(_LICENSE_URL_ID, _SIL_LICENSE_URL) if autofix_for_release.fix_fstype(ttfont): _autofix["fstype"].append(noto_font.filepath) if autofix_for_release.fix_vendor_id(ttfont): _autofix["vendor_id"].append(noto_font.filepath) if autofix_for_release.fix_attachlist(ttfont): _autofix["attachlist"].append(noto_font.filepath) if noto_font.is_hinted: tables_to_drop = _HINTED_TABLES_TO_DROP else: tables_to_drop = _UNHINTED_TABLES_TO_DROP if autofix_for_release.drop_hints(ttfont): _autofix["drop_hints"].append(noto_font.filepath) if autofix_for_release.drop_tables(ttfont, tables_to_drop): _autofix["drop_tables"].append(noto_font.filepath) if noto_font.family == "Noto": if autofix_for_release.fix_linegap(ttfont): _autofix["linegap"].append(noto_font.filepath) if autofix_for_release.fix_os2_unicoderange(ttfont): _autofix["os2_unicoderange"].append(noto_font.filepath) if dry_run: return ttfont["head"].fontRevision = float_revision dst_dir = path.dirname(dst_file) if not path.isdir(dst_dir): os.makedirs(dst_dir) ttfont.save(dst_file) print("Wrote file.")