Example #1
0
    class AlphabeticIndex(icuAlphabeticIndex):
        """
        Call the ICU AlphabeticIndex, passing the ICU Locale
        """
        def __init__(self, rlocale):
            self.iculocale = Locale(rlocale.collation)
            super().__init__(self.iculocale)

            # set the maximum number of buckets, the undocumented default is 99
            # Latin + Greek + Cyrillic + Hebrew + Arabic + Tamil + Hiragana +
            # CJK Unified is about 206 different buckets
            self.maxLabelCount = 500  # pylint: disable=invalid-name

            # Add bucket labels for scripts other than the one for the output
            # which is being generated
            self.iculocale.addLikelySubtags()
            default_script = self.iculocale.getDisplayScript()
            used_scripts = [default_script]

            for lang_code in glocale.get_language_dict().values():
                loc = Locale(lang_code)
                loc.addLikelySubtags()
                script = loc.getDisplayScript()
                if script not in used_scripts:
                    used_scripts.append(script)
                    super().addLabels(loc)
Example #2
0
def coverage(font, threshold=10):
    cmap = set(chr(c) for c in font.getBestCmap())

    languages = set()
    scripts = set()
    partial = {}

    for locale in Locale.getAvailableLocales():
        data = LocaleData(locale)
        examplar = set("".join(data.getExemplarSet()))
        if not cmap.isdisjoint(examplar):
            locale = Locale(locale)
            locale.addLikelySubtags()
            diff = examplar - cmap
            if not diff:
                scripts.add(locale.getDisplayScript())
                languages.add(locale.getDisplayLanguage())
            elif len(diff) <= threshold:
                partial[locale.getDisplayLanguage()] = diff

    return scripts, languages, partial