Docs: fix code-example blocks in ttLib.

This commit is contained in:
Nathan Williis 2024-09-03 17:55:02 +01:00
parent df49533892
commit 21d04842f8
2 changed files with 16 additions and 15 deletions

View File

@ -1,8 +1,9 @@
"""ttLib/sfnt.py -- low-level module to deal with the sfnt file format. """ttLib/sfnt.py -- low-level module to deal with the sfnt file format.
Defines two public classes: Defines two public classes:
SFNTReader
SFNTWriter - SFNTReader
- SFNTWriter
(Normally you don't have to use these classes explicitly; they are (Normally you don't have to use these classes explicitly; they are
used automatically by ttLib.TTFont.) used automatically by ttLib.TTFont.)

View File

@ -28,34 +28,34 @@ class TTFont(object):
Example usage:: Example usage::
>> from fontTools import ttLib >>> from fontTools import ttLib
>> tt = ttLib.TTFont("afont.ttf") # Load an existing font file >>> tt = ttLib.TTFont("afont.ttf") # Load an existing font file
>> tt['maxp'].numGlyphs >>> tt['maxp'].numGlyphs
242 242
>> tt['OS/2'].achVendID >>> tt['OS/2'].achVendID
'B&H\000' 'B&H\000'
>> tt['head'].unitsPerEm >>> tt['head'].unitsPerEm
2048 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::
>> os2 = newTable("OS/2") >>> os2 = newTable("OS/2")
>> os2.version = 4 >>> os2.version = 4
>> # set other attributes >>> # set other attributes
>> font["OS/2"] = os2 >>> 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)::
>> tt.saveXML("afont.ttx") >>> tt.saveXML("afont.ttx")
Dumping 'LTSH' table... Dumping 'LTSH' table...
Dumping 'OS/2' table... Dumping 'OS/2' table...
[...] [...]
>> tt2 = ttLib.TTFont() # Create a new font object >>> tt2 = ttLib.TTFont() # Create a new font object
>> tt2.importXML("afont.ttx") >>> tt2.importXML("afont.ttx")
>> tt2['maxp'].numGlyphs >>> tt2['maxp'].numGlyphs
242 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