# Path: Lib/glyphsLib/builder/common.py
# def to_ufo_color(color):
#     if isinstance(color, str):
#         color = [int(v) for v in color.split(",")]
#     if len(color) == 2:
#         # Greyscale color
#         color = (color[0], color[0], color[0], color[1])
#     elif len(color) == 5:
#         # CMYK color
#         raise NotImplementedError("CMYK colors are not supported")
#     return tuple(c / 255 for c in color)
# 
# Path: Lib/glyphsLib/builder/constants.py
# UFO2FT_COLOR_LAYERS_KEY = "com.github.googlei18n.ufo2ft.colorLayers"
# 
# UFO2FT_COLOR_PALETTES_KEY = "com.github.googlei18n.ufo2ft.colorPalettes"


import math
        import pathops
from fontTools.misc.transform import Identity, Transform
from fontTools.ttLib.tables.otTables import PaintFormat
from .common import to_ufo_color
from .constants import UFO2FT_COLOR_LAYERS_KEY, UFO2FT_COLOR_PALETTES_KEY
                builder.to_ufo_glyph(ufo_glyph, layer, glyph, do_color_layers=False)

            attributes = layer.paths[0].attributes if layer.paths else {}
            if "gradient" in attributes:
                gradient = attributes["gradient"]
                paint = _to_gradient_paint(gradient, layer, palette)
            elif "fillColor" in attributes:
                color = attributes["fillColor"]
                paletteIndex, a = _find_or_insert_color(color, palette)
                paint = dict(
                    Format=PaintFormat.PaintSolid, Alpha=a, PaletteIndex=paletteIndex
                )
            elif (
                "strokeColor" in attributes
                or "strokeWidth" in attributes
                or not attributes
            ):
                paint = _to_stroked_paint(attributes, layer, palette, ufo_glyph, ufo)
            else:
                raise NotImplementedError(
                    f"Unsupported color layer path attributes in '{glyph.name}'"
                )

            paintGlyph = dict(
                Format=PaintFormat.PaintGlyph, Glyph=layerGlyphName, Paint=paint
            )
            colorLayers.append(paintGlyph)
        layerMapping[glyph.name] = dict(Format=1, Layers=colorLayers)

    if palette[0]:

# Path: Lib/glyphsLib/builder/common.py
# def to_ufo_color(color):
#     if isinstance(color, str):
#         color = [int(v) for v in color.split(",")]
#     if len(color) == 2:
#         # Greyscale color
#         color = (color[0], color[0], color[0], color[1])
#     elif len(color) == 5:
#         # CMYK color
#         raise NotImplementedError("CMYK colors are not supported")
#     return tuple(c / 255 for c in color)
# 
# Path: Lib/glyphsLib/builder/constants.py
# UFO2FT_COLOR_LAYERS_KEY = "com.github.googlei18n.ufo2ft.colorLayers"
# 
# UFO2FT_COLOR_PALETTES_KEY = "com.github.googlei18n.ufo2ft.colorPalettes"


# Path: Lib/glyphsLib/builder/color_layers.py
import math
        import pathops
from fontTools.misc.transform import Identity, Transform
from fontTools.ttLib.tables.otTables import PaintFormat
from .common import to_ufo_color
from .constants import UFO2FT_COLOR_LAYERS_KEY, UFO2FT_COLOR_PALETTES_KEY

                builder.to_ufo_glyph(ufo_glyph, layer, glyph, do_color_layers=False)

            attributes = layer.paths[0].attributes if layer.paths else {}
            if "gradient" in attributes:
                gradient = attributes["gradient"]
                paint = _to_gradient_paint(gradient, layer, palette)
            elif "fillColor" in attributes:
                color = attributes["fillColor"]
                paletteIndex, a = _find_or_insert_color(color, palette)
                paint = dict(
                    Format=PaintFormat.PaintSolid, Alpha=a, PaletteIndex=paletteIndex
                )
            elif (
                "strokeColor" in attributes
                or "strokeWidth" in attributes
                or not attributes
            ):
                paint = _to_stroked_paint(attributes, layer, palette, ufo_glyph, ufo)
            else:
                raise NotImplementedError(
                    f"Unsupported color layer path attributes in '{glyph.name}'"
                )

            paintGlyph = dict(
                Format=PaintFormat.PaintGlyph, Glyph=layerGlyphName, Paint=paint
            )
            colorLayers.append(paintGlyph)
        layerMapping[glyph.name] = dict(Format=1, Layers=colorLayers)

    if palette[0]:

        for p in ufo.lib.setdefault(UFO2FT_COLOR_PALETTES_KEY, [[]]):