def build_data_json(self, family_id_to_lang_scr_to_sample_key,
                      families, family_zip_info, universal_zip_info,
                      family_id_to_regions, region_to_family_ids):

    data_obj = collections.OrderedDict()
    families_obj = collections.OrderedDict()
    # Sort families by English name, except 'Noto Sans' and 'Noto Serif' come first
    family_ids = [family_id for family_id
                  in family_id_to_lang_scr_to_sample_key
                  if family_id != 'sans-lgc' and family_id != 'serif-lgc']
    family_ids = sorted(family_ids, key=lambda f: families[f].name)
    sorted_ids = ['sans-lgc', 'serif-lgc']
    sorted_ids.extend(family_ids)
    for k in sorted_ids:
      family = families[k]
      family_obj = {}
      family_obj['name'] = family.name

      name, hinted_size, unhinted_size = family_zip_info[k]
      pkg_obj = collections.OrderedDict()
      if hinted_size:
        pkg_obj['hinted'] = hinted_size
      if unhinted_size:
        pkg_obj['unhinted'] = unhinted_size
      family_obj['pkgSize'] = pkg_obj

      # special case number of fonts for CJK
      if family.rep_member.is_cjk:
        num_fonts = 7 #ignore mono
      else:
        num_fonts = len(family.hinted_members or family.unhinted_members)
      family_obj['fonts'] = num_fonts
      # only displayed langs -- see build_family_json lang_scrs
      lang_scrs_map = family_id_to_lang_scr_to_sample_key[k]
      family_obj['langs'] = sum([1 for l in lang_scrs_map if not l.startswith('und-')])
      family_obj['regions'] = len(family_id_to_regions[k])

      families_obj[k] = family_obj
    data_obj['family'] = families_obj

    data_obj['familyOrder'] = sorted_ids

    # get inverse map from lang_scr to family_id
    lang_scr_to_family_ids = collections.defaultdict(set)
    for family_id, lang_scrs in family_id_to_lang_scr_to_sample_key.iteritems():
      for lang_scr in lang_scrs:
        lang_scr_to_family_ids[lang_scr].add(family_id)

    # Dont list 'und-' lang tags, these are for default samples and not listed in the UI
    lang_scrs = [l for l in lang_scr_to_family_ids if not l.startswith('und-')]

    langs_obj = collections.OrderedDict()
    # sort by english name
    for lang_scr in sorted(lang_scrs,
                           key=lambda l: lang_data.lang_script_to_names(l)[0]):
      lang_obj = collections.OrderedDict()
      names = lang_data.lang_script_to_names(lang_scr)
      english_name = names[0]
      lang_obj['name'] = english_name
      if cldr_data.is_rtl(lang_scr):
        lang_obj['rtl'] = True
      lang_obj['families'] = sorted(lang_scr_to_family_ids[lang_scr])
      native_names = [n for n in names[1:] if n != english_name]
      if native_names:
        lang_obj['keywords'] = native_names
      langs_obj[lang_scr] = lang_obj
    data_obj['lang'] = langs_obj

    regions_obj = collections.OrderedDict()
    for region in sorted(region_to_family_ids,
                         key=lambda r: cldr_data.get_english_region_name(r)):
      region_obj = collections.OrderedDict()
      region_obj['families'] = sorted(region_to_family_ids[region])
      region_obj['keywords'] = [cldr_data.get_english_region_name(region)]
      regions_obj[region] = region_obj
    data_obj['region'] = regions_obj

    pkg_obj = collections.OrderedDict()
    pkg_obj['hinted'] = universal_zip_info[1]
    pkg_obj['unhinted'] = universal_zip_info[2]
    data_obj['pkgSize'] = pkg_obj

    self.write_json(data_obj, 'data')
