Next: , Previous: Coverage Maps, Up: Top


3 Fonts

Structures representing abstract fonts

3.1 Overview

Pango supports a flexible architecture where a particular rendering architecture can supply an implementation of fonts. The <pango-font> structure represents an abstract rendering-system-independent font. Pango provides routines to list available fonts, and to load a font of a given description.

3.2 Usage

— Class: <pango-font-description>

Derives from <gboxed>.

This class defines no direct slots.

— Class: <pango-font-metrics>

Derives from <gboxed>.

This class defines no direct slots.

— Class: <pango-font>

Derives from <gobject>.

This class defines no direct slots.

— Class: <pango-font-family>

Derives from <gobject>.

This class defines no direct slots.

— Class: <pango-font-face>

Derives from <gobject>.

This class defines no direct slots.

— Class: <pango-font-map>

Derives from <gobject>.

This class defines no direct slots.

— Class: <pango-fontset>

Derives from <gobject>.

This class defines no direct slots.

— Function: pango-font-description-new ⇒  (ret <pango-font-description>)

Creates a new font description structure with all fields unset.

ret
the newly allocated <pango-font-description>, which should be freed using pango-font-description-free.
— Function: pango-font-description-copy (self <pango-font-description>) ⇒  (ret <pango-font-description>)

Make a copy of a <pango-font-description>.

desc
a <pango-font-description>
ret
the newly allocated <pango-font-description>, which should be freed with pango-font-description-free.
— Function: pango-font-description-hash (self <pango-font-description>) ⇒  (ret unsigned-int)

Computes a hash of a <pango-font-description> structure suitable to be used, for example, as an argument to g-hash-table-new. The hash value is independent of desc->mask.

desc
a <pango-font-description>
ret
the hash value.
— Function: pango-font-description-equal (self <pango-font-description>) (desc2 <pango-font-description>) ⇒  (ret bool)

