def get_script_to_family_ids(family_map): """The keys in the returned map are all the supported scripts.""" script_to_family_ids = collections.defaultdict(set) for key in family_map: script_key = family_map[key].rep_member.script for script in noto_fonts.script_key_to_scripts(script_key): script_to_family_ids[script].add(key) return script_to_family_ids
def get_family_id_to_default_lang_scr(family_id_to_lang_scrs, families): """Return a mapping from family id to default lang tag, for families that have multiple lang tags. This is based on likely subtags and the script of the family (Latn for LGC). """ family_id_to_default_lang_scr = {} for family_id, lang_scrs in family_id_to_lang_scrs.iteritems(): script_key = families[family_id].rep_member.script primary_script = noto_fonts.script_key_to_scripts(script_key)[0] if script_key == 'Aran': # patch for Nastaliq lang = 'ur' else: lang = lang_data.script_to_default_lang(primary_script) lang_scr = lang + '-' + primary_script if lang_scr not in lang_scrs: print 'default lang_scr \'%s\' not listed for family %s %s' % ( lang_scr, family_id, lang_scrs) family_id_to_default_lang_scr[family_id] = lang_scr return family_id_to_default_lang_scr
def write_csv(outfile, lang, script, style, ui, members): if members: print >> outfile, ','.join( [lang, script, style, ui, noto_fonts.get_font_family_name(members[0].filepath)]) with open('lang_to_font_table.csv', 'w') as outfile: write_csv_header(outfile) for lang in LANGS: script = cldr_data.get_likely_script(lang) found_font = False for family in sorted(families, key=lambda f: f.name): if script not in noto_fonts.script_key_to_scripts( family.rep_member.script): continue found_font = True members = family.hinted_members or family.unhinted_members ui_members = [m for m in members if m.is_UI] non_ui_members = [m for m in members if not m.is_UI] assert len(ui_members) <= 1 assert len(non_ui_members) <= 1 write_csv(outfile, lang, script, family.rep_member.style, '', non_ui_members) write_csv(outfile, lang, script, family.rep_member.style, 'UI', ui_members) if not found_font: print '## no font found for lang %s' % lang
def _get_sample_text(directory, font_names, lang): script_keys = set() scripts = set() for name in font_names: noto_font = noto_fonts.get_noto_font(path.join(directory, name)) if noto_font.script not in script_keys: script_keys.add(noto_font.script) scripts |= noto_fonts.script_key_to_scripts(noto_font.script) if lang: lang_scripts = ["%s-%s" % (lang, script) for script in scripts] else: lang_scripts = [ "%s-%s" % (lang_data.script_to_default_lang(script), script) for script in scripts ] lang_scripts.extend("und-%s" % script for script in scripts) samples = [] sample_dir = tool_utils.resolve_path("[tools]/sample_texts") for f in os.listdir(sample_dir): for lang_script in lang_scripts: if f.startswith(lang_script): samples.append(f) break print(sorted(samples)) # limit to scripts supported by all fonts selected = [] for sample in samples: sample_supported = True for script_key in script_keys: script_key_supported = False for script in noto_fonts.script_key_to_scripts(script_key): if "-%s_" % script in sample: script_key_supported = True break if not script_key_supported: sample_supported = False break if sample_supported: selected.append(sample) if not selected: raise Exception("no sample supported by all fonts") samples = selected # limit to udhr ones if any exist selected = [s for s in samples if "_udhr" in s] if selected: samples = selected # limit to non-'und' ones if any exist selected = [s for s in samples if not s.startswith("und-")] if selected: samples = selected if len(samples) != 1: raise Exception( "found %d sample files (%s) but need exactly 1" % (len(samples), ", ".join(sorted(samples))) ) print("selected sample %s" % samples[0]) with codecs.open(path.join(sample_dir, samples[0]), "r", "utf-8") as f: text = f.read() return text.strip()