3.1.3.2. Encoding

This module handles TeX encoding file.

An encoding file map the glyph index with its symbolic name. It uses the .enc extension.

For example, the content of cork.enc is:

/CorkEncoding [ % now 256 chars follow
% 0x00
  /grave /acute /circumflex /tilde /dieresis /hungarumlaut /ring /caron
  /breve /macron /dotaccent /cedilla
  /ogonek /quotesinglbase /guilsinglleft /guilsinglright
...
% 0xF0
  /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /oe
  /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /germandbls
] def

The percent character is used for comment as for TeX.

The content of this file can be parsed using:

cork_encoding = Encoding('/usr/share/texmf/fonts/enc/dvips/base/cork.enc')

The encoding’s name can be retrieved using:

>>> cork_encoding.name
'CorkEncoding'

The number of glyphes can be obtained using the function len():

>>> len(cork_encoding)
256

The index of the glyph eth can be retrieved using:

>>> cork_encoding['eth']
0xF0

and reciprocally:

>>> cork_encoding[0xF0]
'eth'

The methods to_index() and to_name() are used internally for this purpose.

class PyDvi.Font.Encoding.Encoding(filename)[source]

Bases: object

Parse an encoding file and store the association between the index and the glyph’s name.

Public attributes are:

name
_parse_glyph_names(line)[source]

Find glyph names in line, as ‘/grave /acute /circumflex ...’.

_parse_name(line)[source]

Find the encoding name at the left of the line, as ‘/CorkEncoding’.

print_summary()[source]
to_index(name)[source]

Return the glyph index corresponding to the symbolic name.

to_name(i)[source]

Return the symbolic name corresponding to the glyph index i.

Previous topic

3.1.3.1. AfmParser

Next topic

3.1.3.3. Font

This Page