]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk/tmpl/fonts.sgml
Minor documentation fixes. (#80021, Yao Zhang; #75567, #75279, Vitaly
[~andy/gtk] / docs / reference / gdk / tmpl / fonts.sgml
1 <!-- ##### SECTION Title ##### -->
2 Fonts
3
4 <!-- ##### SECTION Short_Description ##### -->
5 loading and manipulating fonts
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
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
13 font.
14 </para>
15
16 <para>
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
24 full description: 
25 <informalexample><programlisting>
26 "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"
27 </programlisting></informalexample>
28 </para>
29
30 <para>
31 The fields in the XLFD are:
32
33 <informaltable pgwide="1" frame="none">
34 <tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
35 <tbody>
36
37 <row>
38 <entry>Foundry</entry>
39 <entry>the company or organization where the font originated.</entry>
40 </row>
41
42 <row>
43 <entry>Family</entry>
44 <entry>the font family (a group of related font designs).</entry>
45 </row>
46
47 <row>
48 <entry>Weight</entry>
49 <entry>A name for the font's typographic weight
50 For example, 'bold' or 'medium').</entry>
51 </row>
52
53 <row>
54 <entry>Slant</entry>
55 <entry>The slant of the font. Common values are 'R' for Roman,
56 'I' for italoc, and 'O' for oblique.</entry>
57 </row>
58
59 <row>
60 <entry>Set Width</entry>
61 <entry>A name for the width of the font. For example,
62 'normal' or 'condensed'.</entry>
63 </row>
64
65 <row>
66 <entry>Add Style</entry>
67 <entry>Additional information to distinguish a font from
68 other fonts of the same family.</entry>
69 </row>
70
71 <row>
72 <entry>Pixel Size</entry>
73 <entry>The body size of the font in pixels.</entry>
74 </row>
75
76 <row>
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>
80 </row>
81
82 <row>
83 <entry>Resolution X</entry>
84 <entry>The horizontal resolution that the font was designed for.</entry>
85 </row>
86
87 <row>
88 <entry>Resolution Y</entry>
89 <entry>The vertical resolution that the font was designed for .</entry>
90 </row>
91
92 <row>
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>
96 </row>
97
98 <row>
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>
102 </row>
103
104 <row>
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>
109 </row>
110
111 <row>
112 <entry>Charset Encoding</entry>
113 <entry>An identifier for the particular character set encoding.</entry>
114 </row>
115
116 </tbody></tgroup></informaltable>
117 </para>
118
119 <para>
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
123 also be specified as
124 <informalexample><programlisting>
125 "-*-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-1"
126 </programlisting></informalexample>
127
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.
132 </para>
133
134 <para>
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. 
139 </para>
140
141 <para>
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.
151 </para>
152
153 <para>
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:
157
158 <variablelist>
159   <varlistentry>
160     <term>8-bit string</term>
161     <listitem><para>
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.
166     </para></listitem>
167   </varlistentry>
168   <varlistentry>
169     <term>16-bit string</term>
170     <listitem><para>
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.
177     </para></listitem>
178   </varlistentry>
179   <varlistentry>
180     <term>Multibyte string</term>
181     <listitem><para>
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
192     the fontset.
193     </para></listitem>
194   </varlistentry>
195   <varlistentry>
196     <term>Wide character string</term>
197     <listitem><para>
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 
206     constant.)
207     </para></listitem>
208   </varlistentry>
209 </variablelist>
210 </para>
211
212 <para>
213 GDK provides functions to determine a number of different
214 measurements (metrics) for a given string. (Need diagram
215 here).
216
217 <variablelist>
218   <varlistentry>
219     <term>ascent</term>
220     <listitem><para>
221     The vertical distance from the origin of the drawing
222     opereration to the top of the drawn character.
223     </para></listitem>
224   </varlistentry>
225   <varlistentry>
226     <term>descent</term>
227     <listitem><para>
228     The vertical distance from the origin of the drawing
229     opereration to the bottom of the drawn character.
230     </para></listitem>
231   </varlistentry>
232   <varlistentry>
233     <term>left bearing</term>
234     <listitem><para>
235     The horizontal distance from the origin of the drawing
236     operation to the left-most part of the drawn character.
237     </para></listitem>
238   </varlistentry>
239   <varlistentry>
240     <term>right bearing</term>
241     <listitem><para>
242     The horizontal distance from the origin of the drawing
243     operation to the right-most part of the drawn character.
244     </para></listitem>
245   </varlistentry>
246   <varlistentry>
247     <term>width bearing</term>
248     <listitem><para>
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 
253     right bearing.
254     </para></listitem>
255   </varlistentry>
256 </variablelist>
257 </para>
258
259 <!-- ##### SECTION See_Also ##### -->
260 <para>
261
262 </para>
263
264 <!-- ##### STRUCT GdkFont ##### -->
265 <para>
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()
270 </para>
271
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.
278
279 <!-- ##### ENUM GdkFontType ##### -->
280 <para>
281 Indicates the type of a font. The possible values
282 are currently:
283 </para>
284
285 @GDK_FONT_FONT: the font is a single font.
286 @GDK_FONT_FONTSET: the font is a fontset.
287
288 <!-- ##### FUNCTION gdk_font_load ##### -->
289 <para>
290 Loads a font.
291 </para>
292
293 <para>
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.
296 </para>
297
298 @font_name: a XLFD describing the font to load.
299 @Returns: a #GdkFont, or %NULL if the font could not be loaded.
300
301
302 <!-- ##### FUNCTION gdk_font_load_for_display ##### -->
303 <para>
304
305 </para>
306
307 @display: 
308 @font_name: 
309 @Returns: 
310
311
312 <!-- ##### FUNCTION gdk_fontset_load ##### -->
313 <para>
314 Loads a fontset.
315 </para>
316 <para>
317 The fontset may be newly loaded or looked up in a cache. 
318 You should make no assumptions about the initial reference count.
319 </para>
320
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.
324
325
326 <!-- ##### FUNCTION gdk_fontset_load_for_display ##### -->
327 <para>
328
329 </para>
330
331 @display: 
332 @fontset_name: 
333 @Returns: 
334
335
336 <!-- ##### FUNCTION gdk_font_from_description ##### -->
337 <para>
338
339 </para>
340
341 @font_desc: 
342 @Returns: 
343
344
345 <!-- ##### FUNCTION gdk_font_from_description_for_display ##### -->
346 <para>
347
348 </para>
349
350 @display: 
351 @font_desc: 
352 @Returns: 
353
354
355 <!-- ##### FUNCTION gdk_font_get_display ##### -->
356 <para>
357
358 </para>
359
360 @font: 
361 @Returns: 
362
363
364 <!-- ##### FUNCTION gdk_font_ref ##### -->
365 <para>
366 Increases the reference count of a font by one.
367 </para>
368
369 @font: a #GdkFont
370 @Returns: @font
371
372
373 <!-- ##### FUNCTION gdk_font_unref ##### -->
374 <para>
375 Decreases the reference count of a font by one.
376 If the result is zero, destroys the font.
377 </para>
378
379 @font: a #GdkFont
380
381
382 <!-- ##### FUNCTION gdk_font_id ##### -->
383 <para>
384 Returns the X Font ID for the given font. 
385 </para>
386
387 @font: a #GdkFont.
388 @Returns: the numeric X Font ID
389
390
391 <!-- ##### FUNCTION gdk_font_equal ##### -->
392 <para>
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.
396 </para>
397
398 @fonta: a #GdkFont.
399 @fontb: another #GdkFont.
400 @Returns: %TRUE if the fonts are equal.
401
402
403 <!-- ##### FUNCTION gdk_string_extents ##### -->
404 <para>
405 Returns the metrics of a nul-terminated string.
406 </para>
407
408 @font: a #GdkFont.
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.
415
416
417 <!-- ##### FUNCTION gdk_text_extents ##### -->
418 <para>
419 Returns the metrics of a string.
420 </para>
421
422 @font: a #GdkFont
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.
432
433
434 <!-- ##### FUNCTION gdk_text_extents_wc ##### -->
435 <para>
436 Returns the metrics of a string of wide characters.
437 </para>
438
439 @font: a #GdkFont
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.
447
448
449 <!-- ##### FUNCTION gdk_string_width ##### -->
450 <para>
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
454 should be drawn)
455 </para>
456
457 @font: a #GdkFont
458 @string: the nul-terminated string to measure
459 @Returns: the width of the string in pixels.
460
461
462 <!-- ##### FUNCTION gdk_text_width ##### -->
463 <para>
464 Determines the width of a given string.
465 </para>
466
467 @font: a #GdkFont
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.
471
472
473 <!-- ##### FUNCTION gdk_text_width_wc ##### -->
474 <para>
475 Determines the width of a given wide-character string.
476 </para>
477
478 @font: a #GdkFont
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.
482
483
484 <!-- ##### FUNCTION gdk_char_width ##### -->
485 <para>
486 Determines the width of a given character.
487 </para>
488
489 @font: a #GdkFont
490 @character: the character to measure.
491 @Returns: the width of the character in pixels.
492
493
494 <!-- ##### FUNCTION gdk_char_width_wc ##### -->
495 <para>
496 Determines the width of a given wide character. (Encoded
497 in the wide-character encoding of the current locale).
498 </para>
499
500 @font: a #GdkFont
501 @character: the character to measure.
502 @Returns: the width of the character in pixels.
503
504
505 <!-- ##### FUNCTION gdk_string_measure ##### -->
506 <para>
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().
512 </para>
513
514 @font: a #GdkFont
515 @string: the nul-terminated string to measure.
516 @Returns: the right bearing of the string in pixels.
517
518
519 <!-- ##### FUNCTION gdk_text_measure ##### -->
520 <para>
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().
526 </para>
527
528 @font: a #GdkFont
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.
532
533
534 <!-- ##### FUNCTION gdk_char_measure ##### -->
535 <para>
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. 
540 </para>
541
542 @font: a #GdkFont
543 @character: the character to measure.
544 @Returns: the right bearing of the character in pixels.
545
546
547 <!-- ##### FUNCTION gdk_string_height ##### -->
548 <para>
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().
553 </para>
554
555 @font: a #GdkFont
556 @string: the nul-terminated string to measure.
557 @Returns: the height of the string in pixels.
558
559
560 <!-- ##### FUNCTION gdk_text_height ##### -->
561 <para>
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().
566 </para>
567
568 @font: a #GdkFont
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.
572
573
574 <!-- ##### FUNCTION gdk_char_height ##### -->
575 <para>
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().
580 </para>
581
582 @font: a #GdkFont
583 @character: the character to measure.
584 @Returns: the height of the character in pixels.
585
586
587 <!-- ##### TYPEDEF GdkWChar ##### -->
588 <para>
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).
592 </para>
593 <para>
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
597 using the char type.
598 </para>
599 <para>
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.
609 </para>
610 <para>
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.
615 </para>
616 <para>
617 See the 'Extended Characters' section of the GNU C Library Reference Manual
618 for more detailed information on wide and multi-byte characters.
619 </para>
620
621
622 <!-- ##### FUNCTION gdk_wcstombs ##### -->
623 <para>
624 Converts a wide character string to a multi-byte string.
625 (The function name comes from an acronym of 'Wide Character String TO
626 Multi-Byte String').
627 </para>
628
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
632 longer needed.
633
634
635 <!-- ##### FUNCTION gdk_mbstowcs ##### -->
636 <para>
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
639 Character String').
640 </para>
641
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
646 conversion failed.
647
648