]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk/tmpl/fonts.sgml
Make 3.0 parallel-installable to 2.x
[~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 <!-- ##### SECTION Stability_Level ##### -->
265
266
267 <!-- ##### SECTION Image ##### -->
268
269
270 <!-- ##### STRUCT GdkFont ##### -->
271 <para>
272 The <structname>GdkFont</structname> structure represents a font or fontset. It
273 contains the following public fields. A new <structname>GdkFont</structname>
274 structure is returned by gdk_font_load() or gdk_fontset_load(),
275 and is reference counted with gdk_font_ref() and gdk_font_unref()
276 </para>
277
278 @type: a value of type #GdkFontType which indicates
279   whether this font is a single font or a fontset.
280 @ascent: the maximum distance that the font, when drawn,
281   ascends above the baseline.
282 @descent: the maximum distance that the font, when drawn,
283 descends below the baseline.
284
285 <!-- ##### ENUM GdkFontType ##### -->
286 <para>
287 Indicates the type of a font. The possible values
288 are currently:
289 </para>
290
291 @GDK_FONT_FONT: the font is a single font.
292 @GDK_FONT_FONTSET: the font is a fontset.
293
294 <!-- ##### FUNCTION gdk_font_load ##### -->
295 <para>
296 </para>
297
298 @font_name: 
299 @Returns: 
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 </para>
315
316 @fontset_name: 
317 @Returns: 
318
319
320 <!-- ##### FUNCTION gdk_fontset_load_for_display ##### -->
321 <para>
322
323 </para>
324
325 @display: 
326 @fontset_name: 
327 @Returns: 
328
329
330 <!-- ##### FUNCTION gdk_font_from_description ##### -->
331 <para>
332
333 </para>
334
335 @font_desc: 
336 @Returns: 
337
338
339 <!-- ##### FUNCTION gdk_font_from_description_for_display ##### -->
340 <para>
341
342 </para>
343
344 @display: 
345 @font_desc: 
346 @Returns: 
347
348
349 <!-- ##### FUNCTION gdk_font_get_display ##### -->
350 <para>
351
352 </para>
353
354 @font: 
355 @Returns: 
356
357
358 <!-- ##### FUNCTION gdk_font_ref ##### -->
359 <para>
360 </para>
361
362 @font: 
363 @Returns: 
364
365
366 <!-- ##### FUNCTION gdk_font_unref ##### -->
367 <para>
368 </para>
369
370 @font: 
371
372
373 <!-- ##### FUNCTION gdk_font_id ##### -->
374 <para>
375 </para>
376
377 @font: 
378 @Returns: 
379
380
381 <!-- ##### FUNCTION gdk_font_equal ##### -->
382 <para>
383 </para>
384
385 @fonta: 
386 @fontb: 
387 @Returns: 
388
389
390 <!-- ##### FUNCTION gdk_string_extents ##### -->
391 <para>
392 </para>
393
394 @font: 
395 @string: 
396 @lbearing: 
397 @rbearing: 
398 @width: 
399 @ascent: 
400 @descent: 
401
402
403 <!-- ##### FUNCTION gdk_text_extents ##### -->
404 <para>
405 </para>
406
407 @font: 
408 @text: 
409 @text_length: 
410 @lbearing: 
411 @rbearing: 
412 @width: 
413 @ascent: 
414 @descent: 
415
416
417 <!-- ##### FUNCTION gdk_text_extents_wc ##### -->
418 <para>
419 </para>
420
421 @font: 
422 @text: 
423 @text_length: 
424 @lbearing: 
425 @rbearing: 
426 @width: 
427 @ascent: 
428 @descent: 
429
430
431 <!-- ##### FUNCTION gdk_string_width ##### -->
432 <para>
433 </para>
434
435 @font: 
436 @string: 
437 @Returns: 
438
439
440 <!-- ##### FUNCTION gdk_text_width ##### -->
441 <para>
442 </para>
443
444 @font: 
445 @text: 
446 @text_length: 
447 @Returns: 
448
449
450 <!-- ##### FUNCTION gdk_text_width_wc ##### -->
451 <para>
452 </para>
453
454 @font: 
455 @text: 
456 @text_length: 
457 @Returns: 
458
459
460 <!-- ##### FUNCTION gdk_char_width ##### -->
461 <para>
462 </para>
463
464 @font: 
465 @character: 
466 @Returns: 
467
468
469 <!-- ##### FUNCTION gdk_char_width_wc ##### -->
470 <para>
471 </para>
472
473 @font: 
474 @character: 
475 @Returns: 
476
477
478 <!-- ##### FUNCTION gdk_string_measure ##### -->
479 <para>
480 </para>
481
482 @font: 
483 @string: 
484 @Returns: 
485
486
487 <!-- ##### FUNCTION gdk_text_measure ##### -->
488 <para>
489 </para>
490
491 @font: 
492 @text: 
493 @text_length: 
494 @Returns: 
495
496
497 <!-- ##### FUNCTION gdk_char_measure ##### -->
498 <para>
499 </para>
500
501 @font: 
502 @character: 
503 @Returns: 
504
505
506 <!-- ##### FUNCTION gdk_string_height ##### -->
507 <para>
508 </para>
509
510 @font: 
511 @string: 
512 @Returns: 
513
514
515 <!-- ##### FUNCTION gdk_text_height ##### -->
516 <para>
517 </para>
518
519 @font: 
520 @text: 
521 @text_length: 
522 @Returns: 
523
524
525 <!-- ##### FUNCTION gdk_char_height ##### -->
526 <para>
527 </para>
528
529 @font: 
530 @character: 
531 @Returns: 
532
533
534 <!-- ##### TYPEDEF GdkWChar ##### -->
535 <para>
536 Specifies a wide character type, used to represent character codes.
537 This is needed since some native languages have character sets which have
538 more than 256 characters (Japanese and Chinese, for example).
539 </para>
540 <para>
541 Wide character values between 0 and 127 are always identical in meaning to
542 the ASCII character codes. The wide character value 0 is often used to
543 terminate strings of wide characters in a similar way to normal strings
544 using the char type.
545 </para>
546 <para>
547 An alternative to wide characters is multi-byte characters, which extend
548 normal char strings to cope with larger character sets. As the name suggests,
549 multi-byte characters use a different number of bytes to store different
550 character codes. For example codes 0-127 (i.e. the ASCII codes) often
551 use just one byte of memory, while other codes may use 2, 3 or even 4 bytes.
552 Multi-byte characters have the advantage that they can often be used in an
553 application with little change, since strings are still represented as arrays
554 of char values. However multi-byte strings are much easier to manipulate since
555 the character are all of the same size.
556 </para>
557 <para>
558 Applications typically use wide characters to represent character codes
559 internally, and multi-byte strings when saving the characters to a file.
560 The gdk_wcstombs() and gdk_mbstowcs() functions can be used to convert from
561 one representation to the other.
562 </para>
563 <para>
564 See the 'Extended Characters' section of the GNU C Library Reference Manual
565 for more detailed information on wide and multi-byte characters.
566 </para>
567
568
569 <!-- ##### FUNCTION gdk_wcstombs ##### -->
570 <para>
571 </para>
572
573 @src: 
574 @Returns: 
575
576
577 <!-- ##### FUNCTION gdk_mbstowcs ##### -->
578 <para>
579 </para>
580
581 @dest: 
582 @src: 
583 @dest_max: 
584 @Returns: 
585
586