Fonts
Loading and manipulating fonts
The #GdkFont 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:
Foundry
the company or organization where the font originated.
Family
the font family (a group of related font designs).
Weight
A name for the font's typographic weight
For example, 'bold' or 'medium').
Slant
The slant of the font. Common values are 'R' for Roman,
'I' for italoc, and 'O' for oblique.
Set Width
A name for the width of the font. For example,
'normal' or 'condensed'.
Add Style
Additional information to distinguish a font from
other fonts of the same family.
Pixel Size
The body size of the font in pixels.
Point Size
The body size of the font in 10ths of a point.
(A point is 1/72.27 inch)
Resolution X
The horizontal resolution that the font was designed for.
Resolution Y
The vertical resolution that the font was designed for .
Spacing
The type of spacing for the font - can be 'p' for proportional,
'm' for monospaced or 'c' for charcell.
Average Width
The average width of a glyph in the font. For monospaced
and charcell fonts, all glyphs in the font have this width
Charset Registry
The registration authority that owns the encoding for
the font. Together with the Charset Encoding field, this
defines the character set for the font.
Charset Encoding
An identifier for the particular character set encoding.
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
"-*-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-1"
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.
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:
8-bit 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.
16-bit string
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.
Multibyte string
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.
Wide character string
For a number of the text-measuring functions, GDK
provides a variant (such as gdk_text_width_wc()) which
takes a GdkWChar * 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).
ascent
The vertical distance from the origin of the drawing
opereration to the top of the drawn character.
descent
The vertical distance from the origin of the drawing
opereration to the bottom of the drawn character.
left bearing
The horizontal distance from the origin of the drawing
operation to the left-most part of the drawn character.
right bearing
The horizontal distance from the origin of the drawing
operation to the right-most part of the drawn character.
width bearing
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.
The GdkFont structure represents a font or fontset. It
contains the following public fields. A new GdkFont
structure is returned by gdk_font_load() or gdk_fontset_load(),
and is reference counted with gdk_font_ref() and gdk_font_unref()
@type: a value of type #GdkFontType which indicates
whether this font is a single font or a fontset.
@ascent: the maximum distance that the font, when drawn,
ascends above the baseline.
@descent: the maximum distance that the font, when drawn,
descends below the baseline.
Indicates the type of a font. The possible values
are currently:
@GDK_FONT_FONT: the font is a single font.
@GDK_FONT_FONTSET: the font is a fontset.
@font_name:
@Returns:
@display:
@font_name:
@Returns:
@fontset_name:
@Returns:
@display:
@fontset_name:
@Returns:
@font_desc:
@Returns:
@display:
@font_desc:
@Returns:
@font:
@Returns:
@font:
@Returns:
@font:
@font:
@Returns:
@fonta:
@fontb:
@Returns:
@font:
@string:
@lbearing:
@rbearing:
@width:
@ascent:
@descent:
@font:
@text:
@text_length:
@lbearing:
@rbearing:
@width:
@ascent:
@descent:
@font:
@text:
@text_length:
@lbearing:
@rbearing:
@width:
@ascent:
@descent:
@font:
@string:
@Returns:
@font:
@text:
@text_length:
@Returns:
@font:
@text:
@text_length:
@Returns:
@font:
@character:
@Returns:
@font:
@character:
@Returns:
@font:
@string:
@Returns:
@font:
@text:
@text_length:
@Returns:
@font:
@character:
@Returns:
@font:
@string:
@Returns:
@font:
@text:
@text_length:
@Returns:
@font:
@character:
@Returns:
Specifies a wide character type, used to represent character codes.
This is needed since some native languages have character sets which have
more than 256 characters (Japanese and Chinese, for example).
Wide character values between 0 and 127 are always identical in meaning to
the ASCII character codes. The wide character value 0 is often used to
terminate strings of wide characters in a similar way to normal strings
using the char type.
An alternative to wide characters is multi-byte characters, which extend
normal char strings to cope with larger character sets. As the name suggests,
multi-byte characters use a different number of bytes to store different
character codes. For example codes 0-127 (i.e. the ASCII codes) often
use just one byte of memory, while other codes may use 2, 3 or even 4 bytes.
Multi-byte characters have the advantage that they can often be used in an
application with little change, since strings are still represented as arrays
of char values. However multi-byte strings are much easier to manipulate since
the character are all of the same size.
Applications typically use wide characters to represent character codes
internally, and multi-byte strings when saving the characters to a file.
The gdk_wcstombs() and gdk_mbstowcs() functions can be used to convert from
one representation to the other.
See the 'Extended Characters' section of the GNU C Library Reference Manual
for more detailed information on wide and multi-byte characters.
@src:
@Returns:
@dest:
@src:
@dest_max:
@Returns: