Ejemplo n.º 1
0
def buildColrV1(
    colorGlyphs: _ColorGlyphsDict,
    glyphMap: Optional[Mapping[str, int]] = None,
) -> Tuple[ot.LayerV1List, ot.BaseGlyphV1List]:
    if glyphMap is not None:
        colorGlyphItems = sorted(colorGlyphs.items(),
                                 key=lambda item: glyphMap[item[0]])
    else:
        colorGlyphItems = colorGlyphs.items()

    errors = {}
    baseGlyphs = []
    layerBuilder = LayerV1ListBuilder()
    for baseGlyph, paint in colorGlyphItems:
        try:
            baseGlyphs.append(
                buildBaseGlyphV1Record(baseGlyph, layerBuilder, paint))

        except (ColorLibError, OverflowError, ValueError, TypeError) as e:
            errors[baseGlyph] = e

    if errors:
        failed_glyphs = _format_glyph_errors(errors)
        exc = ColorLibError(
            f"Failed to build BaseGlyphV1List:\n{failed_glyphs}")
        exc.errors = errors
        raise exc from next(iter(errors.values()))

    layers = layerBuilder.build()
    glyphs = ot.BaseGlyphV1List()
    glyphs.BaseGlyphCount = len(baseGlyphs)
    glyphs.BaseGlyphV1Record = baseGlyphs
    return (layers, glyphs)
Ejemplo n.º 2
0
def buildBaseGlyphV1List(
    colorGlyphs: Union[_ColorGlyphsDict, Dict[str, ot.LayerV1List]],
    glyphMap: Optional[Mapping[str, int]] = None,
) -> ot.BaseGlyphV1List:
    if glyphMap is not None:
        colorGlyphItems = sorted(colorGlyphs.items(),
                                 key=lambda item: glyphMap[item[0]])
    else:
        colorGlyphItems = colorGlyphs.items()
    records = [
        buildBaseGlyphV1Record(baseGlyph, layers)
        for baseGlyph, layers in colorGlyphItems
    ]
    self = ot.BaseGlyphV1List()
    self.BaseGlyphCount = len(records)
    self.BaseGlyphV1Record = records
    return self