示例#1
0
                    f"got {len(paletteEntryLabels)}")
            cpal.paletteEntryLabels = buildPaletteLabels(
                paletteEntryLabels, nameTable)
        else:
            cpal.paletteEntryLabels = [C_P_A_L_.table_C_P_A_L_.NO_NAME_ID
                                       ] * cpal.numPaletteEntries
    else:
        cpal.version = 0

    return cpal


# COLR v1 tables
# See draft proposal at: https://github.com/googlefonts/colr-gradients-spec

_DEFAULT_ALPHA = VariableFloat(1.0)


def _is_colrv0_layer(layer: Any) -> bool:
    # Consider as COLRv0 layer any sequence of length 2 (be it tuple or list) in which
    # the first element is a str (the layerGlyph) and the second element is an int
    # (CPAL paletteIndex).
    # https://github.com/googlefonts/ufo2ft/issues/426
    try:
        layerGlyph, paletteIndex = layer
    except (TypeError, ValueError):
        return False
    else:
        return isinstance(layerGlyph, str) and isinstance(paletteIndex, int)

示例#2
0
                    f"got {len(paletteEntryLabels)}")
            cpal.paletteEntryLabels = buildPaletteLabels(
                paletteEntryLabels, nameTable)
        else:
            cpal.paletteEntryLabels = [C_P_A_L_.table_C_P_A_L_.NO_NAME_ID
                                       ] * cpal.numPaletteEntries
    else:
        cpal.version = 0

    return cpal


# COLR v1 tables
# See draft proposal at: https://github.com/googlefonts/colr-gradients-spec

_DEFAULT_TRANSPARENCY = VariableFloat(0.0)


def _splitSolidAndGradientGlyphs(
    colorGlyphs: _ColorGlyphsDict,
) -> Tuple[Dict[str, List[Tuple[str, int]]], Dict[str, List[Tuple[str,
                                                                  ot.Paint]]]]:
    colorGlyphsV0 = {}
    colorGlyphsV1 = {}
    for baseGlyph, layers in colorGlyphs.items():
        newLayers = []
        allSolidColors = True
        for layerGlyph, paint in layers:
            paint = _to_ot_paint(paint)
            if (paint.Format != 1 or paint.Color.Transparency.value !=
                    _DEFAULT_TRANSPARENCY.value):