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
Example #2
0
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_primary_script(script_key)

    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
Example #3
0
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()