Trees | Indices | Toggle frames |
---|
Load fonts and render text.
This is a fairly-low level interface to text rendering. Obtain a font using load:
from pyglet import font arial = font.load('Arial', 14, bold=True, italic=False)
pyglet will load any system-installed fonts. You can add additional fonts (for example, from your program resources) using add_file or add_directory.
Obtain a list of Glyph objects for a string of text using the Font object:
text = 'Hello, world!'
glyphs = arial.get_glyphs(text)
The most efficient way to render these glyphs is with a GlyphString:
glyph_string = GlyphString(text, glyphs) glyph_string.draw()
There are also a variety of methods in both Font and GlyphString to facilitate word-wrapping.
A convenient way to render a string of text is with a Text:
text = Text(font, text) text.draw()
See the pyglet.font.base module for documentation on the base classes used by this package.
pyglet.font.base Abstract classes used by pyglet.font implementations. |
GlyphString
An immutable string of glyphs that can be rendered quickly.
|
|
Text
Simple displayable text.
|
Font |
load(name=None,
size=None,
bold=False,
italic=False,
dpi=None)
Load a font for rendering.
|
add_file(font)
Add a font to pyglet's search path.
|
|
add_directory(dir)
Add a directory of fonts to pyglet's search path.
|
__package__ =
|
Add a font to pyglet's search path.
In order to load a font that is not installed on the system, you must call this method to tell pyglet that it exists. You can supply either a filename or any file-like object.
The font format is platform-dependent, but is typically a TrueType font file containing a single font face. Note that to load this file after adding it you must specify the face name to load, not the filename.
Add a directory of fonts to pyglet's search path.
This function simply calls add_file for each file with a .ttf extension in the given directory. Subdirectories are not searched.
Trees | Indices | Toggle frames |
---|
Generated by Epydoc 3.0beta1 on Thu Dec 31 17:58:17 2009 | http://epydoc.sourceforge.net |