Top |
Functions
GdkFont * | gdk_font_load () |
GdkFont * | gdk_font_load_for_display () |
GdkFont * | gdk_fontset_load () |
GdkFont * | gdk_fontset_load_for_display () |
GdkFont * | gdk_font_from_description () |
GdkFont * | gdk_font_from_description_for_display () |
GdkDisplay * | gdk_font_get_display () |
GdkFont * | gdk_font_ref () |
void | gdk_font_unref () |
gint | gdk_font_id () |
gboolean | gdk_font_equal () |
void | gdk_string_extents () |
void | gdk_text_extents () |
void | gdk_text_extents_wc () |
gint | gdk_string_width () |
gint | gdk_text_width () |
gint | gdk_text_width_wc () |
gint | gdk_char_width () |
gint | gdk_char_width_wc () |
gint | gdk_string_measure () |
gint | gdk_text_measure () |
gint | gdk_char_measure () |
gint | gdk_string_height () |
gint | gdk_text_height () |
gint | gdk_char_height () |
gchar * | gdk_wcstombs () |
gint | gdk_mbstowcs () |
Description
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:
1 |
"-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
1 |
"-*-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 |
16-bit string |
For functions taking a gchar *, if the
font is of type |
Multibyte string |
For functions taking a gchar *, if the
font is of type |
Wide character string |
For a number of the text-measuring functions, GDK
provides a variant (such as |
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. |
Functions
gdk_font_load ()
GdkFont *
gdk_font_load (const gchar *font_name
);
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.
gdk_font_load_for_display ()
GdkFont * gdk_font_load_for_display (GdkDisplay *display
,const gchar *font_name
);
gdk_font_load_for_display
is deprecated and should not be used in newly-written code.
Loads a font for use on display
.
The font may be newly loaded or looked up the font in a cache. You should make no assumptions about the initial reference count.
Since: 2.2
gdk_fontset_load ()
GdkFont *
gdk_fontset_load (const gchar *fontset_name
);
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.
gdk_fontset_load_for_display ()
GdkFont * gdk_fontset_load_for_display (GdkDisplay *display
,const gchar *fontset_name
);
gdk_fontset_load_for_display
is deprecated and should not be used in newly-written code.
Loads a fontset for use on display
.
The fontset may be newly loaded or looked up in a cache. You should make no assumptions about the initial reference count.
Parameters
display |
||
fontset_name |
a comma-separated list of XLFDs describing the component fonts of the fontset to load. |
Since: 2.2
gdk_font_from_description ()
GdkFont *
gdk_font_from_description (PangoFontDescription *font_desc
);
gdk_font_from_description
is deprecated and should not be used in newly-written code.
Load a GdkFont 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.
gdk_font_from_description_for_display ()
GdkFont * gdk_font_from_description_for_display (GdkDisplay *display
,PangoFontDescription *font_desc
);
gdk_font_from_description_for_display
is deprecated and should not be used in newly-written code.
Loads a GdkFont based on a Pango font description for use on display
.
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.
Since: 2.2
gdk_font_get_display ()
GdkDisplay *
gdk_font_get_display (GdkFont *font
);
gdk_font_get_display
is deprecated and should not be used in newly-written code.
Returns the GdkDisplay for font
.
Since: 2.2
gdk_font_ref ()
GdkFont *
gdk_font_ref (GdkFont *font
);
gdk_font_ref
is deprecated and should not be used in newly-written code.
Increases the reference count of a font by one.
gdk_font_unref ()
void
gdk_font_unref (GdkFont *font
);
gdk_font_unref
is deprecated and should not be used in newly-written code.
Decreases the reference count of a font by one. If the result is zero, destroys the font.
gdk_font_id ()
gint
gdk_font_id (const GdkFont *font
);
gdk_font_id
is deprecated and should not be used in newly-written code.
Returns the X Font ID for the given font.
gdk_font_equal ()
gboolean gdk_font_equal (const GdkFont *fonta
,const GdkFont *fontb
);
gdk_font_equal
is deprecated and should not be used in newly-written code.
Compares two fonts for equality. Single fonts compare equal if they have the same X font ID. This operation does not currently work correctly for fontsets.
gdk_string_extents ()
void gdk_string_extents (GdkFont *font
,const gchar *string
,gint *lbearing
,gint *rbearing
,gint *width
,gint *ascent
,gint *descent
);
gdk_string_extents
is deprecated and should not be used in newly-written code.
Gets the metrics of a nul-terminated string.
Parameters
font |
a GdkFont. |
|
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. |
gdk_text_extents ()
void gdk_text_extents (GdkFont *font
,const gchar *text
,gint text_length
,gint *lbearing
,gint *rbearing
,gint *width
,gint *ascent
,gint *descent
);
gdk_text_extents
is deprecated and should not be used in newly-written code.
Gets the metrics of a string.
Parameters
font |
a GdkFont |
|
text |
the text to measure |
|
text_length |
the length of the text in bytes. (If the font is a 16-bit font, this is twice the length of the text in characters.) |
|
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. |
gdk_text_extents_wc ()
void gdk_text_extents_wc (GdkFont *font
,const GdkWChar *text
,gint text_length
,gint *lbearing
,gint *rbearing
,gint *width
,gint *ascent
,gint *descent
);
gdk_text_extents_wc
is deprecated and should not be used in newly-written code.
Gets the metrics of a string of wide characters.
Parameters
font |
a GdkFont |
|
text |
the text to measure. |
|
text_length |
the length of the text in character. |
|
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. |
gdk_string_width ()
gint gdk_string_width (GdkFont *font
,const gchar *string
);
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)
gdk_text_width ()
gint gdk_text_width (GdkFont *font
,const gchar *text
,gint text_length
);
gdk_text_width
is deprecated and should not be used in newly-written code.
Determines the width of a given string.
gdk_text_width_wc ()
gint gdk_text_width_wc (GdkFont *font
,const GdkWChar *text
,gint text_length
);
gdk_text_width_wc
is deprecated and should not be used in newly-written code.
Determines the width of a given wide-character string.
Parameters
font |
a GdkFont |
|
text |
the text to measure. |
|
text_length |
the length of the text in characters. |
gdk_char_width ()
gint gdk_char_width (GdkFont *font
,gchar character
);
gdk_char_width
has been deprecated since version 2.2 and should not be used in newly-written code.
Use gdk_text_extents()
instead.
Determines the width of a given character.
gdk_char_width_wc ()
gint gdk_char_width_wc (GdkFont *font
,GdkWChar character
);
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).
gdk_string_measure ()
gint gdk_string_measure (GdkFont *font
,const gchar *string
);
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()
.
gdk_text_measure ()
gint gdk_text_measure (GdkFont *font
,const gchar *text
,gint text_length
);
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()
.
gdk_char_measure ()
gint gdk_char_measure (GdkFont *font
,gchar character
);
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.
gdk_string_height ()
gint gdk_string_height (GdkFont *font
,const gchar *string
);
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()
.
gdk_text_height ()
gint gdk_text_height (GdkFont *font
,const gchar *text
,gint text_length
);
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()
.
gdk_char_height ()
gint gdk_char_height (GdkFont *font
,gchar character
);
gdk_char_height
has been deprecated since version 2.2 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()
.
gdk_wcstombs ()
gchar *
gdk_wcstombs (const GdkWChar *src
);
gdk_wcstombs
is deprecated and should not be used in newly-written code.
Converts a wide character string to a multi-byte string. (The function name comes from an acronym of 'Wide Character String TO Multi-Byte String').
gdk_mbstowcs ()
gint gdk_mbstowcs (GdkWChar *dest
,const gchar *src
,gint dest_max
);
gdk_mbstowcs
is deprecated and should not be used in newly-written code.
Converts a multi-byte string to a wide character string. (The function name comes from an acronym of 'Multi-Byte String TO Wide Character String').
Types and Values
GdkFont
typedef struct { GdkFontType type; gint ascent; gint descent; } GdkFont;
GdkFont
is deprecated and should not be used in newly-written code.
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()
Members
GdkFontType |
a value of type GdkFontType which indicates whether this font is a single font or a fontset. |
|
gint |
the maximum distance that the font, when drawn, ascends above the baseline. |
|
gint |
the maximum distance that the font, when drawn, descends below the baseline. |
enum GdkFontType
GdkFontType
is deprecated and should not be used in newly-written code.
Indicates the type of a font. The possible values are currently:
GdkWChar
typedef guint32 GdkWChar;
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.