Compares two font descriptions for equality. Two font descriptions are considered equal if the fonts they describe are provably identical. This means that their masks do not have to match, as long as other fields are all the same. (Two font descriptions may result in identical fonts being loaded, but still compare ‘#f’.)

desc1
a <pango-font-description>
desc2
another <pango-font-description>
ret
#t’ if the two font descriptions are identical, ‘#f’ otherwise.
— Function: pango-font-description-set-family (self <pango-font-description>) (family mchars)

Sets the family name field of a font description. The family name represents a family of related font styles, and will resolve to a particular <pango-font-family>. In some uses of <pango-font-description>, it is also possible to use a comma separated list of family names for this field.

desc
a <pango-font-description>.
family
a string representing the family name.
— Function: pango-font-description-get-family (self <pango-font-description>) ⇒  (ret mchars)

Gets the family name field of a font description. See pango-font-description-set-family.

desc
a <pango-font-description>.
ret
the family name field for the font description, or ‘#f’ if not previously set. This has the same life-time as the font description itself and should not be freed.
— Function: pango-font-description-set-style (self <pango-font-description>) (style <pango-style>)

Sets the style field of a <pango-font-description>. The <pango-style> enumeration describes whether the font is slanted and the manner in which it is slanted; it can be either <pango-style-normal>, <pango-style-italic>, or <pango-style-oblique>. Most fonts will either have a italic style or an oblique style, but not both, and font matching in Pango will match italic specifications with oblique fonts and vice-versa if an exact match is not found.

desc
a <pango-font-description>
style
the style for the font description
— Function: pango-font-description-get-style (self <pango-font-description>) ⇒  (ret <pango-style>)

Gets the style field of a <pango-font-description>. See pango-font-description-set-style.

desc
a <pango-font-description>
ret
the style field for the font description. Use pango-font-description-get-set-fields to find out if the field was explicitly set or not.
— Function: pango-font-description-set-variant (self <pango-font-description>) (variant <pango-variant>)

Sets the variant field of a font description. The <pango-variant> can either be ‘PANGO_VARIANT_NORMAL’ or ‘PANGO_VARIANT_SMALL_CAPS’.

desc
a <pango-font-description>
variant
the variant type for the font description.
— Function: pango-font-description-get-variant (self <pango-font-description>) ⇒  (ret <pango-variant>)

Gets the variant field of a <pango-font-description>. See pango-font-description-set-variant.

desc
a <pango-font-description>.
ret
the variant field for the font description. Use pango-font-description-get-set-fields to find out if the field was explicitly set or not.
— Function: pango-font-description-set-weight (self <pango-font-description>) (weight <pango-weight>)

Sets the weight field of a font description. The weight field specifies how bold or light the font should be. In addition to the values of the <pango-weight> enumeration, other intermediate numeric values are possible.

desc
a <pango-font-description>
weight
the weight for the font description.
— Function: pango-font-description-get-weight (self <pango-font-description>) ⇒  (ret <pango-weight>)

Gets the weight field of a font description. See pango-font-description-set-weight.

desc
a <pango-font-description>
ret
the weight field for the font description. Use pango-font-description-get-set-fields to find out if the field was explicitly set or not.
— Function: pango-font-description-set-stretch (self <pango-font-description>) (stretch <pango-stretch>)

Sets the stretch field of a font description. The stretch field specifies how narrow or wide the font should be.

desc
a <pango-font-description>
stretch
the stretch for the font description
— Function: pango-font-description-get-stretch (self <pango-font-description>) ⇒  (ret <pango-stretch>)

Gets the stretch field of a font description. See pango-font-description-set-stretch.

desc
a <pango-font-description>.
ret
the stretch field for the font description. Use pango-font-description-get-set-fields to find out if the field was explicitly set or not.
— Function: pango-font-description-set-size (self <pango-font-description>) (size int)

Sets the size field of a font description in fractional points. This is mutually exclusive with pango-font-description-set-absolute-size.

desc
a <pango-font-description>
size
the size of the font in points, scaled by PANGO_SCALE. (That is, a size value of 10 * PANGO_SCALE is a 10 point font. The conversion factor between points and device units depends on system configuration and the output device. For screen display, a logical DPI of 96 is common, in which case a 10 point font corresponds to a 10 * (96 / 72) = 13.3 pixel font. Use pango-font-description-set-absolute-size if you need a particular size in device units.
— Function: pango-font-description-get-size (self <pango-font-description>) ⇒  (ret int)

Gets the size field of a font description. See pango-font-description-set-size.

desc
a <pango-font-description>
ret
the size field for the font description in points or device units. You must call pango-font-description-get-size-is-absolute to find out which is the case. Returns 0 if the size field has not previously been set or it has been set to 0 explicitly. Use pango-font-description-get-set-fields to find out if the field was explicitly set or not.
— Function: pango-font-description-unset-fields (self <pango-font-description>) (to_unset <pango-font-mask>)

Unsets some of the fields in a <pango-font-description>. The unset fields will get back to their default values.

desc
a <pango-font-description>
to-unset
bitmask of fields in the desc to unset.
— Function: pango-font-description-merge (self <pango-font-description>) (desc_to_merge <pango-font-description>) (replace_existing bool)

Merges the fields that are set in desc-to-merge into the fields in desc. If replace-existing is ‘#f’, only fields in desc that are not already set are affected. If ‘#t’, then fields that are already set will be replaced as well.

desc
a <pango-font-description>
desc-to-merge
the <pango-font-description> to merge from
replace-existing
if ‘#t’, replace fields in desc with the corresponding values from desc-to-merge, even if they are already exist.
— Function: pango-font-description-merge-static (self <pango-font-description>) (desc_to_merge <pango-font-description>) (replace_existing bool)

Like pango-font-description-merge, but only a shallow copy is made of the family name and other allocated fields. desc can only be used until desc-to-merge is modified or freed. This is meant to be used when the merged font description is only needed temporarily.

desc
a <pango-font-description>
desc-to-merge
the <pango-font-description> to merge from
replace-existing
if ‘#t’, replace fields in desc with the corresponding values from desc-to-merge, even if they are already exist.
— Function: pango-font-description-better-match (self <pango-font-description>) (old_match <pango-font-description>) (new_match <pango-font-description>) ⇒  (ret bool)

Determines if the style attributes of new-match are a closer match for desc than old-match, or if old-match is ‘#f’, determines if new-match is a match at all. Approximate matching is done for weight and style; other attributes must match exactly.

desc
a <pango-font-description>
old-match
a <pango-font-description>, or ‘#f
new-match
a <pango-font-description>
ret
#t’ if new-match is a better match
— Function: pango-font-description-to-string (self <pango-font-description>) ⇒  (ret mchars)

Creates a string representation of a font description. See pango-font-description-from-string for a description of the format of the string representation. The family list in the string description will only have a terminating comma if the last word of the list is a valid style option.

desc
a <pango-font-description>
ret
a new string that must be freed with g-free.
— Function: pango-font-description-to-filename (self <pango-font-description>) ⇒  (ret mchars)

Creates a filename representation of a font description. The filename is identical to the result from calling pango-font-description-to-string, but with underscores instead of characters that are untypical in filenames, and in lower case only.

desc
a <pango-font-description>
ret
a new string that must be freed with g-free.
— Function: pango-font-metrics-get-ascent (self <pango-font-metrics>) ⇒  (ret int)

Gets the ascent from a font metrics structure. The ascent is the distance from the baseline to the logical top of a line of text. (The logical top may be above or below the top of the actual drawn ink. It is necessary to lay out the text to figure where the ink will be.)

metrics
a <pango-font-metrics> structure
ret
the ascent, in Pango units. (1 point == ‘PANGO_SCALE’ Pango units.)
— Function: pango-font-metrics-get-descent (self <pango-font-metrics>) ⇒  (ret int)

Gets the descent from a font metrics structure. The descent is the distance from the baseline to the logical bottom of a line of text. (The logical bottom may be above or below the bottom of the actual drawn ink. It is necessary to lay out the text to figure where the ink will be.)

metrics
a <pango-font-metrics> structure
ret
the descent, in Pango units. (1 point == ‘PANGO_SCALE’ Pango units.)
— Function: pango-font-describe (self <pango-font>) ⇒  (ret <pango-font-description>)
— Method: describe

Returns a description of the font, with font size set in points. Use pango-font-describe-with-absolute-size if you want the font size in device units.

font
a <pango-font>
ret
a newly-allocated <pango-font-description> object.
— Function: pango-font-get-coverage (self <pango-font>) (language <pango-language>) ⇒  (ret <pango-coverage>)
— Method: get-coverage

Computes the coverage map for a given font and language tag.

font
a <pango-font>
language
the language tag
ret
a newly-allocated <pango-coverage> object.
— Function: pango-font-get-glyph-extents (self <pango-font>) (glyph unsigned-int32) ⇒  (ink_rect <pango-rectangle>) (logical_rect <pango-rectangle>)
— Method: get-glyph-extents

Gets the logical and ink extents of a glyph within a font. The coordinate system for each rectangle has its origin at the base line and horizontal origin of the character with increasing coordinates extending to the right and down. The macros pango-ascent, pango-descent, pango-lbearing, and pango-rbearing can be used to convert from the extents rectangle to more traditional font metrics. The units of the rectangles are in 1/PANGO_SCALE of a device unit.

font
a <pango-font>
glyph
the glyph index
ink-rect
rectangle used to store the extents of the glyph as drawn or ‘#f’ to indicate that the result is not needed.
logical-rect
rectangle used to store the logical extents of the glyph or ‘#f’ to indicate that the result is not needed.
— Function: pango-font-get-metrics (self <pango-font>) (language <pango-language>) ⇒  (ret <pango-font-metrics>)
— Method: get-metrics

Gets overall metric information for a font. Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.

font
a <pango-font>
language
language tag used to determine which script to get the metrics for, or ‘#f’ to indicate to get the metrics for the entire font.
ret
a <pango-font-metrics> object. The caller must call pango-font-metrics-unref when finished using the object.
— Function: pango-font-get-font-map (self <pango-font>) ⇒  (ret <pango-font-map>)
— Method: get-font-map

Gets the font map for which the font was created.

font
a <pango-font>
ret
the <pango-font-map> for the font

Since 1.10

— Function: pango-font-family-get-name (self <pango-font-family>) ⇒  (ret mchars)
— Method: get-name

Gets the name of the family. The name is unique among all fonts for the font backend and can be used in a <pango-font-description> to specify that a face from this family is desired.

family
a <pango-font-family>
ret
the name of the family. This string is owned by the family object and must not be modified or freed.
— Function: pango-font-family-is-monospace (self <pango-font-family>) ⇒  (ret bool)
— Method: is-monospace

A monospace font is a font designed for text display where the the characters form a regular grid. For Western languages this would mean that the advance width of all characters are the same, but this categorization also includes Asian fonts which include double-width characters: characters that occupy two grid cells. g-unichar-iswide returns a result that indicates whether a character is typically double-width in a monospace font.

The best way to find out the grid-cell size is to call pango-font-metrics-get-approximate-digit-width, since the results of pango-font-metrics-get-approximate-char-width may be affected by double-width characters.

family
a <pango-font-family>
ret
#t’ if the family is monospace.

Since 1.4

— Function: pango-font-face-get-face-name (self <pango-font-face>) ⇒  (ret mchars)
— Method: get-face-name

Gets a name representing the style of this face among the different faces in the <pango-font-family> for the face. This name is unique among all faces in the family and is suitable for displaying to users.

face
a <pango-font-face>.
ret
the face name for the face. This string is owned by the face object and must not be modified or freed.
— Function: pango-font-face-describe (self <pango-font-face>) ⇒  (ret <pango-font-description>)
— Method: describe

Returns the family, style, variant, weight and stretch of a <pango-font-face>. The size field of the resulting font description will be unset.

face
a <pango-font-face>
ret
a newly-created <pango-font-description> structure holding the description of the face. Use pango-font-description-free to free the result.
— Function: pango-font-map-load-font (self <pango-font-map>) (context <pango-context>) (desc <pango-font-description>) ⇒  (ret <pango-font>)
— Method: load-font

Load the font in the fontmap that is the closest match for desc.

fontmap
a <pango-font-map>
context
the <pango-context> the font will be used with
desc
a <pango-font-description> describing the font to load
ret
the font loaded, or ‘#f’ if no font matched.
— Function: pango-font-map-load-fontset (self <pango-font-map>) (context <pango-context>) (desc <pango-font-description>) (language <pango-language>) ⇒  (ret <pango-fontset>)
— Method: load-fontset

Load a set of fonts in the fontmap that can be used to render a font matching desc.

fontmap
a <pango-font-map>
context
the <pango-context> the font will be used with
desc
a <pango-font-description> describing the font to load
language
a <pango-language> the fonts will be used for
ret
the fontset, or ‘#f’ if no font matched.