Пример #1
0
    def _add_feature(self, font: Font, table: otTables.GPOS, feature_tag: str,
                     lookup_indices: List[int]) -> None:
        logger.debug('Adding "%s" to: "%s" %s', feature_tag, font,
                     self._to_str(glyph_ids=True))
        assert not Font._has_ottable_feature(table, feature_tag)
        features = table.FeatureList.FeatureRecord
        feature_index = len(features)
        logger.info('Adding Feature "%s" at index %d for lookup %s',
                    feature_tag, feature_index, lookup_indices)
        feature_record = otTables.FeatureRecord()
        feature_record.FeatureTag = feature_tag
        feature_record.Feature = otTables.Feature()
        feature_record.Feature.LookupListIndex = lookup_indices
        feature_record.Feature.LookupCount = len(lookup_indices)
        features.append(feature_record)

        scripts = table.ScriptList.ScriptRecord
        for script_record in scripts:
            default_lang_sys = script_record.Script.DefaultLangSys
            if default_lang_sys:
                logger.debug(
                    "Adding Feature index %d to script '%s' DefaultLangSys",
                    feature_index, script_record.ScriptTag)
                default_lang_sys.FeatureIndex.append(feature_index)
            for lang_sys in script_record.Script.LangSysRecord:
                logger.debug(
                    "Adding Feature index %d to script '%s' LangSys '%s'",
                    feature_index, script_record.ScriptTag,
                    lang_sys.LangSysTag)
                lang_sys.LangSys.FeatureIndex.append(feature_index)
Пример #2
0
    def add_to_font(self, font: Font) -> bool:
        self.assert_font(font)
        self.assert_glyphs_are_disjoint()
        if not self._can_add_to_table:
            if self._add_glyphs_count:
                logger.warning('Skipped because no pairs: "%s"', font)
            return False

        table = font.gpos_ottable(create=True)
        lookups = table.LookupList.Lookup
        pos = GlyphSets.PosValues(font, self)
        logger.info('Adding Lookups for %dL, %dR, %dM, %dS', len(pos.left),
                    len(pos.right), len(pos.middle), len(pos.space))

        feature_tag = 'vhal' if font.is_vertical else 'halt'
        if not Font._has_ottable_feature(table, feature_tag):
            lookup_index = self._build_halt_lookup(font, lookups, pos)
            self._add_feature(font, table, feature_tag, [lookup_index])

        feature_tag = 'vchw' if font.is_vertical else 'chws'
        lookup_indices = self._build_chws_lookup(font, lookups, pos)
        self._add_feature(font, table, feature_tag, lookup_indices)
        return True