1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 loading and manipulating fonts
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GdkFont data type represents a font for drawing on
10 the screen. These functions provide support for
11 loading fonts, and also for determining the dimensions
12 of characters and strings when drawn with a particular
17 Fonts in X are specified by a
18 <firstterm>X Logical Font Description</firstterm>.
19 The following description is considerably simplified.
20 For definitive information about XLFD's see the
21 X reference documentation. A X Logical Font Description (XLFD)
22 consists of a sequence of fields separated (and surrounded by) '-'
23 characters. For example, Adobe Helvetica Bold 12 pt, has the
25 <informalexample><programlisting>
26 "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"
27 </programlisting></informalexample>
31 The fields in the XLFD are:
33 <informaltable pgwide="1" frame="none">
34 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
38 <entry>Foundry</entry>
39 <entry>the company or organization where the font originated.</entry>
44 <entry>the font family (a group of related font designs).</entry>
49 <entry>A name for the font's typographic weight
50 For example, 'bold' or 'medium').</entry>
55 <entry>The slant of the font. Common values are 'R' for Roman,
56 'I' for italoc, and 'O' for oblique.</entry>
60 <entry>Set Width</entry>
61 <entry>A name for the width of the font. For example,
62 'normal' or 'condensed'.</entry>
66 <entry>Add Style</entry>
67 <entry>Additional information to distinguish a font from
68 other fonts of the same family.</entry>
72 <entry>Pixel Size</entry>
73 <entry>The body size of the font in pixels.</entry>
77 <entry>Point Size</entry>
78 <entry>The body size of the font in 10ths of a point.
79 (A <firstterm>point</firstterm> is 1/72.27 inch) </entry>
83 <entry>Resolution X</entry>
84 <entry>The horizontal resolution that the font was designed for.</entry>
88 <entry>Resolution Y</entry>
89 <entry>The vertical resolution that the font was designed for .</entry>
93 <entry>Spacing</entry>
94 <entry>The type of spacing for the font - can be 'p' for proportional,
95 'm' for monospaced or 'c' for charcell.</entry>
99 <entry>Average Width</entry>
100 <entry>The average width of a glyph in the font. For monospaced
101 and charcell fonts, all glyphs in the font have this width</entry>
105 <entry>Charset Registry</entry>
106 <entry>The registration authority that owns the encoding for
107 the font. Together with the Charset Encoding field, this
108 defines the character set for the font.</entry>
112 <entry>Charset Encoding</entry>
113 <entry>An identifier for the particular character set encoding.</entry>
116 </tbody></tgroup></informaltable>
120 When specifying a font via a X logical Font Description,
121 '*' can be used as a wildcard to match any portion of
122 the XLFD. For instance, the above example could
124 <informalexample><programlisting>
125 "-*-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-1"
126 </programlisting></informalexample>
128 It is generally a good idea to use wildcards for any
129 portion of the XLFD that your program does not care
130 about specifically, since that will improve the
131 chances of finding a matching font.
135 A <firstterm>fontset</firstterm> is a list of fonts
136 that is used for drawing international text that may
137 contain characters from a number of different character
138 sets. It is represented by a list of XLFD's.
142 The font for a given character set is determined by going
143 through the list of XLFD's in order. For each one, if
144 the registry and and encoding fields match the desired
145 character set, then that font is used, otherwise if
146 the XLFD contains wild-cards for the registry and encoding
147 fields, the registry and encoding for the desired character
148 set are substituted in and a lookup is done. If a match is found
149 that font is used. Otherwise, processing continues
150 on to the next font in the list.
154 The functions for determining the metrics of a string
155 come in several varieties that can take a number
156 of forms of string input:
160 <term>8-bit string</term>
162 When using functions like gdk_string_width() that
163 take a <type>gchar *</type>, if the font is of type
164 %GDK_FONT_FONT and is an 8-bit font, then each
165 <type>gchar</type> indexes the glyphs in the font directly.
169 <term>16-bit string</term>
171 For functions taking a <type>gchar *</type>, if the
172 font is of type %GDK_FONT_FONT, and is a 16-bit
173 font, then the <type>gchar *</type> argument is
174 interpreted as a <type>guint16 *</type> cast to
175 a <type>gchar *</type> and each <type>guint16</type>
176 indexes the glyphs in the font directly.
180 <term>Multibyte string</term>
182 For functions taking a <type>gchar *</type>, if the
183 font is of type %GDK_FONT_FONTSET, then the input
184 string is interpreted as a <firstterm>multibyte</firstterm>
185 encoded according to the current locale. (A multibyte
186 string is one in which each character may consist
187 of one or more bytes, with different lengths for different
188 characters in the string). They can be converted to and
189 from wide character strings (see below) using
190 gdk_wcstombs() and gdk_mbstowcs().) The string will
191 be rendered using one or more different fonts from
196 <term>Wide character string</term>
198 For a number of the text-measuring functions, GDK
199 provides a variant (such as gdk_text_width_wc()) which
200 takes a <type>GdkWChar *</type> instead of a
201 <type>gchar *</type>. The input is then taken to
202 be a wide character string in the encoding of the
203 current locale. (A wide character string is a string
204 in which each character consists of several bytes,
205 and the width of each character in the string is
213 GDK provides functions to determine a number of different
214 measurements (metrics) for a given string. (Need diagram
221 The vertical distance from the origin of the drawing
222 opereration to the top of the drawn character.
228 The vertical distance from the origin of the drawing
229 opereration to the bottom of the drawn character.
233 <term>left bearing</term>
235 The horizontal distance from the origin of the drawing
236 operation to the left-most part of the drawn character.
240 <term>right bearing</term>
242 The horizontal distance from the origin of the drawing
243 operation to the right-most part of the drawn character.
247 <term>width bearing</term>
249 The horizontal distance from the origin of the drawing
250 operation to the correct origin for drawing another
251 string to follow the current one. Depending on the
252 font, this could be greater than or less than the
259 <!-- ##### SECTION See_Also ##### -->
264 <!-- ##### STRUCT GdkFont ##### -->
266 The <structname>GdkFont</structname> structure represents a font or fontset. It
267 contains the following public fields. A new <structname>GdkFont</structname>
268 structure is returned by gdk_font_load() or gdk_fontset_load(),
269 and is reference counted with gdk_font_ref() and gdk_font_unref()
272 @type: a value of type #GdkFontType which indicates
273 whether this font is a single font or a fontset.
274 @ascent: the maximum distance that the font, when drawn,
275 ascends above the baseline.
276 @descent: the maximum distance that the font, when drawn,
277 descends below the baseline.
279 <!-- ##### ENUM GdkFontType ##### -->
281 Indicates the type of a font. The possible values
285 @GDK_FONT_FONT: the font is a single font.
286 @GDK_FONT_FONTSET: the font is a fontset.
288 <!-- ##### FUNCTION gdk_font_load ##### -->
294 The font may be newly loaded or looked up the font in a cache.
295 You should make no assumptions about the initial reference count.
298 @font_name: a XLFD describing the font to load.
299 @Returns: a #GdkFont, or %NULL if the font could not be loaded.
302 <!-- ##### FUNCTION gdk_font_load_for_display ##### -->
312 <!-- ##### FUNCTION gdk_fontset_load ##### -->
317 The fontset may be newly loaded or looked up in a cache.
318 You should make no assumptions about the initial reference count.
321 @fontset_name: a comma-separated list of XLFDs describing
322 the component fonts of the fontset to load.
323 @Returns: a #GdkFont, or %NULL if the fontset could not be loaded.
326 <!-- ##### FUNCTION gdk_fontset_load_for_display ##### -->
336 <!-- ##### FUNCTION gdk_font_from_description ##### -->
345 <!-- ##### FUNCTION gdk_font_from_description_for_display ##### -->
355 <!-- ##### FUNCTION gdk_font_get_display ##### -->
364 <!-- ##### FUNCTION gdk_font_ref ##### -->
366 Increases the reference count of a font by one.
373 <!-- ##### FUNCTION gdk_font_unref ##### -->
375 Decreases the reference count of a font by one.
376 If the result is zero, destroys the font.
382 <!-- ##### FUNCTION gdk_font_id ##### -->
384 Returns the X Font ID for the given font.
388 @Returns: the numeric X Font ID
391 <!-- ##### FUNCTION gdk_font_equal ##### -->
393 Compares two fonts for equality. Single fonts compare equal
394 if they have the same X font ID. This operation does
395 not currently work correctly for fontsets.
399 @fontb: another #GdkFont.
400 @Returns: %TRUE if the fonts are equal.
403 <!-- ##### FUNCTION gdk_string_extents ##### -->
405 Returns the metrics of a nul-terminated string.
409 @string: the nul-terminated string to measure.
410 @lbearing: the left bearing of the string.
411 @rbearing: the right bearing of the string.
412 @width: the width of the string.
413 @ascent: the ascent of the string.
414 @descent: the descent of the string.
417 <!-- ##### FUNCTION gdk_text_extents ##### -->
419 Returns the metrics of a string.
423 @text: the text to measure
424 @text_length: the length of the text in bytes. (If the
425 font is a 16-bit font, this is twice the length
426 of the text in characters.)
427 @lbearing: the left bearing of the string.
428 @rbearing: the right bearing of the string.
429 @width: the width of the string.
430 @ascent: the ascent of the string.
431 @descent: the descent of the string.
434 <!-- ##### FUNCTION gdk_text_extents_wc ##### -->
436 Returns the metrics of a string of wide characters.
440 @text: the text to measure.
441 @text_length: the length of the text in character.
442 @lbearing: the left bearing of the string.
443 @rbearing: the right bearing of the string.
444 @width: the width of the string.
445 @ascent: the ascent of the string.
446 @descent: the descent of the string.
449 <!-- ##### FUNCTION gdk_string_width ##### -->
451 Determines the width of a nul-terminated string.
452 (The distance from the origin of the string to the
453 point where the next string in a sequence of strings
458 @string: the nul-terminated string to measure
459 @Returns: the width of the string in pixels.
462 <!-- ##### FUNCTION gdk_text_width ##### -->
464 Determines the width of a given string.
468 @text: the text to measure.
469 @text_length: the length of the text in bytes.
470 @Returns: the width of the string in pixels.
473 <!-- ##### FUNCTION gdk_text_width_wc ##### -->
475 Determines the width of a given wide-character string.
479 @text: the text to measure.
480 @text_length: the length of the text in characters.
481 @Returns: the width of the string in pixels.
484 <!-- ##### FUNCTION gdk_char_width ##### -->
486 Determines the width of a given character.
490 @character: the character to measure.
491 @Returns: the width of the character in pixels.
494 <!-- ##### FUNCTION gdk_char_width_wc ##### -->
496 Determines the width of a given wide character. (Encoded
497 in the wide-character encoding of the current locale).
501 @character: the character to measure.
502 @Returns: the width of the character in pixels.
505 <!-- ##### FUNCTION gdk_string_measure ##### -->
507 Determines the distance from the origin to the rightmost
508 portion of a nul-terminated string when drawn. This is not the
509 correct value for determining the origin of the next
510 portion when drawing text in multiple pieces.
511 See gdk_string_width().
515 @string: the nul-terminated string to measure.
516 @Returns: the right bearing of the string in pixels.
519 <!-- ##### FUNCTION gdk_text_measure ##### -->
521 Determines the distance from the origin to the rightmost
522 portion of a string when drawn. This is not the
523 correct value for determining the origin of the next
524 portion when drawing text in multiple pieces.
525 See gdk_text_width().
529 @text: the text to measure.
530 @text_length: the length of the text in bytes.
531 @Returns: the right bearing of the string in pixels.
534 <!-- ##### FUNCTION gdk_char_measure ##### -->
536 Determines the distance from the origin to the rightmost
537 portion of a character when drawn. This is not the
538 correct value for determining the origin of the next
539 portion when drawing text in multiple pieces.
543 @character: the character to measure.
544 @Returns: the right bearing of the character in pixels.
547 <!-- ##### FUNCTION gdk_string_height ##### -->
549 Determines the total height of a given nul-terminated
550 string. This value is not generally useful, because you
551 cannot determine how this total height will be drawn in
552 relation to the baseline. See gdk_string_extents().
556 @string: the nul-terminated string to measure.
557 @Returns: the height of the string in pixels.
560 <!-- ##### FUNCTION gdk_text_height ##### -->
562 Determines the total height of a given string.
563 This value is not generally useful, because you cannot
564 determine how this total height will be drawn in
565 relation to the baseline. See gdk_text_extents().
569 @text: the text to measure.
570 @text_length: the length of the text in bytes.
571 @Returns: the height of the string in pixels.
574 <!-- ##### FUNCTION gdk_char_height ##### -->
576 Determines the total height of a given character.
577 This value is not generally useful, because you cannot
578 determine how this total height will be drawn in
579 relation to the baseline. See gdk_text_extents().
583 @character: the character to measure.
584 @Returns: the height of the character in pixels.
587 <!-- ##### TYPEDEF GdkWChar ##### -->
589 Specifies a wide character type, used to represent character codes.
590 This is needed since some native languages have character sets which have
591 more than 256 characters (Japanese and Chinese, for example).
594 Wide character values between 0 and 127 are always identical in meaning to
595 the ASCII character codes. The wide character value 0 is often used to
596 terminate strings of wide characters in a similar way to normal strings
600 An alternative to wide characters is multi-byte characters, which extend
601 normal char strings to cope with larger character sets. As the name suggests,
602 multi-byte characters use a different number of bytes to store different
603 character codes. For example codes 0-127 (i.e. the ASCII codes) often
604 use just one byte of memory, while other codes may use 2, 3 or even 4 bytes.
605 Multi-byte characters have the advantage that they can often be used in an
606 application with little change, since strings are still represented as arrays
607 of char values. However multi-byte strings are much easier to manipulate since
608 the character are all of the same size.
611 Applications typically use wide characters to represent character codes
612 internally, and multi-byte strings when saving the characters to a file.
613 The gdk_wcstombs() and gdk_mbstowcs() functions can be used to convert from
614 one representation to the other.
617 See the 'Extended Characters' section of the GNU C Library Reference Manual
618 for more detailed information on wide and multi-byte characters.
622 <!-- ##### FUNCTION gdk_wcstombs ##### -->
624 Converts a wide character string to a multi-byte string.
625 (The function name comes from an acronym of 'Wide Character String TO
629 @src: a wide character string.
630 @Returns: the multi-byte string corresponding to @src, or %NULL if the
631 conversion failed. The returned string should be freed with g_free() when no
635 <!-- ##### FUNCTION gdk_mbstowcs ##### -->
637 Converts a multi-byte string to a wide character string.
638 (The function name comes from an acronym of 'Multi-Byte String TO Wide
642 @dest: the space to place the converted wide character string into.
643 @src: the multi-byte string to convert, which must be nul-terminated.
644 @dest_max: the maximum number of wide characters to place in @dest.
645 @Returns: the number of wide characters written into @dest, or -1 if the