Docs: workaround doctest-vs-Sphinx syntax highlighting.
This commit is contained in:
parent
6914070e00
commit
7d93689aca
@ -46,7 +46,7 @@ class FreeTypePen(BasePen):
|
|||||||
glyphSet: a dictionary of drawable glyph objects keyed by name
|
glyphSet: a dictionary of drawable glyph objects keyed by name
|
||||||
used to resolve component references in composite glyphs.
|
used to resolve component references in composite glyphs.
|
||||||
|
|
||||||
:Examples:
|
Examples:
|
||||||
If `numpy` and `matplotlib` is available, the following code will
|
If `numpy` and `matplotlib` is available, the following code will
|
||||||
show the glyph image of `fi` in a new window::
|
show the glyph image of `fi` in a new window::
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ class FreeTypePen(BasePen):
|
|||||||
object of the resulted bitmap and ``size`` is a 2-tuple of its
|
object of the resulted bitmap and ``size`` is a 2-tuple of its
|
||||||
dimension.
|
dimension.
|
||||||
|
|
||||||
:Notes:
|
Notes:
|
||||||
The image size should always be given explicitly if you need to get
|
The image size should always be given explicitly if you need to get
|
||||||
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
||||||
forcifully fits to the bounding box and the side bearings get
|
forcifully fits to the bounding box and the side bearings get
|
||||||
@ -188,13 +188,14 @@ class FreeTypePen(BasePen):
|
|||||||
maintained but RSB won’t. The difference between the two becomes
|
maintained but RSB won’t. The difference between the two becomes
|
||||||
more obvious when rotate or skew transformation is applied.
|
more obvious when rotate or skew transformation is applied.
|
||||||
|
|
||||||
:Example:
|
Example:
|
||||||
.. code-block::
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> pen = FreeTypePen(None)
|
>>>
|
||||||
>>> glyph.draw(pen)
|
>> pen = FreeTypePen(None)
|
||||||
>>> buf, size = pen.buffer(width=500, height=1000)
|
>> glyph.draw(pen)
|
||||||
>>> type(buf), len(buf), size
|
>> buf, size = pen.buffer(width=500, height=1000)
|
||||||
|
>> type(buf), len(buf), size
|
||||||
(<class 'bytes'>, 500000, (500, 1000))
|
(<class 'bytes'>, 500000, (500, 1000))
|
||||||
"""
|
"""
|
||||||
transform = transform or Transform()
|
transform = transform or Transform()
|
||||||
@ -268,7 +269,7 @@ class FreeTypePen(BasePen):
|
|||||||
A ``numpy.ndarray`` object with a shape of ``(height, width)``.
|
A ``numpy.ndarray`` object with a shape of ``(height, width)``.
|
||||||
Each element takes a value in the range of ``[0.0, 1.0]``.
|
Each element takes a value in the range of ``[0.0, 1.0]``.
|
||||||
|
|
||||||
:Notes:
|
Notes:
|
||||||
The image size should always be given explicitly if you need to get
|
The image size should always be given explicitly if you need to get
|
||||||
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
||||||
forcifully fits to the bounding box and the side bearings get
|
forcifully fits to the bounding box and the side bearings get
|
||||||
@ -278,15 +279,17 @@ class FreeTypePen(BasePen):
|
|||||||
maintained but RSB won’t. The difference between the two becomes
|
maintained but RSB won’t. The difference between the two becomes
|
||||||
more obvious when rotate or skew transformation is applied.
|
more obvious when rotate or skew transformation is applied.
|
||||||
|
|
||||||
:Example:
|
Example:
|
||||||
.. code-block::
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> pen = FreeTypePen(None)
|
>>>
|
||||||
>>> glyph.draw(pen)
|
>> pen = FreeTypePen(None)
|
||||||
>>> arr = pen.array(width=500, height=1000)
|
>> glyph.draw(pen)
|
||||||
>>> type(a), a.shape
|
>> arr = pen.array(width=500, height=1000)
|
||||||
|
>> type(a), a.shape
|
||||||
(<class 'numpy.ndarray'>, (1000, 500))
|
(<class 'numpy.ndarray'>, (1000, 500))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
buf, size = self.buffer(
|
buf, size = self.buffer(
|
||||||
@ -317,7 +320,7 @@ class FreeTypePen(BasePen):
|
|||||||
rendering glyphs with negative sidebearings without clipping.
|
rendering glyphs with negative sidebearings without clipping.
|
||||||
evenOdd: Pass ``True`` for even-odd fill instead of non-zero.
|
evenOdd: Pass ``True`` for even-odd fill instead of non-zero.
|
||||||
|
|
||||||
:Notes:
|
Notes:
|
||||||
The image size should always be given explicitly if you need to get
|
The image size should always be given explicitly if you need to get
|
||||||
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
||||||
forcifully fits to the bounding box and the side bearings get
|
forcifully fits to the bounding box and the side bearings get
|
||||||
@ -327,12 +330,13 @@ class FreeTypePen(BasePen):
|
|||||||
maintained but RSB won’t. The difference between the two becomes
|
maintained but RSB won’t. The difference between the two becomes
|
||||||
more obvious when rotate or skew transformation is applied.
|
more obvious when rotate or skew transformation is applied.
|
||||||
|
|
||||||
:Example:
|
Example:
|
||||||
.. code-block::
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> pen = FreeTypePen(None)
|
>>>
|
||||||
>>> glyph.draw(pen)
|
>> pen = FreeTypePen(None)
|
||||||
>>> pen.show(width=500, height=1000)
|
>> glyph.draw(pen)
|
||||||
|
>> pen.show(width=500, height=1000)
|
||||||
"""
|
"""
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
@ -369,7 +373,7 @@ class FreeTypePen(BasePen):
|
|||||||
A ``PIL.image`` object. The image is filled in black with alpha
|
A ``PIL.image`` object. The image is filled in black with alpha
|
||||||
channel obtained from the rendered bitmap.
|
channel obtained from the rendered bitmap.
|
||||||
|
|
||||||
:Notes:
|
Notes:
|
||||||
The image size should always be given explicitly if you need to get
|
The image size should always be given explicitly if you need to get
|
||||||
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
a proper glyph image. When ``width`` and ``height`` are omitted, it
|
||||||
forcifully fits to the bounding box and the side bearings get
|
forcifully fits to the bounding box and the side bearings get
|
||||||
@ -379,13 +383,14 @@ class FreeTypePen(BasePen):
|
|||||||
maintained but RSB won’t. The difference between the two becomes
|
maintained but RSB won’t. The difference between the two becomes
|
||||||
more obvious when rotate or skew transformation is applied.
|
more obvious when rotate or skew transformation is applied.
|
||||||
|
|
||||||
:Example:
|
Example:
|
||||||
.. code-block::
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> pen = FreeTypePen(None)
|
>>>
|
||||||
>>> glyph.draw(pen)
|
>> pen = FreeTypePen(None)
|
||||||
>>> img = pen.image(width=500, height=1000)
|
>> glyph.draw(pen)
|
||||||
>>> type(img), img.size
|
>> img = pen.image(width=500, height=1000)
|
||||||
|
>> type(img), img.size
|
||||||
(<class 'PIL.Image.Image'>, (500, 1000))
|
(<class 'PIL.Image.Image'>, (500, 1000))
|
||||||
"""
|
"""
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -26,37 +26,43 @@ class TTFont(object):
|
|||||||
accessing tables. Tables will be only decompiled when necessary, ie. when
|
accessing tables. Tables will be only decompiled when necessary, ie. when
|
||||||
they're actually accessed. This means that simple operations can be extremely fast.
|
they're actually accessed. This means that simple operations can be extremely fast.
|
||||||
|
|
||||||
Example usage::
|
Example usage:
|
||||||
|
.. code-block:: pycon
|
||||||
>>> from fontTools import ttLib
|
|
||||||
>>> tt = ttLib.TTFont("afont.ttf") # Load an existing font file
|
>>>
|
||||||
>>> tt['maxp'].numGlyphs
|
>> from fontTools import ttLib
|
||||||
242
|
>> tt = ttLib.TTFont("afont.ttf") # Load an existing font file
|
||||||
>>> tt['OS/2'].achVendID
|
>> tt['maxp'].numGlyphs
|
||||||
'B&H\000'
|
242
|
||||||
>>> tt['head'].unitsPerEm
|
>> tt['OS/2'].achVendID
|
||||||
2048
|
'B&H\000'
|
||||||
|
>> tt['head'].unitsPerEm
|
||||||
|
2048
|
||||||
|
|
||||||
For details of the objects returned when accessing each table, see :ref:`tables`.
|
For details of the objects returned when accessing each table, see :ref:`tables`.
|
||||||
To add a table to the font, use the :py:func:`newTable` function::
|
To add a table to the font, use the :py:func:`newTable` function:
|
||||||
|
.. code-block:: pycon
|
||||||
>>> os2 = newTable("OS/2")
|
|
||||||
>>> os2.version = 4
|
>>>
|
||||||
>>> # set other attributes
|
>> os2 = newTable("OS/2")
|
||||||
>>> font["OS/2"] = os2
|
>> os2.version = 4
|
||||||
|
>> # set other attributes
|
||||||
|
>> font["OS/2"] = os2
|
||||||
|
|
||||||
TrueType fonts can also be serialized to and from XML format (see also the
|
TrueType fonts can also be serialized to and from XML format (see also the
|
||||||
:ref:`ttx` binary)::
|
:ref:`ttx` binary):
|
||||||
|
.. code-block:: pycon
|
||||||
>>> tt.saveXML("afont.ttx")
|
|
||||||
Dumping 'LTSH' table...
|
>>
|
||||||
Dumping 'OS/2' table...
|
>> tt.saveXML("afont.ttx")
|
||||||
[...]
|
Dumping 'LTSH' table...
|
||||||
|
Dumping 'OS/2' table...
|
||||||
>>> tt2 = ttLib.TTFont() # Create a new font object
|
[...]
|
||||||
>>> tt2.importXML("afont.ttx")
|
|
||||||
>>> tt2['maxp'].numGlyphs
|
>> tt2 = ttLib.TTFont() # Create a new font object
|
||||||
242
|
>> tt2.importXML("afont.ttx")
|
||||||
|
>> tt2['maxp'].numGlyphs
|
||||||
|
242
|
||||||
|
|
||||||
The TTFont object may be used as a context manager; this will cause the file
|
The TTFont object may be used as a context manager; this will cause the file
|
||||||
reader to be closed after the context ``with`` block is exited::
|
reader to be closed after the context ``with`` block is exited::
|
||||||
@ -981,14 +987,16 @@ def tagToIdentifier(tag):
|
|||||||
letters get an underscore after the letter. Trailing spaces are
|
letters get an underscore after the letter. Trailing spaces are
|
||||||
trimmed. Illegal characters are escaped as two hex bytes. If the
|
trimmed. Illegal characters are escaped as two hex bytes. If the
|
||||||
result starts with a number (as the result of a hex escape), an
|
result starts with a number (as the result of a hex escape), an
|
||||||
extra underscore is prepended. Examples::
|
extra underscore is prepended. Examples:
|
||||||
|
.. code-block:: pycon
|
||||||
>>> tagToIdentifier('glyf')
|
|
||||||
'_g_l_y_f'
|
>>>
|
||||||
>>> tagToIdentifier('cvt ')
|
>> tagToIdentifier('glyf')
|
||||||
'_c_v_t'
|
'_g_l_y_f'
|
||||||
>>> tagToIdentifier('OS/2')
|
>> tagToIdentifier('cvt ')
|
||||||
'O_S_2f_2'
|
'_c_v_t'
|
||||||
|
>> tagToIdentifier('OS/2')
|
||||||
|
'O_S_2f_2'
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -19,31 +19,37 @@ and returns a new TTFont representing either a partial VF, or full instance if a
|
|||||||
the VF axes were given an explicit coordinate.
|
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
|
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::
|
font, keeping only the deltas associated with the wdth axis:
|
||||||
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> from fontTools import ttLib
|
>>>
|
||||||
>>> from fontTools.varLib import instancer
|
>> from fontTools import ttLib
|
||||||
>>> varfont = ttLib.TTFont("path/to/MyVariableFont.ttf")
|
>> from fontTools.varLib import instancer
|
||||||
>>> [a.axisTag for a in varfont["fvar"].axes] # the varfont's current axes
|
>> varfont = ttLib.TTFont("path/to/MyVariableFont.ttf")
|
||||||
|
>> [a.axisTag for a in varfont["fvar"].axes] # the varfont's current axes
|
||||||
['wght', 'wdth']
|
['wght', 'wdth']
|
||||||
>>> partial = instancer.instantiateVariableFont(varfont, {"wght": 300})
|
>> partial = instancer.instantiateVariableFont(varfont, {"wght": 300})
|
||||||
>>> [a.axisTag for a in partial["fvar"].axes] # axes left after pinning 'wght'
|
>> [a.axisTag for a in partial["fvar"].axes] # axes left after pinning 'wght'
|
||||||
['wdth']
|
['wdth']
|
||||||
|
|
||||||
If the input location specifies all the axes, the resulting instance is no longer
|
If the input location specifies all the axes, the resulting instance is no longer
|
||||||
'variable' (same as using fontools varLib.mutator):
|
'variable' (same as using fontools varLib.mutator):
|
||||||
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> instance = instancer.instantiateVariableFont(
|
>>>
|
||||||
|
>> instance = instancer.instantiateVariableFont(
|
||||||
... varfont, {"wght": 700, "wdth": 67.5}
|
... varfont, {"wght": 700, "wdth": 67.5}
|
||||||
... )
|
... )
|
||||||
>>> "fvar" not in instance
|
>> "fvar" not in instance
|
||||||
True
|
True
|
||||||
|
|
||||||
If one just want to drop an axis at the default location, without knowing in
|
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:
|
advance what the default value for that axis is, one can pass a `None` value:
|
||||||
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> instance = instancer.instantiateVariableFont(varfont, {"wght": None})
|
>>>
|
||||||
>>> len(varfont["fvar"].axes)
|
>> instance = instancer.instantiateVariableFont(varfont, {"wght": None})
|
||||||
|
>> len(varfont["fvar"].axes)
|
||||||
1
|
1
|
||||||
|
|
||||||
From the console script, this is equivalent to passing `wght=drop` as input.
|
From the console script, this is equivalent to passing `wght=drop` as input.
|
||||||
@ -58,25 +64,33 @@ course be combined:
|
|||||||
|
|
||||||
L1
|
L1
|
||||||
dropping one or more axes while leaving the default tables unmodified;
|
dropping one or more axes while leaving the default tables unmodified;
|
||||||
|
.. code-block:: pycon
|
||||||
|
|
||||||
>>> font = instancer.instantiateVariableFont(varfont, {"wght": None})
|
>>>
|
||||||
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": None})
|
||||||
|
|
||||||
L2
|
L2
|
||||||
dropping one or more axes while pinning them at non-default locations;
|
dropping one or more axes while pinning them at non-default locations;
|
||||||
|
.. code-block:: pycon
|
||||||
>>> font = instancer.instantiateVariableFont(varfont, {"wght": 700})
|
|
||||||
|
>>>
|
||||||
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": 700})
|
||||||
|
|
||||||
L3
|
L3
|
||||||
restricting the range of variation of one or more axes, by setting either
|
restricting the range of variation of one or more axes, by setting either
|
||||||
a new minimum or maximum, potentially -- though not necessarily -- dropping
|
a new minimum or maximum, potentially -- though not necessarily -- dropping
|
||||||
entire regions of variations that fall completely outside this new range.
|
entire regions of variations that fall completely outside this new range.
|
||||||
|
.. code-block:: pycon
|
||||||
>>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300)})
|
|
||||||
|
>>>
|
||||||
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300)})
|
||||||
|
|
||||||
L4
|
L4
|
||||||
moving the default location of an axis, by specifying (min,defalt,max) values:
|
moving the default location of an axis, by specifying (min,defalt,max) values:
|
||||||
|
.. code-block:: pycon
|
||||||
>>> 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)
|
Currently only TrueType-flavored variable fonts (i.e. containing 'glyf' table)
|
||||||
are supported, but support for CFF2 variable fonts will be added soon.
|
are supported, but support for CFF2 variable fonts will be added soon.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user