Debian Codegraph @

doc/defuns-cairo-paths.xml.texi

raw
1
2 @c %start of fragment
3
4 @deffn Function cairo-copy-path (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-path-t >})
5 Creates a copy of the current path and returns it to the user as a
6 @code{<cairo-path-t>}. See @code{<cairo-path-data-t>} for hints on how
7 to iterate over the returned data structure.
8
9 This function will always return a valid pointer, but the result will
10 have no data (@samp{data==@samp{@code{#f}}} and @samp{num_data==0}), if
11 either of the following conditions hold:
12
13 @enumerate
14 @item
15 If there is insufficient memory to copy the path. In this
16 case @samp{path->status} will be set to
17 @samp{CAIRO_STATUS_NO_MEMORY}.@item
18 If @var{cr} is already in an error state. In this case
19 @samp{path->status} will contain the same status that
20 would be returned by @code{cairo-status}.@end enumerate
21
22 @table @var
23 @item cr
24 a cairo context
25
26 @item ret
27 the copy of the current path. The caller owns the returned object and
28 should call @code{cairo-path-destroy} when finished with it.
29
30 @end table
31
32 @end deffn
33
34 @deffn Function cairo-copy-path-flat (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-path-t >})
35 Gets a flattened copy of the current path and returns it to the user as
36 a @code{<cairo-path-t>}. See @code{<cairo-path-data-t>} for hints on how
37 to iterate over the returned data structure.
38
39 This function is like @code{cairo-copy-path} except that any curves in
40 the path will be approximated with piecewise-linear approximations,
41 (accurate to within the current tolerance value). That is, the result is
42 guaranteed to not have any elements of type @samp{CAIRO_PATH_CURVE_TO}
43 which will instead be replaced by a series of @samp{CAIRO_PATH_LINE_TO}
44 elements.
45
46 This function will always return a valid pointer, but the result will
47 have no data (@samp{data==@samp{@code{#f}}} and @samp{num_data==0}), if
48 either of the following conditions hold:
49
50 @enumerate
51 @item
52 If there is insufficient memory to copy the path. In this
53 case @samp{path->status} will be set to
54 @samp{CAIRO_STATUS_NO_MEMORY}.@item
55 If @var{cr} is already in an error state. In this case
56 @samp{path->status} will contain the same status that
57 would be returned by @code{cairo-status}.@end enumerate
58
59 @table @var
60 @item cr
61 a cairo context
62
63 @item ret
64 the copy of the current path. The caller owns the returned object and
65 should call @code{cairo-path-destroy} when finished with it.
66
67 @end table
68
69 @end deffn
70
71 @deffn Function cairo-append-path (@var{cr}@tie{}@code{<cairo-t>}) (@var{path}@tie{}@code{<cairo-path-t>})
72 Append the @var{path} onto the current path. The @var{path} may be
73 either the return value from one of @code{cairo-copy-path} or
74 @code{cairo-copy-path-flat} or it may be constructed manually. See
75 @code{<cairo-path-t>} for details on how the path data structure should
76 be initialized, and note that @samp{path->status} must be initialized to
77 @samp{CAIRO_STATUS_SUCCESS}.
78
79 @table @var
80 @item cr
81 a cairo context
82
83 @item path
84 path to be appended
85
86 @end table
87
88 @end deffn
89
90 @deffn Function cairo-has-current-point (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{ret}@tie{}@code{<cairo-bool-t>})
91 Returns whether a current point is defined on the current path. See
92 @code{cairo-get-current-point} for details on the current point.
93
94 @table @var
95 @item cr
96 a cairo context
97
98 @item ret
99 whether a current point is defined.
100
101 @end table
102
103 Since 1.6
104
105 @end deffn
106
107 @deffn Function cairo-get-current-point (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{x}@tie{}@code{<double>}) (@var{y}@tie{}@code{<double>})
108 Gets the current point of the current path, which is conceptually the
109 final point reached by the path so far.
110
111 The current point is returned in the user-space coordinate system. If
112 there is no defined current point or if @var{cr} is in an error status,
113 @var{x} and @var{y} will both be set to 0.0. It is possible to check
114 this in advance with @code{cairo-has-current-point}.
115
116 Most path construction functions alter the current point. See the
117 following for details on how they affect the current point:
118 @code{cairo-new-path}, @code{cairo-new-sub-path},
119 @code{cairo-append-path}, @code{cairo-close-path}, @code{cairo-move-to},
120 @code{cairo-line-to}, @code{cairo-curve-to}, @code{cairo-rel-move-to},
121 @code{cairo-rel-line-to}, @code{cairo-rel-curve-to}, @code{cairo-arc},
122 @code{cairo-arc-negative}, @code{cairo-rectangle},
123 @code{cairo-text-path}, @code{cairo-glyph-path},
124 @code{cairo-stroke-to-path}.
125
126 Some functions use and alter the current point but do not otherwise
127 change current path: @code{cairo-show-text}.
128
129 Some functions unset the current path and as a result, current point:
130 @code{cairo-fill}, @code{cairo-stroke}.
131
132 @table @var
133 @item cr
134 a cairo context
135
136 @item x
137 return value for X coordinate of the current point
138
139 @item y
140 return value for Y coordinate of the current point
141
142 @end table
143
144 @end deffn
145
146 @deffn Function cairo-new-path (@var{cr}@tie{}@code{<cairo-t>})
147 Clears the current path. After this call there will be no path and no
148 current point.
149
150 @table @var
151 @item cr
152 a cairo context
153
154 @end table
155
156 @end deffn
157
158 @deffn Function cairo-new-sub-path (@var{cr}@tie{}@code{<cairo-t>})
159 Begin a new sub-path. Note that the existing path is not affected. After
160 this call there will be no current point.
161
162 In many cases, this call is not needed since new sub-paths are
163 frequently started with @code{cairo-move-to}.
164
165 A call to @code{cairo-new-sub-path} is particularly useful when
166 beginning a new sub-path with one of the @code{cairo-arc} calls. This
167 makes things easier as it is no longer necessary to manually compute the
168 arc's initial coordinates for a call to @code{cairo-move-to}.
169
170 @table @var
171 @item cr
172 a cairo context
173
174 @end table
175
176 Since 1.2
177
178 @end deffn
179
180 @deffn Function cairo-close-path (@var{cr}@tie{}@code{<cairo-t>})
181 Adds a line segment to the path from the current point to the beginning
182 of the current sub-path, (the most recent point passed to
183 @code{cairo-move-to}), and closes this sub-path. After this call the
184 current point will be at the joined endpoint of the sub-path.
185
186 The behavior of @code{cairo-close-path} is distinct from simply calling
187 @code{cairo-line-to} with the equivalent coordinate in the case of
188 stroking. When a closed sub-path is stroked, there are no caps on the
189 ends of the sub-path. Instead, there is a line join connecting the final
190 and initial segments of the sub-path.
191
192 If there is no current point before the call to @code{cairo-close-path},
193 this function will have no effect.
194
195 Note: As of cairo version 1.2.4 any call to @code{cairo-close-path} will
196 place an explicit MOVE_TO element into the path immediately after the
197 CLOSE_PATH element, (which can be seen in @code{cairo-copy-path} for
198 example). This can simplify path processing in some cases as it may not
199 be necessary to save the "last move_to point" during processing as the
200 MOVE_TO immediately after the CLOSE_PATH will provide that point.
201
202 @table @var
203 @item cr
204 a cairo context
205
206 @end table
207
208 @end deffn
209
210 @deffn Function cairo-arc (@var{cr}@tie{}@code{<cairo-t>}) (@var{xc}@tie{}@code{<double>}) (@var{yc}@tie{}@code{<double>}) (@var{radius}@tie{}@code{<double>}) (@var{angle1}@tie{}@code{<double>}) (@var{angle2}@tie{}@code{<double>})
211 Adds a circular arc of the given @var{radius} to the current path. The
212 arc is centered at (@var{xc}, @var{yc}), begins at @var{angle1} and
213 proceeds in the direction of increasing angles to end at @var{angle2}.
214 If @var{angle2} is less than @var{angle1} it will be progressively
215 increased by 2*M_PI until it is greater than @var{angle1}.
216
217 If there is a current point, an initial line segment will be added to
218 the path to connect the current point to the beginning of the arc. If
219 this initial line is undesired, it can be avoided by calling
220 @code{cairo-new-sub-path} before calling @code{cairo-arc}.
221
222 Angles are measured in radians. An angle of 0.0 is in the direction of
223 the positive X axis (in user space). An angle of @samp{M_PI}/2.0 radians
224 (90 degrees) is in the direction of the positive Y axis (in user space).
225 Angles increase in the direction from the positive X axis toward the
226 positive Y axis. So with the default transformation matrix, angles
227 increase in a clockwise direction.
228
229 (To convert from degrees to radians, use @samp{degrees * (M_PI /
230 180.)}.)
231
232 This function gives the arc in the direction of increasing angles; see
233 @code{cairo-arc-negative} to get the arc in the direction of decreasing
234 angles.
235
236 The arc is circular in user space. To achieve an elliptical arc, you can
237 scale the current transformation matrix by different amounts in the X
238 and Y directions. For example, to draw an ellipse in the box given by
239 @var{x}, @var{y}, @var{width}, @var{height}:
240
241 @example
242
243 cairo_save (cr);
244 cairo_translate (cr, x + width / 2., y + height / 2.);
245 cairo_scale (cr, width / 2., height / 2.);
246 cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
247 cairo_restore (cr);
248 @end example
249
250 @table @var
251 @item cr
252 a cairo context
253
254 @item xc
255 X position of the center of the arc
256
257 @item yc
258 Y position of the center of the arc
259
260 @item radius
261 the radius of the arc
262
263 @item angle1
264 the start angle, in radians
265
266 @item angle2
267 the end angle, in radians
268
269 @end table
270
271 @end deffn
272
273 @deffn Function cairo-arc-negative (@var{cr}@tie{}@code{<cairo-t>}) (@var{xc}@tie{}@code{<double>}) (@var{yc}@tie{}@code{<double>}) (@var{radius}@tie{}@code{<double>}) (@var{angle1}@tie{}@code{<double>}) (@var{angle2}@tie{}@code{<double>})
274 Adds a circular arc of the given @var{radius} to the current path. The
275 arc is centered at (@var{xc}, @var{yc}), begins at @var{angle1} and
276 proceeds in the direction of decreasing angles to end at @var{angle2}.
277 If @var{angle2} is greater than @var{angle1} it will be progressively
278 decreased by 2*M_PI until it is less than @var{angle1}.
279
280 See @code{cairo-arc} for more details. This function differs only in the
281 direction of the arc between the two angles.
282
283 @table @var
284 @item cr
285 a cairo context
286
287 @item xc
288 X position of the center of the arc
289
290 @item yc
291 Y position of the center of the arc
292
293 @item radius
294 the radius of the arc
295
296 @item angle1
297 the start angle, in radians
298
299 @item angle2
300 the end angle, in radians
301
302 @end table
303
304 @end deffn
305
306 @deffn Function cairo-curve-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{x1}@tie{}@code{<double>}) (@var{y1}@tie{}@code{<double>}) (@var{x2}@tie{}@code{<double>}) (@var{y2}@tie{}@code{<double>}) (@var{x3}@tie{}@code{<double>}) (@var{y3}@tie{}@code{<double>})
307 Adds a cubic Bézier spline to the path from the current point to
308 position (@var{x3}, @var{y3}) in user-space coordinates, using
309 (@var{x1}, @var{y1}) and (@var{x2}, @var{y2}) as the control points.
310 After this call the current point will be (@var{x3}, @var{y3}).
311
312 If there is no current point before the call to @code{cairo-curve-to}
313 this function will behave as if preceded by a call to
314 cairo_move_to(@var{cr}, @var{x1}, @var{y1}).
315
316 @table @var
317 @item cr
318 a cairo context
319
320 @item x1
321 the X coordinate of the first control point
322
323 @item y1
324 the Y coordinate of the first control point
325
326 @item x2
327 the X coordinate of the second control point
328
329 @item y2
330 the Y coordinate of the second control point
331
332 @item x3
333 the X coordinate of the end of the curve
334
335 @item y3
336 the Y coordinate of the end of the curve
337
338 @end table
339
340 @end deffn
341
342 @deffn Function cairo-line-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{x}@tie{}@code{<double>}) (@var{y}@tie{}@code{<double>})
343 Adds a line to the path from the current point to position (@var{x},
344 @var{y}) in user-space coordinates. After this call the current point
345 will be (@var{x}, @var{y}).
346
347 If there is no current point before the call to @code{cairo-line-to}
348 this function will behave as cairo_move_to(@var{cr}, @var{x}, @var{y}).
349
350 @table @var
351 @item cr
352 a cairo context
353
354 @item x
355 the X coordinate of the end of the new line
356
357 @item y
358 the Y coordinate of the end of the new line
359
360 @end table
361
362 @end deffn
363
364 @deffn Function cairo-move-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{x}@tie{}@code{<double>}) (@var{y}@tie{}@code{<double>})
365 Begin a new sub-path. After this call the current point will be
366 (@var{x}, @var{y}).
367
368 @table @var
369 @item cr
370 a cairo context
371
372 @item x
373 the X coordinate of the new position
374
375 @item y
376 the Y coordinate of the new position
377
378 @end table
379
380 @end deffn
381
382 @deffn Function cairo-rectangle (@var{cr}@tie{}@code{<cairo-t>}) (@var{x}@tie{}@code{<double>}) (@var{y}@tie{}@code{<double>}) (@var{width}@tie{}@code{<double>}) (@var{height}@tie{}@code{<double>})
383 Adds a closed sub-path rectangle of the given size to the current path
384 at position (@var{x}, @var{y}) in user-space coordinates.
385
386 This function is logically equivalent to:
387
388 @example
389
390 cairo_move_to (cr, x, y);
391 cairo_rel_line_to (cr, width, 0);
392 cairo_rel_line_to (cr, 0, height);
393 cairo_rel_line_to (cr, -width, 0);
394 cairo_close_path (cr);
395 @end example
396
397 @table @var
398 @item cr
399 a cairo context
400
401 @item x
402 the X coordinate of the top left corner of the rectangle
403
404 @item y
405 the Y coordinate to the top left corner of the rectangle
406
407 @item width
408 the width of the rectangle
409
410 @item height
411 the height of the rectangle
412
413 @end table
414
415 @end deffn
416
417 @deffn Function cairo-glyph-path (@var{cr}@tie{}@code{<cairo-t>}) (@var{glyphs}@tie{}@code{<cairo-glyph-t>}) (@var{num-glyphs}@tie{}@code{<int>})
418 Adds closed paths for the glyphs to the current path. The generated path
419 if filled, achieves an effect similar to that of
420 @code{cairo-show-glyphs}.
421
422 @table @var
423 @item cr
424 a cairo context
425
426 @item glyphs
427 array of glyphs to show
428
429 @item num-glyphs
430 number of glyphs to show
431
432 @end table
433
434 @end deffn
435
436 @deffn Function cairo-text-path (@var{cr}@tie{}@code{<cairo-t>}) (@var{utf8}@tie{}@code{<char>})
437 Adds closed paths for text to the current path. The generated path if
438 filled, achieves an effect similar to that of @code{cairo-show-text}.
439
440 Text conversion and positioning is done similar to
441 @code{cairo-show-text}.
442
443 Like @code{cairo-show-text}, After this call the current point is moved
444 to the origin of where the next glyph would be placed in this same
445 progression. That is, the current point will be at the origin of the
446 final glyph offset by its advance values. This allows for chaining
447 multiple calls to to @code{cairo-text-path} without having to set
448 current point in between.
449
450 Note: The @code{cairo-text-path} function call is part of what the cairo
451 designers call the "toy" text API. It is convenient for short demos and
452 simple programs, but it is not expected to be adequate for serious
453 text-using applications. See @code{cairo-glyph-path} for the "real" text
454 path API in cairo.
455
456 @table @var
457 @item cr
458 a cairo context
459
460 @item utf8
461 a NUL-terminated string of text encoded in UTF-8, or @samp{@code{#f}}
462
463 @end table
464
465 @end deffn
466
467 @deffn Function cairo-rel-curve-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{dx1}@tie{}@code{<double>}) (@var{dy1}@tie{}@code{<double>}) (@var{dx2}@tie{}@code{<double>}) (@var{dy2}@tie{}@code{<double>}) (@var{dx3}@tie{}@code{<double>}) (@var{dy3}@tie{}@code{<double>})
468 Relative-coordinate version of @code{cairo-curve-to}. All offsets are
469 relative to the current point. Adds a cubic Bézier spline to the path
470 from the current point to a point offset from the current point by
471 (@var{dx3}, @var{dy3}), using points offset by (@var{dx1}, @var{dy1})
472 and (@var{dx2}, @var{dy2}) as the control points. After this call the
473 current point will be offset by (@var{dx3}, @var{dy3}).
474
475 Given a current point of (x, y), cairo_rel_curve_to(@var{cr}, @var{dx1},
476 @var{dy1}, @var{dx2}, @var{dy2}, @var{dx3}, @var{dy3}) is logically
477 equivalent to cairo_curve_to(@var{cr}, x+@var{dx1}, y+@var{dy1},
478 x+@var{dx2}, y+@var{dy2}, x+@var{dx3}, y+@var{dy3}).
479
480 It is an error to call this function with no current point. Doing so
481 will cause @var{cr} to shutdown with a status of
482 @samp{CAIRO_STATUS_NO_CURRENT_POINT}.
483
484 @table @var
485 @item cr
486 a cairo context
487
488 @item dx1
489 the X offset to the first control point
490
491 @item dy1
492 the Y offset to the first control point
493
494 @item dx2
495 the X offset to the second control point
496
497 @item dy2
498 the Y offset to the second control point
499
500 @item dx3
501 the X offset to the end of the curve
502
503 @item dy3
504 the Y offset to the end of the curve
505
506 @end table
507
508 @end deffn
509
510 @deffn Function cairo-rel-line-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{dx}@tie{}@code{<double>}) (@var{dy}@tie{}@code{<double>})
511 Relative-coordinate version of @code{cairo-line-to}. Adds a line to the
512 path from the current point to a point that is offset from the current
513 point by (@var{dx}, @var{dy}) in user space. After this call the current
514 point will be offset by (@var{dx}, @var{dy}).
515
516 Given a current point of (x, y), cairo_rel_line_to(@var{cr}, @var{dx},
517 @var{dy}) is logically equivalent to cairo_line_to(@var{cr}, x +
518 @var{dx}, y + @var{dy}).
519
520 It is an error to call this function with no current point. Doing so
521 will cause @var{cr} to shutdown with a status of
522 @samp{CAIRO_STATUS_NO_CURRENT_POINT}.
523
524 @table @var
525 @item cr
526 a cairo context
527
528 @item dx
529 the X offset to the end of the new line
530
531 @item dy
532 the Y offset to the end of the new line
533
534 @end table
535
536 @end deffn
537
538 @deffn Function cairo-rel-move-to (@var{cr}@tie{}@code{<cairo-t>}) (@var{dx}@tie{}@code{<double>}) (@var{dy}@tie{}@code{<double>})
539 Begin a new sub-path. After this call the current point will offset by
540 (@var{x}, @var{y}).
541
542 Given a current point of (x, y), cairo_rel_move_to(@var{cr}, @var{dx},
543 @var{dy}) is logically equivalent to cairo_move_to(@var{cr}, x +
544 @var{dx}, y + @var{dy}).
545
546 It is an error to call this function with no current point. Doing so
547 will cause @var{cr} to shutdown with a status of
548 @samp{CAIRO_STATUS_NO_CURRENT_POINT}.
549
550 @table @var
551 @item cr
552 a cairo context
553
554 @item dx
555 the X offset
556
557 @item dy
558 the Y offset
559
560 @end table
561
562 @end deffn
563
564 @deffn Function cairo-path-extents (@var{cr}@tie{}@code{<cairo-t>}) @result{}@tie{} (@var{x1}@tie{}@code{<double>}) (@var{y1}@tie{}@code{<double>}) (@var{x2}@tie{}@code{<double>}) (@var{y2}@tie{}@code{<double>})
565 Computes a bounding box in user-space coordinates covering the points on
566 the current path. If the current path is empty, returns an empty
567 rectangle ((0,0), (0,0)). Stroke parameters, fill rule, surface
568 dimensions and clipping are not taken into account.
569
570 Contrast with @code{cairo-fill-extents} and @code{cairo-stroke-extents}
571 which return the extents of only the area that would be "inked" by the
572 corresponding drawing operations.
573
574 The result of @code{cairo-path-extents} is defined as equivalent to the
575 limit of @code{cairo-stroke-extents} with @samp{CAIRO_LINE_CAP_ROUND} as
576 the line width approaches 0.0, (but never reaching the empty-rectangle
577 returned by @code{cairo-stroke-extents} for a line width of 0.0).
578
579 Specifically, this means that zero-area sub-paths such as
580 @code{cairo-move-to};@code{cairo-line-to} segments, (even degenerate
581 cases where the coordinates to both calls are identical), will be
582 considered as contributing to the extents. However, a lone
583 @code{cairo-move-to} will not contribute to the results of
584 @code{cairo-path-extents}.
585
586 @table @var
587 @item cr
588 a cairo context
589
590 @item x1
591 left of the resulting extents
592
593 @item y1
594 top of the resulting extents
595
596 @item x2
597 right of the resulting extents
598
599 @item y2
600 bottom of the resulting extents
601
602 @end table
603
604 Since 1.6
605
606 @end deffn
607
608
609 @c %end of fragment