def test_all(self, ttFont): set_default_weight_width_slant( ttFont, {"wght": 500, "wdth": 150, "slnt": -12.0} ) assert ttFont["OS/2"].usWeightClass == 500 assert ttFont["OS/2"].usWidthClass == 8 assert ttFont["post"].italicAngle == -12.0
def test_wdth(self, ttFont, location, expected): set_default_weight_width_slant(ttFont, location) assert ttFont["OS/2"].usWidthClass == expected
def test_slnt(self, ttFont, location, expected): set_default_weight_width_slant(ttFont, location) assert ttFont["post"].italicAngle == expected
def instantiateVariableFont(varfont, axisLimits, inplace=False, optimize=True, overlap=True): """ Instantiate variable font, either fully or partially. Depending on whether the `axisLimits` dictionary references all or some of the input varfont's axes, the output font will either be a full instance (static font) or a variable font with possibly less variation data. Args: varfont: a TTFont instance, which must contain at least an 'fvar' table. Note that variable fonts with 'CFF2' table are not supported yet. axisLimits: a dict keyed by axis tags (str) containing the coordinates (float) along one or more axes where the desired instance will be located. If the value is `None`, the default coordinate as per 'fvar' table for that axis is used. The limit values can also be (min, max) tuples for restricting an axis's variation range, but this is not implemented yet. inplace (bool): whether to modify input TTFont object in-place instead of returning a distinct object. optimize (bool): if False, do not perform IUP-delta optimization on the remaining 'gvar' table's deltas. Possibly faster, and might work around rendering issues in some buggy environments, at the cost of a slightly larger file size. overlap (bool): variable fonts usually contain overlapping contours, and some font rendering engines on Apple platforms require that the `OVERLAP_SIMPLE` and `OVERLAP_COMPOUND` flags in the 'glyf' table be set to force rendering using a non-zero fill rule. Thus we always set these flags on all glyphs to maximise cross-compatibility of the generated instance. You can disable this by setting `overalap` to False. """ sanityCheckVariableTables(varfont) if not inplace: varfont = deepcopy(varfont) axisLimits = populateAxisDefaults(varfont, axisLimits) normalizedLimits = normalizeAxisLimits(varfont, axisLimits) log.info("Normalized limits: %s", normalizedLimits) # TODO Remove this check once ranges are supported if any(isinstance(v, tuple) for v in axisLimits.values()): raise NotImplementedError("Axes range limits are not supported yet") if "gvar" in varfont: instantiateGvar(varfont, normalizedLimits, optimize=optimize) if "cvar" in varfont: instantiateCvar(varfont, normalizedLimits) if "MVAR" in varfont: instantiateMVAR(varfont, normalizedLimits) if "HVAR" in varfont: instantiateHVAR(varfont, normalizedLimits) if "VVAR" in varfont: instantiateVVAR(varfont, normalizedLimits) instantiateOTL(varfont, normalizedLimits) instantiateFeatureVariations(varfont, normalizedLimits) if "avar" in varfont: instantiateAvar(varfont, normalizedLimits) with pruningUnusedNames(varfont): if "STAT" in varfont: instantiateSTAT(varfont, axisLimits) instantiateFvar(varfont, axisLimits) if "fvar" not in varfont: if "glyf" in varfont and overlap: setMacOverlapFlags(varfont["glyf"]) varLib.set_default_weight_width_slant( varfont, location={ axisTag: limit for axisTag, limit in axisLimits.items() if not isinstance(limit, tuple) }, ) return varfont