Skip to content

Commit

Permalink
Merge pull request #521 from googlefonts/colr-clip-boxes
Browse files Browse the repository at this point in the history
define 'colrClipBoxes' lib key, pass it on to buildCOLR
  • Loading branch information
anthrotype authored Aug 3, 2021
2 parents 63aa172 + 7119fd5 commit 0e8edb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Lib/ufo2ft/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
COLOR_LAYERS_KEY = UFO2FT_PREFIX + "colorLayers"
COLOR_PALETTES_KEY = UFO2FT_PREFIX + "colorPalettes"
COLOR_LAYER_MAPPING_KEY = UFO2FT_PREFIX + "colorLayerMapping"
# sequence of [glyphs, clipBox], where 'glyphs' is in turn a sequence of
# glyph names, and 'clipBox' a 5- or 4-item sequence of numbers:
# Sequence[
# Sequence[
# Sequence[str, ...], # glyph names
# Union[
# Sequence[float, float, float, float, float], # variable box
# Sequence[float, float, float, float], # non-variable box
# ]
# ],
# ...
# ]
COLR_CLIP_BOXES_KEY = UFO2FT_PREFIX + "colrClipBoxes"

OPENTYPE_CATEGORIES_KEY = "public.openTypeCategories"
OPENTYPE_META_KEY = "public.openTypeMeta"
Expand Down
14 changes: 13 additions & 1 deletion Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ufo2ft.constants import (
COLOR_LAYERS_KEY,
COLOR_PALETTES_KEY,
COLR_CLIP_BOXES_KEY,
OPENTYPE_META_KEY,
UNICODE_VARIATION_SEQUENCES_KEY,
)
Expand Down Expand Up @@ -959,7 +960,18 @@ def setupTable_COLR(self):
layerInfo = self.ufo.lib[COLOR_LAYERS_KEY]
glyphMap = self.otf.getReverseGlyphMap()
if layerInfo:
self.otf["COLR"] = buildCOLR(layerInfo, glyphMap=glyphMap)
# unpack (glyphs, clipBox) tuples to a flat dict keyed by glyph name,
# as colorLib buildCOLR expects
clipBoxes = {
glyphName: tuple(box)
for glyphs, box in self.ufo.lib.get(COLR_CLIP_BOXES_KEY, ())
for glyphName in glyphs
}
self.otf["COLR"] = buildCOLR(
layerInfo,
glyphMap=glyphMap,
clipBoxes=clipBoxes,
)

def setupTable_CPAL(self):
"""
Expand Down

0 comments on commit 0e8edb5

Please sign in to comment.