Next: , Previous: Visuals, Up: Top


15 Fonts

Loading and manipulating fonts

15.1 Overview

The <gdk-font> data type represents a font for drawing on the screen. These functions provide support for loading fonts, and also for determining the dimensions of characters and strings when drawn with a particular font.

Fonts in X are specified by a X Logical Font Description. The following description is considerably simplified. For definitive information about XLFD's see the X reference documentation. A X Logical Font Description (XLFD) consists of a sequence of fields separated (and surrounded by) '-' characters. For example, Adobe Helvetica Bold 12 pt, has the full description:

     
     "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"

The fields in the XLFD are:

When specifying a font via a X logical Font Description, '*' can be used as a wildcard to match any portion of the XLFD. For instance, the above example could also be specified as It is generally a good idea to use wildcards for any portion of the XLFD that your program does not care about specifically, since that will improve the chances of finding a matching font.

     
     "-*-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-1"

A fontset is a list of fonts that is used for drawing international text that may contain characters from a number of different character sets. It is represented by a list of XLFD's.

The font for a given character set is determined by going through the list of XLFD's in order. For each one, if the registry and and encoding fields match the desired character set, then that font is used, otherwise if the XLFD contains wild-cards for the registry and encoding fields, the registry and encoding for the desired character set are substituted in and a lookup is done. If a match is found that font is used. Otherwise, processing continues on to the next font in the list.

The functions for determining the metrics of a string come in several varieties that can take a number of forms of string input:

16-bit string

Multibyte string

Wide character string

When using functions like gdk-string-width that take a <gchar *>, if the font is of type ‘GDK_FONT_FONT’ and is an 8-bit font, then each <gchar> indexes the glyphs in the font directly.

For functions taking a <gchar *>, if the font is of type ‘GDK_FONT_FONT’, and is a 16-bit font, then the <gchar *> argument is interpreted as a <guint16 *> cast to a <gchar *> and each <guint16> indexes the glyphs in the font directly.

For functions taking a <gchar *>, if the font is of type ‘GDK_FONT_FONTSET’, then the input string is interpreted as a multibyte encoded according to the current locale. (A multibyte string is one in which each character may consist of one or more bytes, with different lengths for different characters in the string). They can be converted to and from wide character strings (see below) using gdk-wcstombs and gdk-mbstowcs.) The string will be rendered using one or more different fonts from the fontset.

For a number of the text-measuring functions, GDK provides a variant (such as gdk-text-width-wc) which takes a <gdk-wchar *> instead of a <gchar *>. The input is then taken to be a wide character string in the encoding of the current locale. (A wide character string is a string in which each character consists of several bytes, and the width of each character in the string is constant.)

GDK provides functions to determine a number of different measurements (metrics) for a given string. (Need diagram here).

descent

left bearing

right bearing

width bearing

The vertical distance from the origin of the drawing opereration to the top of the drawn character.

The vertical distance from the origin of the drawing opereration to the bottom of the drawn character.

The horizontal distance from the origin of the drawing operation to the left-most part of the drawn character.

The horizontal distance from the origin of the drawing operation to the right-most part of the drawn character.

The horizontal distance from the origin of the drawing operation to the correct origin for drawing another string to follow the current one. Depending on the font, this could be greater than or less than the right bearing.

15.2 Usage

— Class: <gdk-font>

Derives from <gboxed>.

This class defines no direct slots.

— Function: gdk-font-load (font_name mchars) ⇒  (ret <gdk-font>)

gdk_font_load’ is deprecated and should not be used in newly-written code.

Loads a font.

The font may be newly loaded or looked up the font in a cache. You should make no assumptions about the initial reference count.

font-name
a XLFD describing the font to load.
ret
a <gdk-font>, or ‘#f’ if the font could not be loaded.
— Function: gdk-fontset-load (fontset_name mchars) ⇒  (ret <gdk-font>)

gdk_fontset_load’ is deprecated and should not be used in newly-written code.

Loads a fontset.

The fontset may be newly loaded or looked up in a cache. You should make no assumptions about the initial reference count.

fontset-name
a comma-separated list of XLFDs describing the component fonts of the fontset to load.
ret
a <gdk-font>, or ‘#f’ if the fontset could not be loaded.
— Function: gdk-font-from-description (font_desc <pango-font-description>) ⇒  (ret <gdk-font>)

gdk_font_from_description’ is deprecated and should not be used in newly-written code.

Load a <gdk-font> based on a Pango font description. This font will only be an approximation of the Pango font, and internationalization will not be handled correctly. This function should only be used for legacy code that cannot be easily converted to use Pango. Using Pango directly will produce better results.

font-desc
a <pango-font-description>.
ret
the newly loaded font, or ‘#f’ if the font cannot be loaded.
— Function: gdk-font-id (self <gdk-font>) ⇒  (ret int)

