Documentation for module t1lib


Object-oriented interface to the t1lib Type1 font rasterizer.

This is the interface that should actually be used; _t1lib is the actual C extension which exposes the low-level interface.

Constants

LOG_ERROR
Log only serious errors. This can include such events as memory allocation failures.
LOG_WARNING
Log anything that might be useful in diagnosing misbehavior in a debugged application. This can include such information as missing font metrics (AFM) files.
LOG_STATISTIC
Various informational messages are included in the log; this can include memory consumption information.
LOG_DEBUG
Logging level to support debugging. All sorts of mess gets included in the log. This should be used primarily when debugging t1lib or tracking really nasty memory problems.

Exception T1Error

Raised by primitive t1lib operations that fail.

The string value describes what went wrong.


Exception UnknownFontError

Raised when a requested fontname is not recognized.

Public Members

fontname
requested font name

Exception EncodingFormatError

Raised when a font encoding file has a formatting error.


Class BBox

A bounding box.

Public Members

llx
lower-left x coordinate
lly
lower-left y coordinate
urx
upper-right x coordinate
ury
upper-right y coordinate

All values are measured in character space units.

Constructor
bbox
getHeight()

Return the height of the region.

getWidth()

Return the width of the region.


Class MetricsInfo

Metrics information derived from AFM data.

Public Members

width
bbox
bounding box of the glyph which would be generated for string
numchars
number of characters in the string measured
charpos
vector of numchars integers; see below
string
the string measured

All values are measured in character space units.

The charpos vector contains values which represent the horizontal escapement of string[:i + 1], where i is an index into string.

Constructor
metrics
string

Class Glyph

A rasterized bitmap.

Public Members

bits
string representing the bitmap as generated by t1lib
ascent
number of pixels image rises above the baseline
descent
number of pixels image descends below the baseline
leftSideBearing
number of pixels between the origin of the glyph and the leftmost bitmap pixel
rightSideBearing
number of pixels between the origin of the glyph and the rightmost bitmap pixel
characterWidth
width of the glyph, including character margins; this is the amount of horizontal movement needed before placing a subsequent bitmap
bpp
number of data bits per pixel
Constructor

Initialize a Glyph instance.

bits
string containing the bitmaps as generated by t1lib
metrics
5-tuple representing the metrics field of a t1lib GLYPH structure
bpp
bits per pixel

See the t1lib documentation for information on the format of the bits field.

getHeight()

Return the height of the bitmap.

Character margin areas are not included.

getWidth()

Return the width of the bitmap.

Character margin areas are not included.


Class T1Font

A font.

Instances of this class should not be created explicitly in user code.

isLogical()

Return true iff this font is a t1lib 'logical' font.

isPhysical()

Return true iff this font is a t1lib 'physical' font.

getLogicalPeers()

Return sequence of all logical fonts generated from the physical font associated with this font.

getPhysicalFont()

Return the t1lib 'physical' font associated with this font.

getUnderlinePosition()

Return the underline position of this font.

If no AFM data is available, return 0.

getUnderlineThickness()

Return the underline thickness of this font.

If no AFM data is available, return 0.

getPostScriptName()

Return the PostScript name for this font.

getCharName()

Return the PostScript name of a character in the current encoding.

char
character for which the name is desired
getEncodingIndex()

Return the index of a character in the current encoding.

charname
PostScript character name

If the character is not present in the current encoding, a T1Error exception is raised.

getLigatures()
char
getKerning()

Return the kerning for a character pair.

char1
char2

The value returned is measured in character space units. If no AFM data is available, 0 is returned.

getEncoding()

Return the current encoding vector.

setEncoding()

Change the encoding vector.

encoding = None
new encoding vector

If the new encoding vector is different from the old vector, the bitmap cache is cleared.

getExtension()

Return the current extension factor for the font.

setExtension()

Change the extension of the font.

extend
the new extension factor

The new slant replaces the old extension; it is not a modifier. If the new extension factor is different from the old factor, the bitmap cache is cleared.

getSlant()

Return the current slant factor for the font.

setSlant()

Change the slant of the font.

slant
the new slant factor

The new slant replaces the old slant; it is not a modifier. If the new slant factor is different from the old facter, the bitmap cache is cleared.

copy()

Return a new logical font based on the same physical font as this font.

reset()

Delete all cached bitmaps for this font.

delete()

Attempt to free all memory used by this font.

If this is a physical font still referenced by any logical fonts, a T1Error exception will be raised.


Class FontSetter

Constructor

Initialize a FontSetter instance.

font
T1Font instance
size
point size of the rasterized characters
angle = 0.0
rotation angle of the rasterized image (measured counter-clockwise)
spaceoff = 0.0
kerning = 0
flag indicating whether pairwise kerning should be used
bpp = 1
bits-per-pixel for the generated rasterizations
setChar()

Rasterize a single character.

char
the character to rasterize

Returns a Glyph instance.

setString()

Rasterize a string.

string
the string to rasterize

Returns a Glyph instance.

getMetrics()

Return metrics information for a string.

string
the string to compute metrics information for.
getWidth()

Return the width of a string in character space units.

string
the string to measure
getBBox()

Return the bounding box for a string.

string
string to compute the bounding box for

Returns a BBox instance.

setBitsPerPixel()

Set the number of bits per pixel for the resulting glyphs.

bpp
new bit depth

If bpp is not 1, 8, 16, 24, or 32, ValueError is raised.

newGlyph()

Return a glyph object for the specified information.

bits
string representing the raw bitmap generated by t1lib
metrics
bpp
bits-per-pixel for the bitmap
resetSize()

Clear bitmap cache in underlying t1lib.


Functions

init()

Initialize the library.

logging = 0
flag to indicate whether logging should be enabled

Use of this function is only necessary to enable logging. In that case, this must be called before any other calls to this module have been made.

printLog()

Add an entry to the t1lib.log file.

message
string containing the text to write out
level = LOG_WARNING
severity level; one of LOG_ERROR, LOG_WARNING, LOG_STATISTIC, or LOG_DEBUG

The name of the calling function or method is determined automatically and cannot be supplied by the caller.

setLogLevel()

Set the level of severity at which log entries are written to the log.

level
severity level; one of LOG_ERROR, LOG_WARNING, LOG_STATISTIC, or LOG_DEBUG
setDeviceResolutions()

Set the resolution of the output device in dots-per-inch.

xres
horizontal DPI
yres
vertical DPI
setAAGrayValues()

Set the values used for each level of gray for anti-aliasing.

white
gray75
gray50
gray25
black

Each value is interpreted as an unsigned 32-bit integer. Long integers may be used.

getFont()

Return a font object for a named font.

fontname
PostScript name of the font to be located

If the named font is not found, an UnknownFontError exception is raised. The fontname value is case-sensitive.

Font objects returned by this function will always refer to 'physical' fonts in t1lib terminology; logical fonts generated from the same physical base may exist.

loadEncoding()

Return an encoding vector read from a file.

fp_or_filename
either a file-like object or the name of a disk file

If a string is passed in, it will be used as a filename and passed to open(), otherwise fp_or_filename will be treated as any file-like object and assumed to have a readline() method.


Documentation for module t1lib