Cairo has two sets of text rendering capabilities:
A cairo.FontFace specifies all aspects of a font other than the size or font matrix (a font matrix is used to distort a font by sheering it or scaling it unequally in the two directions). A FontFace can be set on a Context by using Context.set_font_face() the size and font matrix are set with Context.set_font_size() and Context.set_font_matrix().
There are various types of FontFace, depending on the font backend they use.
Note
This class cannot be instantiated directly, it is returned by Context.get_font_face().
FreeType Fonts - Font support for FreeType.
The FreeType font backend is primarily used to render text on GNU/Linux systems, but can be used on other platforms too.
Note
FreeType Fonts are not implemented in pycairo because there is no open source Python bindings to FreeType (and fontconfig) that provides a C API. This a possible project idea for anyone interested in adding FreeType support to pycairo.
The cairo.ToyFontFace class can be used instead of Context.select_font_face() to create a toy font independently of a context.
Parameters: |
|
---|---|
Returns: | a new ToyFontFace |
Creates a ToyFontFace from a triplet of family, slant, and weight. These font faces are used in implementation of the the “toy” font API.
If family is the zero-length string “”, the platform-specific default family is assumed. The default family then can be queried using get_family().
The Context.select_font_face() method uses this to create font faces. See that function for limitations of toy font faces.
New in version 1.8.4.
Returns: | the family name of a toy font |
---|---|
Return type: | str |
New in version 1.8.4.
Returns: | the FONT_SLANT value |
---|
New in version 1.8.4.
Returns: | the FONT_WEIGHT value |
---|
New in version 1.8.4.
The user-font feature allows the cairo user to provide drawings for glyphs in a font. This is most useful in implementing fonts in non-standard formats, like SVG fonts and Flash fonts, but can also be used by games and other application to draw “funky” fonts.
Note
UserFontFace support has not (yet) been added to pycairo. If you need this feature in pycairo register your interest by sending a message to the cairo mailing list, or by opening a pycairo bug report.
A ScaledFont is a font scaled to a particular size and device resolution. A ScaledFont is most useful for low-level font usage where a library or application wants to cache a reference to a scaled font to speed up the computation of metrics.
There are various types of scaled fonts, depending on the font backend they use.
Parameters: |
|
---|
Creates a ScaledFont object from a FontFace and matrices that describe the size of the font and the environment in which it will be used.
Returns: | (ascent, descent, height, max_x_advance, max_y_advance), a tuple of float values. |
---|
Gets the metrics for a ScaledFont.
Not implemented in pycairo (yet)
Not implemented in pycairo (yet)
Not implemented in pycairo (yet)
Returns: | the scale Matrix |
---|
The scale matrix is product of the font matrix and the ctm associated with the scaled font, and hence is the matrix mapping from font space to device space.
New in version 1.8.
Not implemented in pycairo (yet)
Parameters: | text (str) – text |
---|---|
Returns: | (x_bearing, y_bearing, width, height, x_advance, y_advance) |
Return type: | 6-tuple of float |
Gets the extents for a string of text. The extents describe a user-space rectangle that encloses the “inked” portion of the text drawn at the origin (0,0) (as it would be drawn by Context.show_text() if the cairo graphics state were set to the same font_face, font_matrix, ctm, and font_options as ScaledFont). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by Context.show_text().
Note that whitespace characters do not directly contribute to the size of the rectangle (width and height). They do contribute indirectly by changing the position of non-whitespace characters. In particular, trailing whitespace characters are likely to not affect the size of the rectangle, though they will affect the x_advance and y_advance values.
New in version 1.2.
Not implemented in pycairo (yet)
An opaque structure holding all options that are used when rendering fonts.
Individual features of a FontOptions can be set or accessed using functions named FontOptions.set_<feature_name> and FontOptions.get_<feature_name>, like FontOptions.set_antialias() and FontOptions.get_antialias().
New features may be added to a FontOptions in the future. For this reason, FontOptions.copy(), FontOptions.equal(), FontOptions.merge(), and FontOptions.hash() should be used to copy, check for equality, merge, or compute a hash value of FontOptions objects.
Returns: | a newly allocated FontOptions. |
---|
Allocates a new FontOptions object with all options initialized to default values.
Returns: | the HINT METRICS mode for the FontOptions object |
---|
Returns: | the HINT STYLE for the FontOptions object |
---|
Returns: | the SUBPIXEL_ORDER for the FontOptions object |
---|
Parameters: | antialias – the ANTIALIAS mode |
---|
This specifies the type of antialiasing to do when rendering text.
Parameters: | hint_metrics – the HINT METRICS mode |
---|
This controls whether metrics are quantized to integer values in device units.
Parameters: | hint_style – the HINT STYLE |
---|
This controls whether to fit font outlines to the pixel grid, and if so, whether to optimize for fidelity or contrast.
Parameters: | subpixel_order – the SUBPIXEL_ORDER |
---|
The subpixel order specifies the order of color elements within each pixel on the display device when rendering with an antialiasing mode of cairo.ANTIALIAS_SUBPIXEL.