TruetypeInfo Class

Inheritance diagram of TruetypeInfo

class TruetypeInfo(filename)

Information about a single Truetype face.

The class memory-maps the font file to read the tables, so it is vital that you call the close method to avoid large memory leaks. Once closed, you cannot call any of the get_* methods.

Not all tables have been implemented yet (or likely ever will). Currently only the name and metric tables are read; in particular there is no glyph or hinting information.

Constructor:

__init__(filename)

Read the given TrueType file.

Parameters:filename – The name of any Windows, OS2 or Macintosh Truetype file.

The object must be closed (see close) after use.

An exception will be raised if the file does not exist or cannot be read.

Methods:

close() Close the font file.
get_character_advances() Return a dictionary of character->advance.
get_character_kernings() Return a dictionary of (left,right)->kerning
get_character_map() Return the character map.
get_font_selection_flags() Return the font selection flags, as defined in OS/2 table
get_glyph_advances() Return a dictionary of glyph->advance.
get_glyph_kernings() Return a dictionary of (left,right)->kerning
get_glyph_map() Calculate and return a reverse character map.
get_horizontal_metrics() Return all horizontal metric entries in table format.
get_name(name[, platform, languages]) Returns the value of the given name in this font.
get_names() Returns a dictionary of names defined in the file.
is_bold() Returns True iff the font describes itself as bold.
is_italic() Returns True iff the font describes itself as italic.

Methods

TruetypeInfo.close()

Close the font file.

This is a good idea, since the entire file is memory mapped in until this method is called. After closing cannot rely on the get_* methods.

TruetypeInfo.get_character_advances()

Return a dictionary of character->advance.

They key of the dictionary is a unit-length unicode string, and the value is a float giving the horizontal advance in em.

TruetypeInfo.get_character_kernings()

Return a dictionary of (left,right)->kerning

The key of the dictionary is a tuple of (left, right) where each element is a unit-length unicode string. The value of the dictionary is the horizontal pairwise kerning in em.

TruetypeInfo.get_character_map()

Return the character map.

Returns a dictionary where the key is a unit-length unicode string and the value is a glyph index. Currently only format 4 character maps are read.

TruetypeInfo.get_font_selection_flags()

Return the font selection flags, as defined in OS/2 table

TruetypeInfo.get_glyph_advances()

Return a dictionary of glyph->advance.

They key of the dictionary is the glyph index and the value is a float giving the horizontal advance in em.

TruetypeInfo.get_glyph_kernings()

Return a dictionary of (left,right)->kerning

The key of the dictionary is a tuple of (left, right) where each element is a glyph index. The value of the dictionary is the horizontal pairwise kerning in em.

TruetypeInfo.get_glyph_map()

Calculate and return a reverse character map.

Returns a dictionary where the key is a glyph index and the value is a unit-length unicode string.

TruetypeInfo.get_horizontal_metrics()

Return all horizontal metric entries in table format.

TruetypeInfo.get_name(name, platform=None, languages=None)

Returns the value of the given name in this font.

Parameters:
  • name – Either an integer, representing the name_id desired (see font format); or a string describing it, see below for valid names.
  • platform – Platform for the requested name. Can be the integer ID, or a string describing it. By default, the Microsoft platform is searched first, then Macintosh.
  • languages – A list of language IDs to search. The first language which defines the requested name will be used. By default, all English dialects are searched.

If the name is not found, None is returned. If the name is found, the value will be decoded and returned as a unicode string. Currently only some common encodings are supported.

Valid names to request are (supply as a string):

'copyright'
'family'
'subfamily'
'identifier'
'name'
'version'
'postscript'
'trademark'
'manufacturer'
'designer'
'description'
'vendor-url'
'designer-url'
'license'
'license-url'
'preferred-family'
'preferred-subfamily'
'compatible-name'
'sample'

Valid platforms to request are (supply as a string):

'unicode'
'macintosh'
'iso'
'microsoft'
'custom'
TruetypeInfo.get_names()

Returns a dictionary of names defined in the file.

The key of each item is a tuple of platform_id, name_id, where each ID is the number as described in the Truetype format.

The value of each item is a tuple of encoding_id, language_id, value, where value is an encoded string.

TruetypeInfo.is_bold()

Returns True iff the font describes itself as bold.

TruetypeInfo.is_italic()

Returns True iff the font describes itself as italic.

Table Of Contents

Previous topic

TruetypeInfo Class

Next topic

GlyphString Class