def _propagate_glyph_anchors(self, ufo, parent, processed):
    """Propagate anchors for a single parent glyph."""

    if parent.name in processed:
        return
    processed.add(parent.name)

    base_components = []
    mark_components = []
    anchor_names = set()
    to_add = {}
    for component in parent.components:
        try:
            glyph = ufo[component.baseGlyph]
        except KeyError:
            self.logger.warning(
                "Anchors not propagated for inexistent component {} in glyph {}".format(
                    component.baseGlyph, parent.name
                )
            )
        else:
            _propagate_glyph_anchors(self, ufo, glyph, processed)
            if any(a.name.startswith("_") for a in glyph.anchors):
                mark_components.append(component)
            else:
                base_components.append(component)
                anchor_names |= {a.name for a in glyph.anchors}

    for anchor_name in anchor_names:
        # don't add if parent already contains this anchor OR any associated
        # ligature anchors (e.g. "top_1, top_2" for "top")
        if not any(a.name.startswith(anchor_name) for a in parent.anchors):
            _get_anchor_data(to_add, ufo, base_components, anchor_name)

    for component in mark_components:
        _adjust_anchors(to_add, ufo, component)

    # we sort propagated anchors to append in a deterministic order
    for name, (x, y) in sorted(to_add.items()):
        anchor_dict = {"name": name, "x": x, "y": y}
        parent.appendAnchor(glyph.anchorClass(anchorDict=anchor_dict))
def _propagate_glyph_anchors ( self , ufo , parent , processed ) : if parent . name in processed : return processed . add ( parent . name ) base_components = [ ] mark_components = [ ] anchor_names = set ( ) to_add = { } for component in parent . components : try : glyph = ufo [ component . baseGlyph ] except KeyError : self . logger . warning ( "Anchors not propagated for inexistent component {} in glyph {}" . format ( component . baseGlyph , parent . name ) ) else : _propagate_glyph_anchors ( self , ufo , glyph , processed ) if any ( a . name . startswith ( "_" ) for a in glyph . anchors ) : mark_components . append ( component ) else : base_components . append ( component ) anchor_names |= { a . name for a in glyph . anchors } for anchor_name in anchor_names : if not any ( a . name . startswith ( anchor_name ) for a in parent . anchors ) : _get_anchor_data ( to_add , ufo , base_components , anchor_name ) for component in mark_components : _adjust_anchors ( to_add , ufo , component ) for name , ( x , y ) in sorted ( to_add . items ( ) ) : anchor_dict = { "name" : name , "x" : x , "y" : y } parent . appendAnchor ( glyph . anchorClass ( anchorDict = anchor_dict ) )
Propagate anchors for a single parent glyph.