gdk_font_id’ is deprecated and should not be used in newly-written code.

Returns the X Font ID for the given font.

font
a <gdk-font>.
ret
the numeric X Font ID
— Function: gdk-string-extents (font <gdk-font>) (string mchars) ⇒  (lbearing int) (rbearing int) (width int) (ascent int) (descent int)

gdk_string_extents’ is deprecated and should not be used in newly-written code.

Gets the metrics of a nul-terminated string.

font
a <gdk-font>.
string
the nul-terminated string to measure.
lbearing
the left bearing of the string.
rbearing
the right bearing of the string.
width
the width of the string.
ascent
the ascent of the string.
descent
the descent of the string.
— Function: gdk-string-width (font <gdk-font>) (string mchars) ⇒  (ret int)

gdk_string_width’ is deprecated and should not be used in newly-written code.

Determines the width of a nul-terminated string. (The distance from the origin of the string to the point where the next string in a sequence of strings should be drawn)

font
a <gdk-font>
string
the nul-terminated string to measure
ret
the width of the string in pixels.
— Function: gdk-text-width (font <gdk-font>) (text mchars) (text_length int) ⇒  (ret int)

gdk_text_width’ is deprecated and should not be used in newly-written code.

Determines the width of a given string.

font
a <gdk-font>
text
the text to measure.
text-length
the length of the text in bytes.
ret
the width of the string in pixels.
— Function: gdk-char-width (font <gdk-font>) (character char) ⇒  (ret int)

gdk_char_width’ is deprecated and should not be used in newly-written code. Use gdk-text-extents instead.

Determines the width of a given character.

font
a <gdk-font>
character
the character to measure.
ret
the width of the character in pixels.
— Function: gdk-char-width-wc (font <gdk-font>) (character unsigned-int32) ⇒  (ret int)

gdk_char_width_wc’ is deprecated and should not be used in newly-written code.

Determines the width of a given wide character. (Encoded in the wide-character encoding of the current locale).

font
a <gdk-font>
character
the character to measure.
ret
the width of the character in pixels.
— Function: gdk-string-measure (font <gdk-font>) (string mchars) ⇒  (ret int)

gdk_string_measure’ is deprecated and should not be used in newly-written code.

Determines the distance from the origin to the rightmost portion of a nul-terminated string when drawn. This is not the correct value for determining the origin of the next portion when drawing text in multiple pieces. See gdk-string-width.

font
a <gdk-font>
string
the nul-terminated string to measure.
ret
the right bearing of the string in pixels.
— Function: gdk-text-measure (font <gdk-font>) (text mchars) (text_length int) ⇒  (ret int)

gdk_text_measure’ is deprecated and should not be used in newly-written code.

Determines the distance from the origin to the rightmost portion of a string when drawn. This is not the correct value for determining the origin of the next portion when drawing text in multiple pieces. See gdk-text-width.

font
a <gdk-font>
text
the text to measure.
text-length
the length of the text in bytes.
ret
the right bearing of the string in pixels.
— Function: gdk-char-measure (font <gdk-font>) (character char) ⇒  (ret int)

gdk_char_measure’ is deprecated and should not be used in newly-written code.

Determines the distance from the origin to the rightmost portion of a character when drawn. This is not the correct value for determining the origin of the next portion when drawing text in multiple pieces.

font
a <gdk-font>
character
the character to measure.
ret
the right bearing of the character in pixels.
— Function: gdk-string-height (font <gdk-font>) (string mchars) ⇒  (ret int)

gdk_string_height’ is deprecated and should not be used in newly-written code.

Determines the total height of a given nul-terminated string. This value is not generally useful, because you cannot determine how this total height will be drawn in relation to the baseline. See gdk-string-extents.

font
a <gdk-font>
string
the nul-terminated string to measure.
ret
the height of the string in pixels.
— Function: gdk-text-height (font <gdk-font>) (text mchars) (text_length int) ⇒  (ret int)

gdk_text_height’ is deprecated and should not be used in newly-written code.

Determines the total height of a given string. This value is not generally useful, because you cannot determine how this total height will be drawn in relation to the baseline. See gdk-text-extents.

font
a <gdk-font>
text
the text to measure.
text-length
the length of the text in bytes.
ret
the height of the string in pixels.
— Function: gdk-char-height (font <gdk-font>) (character char) ⇒  (ret int)

gdk_char_height’ is deprecated and should not be used in newly-written code. Use gdk-text-extents instead.

Determines the total height of a given character. This value is not generally useful, because you cannot determine how this total height will be drawn in relation to the baseline. See gdk-text-extents.

font
a <gdk-font>
character
the character to measure.
ret
the height of the character in pixels.