From 1fc9bc2dcacd817e7784fc5aa8a84c83fae23526 Mon Sep 17 00:00:00 2001 From: Nathan Williis Date: Tue, 3 Sep 2024 17:54:29 +0100 Subject: [PATCH] Docs: fix code-example blocks in varLib/instancer. --- Lib/fontTools/varLib/instancer/__init__.py | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Lib/fontTools/varLib/instancer/__init__.py b/Lib/fontTools/varLib/instancer/__init__.py index 82676d419..fba79dbaa 100644 --- a/Lib/fontTools/varLib/instancer/__init__.py +++ b/Lib/fontTools/varLib/instancer/__init__.py @@ -5,7 +5,9 @@ create full instances (i.e. static fonts) from variable fonts, as well as "parti variable fonts that only contain a subset of the original variation space. For example, if you wish to pin the width axis to a given location while also -restricting the weight axis to 400..700 range, you can do:: +restricting the weight axis to 400..700 range, you can do: + +.. code-block:: sh $ fonttools varLib.instancer ./NotoSans-VF.ttf wdth=85 wght=400:700 @@ -19,30 +21,30 @@ the VF axes were given an explicit coordinate. E.g. here's how to pin the wght axis at a given location in a wght+wdth variable font, keeping only the deltas associated with the wdth axis:: -| >>> from fontTools import ttLib -| >>> from fontTools.varLib import instancer -| >>> varfont = ttLib.TTFont("path/to/MyVariableFont.ttf") -| >>> [a.axisTag for a in varfont["fvar"].axes] # the varfont's current axes -| ['wght', 'wdth'] -| >>> partial = instancer.instantiateVariableFont(varfont, {"wght": 300}) -| >>> [a.axisTag for a in partial["fvar"].axes] # axes left after pinning 'wght' -| ['wdth'] + >>> from fontTools import ttLib + >>> from fontTools.varLib import instancer + >>> varfont = ttLib.TTFont("path/to/MyVariableFont.ttf") + >>> [a.axisTag for a in varfont["fvar"].axes] # the varfont's current axes + ['wght', 'wdth'] + >>> partial = instancer.instantiateVariableFont(varfont, {"wght": 300}) + >>> [a.axisTag for a in partial["fvar"].axes] # axes left after pinning 'wght' + ['wdth'] If the input location specifies all the axes, the resulting instance is no longer 'variable' (same as using fontools varLib.mutator): -| >>> instance = instancer.instantiateVariableFont( -| ... varfont, {"wght": 700, "wdth": 67.5} -| ... ) -| >>> "fvar" not in instance -| True + >>> instance = instancer.instantiateVariableFont( + ... varfont, {"wght": 700, "wdth": 67.5} + ... ) + >>> "fvar" not in instance + True If one just want to drop an axis at the default location, without knowing in advance what the default value for that axis is, one can pass a `None` value: -| >>> instance = instancer.instantiateVariableFont(varfont, {"wght": None}) -| >>> len(varfont["fvar"].axes) -| 1 + >>> instance = instancer.instantiateVariableFont(varfont, {"wght": None}) + >>> len(varfont["fvar"].axes) + 1 From the console script, this is equivalent to passing `wght=drop` as input. @@ -57,24 +59,24 @@ course be combined: L1 dropping one or more axes while leaving the default tables unmodified; - | >>> font = instancer.instantiateVariableFont(varfont, {"wght": None}) + >>> font = instancer.instantiateVariableFont(varfont, {"wght": None}) L2 dropping one or more axes while pinning them at non-default locations; - | >>> font = instancer.instantiateVariableFont(varfont, {"wght": 700}) + >>> font = instancer.instantiateVariableFont(varfont, {"wght": 700}) L3 restricting the range of variation of one or more axes, by setting either a new minimum or maximum, potentially -- though not necessarily -- dropping entire regions of variations that fall completely outside this new range. - | >>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300)}) + >>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300)}) L4 moving the default location of an axis, by specifying (min,defalt,max) values: - | >>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300, 700)}) + >>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300, 700)}) Currently only TrueType-flavored variable fonts (i.e. containing 'glyf' table) are supported, but support for CFF2 variable fonts will be added soon.