Ejemplo n.º 2
0
  def build_data_json(self, families, family_zip_info, universal_zip_info,
                      family_id_to_lang_tags, family_id_to_regions,
                      lang_tag_to_family_ids, region_to_family_ids):

    data_obj = collections.OrderedDict()
    families_obj = collections.OrderedDict()
    # Sort families by English name, except 'Noto Sans' and 'Noto Serif' come first
    family_ids = [family_id for family_id in families if family_id != 'sans' and family_id != 'serif']
    family_ids = sorted(family_ids, key=lambda f: families[f].name)
    sorted_ids = ['sans', 'serif']
    sorted_ids.extend(family_ids)
    for k in sorted_ids:
      family = families[k]
      family_obj = {}
      family_obj['name'] = family.name

      name, hinted_size, unhinted_size = family_zip_info[k]
      pkg_obj = collections.OrderedDict()
      if hinted_size:
        pkg_obj['hinted'] = hinted_size
      if unhinted_size:
        pkg_obj['unhinted'] = unhinted_size
      family_obj['pkgSize'] = pkg_obj

      family_obj['fonts'] = len(family.hinted_members or family.unhinted_members)
      family_obj['langs'] = len(family_id_to_lang_tags[k])
      family_obj['regions'] = len(family_id_to_regions[k])

      families_obj[k] = family_obj
    data_obj['family'] = families_obj

    data_obj['familyOrder'] = sorted_ids

    langs_obj = collections.OrderedDict()
    # Dont list 'und-' lang tags, these are for default samples and not listed in the UI
    lang_tags = [lang for lang in lang_tag_to_family_ids if not lang.startswith('und-')]

    lang_tags = sorted(lang_tags, key=lambda l: cldr_data.get_english_language_name(l))
    for lang in lang_tags:
      lang_obj = collections.OrderedDict()
      english_name = cldr_data.get_english_language_name(lang)
      lang_obj['name'] = english_name
      lang_obj['families'] = sorted(lang_tag_to_family_ids[lang])
      native_name = cldr_data.get_native_language_name(lang)
      if native_name and native_name != english_name:
        lang_obj['keywords'] = [native_name]
      langs_obj[lang] = lang_obj
    data_obj['lang'] = langs_obj

    regions_obj = collections.OrderedDict()
    for region in sorted(region_to_family_ids,
                         key=lambda r: cldr_data.get_english_region_name(r)):
      region_obj = collections.OrderedDict()
      region_obj['families'] = sorted(region_to_family_ids[region])
      region_obj['keywords'] = [cldr_data.get_english_region_name(region)]
      regions_obj[region] = region_obj
    data_obj['region'] = regions_obj

    pkg_obj = collections.OrderedDict()
    pkg_obj['hinted'] = universal_zip_info[1]
    pkg_obj['unhinted'] = universal_zip_info[2]
    data_obj['pkgSize'] = pkg_obj

    self.write_json(data_obj, 'data')
Ejemplo n.º 3
0
  def build_data_json(self, family_id_to_lang_scr_to_sample_key,
                      families, family_zip_info, universal_zip_info,
                      family_id_to_regions, region_to_family_ids):

    data_obj = collections.OrderedDict()
    families_obj = collections.OrderedDict()

    # Sort families by English name, except 'Noto Sans', 'Noto Serif', and
    # 'Noto Mono' come first, in that order
    initial_ids = ['sans-lgc', 'serif-lgc', 'mono-mono']
    family_ids = [family_id for family_id
                  in family_id_to_lang_scr_to_sample_key
                  if family_id not in initial_ids]
    family_ids = sorted(family_ids, key=lambda f: families[f].name)
    sorted_ids = [fid for fid in initial_ids
                  if fid in family_id_to_lang_scr_to_sample_key]
    sorted_ids.extend(family_ids)
    for k in sorted_ids:
      family = families[k]
      family_obj = {}
      family_obj['name'] = family.name

      name, hinted_size, unhinted_size = family_zip_info[k]
      pkg_obj = collections.OrderedDict()
      if hinted_size:
        pkg_obj['hinted'] = hinted_size
      if unhinted_size:
        pkg_obj['unhinted'] = unhinted_size
      family_obj['pkgSize'] = pkg_obj

      # special case number of fonts for CJK
      if family.rep_member.is_cjk:
        num_fonts = 7 #ignore mono
      else:
        num_fonts = len(family.hinted_members or family.unhinted_members)
      family_obj['fonts'] = num_fonts
      # only displayed langs -- see build_family_json lang_scrs
      lang_scrs_map = family_id_to_lang_scr_to_sample_key[k]
      family_obj['langs'] = sum(
          [1 for l in lang_scrs_map if not l.startswith('und-')])
      family_obj['regions'] = len(family_id_to_regions[k])

      families_obj[k] = family_obj
    data_obj['family'] = families_obj

    data_obj['familyOrder'] = sorted_ids

    # get inverse map from lang_scr to family_id
    lang_scr_to_family_ids = collections.defaultdict(set)
    for family_id, lang_scrs in family_id_to_lang_scr_to_sample_key.iteritems():
      for lang_scr in lang_scrs:
        lang_scr_to_family_ids[lang_scr].add(family_id)

    # Dont list 'und-' lang tags, these are for default samples and not
    # listed in the UI
    lang_scrs = [l for l in lang_scr_to_family_ids if not l.startswith('und-')]

    langs_obj = collections.OrderedDict()
    # sort by english name
    for lang_scr in sorted(lang_scrs,
                           key=lambda l: lang_data.lang_script_to_names(l)[0]):
      lang_obj = collections.OrderedDict()
      names = lang_data.lang_script_to_names(lang_scr)
      english_name = names[0]
      lang_obj['name'] = english_name
      if cldr_data.is_rtl(lang_scr):
        lang_obj['rtl'] = True
      lang_obj['families'] = sorted(lang_scr_to_family_ids[lang_scr])
      native_names = [n for n in names[1:] if n != english_name]
      if native_names:
        lang_obj['keywords'] = native_names
      langs_obj[lang_scr] = lang_obj
    data_obj['lang'] = langs_obj

    regions_obj = collections.OrderedDict()
    for region in sorted(region_to_family_ids,
                         key=lambda r: cldr_data.get_english_region_name(r)):
      region_obj = collections.OrderedDict()
      region_obj['families'] = sorted(region_to_family_ids[region])
      region_obj['keywords'] = [cldr_data.get_english_region_name(region)]
      regions_obj[region] = region_obj
    data_obj['region'] = regions_obj

    pkg_obj = collections.OrderedDict()
    pkg_obj['hinted'] = universal_zip_info[1]
    pkg_obj['unhinted'] = universal_zip_info[2]
    data_obj['pkgSize'] = pkg_obj

    self.write_json(data_obj, 'data')
