Ejemplo n.º 1
0
    def action(self, args):
        # `stuff` are tuples of (glyphselector, lookup_list)
        (pre, (stuff, languages), post) = args[0]

        inputs = [
            x[0].resolve(self.parser.fontfeatures, self.parser.font)
            for x in stuff
        ]
        lookupnames = [x[1] or [] for x in stuff]
        lookups = []
        for lu in lookupnames:
            lookups.append([fontFeatures.RoutineReference(name=x) for x in lu])
        pre = [
            g.resolve(self.parser.fontfeatures, self.parser.font) for g in pre
        ]
        post = [
            g.resolve(self.parser.fontfeatures, self.parser.font) for g in post
        ]
        return [
            fontFeatures.Chaining(inputs,
                                  lookups=lookups,
                                  precontext=pre,
                                  postcontext=post,
                                  languages=languages)
        ]
Ejemplo n.º 2
0
 def _unparse_lookups(self, slr, inputs, in_lookups=None):
     lookups = []
     note = None
     if in_lookups:
         lookups = in_lookups
     indices = [sl.SequenceIndex for sl in slr]
     if indices != list(sorted(indices)):
         # https://github.com/adobe-type-tools/afdko/issues/1167
         note = (
             f"Out-of-order lookup application in lookup {self.currentLookup}\n"
             f" A chaining rule calls lookups in the order {indices}\n"
             " This cannot be directly expressed in Adobe FEA syntax;\n"
             "  asFea() output will be incorrect")
         warnings.warn(note)
     for sl in slr:
         if len(lookups) <= sl.SequenceIndex:
             lookups.extend([None] * (1 + sl.SequenceIndex - len(lookups)))
         if not lookups[sl.SequenceIndex]:
             lookups[sl.SequenceIndex] = []
         if sl.LookupListIndex >= len(self.lookups):
             raise ValueError(
                 "Lookups unparsed out of order: unparse %i first!" %
                 sl.LookupListIndex)
         rr = fontFeatures.RoutineReference(
             routine=self.lookups[sl.LookupListIndex])
         lookups[sl.SequenceIndex].append(rr)
     if len(lookups) < len(inputs):
         lookups.extend([None] * (len(inputs) - len(lookups)))
     assert len(lookups) == len(inputs)
     return lookups, note
Ejemplo n.º 3
0
    def action(self, args):
        (routinename, statements, flags_languages) = args
        flags, languages = flags_languages

        if routinename is not None:
            routinename = routinename[0].value

        if flags is None: flags = []

        if not statements:
            rr = fontFeatures.RoutineReference(name = routinename)
            return [rr]
        r = fontFeatures.Routine()
        if routinename:
            r.name = routinename
        r.rules = []
        for res in self.parser.filterResults(statements):
            if isinstance(res, fontFeatures.Routine):
                r.rules.extend(res.rules)
            else:
                r.rules.append(res)
        r.flags = 0
        for f in flags:
            if isinstance(f, tuple):
                r.flags |= f[0]
                if f[0] == 0x10:
                    r.markFilteringSet = f[1].resolve(self.parser.fontfeatures, self.parser.font)
                elif f[0] == 0xFF00:
                    r.markAttachmentSet = f[1].resolve(self.parser.fontfeatures, self.parser.font)
            else:
                r.flags |= f
        r.languages = languages
        if not self.parser.current_feature:
            self.parser.fontfeatures.routines.append(r)
        return [r]
Ejemplo n.º 4
0
    def _prepareFeatureLangSys(self, langTag, langSys, table, features,
                               scriptTag):
        # This is a part of prepareFeatures
        for featureIdx in langSys.FeatureIndex:
            featureRecord = self.table.FeatureList.FeatureRecord[featureIdx]
            featureTag = featureRecord.FeatureTag
            scripts = features.get(featureTag, None)
            if scripts is None:
                scripts = OrderedDict()
                features[featureTag] = scripts

            languages = scripts.get(scriptTag, None)
            if languages is None:
                languages = OrderedDict()
                scripts[scriptTag] = languages

            lookups = languages.get(langTag, None)
            if lookups is None:
                lookups = []
                languages[langTag] = lookups

            for lookupIdx in featureRecord.Feature.LookupListIndex:
                self.lookups[lookupIdx].languages.append((scriptTag, langTag))
                # Add reference if there isn't one
                if not featureTag in self.fontFeatures.features:
                    self.fontFeatures.features[featureTag] = []
                if not any(r.routine == self.lookups[lookupIdx]
                           for r in self.fontFeatures.features[featureTag]):
                    self.fontFeatures.addFeature(featureTag, [
                        fontFeatures.RoutineReference(
                            routine=self.lookups[lookupIdx])
                    ])
                lookups.append(lookupIdx)
Ejemplo n.º 5
0
 def action(self, parser, routinename, tail):
     if not tail:
         rr = fontFeatures.RoutineReference(name=routinename)
         return [rr]
     statements, flags = tail
     r = fontFeatures.Routine()
     if routinename:
         r.name = routinename
     r.rules = []
     for res in parser.filterResults(statements):
         if isinstance(res, fontFeatures.Routine):
             r.rules.extend(res.rules)
         else:
             r.rules.append(res)
     r.flags = 0
     for f in flags:
         if isinstance(f, tuple):
             r.flags |= f[0]
             if f[0] == 0x10:
                 r.markFilteringSet = f[1].resolve(parser.fontfeatures,
                                                   parser.font)
             elif f[0] == 0xFF00:
                 r.markAttachmentSet = f[1].resolve(parser.fontfeatures,
                                                    parser.font)
         else:
             r.flags |= f
     if not parser.current_feature:
         parser.fontfeatures.routines.append(r)
     return [r]
Ejemplo n.º 6
0
 def action(self, parser, stuff, languages, pre, post):
     inputs  = [x[0].resolve(parser.fontfeatures, parser.font) for x in stuff]
     lookupnames = [x[1] or [] for x in stuff]
     lookups = []
     for lu in lookupnames:
         lookups.append([fontFeatures.RoutineReference(name=x) for x in lu])
     pre     = [g.resolve(parser.fontfeatures, parser.font) for g in pre]
     post     = [g.resolve(parser.fontfeatures, parser.font) for g in post]
     languages = None # For now
     return [fontFeatures.Chaining(inputs, lookups = lookups,
         precontext = pre,
         postcontext = post,
         languages=languages)]
Ejemplo n.º 7
0
 def _unparse_lookups(self, slr, inputs, in_lookups=None):
     lookups = []
     if in_lookups:
         lookups = in_lookups
     for sl in slr:
         if len(lookups) <= sl.SequenceIndex:
             lookups.extend([None] * (1 + sl.SequenceIndex - len(lookups)))
         if not lookups[sl.SequenceIndex]:
             lookups[sl.SequenceIndex] = []
         rr = fontFeatures.RoutineReference(
             routine=self.lookups[sl.LookupListIndex])
         lookups[sl.SequenceIndex].append(rr)
     if len(lookups) < len(inputs):
         lookups.extend([None] * (len(inputs) - len(lookups)))
     assert len(lookups) == len(inputs)
     return lookups