| |
- __builtin__.object
-
- FontKey
- FontManager
- FontProperties
class FontKey(__builtin__.object) |
|
A class for storing Font properties. It is used when populating
the font dictionary. |
|
Methods defined here:
- __init__(self, name='', style='normal', variant='normal', weight='normal', stretch='normal', size='medium')
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'FontKey' objects>
- list of weak references to the object (if defined)
|
class FontManager |
|
On import, the FontManager creates a dictionary of TrueType
fonts based on the font properties: name, style, variant, weight,
stretch, and size. The findfont() method searches this dictionary
for a font file name that exactly matches the font properties of the
specified text. If none is found, a default font is returned. By
updating the dictionary with the properties of the found font, the
font dictionary can act like a font cache. |
|
Methods defined here:
- __init__(self, size=None, weight='normal')
- findfont(self, prop, fontext='ttf')
- Search the font dictionary for a font that exactly or closely
matches the specified font properties. See the FontProperties class
for a description.
The properties are searched in the following order: name, style,
variant, weight, stretch, and size. The font weight always matches
returning the closest weight, and the font size always matches for
scalable fonts. An oblique style font will be used inplace of a
missing italic style font if present. See the W3C Cascading Style
Sheet, Level 1 (CSS1; http://www.w3.org/TR/1998/REC-CSS2-19980512/)
documentation for a description of the font finding algorithm.
- get_default_size(self)
- Return the default font size.
- get_default_weight(self)
- Return the default font weight.
- set_default_size(self, size)
- Set the default font size in points. The initial value is set by font.size in rc.
- set_default_weight(self, weight)
- Set the default font weight. The initial value is 'normal'.
- update_fonts(self, filenames)
- Update the font dictionary with new font files.
Currently not implemented.
|
class FontProperties |
|
A class for storing and manipulating font properties.
The font properties are those described in the W3C Cascading Style
Sheet, Level 1 (CSS1; http://www.w3.org/TR/1998/REC-CSS2-19980512/)
font specification. The six properties are:
family - A list of font names in decreasing order of priority.
The last item is the default font name and is given the
name of the font family, either serif, sans-serif,
cursive, fantasy, and monospace.
style - Either normal, italic or oblique.
variant - Either normal or small-caps.
stretch - Either an absolute value of ultra-condensed, extra-
condensed, condensed, semi-condensed, normal, semi-
expanded, expanded, extra-expanded or ultra-expanded;
or a relative value of narrower or wider.
This property is currently not implemented and is set to
normal.
weight - A numeric value in the range 100, 200, 300, ..., 900.
size - Either an absolute value of xx-small, x-small, small,
medium, large, x-large, xx-large; or a relative value
of smaller or larger; or an absolute font size, e.g. 12;
or scalable.
The default font property for TrueType fonts is: sans-serif, normal,
normal, normal, 400, scalable.
The preferred usage of font sizes is to use the absolute values, e.g.
large, instead of absolute font sizes, e.g. 12. This approach allows
all text sizes to be made larger or smaller based on the font manager's
default font size, i.e. by using the set_default_size() method of the
font manager.
Examples:
# Load default font properties
>>> p = FontProperties()
>>> p.get_family()
['Bitstream Vera Sans', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucida', 'Arial', 'Helvetica', 'sans-serif']
# Change font family to 'fantasy'
>>> p.set_family('fantasy')
>>> p.get_family()
['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact', 'Western', 'fantasy']
# Make these fonts highest priority in font family
>>> p.set_name(['foo', 'fantasy', 'bar', 'baz'])
Font name 'fantasy' is a font family. It is being deleted from the list.
>>> p.get_family()
['foo', 'bar', 'baz', 'Comic Sans MS', 'Chicago', 'Charcoal', 'Impact', 'Western', 'fantasy'] |
|
Methods defined here:
- __hash__(self)
- __init__(self, family=None, style=None, variant=None, weight=None, stretch=None, size=None, fname=None)
- __str__(self)
- copy(self)
- Return a deep copy of self
- get_family(self)
- Return a list of font names that comprise the font family.
- get_name(self)
- Return the name of the font that best matches the font
properties.
- get_size(self)
- Return the font size.
- get_size_in_points(self, parent_size=None)
- Return the size property as a numeric value. String values
are converted to their corresponding numeric value.
- get_stretch(self)
- Return the font stretch or width. Options are: normal,
narrow, condensed, or wide.
- get_style(self)
- Return the font style. Values are: normal, italic or oblique.
- get_variant(self)
- Return the font variant. Values are: normal or small-caps.
- get_weight(self)
- Return the font weight. See the FontProperties class for a
a list of possible values.
- set_family(self, family)
- Change the font family. Options are: serif, sans-serif, cursive,
fantasy, or monospace.
- set_name(self, names)
- Add one or more font names to the font family list. If the
font name is already in the list, then the font is given a higher
priority in the font family list. To change the font family, use the
set_family() method.
- set_size(self, size)
- Set the font size.
- set_stretch(self, stretch)
- Set the font stretch or width. Options are: normal, narrow,
condensed, or wide.
- set_style(self, style)
- Set the font style. Values are: normal, italic or oblique.
- set_variant(self, variant)
- Set the font variant. Values are: normal or small-caps.
- set_weight(self, weight)
- Set the font weight. See the FontProperties class for a
a list of possible values.
| |