Ejemplo n.º 4
0
    def build_data_json(self, families, family_zip_info, universal_zip_info,
                        family_id_to_lang_tags, family_id_to_regions,
                        lang_tag_to_family_ids, region_to_family_ids):

        data_obj = collections.OrderedDict()
        families_obj = collections.OrderedDict()
        # Sort families by English name, except 'Noto Sans' and 'Noto Serif' come first
        family_ids = [
            family_id for family_id in families
            if family_id != 'sans' and family_id != 'serif'
        ]
        family_ids = sorted(family_ids, key=lambda f: families[f].name)
        sorted_ids = ['sans', 'serif']
        sorted_ids.extend(family_ids)
        for k in sorted_ids:
            family = families[k]
            family_obj = {}
            family_obj['name'] = family.name

            name, hinted_size, unhinted_size = family_zip_info[k]
            pkg_obj = collections.OrderedDict()
            if hinted_size:
                pkg_obj['hinted'] = hinted_size
            if unhinted_size:
                pkg_obj['unhinted'] = unhinted_size
            family_obj['pkgSize'] = pkg_obj

            family_obj['fonts'] = len(family.hinted_members
                                      or family.unhinted_members)
            family_obj['langs'] = len(family_id_to_lang_tags[k])
            family_obj['regions'] = len(family_id_to_regions[k])

            families_obj[k] = family_obj
        data_obj['family'] = families_obj

        data_obj['familyOrder'] = sorted_ids

        langs_obj = collections.OrderedDict()
        # Dont list 'und-' lang tags, these are for default samples and not listed in the UI
        lang_tags = [
            lang for lang in lang_tag_to_family_ids
            if not lang.startswith('und-')
        ]

        lang_tags = sorted(
            lang_tags, key=lambda l: cldr_data.get_english_language_name(l))
        for lang in lang_tags:
            lang_obj = collections.OrderedDict()
            english_name = cldr_data.get_english_language_name(lang)
            lang_obj['name'] = english_name
            lang_obj['families'] = sorted(lang_tag_to_family_ids[lang])
            native_name = cldr_data.get_native_language_name(lang)
            if native_name and native_name != english_name:
                lang_obj['keywords'] = [native_name]
            langs_obj[lang] = lang_obj
        data_obj['lang'] = langs_obj

        regions_obj = collections.OrderedDict()
        for region in sorted(
                region_to_family_ids,
                key=lambda r: cldr_data.get_english_region_name(r)):
            region_obj = collections.OrderedDict()
            region_obj['families'] = sorted(region_to_family_ids[region])
            region_obj['keywords'] = [
                cldr_data.get_english_region_name(region)
            ]
            regions_obj[region] = region_obj
        data_obj['region'] = regions_obj

        pkg_obj = collections.OrderedDict()
        pkg_obj['hinted'] = universal_zip_info[1]
        pkg_obj['unhinted'] = universal_zip_info[2]
        data_obj['pkgSize'] = pkg_obj

        self.write_json(data_obj, 'data')