From b9ebf87ce106a6587795b5a13898fab6d957a194 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 3 Aug 2021 14:20:35 +0200 Subject: [PATCH 1/2] define 'colorClipBoxes' lib key, pass it on to buildCOLR To be able to build a COLRv1 ClipList using the new api defined in https://github.com/fonttools/fonttools/pull/2379 --- Lib/ufo2ft/constants.py | 12 ++++++++++++ Lib/ufo2ft/outlineCompiler.py | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Lib/ufo2ft/constants.py b/Lib/ufo2ft/constants.py index 0028eac27..1ee48d026 100644 --- a/Lib/ufo2ft/constants.py +++ b/Lib/ufo2ft/constants.py @@ -19,6 +19,18 @@ COLOR_LAYERS_KEY = UFO2FT_PREFIX + "colorLayers" COLOR_PALETTES_KEY = UFO2FT_PREFIX + "colorPalettes" COLOR_LAYER_MAPPING_KEY = UFO2FT_PREFIX + "colorLayerMapping" +# list of (glyphs, clipBox) tuples, where 'glyphs' is a list of +# glyph names, and 'clipBox' a 5- or 4-tuple of ints or floats: +# List[ +# Tuple[ +# List[str], # glyph names +# Union[ +# Tuple[float, float, float, float, float], # variable box +# Tuple[float, float, float, float], # non-variable box +# ] +# ] +# ] +COLOR_CLIP_BOXES_KEY = UFO2FT_PREFIX + "colorClipBoxes" OPENTYPE_CATEGORIES_KEY = "public.openTypeCategories" OPENTYPE_META_KEY = "public.openTypeMeta" diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py index f3aff9272..27ef39a7c 100644 --- a/Lib/ufo2ft/outlineCompiler.py +++ b/Lib/ufo2ft/outlineCompiler.py @@ -25,6 +25,7 @@ from fontTools.ttLib.tables.O_S_2f_2 import Panose from ufo2ft.constants import ( + COLOR_CLIP_BOXES_KEY, COLOR_LAYERS_KEY, COLOR_PALETTES_KEY, OPENTYPE_META_KEY, @@ -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(COLOR_CLIP_BOXES_KEY, ()) + for glyphName in glyphs + } + self.otf["COLR"] = buildCOLR( + layerInfo, + glyphMap=glyphMap, + clipBoxes=clipBoxes, + ) def setupTable_CPAL(self): """ From 7119fd52a07e3378394a7ba371364c691aecf73c Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 3 Aug 2021 18:30:31 +0200 Subject: [PATCH 2/2] rename colorClipBoxes to colrClipBoxes Also, in the comment explaining the new lib key, use a more generic term Sequence instead of List/Tuple, for the distinction is not important in this particular case (and plistlib will return lists anyway when parsing ). --- Lib/ufo2ft/constants.py | 19 ++++++++++--------- Lib/ufo2ft/outlineCompiler.py | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Lib/ufo2ft/constants.py b/Lib/ufo2ft/constants.py index 1ee48d026..48920098a 100644 --- a/Lib/ufo2ft/constants.py +++ b/Lib/ufo2ft/constants.py @@ -19,18 +19,19 @@ COLOR_LAYERS_KEY = UFO2FT_PREFIX + "colorLayers" COLOR_PALETTES_KEY = UFO2FT_PREFIX + "colorPalettes" COLOR_LAYER_MAPPING_KEY = UFO2FT_PREFIX + "colorLayerMapping" -# list of (glyphs, clipBox) tuples, where 'glyphs' is a list of -# glyph names, and 'clipBox' a 5- or 4-tuple of ints or floats: -# List[ -# Tuple[ -# List[str], # glyph names +# 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[ -# Tuple[float, float, float, float, float], # variable box -# Tuple[float, float, float, float], # non-variable box +# Sequence[float, float, float, float, float], # variable box +# Sequence[float, float, float, float], # non-variable box # ] -# ] +# ], +# ... # ] -COLOR_CLIP_BOXES_KEY = UFO2FT_PREFIX + "colorClipBoxes" +COLR_CLIP_BOXES_KEY = UFO2FT_PREFIX + "colrClipBoxes" OPENTYPE_CATEGORIES_KEY = "public.openTypeCategories" OPENTYPE_META_KEY = "public.openTypeMeta" diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py index 27ef39a7c..2c78865c1 100644 --- a/Lib/ufo2ft/outlineCompiler.py +++ b/Lib/ufo2ft/outlineCompiler.py @@ -25,9 +25,9 @@ from fontTools.ttLib.tables.O_S_2f_2 import Panose from ufo2ft.constants import ( - COLOR_CLIP_BOXES_KEY, COLOR_LAYERS_KEY, COLOR_PALETTES_KEY, + COLR_CLIP_BOXES_KEY, OPENTYPE_META_KEY, UNICODE_VARIATION_SEQUENCES_KEY, ) @@ -964,7 +964,7 @@ def setupTable_COLR(self): # as colorLib buildCOLR expects clipBoxes = { glyphName: tuple(box) - for glyphs, box in self.ufo.lib.get(COLOR_CLIP_BOXES_KEY, ()) + for glyphs, box in self.ufo.lib.get(COLR_CLIP_BOXES_KEY, ()) for glyphName in glyphs } self.otf["COLR"] = buildCOLR(