# Path: Lib/glyphsLib/builder/constants.py
# GLYPHS_PREFIX = "com.schriftgestaltung."


from .constants import GLYPHS_PREFIX
from glyphsLib.types import Point


LIB_KEY = GLYPHS_PREFIX + "annotations"


def to_ufo_annotations(self, ufo_glyph, layer):
    try:
        value = layer.annotations
    except KeyError:
        return
    annotations = []
    for an in list(value.values()):
        annot = {}
        for attr in ["angle", "position", "text", "type", "width"]:
            val = getattr(an, attr, None)
            if attr == "position" and val:
                val = list(val)
            if val:
                annot[attr] = val
        annotations.append(annot)

    if annotations:
        ufo_glyph.lib[LIB_KEY] = annotations


def to_glyphs_annotations(self, ufo_glyph, layer):
    if LIB_KEY not in ufo_glyph.lib:
        return

    for annot in ufo_glyph.lib[LIB_KEY]:

# Path: Lib/glyphsLib/builder/constants.py
# GLYPHS_PREFIX = "com.schriftgestaltung."


# Path: Lib/glyphsLib/builder/annotations.py
from .constants import GLYPHS_PREFIX
from glyphsLib.types import Point



LIB_KEY = GLYPHS_PREFIX + "annotations"


def to_ufo_annotations(self, ufo_glyph, layer):
    try:
        value = layer.annotations
    except KeyError:
        return
    annotations = []
    for an in list(value.values()):
        annot = {}
        for attr in ["angle", "position", "text", "type", "width"]:
            val = getattr(an, attr, None)
            if attr == "position" and val:
                val = list(val)
            if val:
                annot[attr] = val
        annotations.append(annot)

    if annotations:
        ufo_glyph.lib[LIB_KEY] = annotations


def to_glyphs_annotations(self, ufo_glyph, layer):
    if LIB_KEY not in ufo_glyph.lib:
        return

    for annot in ufo_glyph.lib[LIB_KEY]:

        annotation = self.glyphs_module.GSAnnotation()