Debian Codegraph @

doc/defuns-cairo-text.xml.texi

raw
1
2 @c %start of fragment
3
4 @deffn Function cairo-select-font-face (@var{cr}@tie{}@code{<cairo-t>}) (@var{family}@tie{}@code{<char>}) (@var{slant}@tie{}@code{<cairo-font-slant-t>}) (@var{weight}@tie{}@code{<cairo-font-weight-t>})
5 Note: The @code{cairo-select-font-face} function call is part of what
6 the cairo designers call the "toy" text API. It is convenient for short
7 demos and simple programs, but it is not expected to be adequate for
8 serious text-using applications.
9
10 Selects a family and style of font from a simplified description as a
11 family name, slant and weight. Cairo provides no operation to list
12 available family names on the system (this is a "toy", remember), but
13 the standard CSS2 generic family names, ("serif", "sans-serif",
14 "cursive", "fantasy", "monospace"), are likely to work as expected.
15
16 If @var{family} starts with the string "@var{cairo}:", or if no native
17 font backends are compiled in, cairo will use an internal font family.
18 The internal font family recognizes many modifiers in the @var{family}
19 string, most notably, it recognizes the string "monospace". That is, the
20 family name "@var{cairo}:monospace" will use the monospace version of
21 the internal font family.
22
23 For "real" font selection, see the font-backend-specific
24 font_face_create functions for the font backend you are using. (For
25 example, if you are using the freetype-based cairo-ft font backend, see
26 @code{cairo-ft-font-face-create-for-ft-face} or
27 @code{cairo-ft-font-face-create-for-pattern}.) The resulting font face
28 could then be used with @code{cairo-scaled-font-create} and
29 @code{cairo-set-scaled-font}.
30
31 Similarly, when using the "real" font support, you can call directly
32 into the underlying font system, (such as fontconfig or freetype), for
33 operations such as listing available fonts, etc.
34
35 It is expected that most applications will need to use a more
36 comprehensive font handling and text layout library, (for example,
37 pango), in conjunction with cairo.
38
39 If text is drawn without a call to @code{cairo-select-font-face}, (nor
40 @code{cairo-set-font-face} nor @code{cairo-set-scaled-font}), the
41 default family is platform-specific, but is essentially "sans-serif".
42 Default slant is @samp{CAIRO_FONT_SLANT_NORMAL}, and default weight is
43 @samp{CAIRO_FONT_WEIGHT_NORMAL}.
44
45 This function is equivalent to a call to
46 @code{cairo-toy-font-face-create} followed by
47 @code{cairo-set-font-face}.
48
49 @table @var
50 @item cr
51 a @code{<cairo-t>}
52
53 @item family
54 a font family name, encoded in UTF-8
55
56 @item slant
57 the slant for the font
58
59 @item weight
60 the weight for the font
61
62 @end table
63
64 @end deffn
65
66 @deffn Function cairo-set-font-size (@var{cr}@tie{}@code{<cairo-t>}) (@var{size}@tie{}@code{<double>})
67 Sets the current font matrix to a scale by a factor of @var{size},
68 replacing any font matrix previously set with @code{cairo-set-font-size}
69 or @code{cairo-set-font-matrix}. This results in a font size of
70 @var{size} user space units. (More precisely, this matrix will result in
71 the font's em-square being a @var{size} by @var{size} square in user
72 space.)
73
74 If text is drawn without a call to @code{cairo-set-font-size}, (nor
75 @code{cairo-set-font-matrix} nor @code{cairo-set-scaled-font}), the
76 default font size is 10.0.
77
78 @table @var
79 @item cr
80 a @code{<cairo-t>}
81
82 @item size
83 the new font size, in user space units
84
85 @end table
86
87 @end deffn
88
89 @deffn Function cairo-set-font-matrix (@var{cr}@tie{}@code{<cairo-t>}) (@var{matrix}@tie{}@code{<cairo-matrix-t>})
90 Sets the current font matrix to @var{matrix}. The font matrix gives a
91 transformation from the design space of the font (in this space, the
92 em-square is 1 unit by 1 unit) to user space. Normally, a simple scale
93 is used (see @code{cairo-set-font-size}), but a more complex font matrix
94 can be used to shear the font or stretch it unequally along the two axes
95
96 @table @var
97 @item cr
98 a @code{<cairo-t>}
99
100 @item matrix
101 a @code{<cairo-matrix-t>} describing a transform to be applied to the
102 current font.
103
104 @end table
105
106 @end deffn
107
108 @deffn Function cairo-get-font-matrix (@var{cr}@tie{}@code{<cairo-t>}) (@var{matrix}@tie{}@code{<cairo-matrix-t>})
109 Stores the current font matrix into @var{matrix}. See
110 @code{cairo-set-font-matrix}.
111
112 @table @var
113 @item cr
114 a @code{<cairo-t>}
115
116 @item matrix
117 return value for the matrix
118
119 @end table
120
121 @end deffn
122
123 @deffn Function cairo-set-font-options (@var{cr}@tie{}@code{<cairo-t>}) (@var{options}@tie{}@code{<cairo-font-options-t>})
124 Sets a set of custom font rendering options for the @code{<cairo-t>}.
125 Rendering options are derived by merging these options with the options
126 derived from underlying surface; if the value in @var{options} has a
127 default value (like @samp{CAIRO_ANTIALIAS_DEFAULT}), then the value from
128 the surface is used.
129
130 @table @var
131 @item cr
132 a @code{<cairo-t>}
133
134 @item options
135 font options to use
136
137 @end table
138
139 @end deffn
140
141 @deffn Function cairo-get-font-options (@var{cr}@tie{}@code{<cairo-t>}) (@var{options}@tie{}@code{<cairo-font-options-t>})
142 Retrieves font rendering options set via
143 @code{<cairo-set-font-options>}. Note that the returned options do not
144 include any options derived from the underlying surface; they are
145 literally the options passed to @code{cairo-set-font-options}.
146
147 @table @var
148 @item cr
149 a @code{<cairo-t>}
150
151 @item options
152 a @code{<cairo-font-options-t>} object into which to store the retrieved
153 options. All existing values are overwritten
154
155 @end table
156
157 @end deffn
158
159 @deffn Function cairo-set-font-face (@var{cr}@tie{}@code{<cairo-t>}) (@var{font-face}@tie{}@code{<cairo-font-face-t>})
160 Replaces the current @code{<cairo-font-face-t>} object in the
161 @code{<cairo-t>} with @var{font-face}. The replaced font face in the
162 @code{<cairo-t>} will be destroyed if there are no other references to
163 it.
164
165 @table @var
166 @item cr
167 a @code{<cairo-t>}
168
169 @item font-face
170 a @code{<cairo-font-face-t>}, or @samp{@code{#f}} to restore to the
171 default font
172
173 @end table
174
175 @end deffn
176
177 @deffn Function cairo-get-font-face (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-font-face-t >})
178 Gets the current font face for a @code{<cairo-t>}.
179
180 @table @var
181 @item cr
182 a @code{<cairo-t>}
183
184 @item ret
185 the current font face. This object is owned by cairo. To keep a
186 reference to it, you must call @code{cairo-font-face-reference}. This
187 function never returns @samp{@code{#f}}. If memory cannot be allocated,
188 a special "nil" @code{<cairo-font-face-t>} object will be returned on
189 which @code{cairo-font-face-status} returns
190 @samp{CAIRO_STATUS_NO_MEMORY}. Using this nil object will cause its
191 error state to propagate to other objects it is passed to, (for example,
192 calling @code{cairo-set-font-face} with a nil font will trigger an error
193 that will shutdown the @code{<cairo-t>} object).
194
195 @end table
196
197 @end deffn
198
199 @deffn Function cairo-set-scaled-font (@var{cr}@tie{}@code{<cairo-t>}) (@var{scaled-font}@tie{}@code{<cairo-scaled-font-t>})
200 Replaces the current font face, font matrix, and font options in the
201 @code{<cairo-t>} with those of the @code{<cairo-scaled-font-t>}. Except
202 for some translation, the current CTM of the @code{<cairo-t>} should be
203 the same as that of the @code{<cairo-scaled-font-t>}, which can be
204 accessed using @code{cairo-scaled-font-get-ctm}.
205
206 @table @var
207 @item cr
208 a @code{<cairo-t>}
209
210 @item scaled-font
211 a @code{<cairo-scaled-font-t>}
212
213 @end table
214
215 Since 1.2
216
217 @end deffn
218
219 @deffn Function cairo-get-scaled-font (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-scaled-font-t >})
220 Gets the current scaled font for a @code{<cairo-t>}.
221
222 @table @var
223 @item cr
224 a @code{<cairo-t>}
225
226 @item ret
227 the current scaled font. This object is owned by cairo. To keep a
228 reference to it, you must call @code{cairo-scaled-font-reference}. This
229 function never returns @samp{@code{#f}}. If memory cannot be allocated,
230 a special "nil" @code{<cairo-scaled-font-t>} object will be returned on
231 which @code{cairo-scaled-font-status} returns
232 @samp{CAIRO_STATUS_NO_MEMORY}. Using this nil object will cause its
233 error state to propagate to other objects it is passed to, (for example,
234 calling @code{cairo-set-scaled-font} with a nil font will trigger an
235 error that will shutdown the @code{<cairo-t>} object).
236
237 @end table
238
239 Since 1.4
240
241 @end deffn
242
243 @deffn Function cairo-show-text (@var{cr}@tie{}@code{<cairo-t>}) (@var{utf8}@tie{}@code{<char>})
244 A drawing operator that generates the shape from a string of UTF-8
245 characters, rendered according to the current font_face, font_size
246 (font_matrix), and font_options.
247
248 This function first computes a set of glyphs for the string of text. The
249 first glyph is placed so that its origin is at the current point. The
250 origin of each subsequent glyph is offset from that of the previous
251 glyph by the advance values of the previous glyph.
252
253 After this call the current point is moved to the origin of where the
254 next glyph would be placed in this same progression. That is, the
255 current point will be at the origin of the final glyph offset by its
256 advance values. This allows for easy display of a single logical string
257 with multiple calls to @code{cairo-show-text}.
258
259 Note: The @code{cairo-show-text} function call is part of what the cairo
260 designers call the "toy" text API. It is convenient for short demos and
261 simple programs, but it is not expected to be adequate for serious
262 text-using applications. See @code{cairo-show-glyphs} for the "real"
263 text display API in cairo.
264
265 @table @var
266 @item cr
267 a cairo context
268
269 @item utf8
270 a NUL-terminated string of text encoded in UTF-8, or @samp{@code{#f}}
271
272 @end table
273
274 @end deffn
275
276 @deffn Function cairo-show-glyphs (@var{cr}@tie{}@code{<cairo-t>}) (@var{glyphs}@tie{}@code{<cairo-glyph-t>}) (@var{num-glyphs}@tie{}@code{<int>})
277 A drawing operator that generates the shape from an array of glyphs,
278 rendered according to the current font face, font size (font matrix),
279 and font options.
280
281 @table @var
282 @item cr
283 a cairo context
284
285 @item glyphs
286 array of glyphs to show
287
288 @item num-glyphs
289 number of glyphs to show
290
291 @end table
292
293 @end deffn
294
295 @deffn Function cairo-show-text-glyphs (@var{cr}@tie{}@code{<cairo-t>}) (@var{utf8}@tie{}@code{<char>}) (@var{utf8-len}@tie{}@code{<int>}) (@var{glyphs}@tie{}@code{<cairo-glyph-t>}) (@var{num-glyphs}@tie{}@code{<int>}) (@var{clusters}@tie{}@code{<cairo-text-cluster-t>}) (@var{num-clusters}@tie{}@code{<int>}) (@var{cluster-flags}@tie{}@code{<cairo-text-cluster-flags-t>})
296 This operation has rendering effects similar to @code{cairo-show-glyphs}
297 but, if the target surface supports it, uses the provided text and
298 cluster mapping to embed the text for the glyphs shown in the output. If
299 the target does not support the extended attributes, this function acts
300 like the basic @code{cairo-show-glyphs} as if it had been passed
301 @var{glyphs} and @var{num-glyphs}.
302
303 The mapping between @var{utf8} and @var{glyphs} is provided by an array
304 of @dfn{clusters}. Each cluster covers a number of text bytes and
305 glyphs, and neighboring clusters cover neighboring areas of @var{utf8}
306 and @var{glyphs}. The clusters should collectively cover @var{utf8} and
307 @var{glyphs} in entirety.
308
309 The first cluster always covers bytes from the beginning of @var{utf8}.
310 If @var{cluster-flags} do not have the
311 @samp{CAIRO_TEXT_CLUSTER_FLAG_BACKWARD} set, the first cluster also
312 covers the beginning of @var{glyphs}, otherwise it covers the end of the
313 @var{glyphs} array and following clusters move backward.
314
315 See @code{<cairo-text-cluster-t>} for constraints on valid clusters.
316
317 @table @var
318 @item cr
319 a cairo context
320
321 @item utf8
322 a string of text encoded in UTF-8
323
324 @item utf8-len
325 length of @var{utf8} in bytes, or -1 if it is NUL-terminated
326
327 @item glyphs
328 array of glyphs to show
329
330 @item num-glyphs
331 number of glyphs to show
332
333 @item clusters
334 array of cluster mapping information
335
336 @item num-clusters
337 number of clusters in the mapping
338
339 @item cluster-flags
340 cluster mapping flags
341
342 @end table
343
344 Since 1.8
345
346 @end deffn
347
348 @deffn Function cairo-font-extents (@var{cr}@tie{}@code{<cairo-t>}) (@var{extents}@tie{}@code{<cairo-font-extents-t>})
349 Gets the font extents for the currently selected font.
350
351 @table @var
352 @item cr
353 a @code{<cairo-t>}
354
355 @item extents
356 a @code{<cairo-font-extents-t>} object into which the results will be
357 stored.
358
359 @end table
360
361 @end deffn
362
363 @deffn Function cairo-text-extents (@var{cr}@tie{}@code{<cairo-t>}) (@var{utf8}@tie{}@code{<char>}) (@var{extents}@tie{}@code{<cairo-text-extents-t>})
364 Gets the extents for a string of text. The extents describe a user-space
365 rectangle that encloses the "inked" portion of the text, (as it would be
366 drawn by @code{cairo-show-text}). Additionally, the x_advance and
367 y_advance values indicate the amount by which the current point would be
368 advanced by @code{cairo-show-text}.
369
370 Note that whitespace characters do not directly contribute to the size
371 of the rectangle (extents.width and extents.height). They do contribute
372 indirectly by changing the position of non-whitespace characters. In
373 particular, trailing whitespace characters are likely to not affect the
374 size of the rectangle, though they will affect the x_advance and
375 y_advance values.
376
377 @table @var
378 @item cr
379 a @code{<cairo-t>}
380
381 @item utf8
382 a NUL-terminated string of text encoded in UTF-8, or @samp{@code{#f}}
383
384 @item extents
385 a @code{<cairo-text-extents-t>} object into which the results will be
386 stored
387
388 @end table
389
390 @end deffn
391
392 @deffn Function cairo-glyph-extents (@var{cr}@tie{}@code{<cairo-t>}) (@var{glyphs}@tie{}@code{<cairo-glyph-t>}) (@var{num-glyphs}@tie{}@code{<int>}) (@var{extents}@tie{}@code{<cairo-text-extents-t>})
393 Gets the extents for an array of glyphs. The extents describe a
394 user-space rectangle that encloses the "inked" portion of the glyphs,
395 (as they would be drawn by @code{cairo-show-glyphs}). Additionally, the
396 x_advance and y_advance values indicate the amount by which the current
397 point would be advanced by @code{cairo-show-glyphs}.
398
399 Note that whitespace glyphs do not contribute to the size of the
400 rectangle (extents.width and extents.height).
401
402 @table @var
403 @item cr
404 a @code{<cairo-t>}
405
406 @item glyphs
407 an array of @code{<cairo-glyph-t>} objects
408
409 @item num-glyphs
410 the number of elements in @var{glyphs}
411
412 @item extents
413 a @code{<cairo-text-extents-t>} object into which the results will be
414 stored
415
416 @end table
417
418 @end deffn
419
420 @deffn Function cairo-toy-font-face-create (@var{family}@tie{}@code{<char>}) (@var{slant}@tie{}@code{<cairo-font-slant-t>}) (@var{weight}@tie{}@code{<cairo-font-weight-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-font-face-t >})
421 Creates a font face from a triplet of family, slant, and weight. These
422 font faces are used in implementation of the the @code{<cairo-t>} "toy"
423 font API.
424
425 If @var{family} is the zero-length string "", the platform-specific
426 default family is assumed. The default family then can be queried using
427 @code{cairo-toy-font-face-get-family}.
428
429 The @code{cairo-select-font-face} function uses this to create font
430 faces. See that function for limitations and other details of toy font
431 faces.
432
433 @table @var
434 @item family
435 a font family name, encoded in UTF-8
436
437 @item slant
438 the slant for the font
439
440 @item weight
441 the weight for the font
442
443 @item ret
444 a newly created @code{<cairo-font-face-t>}. Free with
445 @code{cairo-font-face-destroy} when you are done using it.
446
447 @end table
448
449 Since 1.8
450
451 @end deffn
452
453 @deffn Function cairo-toy-font-face-get-family (@var{font-face}@tie{}@code{<cairo-font-face-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<char >})
454 Gets the familly name of a toy font.
455
456 @table @var
457 @item font-face
458 A toy font face
459
460 @item ret
461 The family name. This string is owned by the font face and remains valid
462 as long as the font face is alive (referenced).
463
464 @end table
465
466 Since 1.8
467
468 @end deffn
469
470 @deffn Function cairo-toy-font-face-get-slant (@var{font-face}@tie{}@code{<cairo-font-face-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-font-slant-t>})
471 Gets the slant a toy font.
472
473 @table @var
474 @item font-face
475 A toy font face
476
477 @item ret
478 The slant value
479
480 @end table
481
482 Since 1.8
483
484 @end deffn
485
486 @deffn Function cairo-toy-font-face-get-weight (@var{font-face}@tie{}@code{<cairo-font-face-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-font-weight-t>})
487 Gets the weight a toy font.
488
489 @table @var
490 @item font-face
491 A toy font face
492
493 @item ret
494 The weight value
495
496 @end table
497
498 Since 1.8
499
500 @end deffn
501
502
503 @c %end of fragment