tizen 2.4 release
[framework/graphics/cairo.git] / src / cairo.c
1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2 /* cairo - a vector graphics library with display and print output
3  *
4  * Copyright © 2002 University of Southern California
5  * Copyright © 2005 Red Hat, Inc.
6  * Copyright © 2011 Intel Corporation
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it either under the terms of the GNU Lesser General Public
10  * License version 2.1 as published by the Free Software Foundation
11  * (the "LGPL") or, at your option, under the terms of the Mozilla
12  * Public License Version 1.1 (the "MPL"). If you do not alter this
13  * notice, a recipient may use your version of this file under either
14  * the MPL or the LGPL.
15  *
16  * You should have received a copy of the LGPL along with this library
17  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
19  * You should have received a copy of the MPL along with this library
20  * in the file COPYING-MPL-1.1
21  *
22  * The contents of this file are subject to the Mozilla Public License
23  * Version 1.1 (the "License"); you may not use this file except in
24  * compliance with the License. You may obtain a copy of the License at
25  * http://www.mozilla.org/MPL/
26  *
27  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29  * the specific language governing rights and limitations.
30  *
31  * The Original Code is the cairo graphics library.
32  *
33  * The Initial Developer of the Original Code is University of Southern
34  * California.
35  *
36  * Contributor(s):
37  *      Carl D. Worth <cworth@cworth.org>
38  *      Chris Wilson <chris@chris-wilson.co.uk>
39  */
40
41 #include "cairoint.h"
42 #include "cairo-private.h"
43
44 #include "cairo-backend-private.h"
45 #include "cairo-error-private.h"
46 #include "cairo-path-private.h"
47 #include "cairo-pattern-private.h"
48 #include "cairo-surface-private.h"
49 #include "cairo-surface-backend-private.h"
50
51 #include <assert.h>
52 #include "cairo-ttrace.h"
53
54 /**
55  * SECTION:cairo
56  * @Title: cairo_t
57  * @Short_Description: The cairo drawing context
58  * @See_Also: #cairo_surface_t
59  *
60  * #cairo_t is the main object used when drawing with cairo. To
61  * draw with cairo, you create a #cairo_t, set the target surface,
62  * and drawing options for the #cairo_t, create shapes with
63  * functions like cairo_move_to() and cairo_line_to(), and then
64  * draw shapes with cairo_stroke() or cairo_fill().
65  *
66  * #cairo_t<!-- -->'s can be pushed to a stack via cairo_save().
67  * They may then safely be changed, without losing the current state.
68  * Use cairo_restore() to restore to the saved state.
69  **/
70
71 /**
72  * SECTION:cairo-text
73  * @Title: text
74  * @Short_Description: Rendering text and glyphs
75  * @See_Also: #cairo_font_face_t, #cairo_scaled_font_t, cairo_text_path(),
76  *            cairo_glyph_path()
77  *
78  * The functions with <emphasis>text</emphasis> in their name form cairo's
79  * <firstterm>toy</firstterm> text API.  The toy API takes UTF-8 encoded
80  * text and is limited in its functionality to rendering simple
81  * left-to-right text with no advanced features.  That means for example
82  * that most complex scripts like Hebrew, Arabic, and Indic scripts are
83  * out of question.  No kerning or correct positioning of diacritical marks
84  * either.  The font selection is pretty limited too and doesn't handle the
85  * case that the selected font does not cover the characters in the text.
86  * This set of functions are really that, a toy text API, for testing and
87  * demonstration purposes.  Any serious application should avoid them.
88  *
89  * The functions with <emphasis>glyphs</emphasis> in their name form cairo's
90  * <firstterm>low-level</firstterm> text API.  The low-level API relies on
91  * the user to convert text to a set of glyph indexes and positions.  This
92  * is a very hard problem and is best handled by external libraries, like
93  * the pangocairo that is part of the Pango text layout and rendering library.
94  * Pango is available from <ulink
95  * url="http://www.pango.org/">http://www.pango.org/</ulink>.
96  **/
97
98 /**
99  * SECTION:cairo-transforms
100  * @Title: Transformations
101  * @Short_Description: Manipulating the current transformation matrix
102  * @See_Also: #cairo_matrix_t
103  *
104  * The current transformation matrix, <firstterm>ctm</firstterm>, is a
105  * two-dimensional affine transformation that maps all coordinates and other
106  * drawing instruments from the <firstterm>user space</firstterm> into the
107  * surface's canonical coordinate system, also known as the <firstterm>device
108  * space</firstterm>.
109  **/
110
111 #define DEFINE_NIL_CONTEXT(status)                                      \
112     {                                                                   \
113         CAIRO_REFERENCE_COUNT_INVALID,  /* ref_count */                 \
114         status,                         /* status */                    \
115         { 0, 0, 0, NULL },              /* user_data */                 \
116         NULL                                                            \
117     }
118
119 static const cairo_t _cairo_nil[] = {
120     DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_MEMORY),
121     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_RESTORE),
122     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_POP_GROUP),
123     DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_CURRENT_POINT),
124     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MATRIX),
125     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STATUS),
126     DEFINE_NIL_CONTEXT (CAIRO_STATUS_NULL_POINTER),
127     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRING),
128     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_PATH_DATA),
129     DEFINE_NIL_CONTEXT (CAIRO_STATUS_READ_ERROR),
130     DEFINE_NIL_CONTEXT (CAIRO_STATUS_WRITE_ERROR),
131     DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_FINISHED),
132     DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_TYPE_MISMATCH),
133     DEFINE_NIL_CONTEXT (CAIRO_STATUS_PATTERN_TYPE_MISMATCH),
134     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CONTENT),
135     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_FORMAT),
136     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_VISUAL),
137     DEFINE_NIL_CONTEXT (CAIRO_STATUS_FILE_NOT_FOUND),
138     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DASH),
139     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DSC_COMMENT),
140     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_INDEX),
141     DEFINE_NIL_CONTEXT (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE),
142     DEFINE_NIL_CONTEXT (CAIRO_STATUS_TEMP_FILE_ERROR),
143     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRIDE),
144     DEFINE_NIL_CONTEXT (CAIRO_STATUS_FONT_TYPE_MISMATCH),
145     DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_IMMUTABLE),
146     DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_ERROR),
147     DEFINE_NIL_CONTEXT (CAIRO_STATUS_NEGATIVE_COUNT),
148     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CLUSTERS),
149     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SLANT),
150     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_WEIGHT),
151     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SIZE),
152     DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED),
153     DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_TYPE_MISMATCH),
154     DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_ERROR),
155     DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MESH_CONSTRUCTION),
156     DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_FINISHED)
157 };
158 COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1);
159
160 /**
161  * _cairo_set_error:
162  * @cr: a cairo context
163  * @status: a status value indicating an error
164  *
165  * Atomically sets cr->status to @status and calls _cairo_error;
166  * Does nothing if status is %CAIRO_STATUS_SUCCESS.
167  *
168  * All assignments of an error status to cr->status should happen
169  * through _cairo_set_error(). Note that due to the nature of the atomic
170  * operation, it is not safe to call this function on the nil objects.
171  *
172  * The purpose of this function is to allow the user to set a
173  * breakpoint in _cairo_error() to generate a stack trace for when the
174  * user causes cairo to detect an error.
175  **/
176 static void
177 _cairo_set_error (cairo_t *cr, cairo_status_t status)
178 {
179     /* Don't overwrite an existing error. This preserves the first
180      * error, which is the most significant. */
181     _cairo_status_set_error (&cr->status, _cairo_error (status));
182 }
183
184 cairo_t *
185 _cairo_create_in_error (cairo_status_t status)
186 {
187     cairo_t *cr;
188
189     assert (status != CAIRO_STATUS_SUCCESS);
190
191     cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY];
192     assert (status == cr->status);
193
194     return cr;
195 }
196
197 /**
198  * cairo_create:
199  * @target: target surface for the context
200  *
201  * Creates a new #cairo_t with all graphics state parameters set to
202  * default values and with @target as a target surface. The target
203  * surface should be constructed with a backend-specific function such
204  * as cairo_image_surface_create() (or any other
205  * <function>cairo_<emphasis>backend</emphasis>_surface_create(<!-- -->)</function>
206  * variant).
207  *
208  * This function references @target, so you can immediately
209  * call cairo_surface_destroy() on it if you don't need to
210  * maintain a separate reference to it.
211  *
212  * Return value: a newly allocated #cairo_t with a reference
213  *  count of 1. The initial reference count should be released
214  *  with cairo_destroy() when you are done using the #cairo_t.
215  *  This function never returns %NULL. If memory cannot be
216  *  allocated, a special #cairo_t object will be returned on
217  *  which cairo_status() returns %CAIRO_STATUS_NO_MEMORY. If
218  *  you attempt to target a surface which does not support
219  *  writing (such as #cairo_mime_surface_t) then a
220  *  %CAIRO_STATUS_WRITE_ERROR will be raised.  You can use this
221  *  object normally, but no drawing will be done.
222  *
223  * Since: 1.0
224  **/
225 cairo_t *
226 cairo_create (cairo_surface_t *target)
227 {
228     CAIRO_TRACE_BEGIN (__func__);
229     if (unlikely (target == NULL)) {
230         CAIRO_TRACE_END (__func__);
231         return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER));
232     }
233     if (unlikely (target->status)) {
234         CAIRO_TRACE_END (__func__);
235         return _cairo_create_in_error (target->status);
236     }
237
238     if (target->backend->create_context == NULL) {
239         CAIRO_TRACE_END (__func__);
240         return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR));
241     }
242
243     cairo_t *cr = target->backend->create_context (target);
244     CAIRO_TRACE_END (__func__);
245     return cr;
246
247 }
248 slim_hidden_def (cairo_create);
249
250 void
251 _cairo_init (cairo_t *cr,
252              const cairo_backend_t *backend)
253 {
254     CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1);
255     cr->status = CAIRO_STATUS_SUCCESS;
256     _cairo_user_data_array_init (&cr->user_data);
257
258     cr->backend = backend;
259 }
260
261 /**
262  * cairo_reference:
263  * @cr: a #cairo_t
264  *
265  * Increases the reference count on @cr by one. This prevents
266  * @cr from being destroyed until a matching call to cairo_destroy()
267  * is made.
268  *
269  * The number of references to a #cairo_t can be get using
270  * cairo_get_reference_count().
271  *
272  * Return value: the referenced #cairo_t.
273  *
274  * Since: 1.0
275  **/
276 cairo_t *
277 cairo_reference (cairo_t *cr)
278 {
279     if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
280         return cr;
281
282     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
283
284     _cairo_reference_count_inc (&cr->ref_count);
285
286     return cr;
287 }
288
289 void
290 _cairo_fini (cairo_t *cr)
291 {
292     _cairo_user_data_array_fini (&cr->user_data);
293 }
294
295 /**
296  * cairo_destroy:
297  * @cr: a #cairo_t
298  *
299  * Decreases the reference count on @cr by one. If the result
300  * is zero, then @cr and all associated resources are freed.
301  * See cairo_reference().
302  *
303  * Since: 1.0
304  **/
305 void
306 cairo_destroy (cairo_t *cr)
307 {
308     CAIRO_TRACE_BEGIN (__func__);
309     if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) {
310         CAIRO_TRACE_END (__func__);
311         return;
312     }
313
314     assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
315
316     if (! _cairo_reference_count_dec_and_test (&cr->ref_count)) {
317         CAIRO_TRACE_END (__func__);
318         return;
319     }
320
321     cr->backend->destroy (cr);
322     CAIRO_TRACE_END (__func__);
323 }
324 slim_hidden_def (cairo_destroy);
325
326 /**
327  * cairo_get_user_data:
328  * @cr: a #cairo_t
329  * @key: the address of the #cairo_user_data_key_t the user data was
330  * attached to
331  *
332  * Return user data previously attached to @cr using the specified
333  * key.  If no user data has been attached with the given key this
334  * function returns %NULL.
335  *
336  * Return value: the user data previously attached or %NULL.
337  *
338  * Since: 1.4
339  **/
340 void *
341 cairo_get_user_data (cairo_t                     *cr,
342                      const cairo_user_data_key_t *key)
343 {
344     return _cairo_user_data_array_get_data (&cr->user_data, key);
345 }
346
347 /**
348  * cairo_set_user_data:
349  * @cr: a #cairo_t
350  * @key: the address of a #cairo_user_data_key_t to attach the user data to
351  * @user_data: the user data to attach to the #cairo_t
352  * @destroy: a #cairo_destroy_func_t which will be called when the
353  * #cairo_t is destroyed or when new user data is attached using the
354  * same key.
355  *
356  * Attach user data to @cr.  To remove user data from a surface,
357  * call this function with the key that was used to set it and %NULL
358  * for @data.
359  *
360  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a
361  * slot could not be allocated for the user data.
362  *
363  * Since: 1.4
364  **/
365 cairo_status_t
366 cairo_set_user_data (cairo_t                     *cr,
367                      const cairo_user_data_key_t *key,
368                      void                        *user_data,
369                      cairo_destroy_func_t        destroy)
370 {
371     if (CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
372         return cr->status;
373
374     return _cairo_user_data_array_set_data (&cr->user_data,
375                                             key, user_data, destroy);
376 }
377
378 /**
379  * cairo_get_reference_count:
380  * @cr: a #cairo_t
381  *
382  * Returns the current reference count of @cr.
383  *
384  * Return value: the current reference count of @cr.  If the
385  * object is a nil object, 0 will be returned.
386  *
387  * Since: 1.4
388  **/
389 unsigned int
390 cairo_get_reference_count (cairo_t *cr)
391 {
392     if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
393         return 0;
394
395     return CAIRO_REFERENCE_COUNT_GET_VALUE (&cr->ref_count);
396 }
397
398 /**
399  * cairo_save:
400  * @cr: a #cairo_t
401  *
402  * Makes a copy of the current state of @cr and saves it
403  * on an internal stack of saved states for @cr. When
404  * cairo_restore() is called, @cr will be restored to
405  * the saved state. Multiple calls to cairo_save() and
406  * cairo_restore() can be nested; each call to cairo_restore()
407  * restores the state from the matching paired cairo_save().
408  *
409  * It isn't necessary to clear all saved states before
410  * a #cairo_t is freed. If the reference count of a #cairo_t
411  * drops to zero in response to a call to cairo_destroy(),
412  * any saved states will be freed along with the #cairo_t.
413  *
414  * Since: 1.0
415  **/
416 void
417 cairo_save (cairo_t *cr)
418 {
419     CAIRO_TRACE_BEGIN (__func__);
420     cairo_status_t status;
421
422     if (unlikely (cr->status)) {
423         CAIRO_TRACE_END (__func__);
424         return;
425     }
426
427     status = cr->backend->save (cr);
428     if (unlikely (status))
429         _cairo_set_error (cr, status);
430     CAIRO_TRACE_END (__func__);
431 }
432 slim_hidden_def(cairo_save);
433
434 /**
435  * cairo_restore:
436  * @cr: a #cairo_t
437  *
438  * Restores @cr to the state saved by a preceding call to
439  * cairo_save() and removes that state from the stack of
440  * saved states.
441  *
442  * Since: 1.0
443  **/
444 void
445 cairo_restore (cairo_t *cr)
446 {
447     CAIRO_TRACE_BEGIN (__func__);
448     cairo_status_t status;
449
450     if (unlikely (cr->status)) {
451         CAIRO_TRACE_END (__func__);
452         return;
453     }
454
455     status = cr->backend->restore (cr);
456     if (unlikely (status))
457         _cairo_set_error (cr, status);
458     CAIRO_TRACE_END (__func__);
459 }
460 slim_hidden_def(cairo_restore);
461
462 /**
463  * cairo_push_group:
464  * @cr: a cairo context
465  *
466  * Temporarily redirects drawing to an intermediate surface known as a
467  * group. The redirection lasts until the group is completed by a call
468  * to cairo_pop_group() or cairo_pop_group_to_source(). These calls
469  * provide the result of any drawing to the group as a pattern,
470  * (either as an explicit object, or set as the source pattern).
471  *
472  * This group functionality can be convenient for performing
473  * intermediate compositing. One common use of a group is to render
474  * objects as opaque within the group, (so that they occlude each
475  * other), and then blend the result with translucence onto the
476  * destination.
477  *
478  * Groups can be nested arbitrarily deep by making balanced calls to
479  * cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new
480  * target group onto/from a stack.
481  *
482  * The cairo_push_group() function calls cairo_save() so that any
483  * changes to the graphics state will not be visible outside the
484  * group, (the pop_group functions call cairo_restore()).
485  *
486  * By default the intermediate group will have a content type of
487  * %CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for
488  * the group by using cairo_push_group_with_content() instead.
489  *
490  * As an example, here is how one might fill and stroke a path with
491  * translucence, but without any portion of the fill being visible
492  * under the stroke:
493  *
494  * <informalexample><programlisting>
495  * cairo_push_group (cr);
496  * cairo_set_source (cr, fill_pattern);
497  * cairo_fill_preserve (cr);
498  * cairo_set_source (cr, stroke_pattern);
499  * cairo_stroke (cr);
500  * cairo_pop_group_to_source (cr);
501  * cairo_paint_with_alpha (cr, alpha);
502  * </programlisting></informalexample>
503  *
504  * Since: 1.2
505  **/
506 void
507 cairo_push_group (cairo_t *cr)
508 {
509     cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
510 }
511
512 /**
513  * cairo_push_group_with_content:
514  * @cr: a cairo context
515  * @content: a #cairo_content_t indicating the type of group that
516  *           will be created
517  *
518  * Temporarily redirects drawing to an intermediate surface known as a
519  * group. The redirection lasts until the group is completed by a call
520  * to cairo_pop_group() or cairo_pop_group_to_source(). These calls
521  * provide the result of any drawing to the group as a pattern,
522  * (either as an explicit object, or set as the source pattern).
523  *
524  * The group will have a content type of @content. The ability to
525  * control this content type is the only distinction between this
526  * function and cairo_push_group() which you should see for a more
527  * detailed description of group rendering.
528  *
529  * Since: 1.2
530  **/
531 void
532 cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
533 {
534     cairo_status_t status;
535
536     if (unlikely (cr->status))
537         return;
538
539     status = cr->backend->push_group (cr, content);
540     if (unlikely (status))
541         _cairo_set_error (cr, status);
542 }
543 slim_hidden_def(cairo_push_group_with_content);
544
545 /**
546  * cairo_pop_group:
547  * @cr: a cairo context
548  *
549  * Terminates the redirection begun by a call to cairo_push_group() or
550  * cairo_push_group_with_content() and returns a new pattern
551  * containing the results of all drawing operations performed to the
552  * group.
553  *
554  * The cairo_pop_group() function calls cairo_restore(), (balancing a
555  * call to cairo_save() by the push_group function), so that any
556  * changes to the graphics state will not be visible outside the
557  * group.
558  *
559  * Return value: a newly created (surface) pattern containing the
560  * results of all drawing operations performed to the group. The
561  * caller owns the returned object and should call
562  * cairo_pattern_destroy() when finished with it.
563  *
564  * Since: 1.2
565  **/
566 cairo_pattern_t *
567 cairo_pop_group (cairo_t *cr)
568 {
569     cairo_pattern_t *group_pattern;
570
571     if (unlikely (cr->status))
572         return _cairo_pattern_create_in_error (cr->status);
573
574     group_pattern = cr->backend->pop_group (cr);
575     if (unlikely (group_pattern->status))
576         _cairo_set_error (cr, group_pattern->status);
577
578     return group_pattern;
579 }
580 slim_hidden_def(cairo_pop_group);
581
582 /**
583  * cairo_pop_group_to_source:
584  * @cr: a cairo context
585  *
586  * Terminates the redirection begun by a call to cairo_push_group() or
587  * cairo_push_group_with_content() and installs the resulting pattern
588  * as the source pattern in the given cairo context.
589  *
590  * The behavior of this function is equivalent to the sequence of
591  * operations:
592  *
593  * <informalexample><programlisting>
594  * cairo_pattern_t *group = cairo_pop_group (cr);
595  * cairo_set_source (cr, group);
596  * cairo_pattern_destroy (group);
597  * </programlisting></informalexample>
598  *
599  * but is more convenient as their is no need for a variable to store
600  * the short-lived pointer to the pattern.
601  *
602  * The cairo_pop_group() function calls cairo_restore(), (balancing a
603  * call to cairo_save() by the push_group function), so that any
604  * changes to the graphics state will not be visible outside the
605  * group.
606  *
607  * Since: 1.2
608  **/
609 void
610 cairo_pop_group_to_source (cairo_t *cr)
611 {
612     cairo_pattern_t *group_pattern;
613
614     group_pattern = cairo_pop_group (cr);
615     cairo_set_source (cr, group_pattern);
616     cairo_pattern_destroy (group_pattern);
617 }
618
619 /**
620  * cairo_set_operator:
621  * @cr: a #cairo_t
622  * @op: a compositing operator, specified as a #cairo_operator_t
623  *
624  * Sets the compositing operator to be used for all drawing
625  * operations. See #cairo_operator_t for details on the semantics of
626  * each available compositing operator.
627  *
628  * The default operator is %CAIRO_OPERATOR_OVER.
629  *
630  * Since: 1.0
631  **/
632 void
633 cairo_set_operator (cairo_t *cr, cairo_operator_t op)
634 {
635     cairo_status_t status;
636
637     if (unlikely (cr->status))
638         return;
639
640     status = cr->backend->set_operator (cr, op);
641     if (unlikely (status))
642         _cairo_set_error (cr, status);
643 }
644 slim_hidden_def (cairo_set_operator);
645
646
647 #if 0
648 /**
649  * cairo_set_opacity:
650  * @cr: a #cairo_t
651  * @opacity: the level of opacity to use when compositing
652  *
653  * Sets the compositing opacity to be used for all drawing
654  * operations. The effect is to fade out the operations
655  * using the alpha value.
656  *
657  * The default opacity is 1.
658  *
659  * Since: TBD
660  **/
661 void
662 cairo_set_opacity (cairo_t *cr, double opacity)
663 {
664     cairo_status_t status;
665
666     if (unlikely (cr->status))
667         return;
668
669     status = cr->backend->set_opacity (cr, opacity);
670     if (unlikely (status))
671         _cairo_set_error (cr, status);
672 }
673 #endif
674
675 /**
676  * cairo_set_source_rgb:
677  * @cr: a cairo context
678  * @red: red component of color
679  * @green: green component of color
680  * @blue: blue component of color
681  *
682  * Sets the source pattern within @cr to an opaque color. This opaque
683  * color will then be used for any subsequent drawing operation until
684  * a new source pattern is set.
685  *
686  * The color components are floating point numbers in the range 0 to
687  * 1. If the values passed in are outside that range, they will be
688  * clamped.
689  *
690  * The default source pattern is opaque black, (that is, it is
691  * equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)).
692  *
693  * Since: 1.0
694  **/
695 void
696 cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
697 {
698     CAIRO_TRACE_BEGIN (__func__);
699     cairo_status_t status;
700
701     if (unlikely (cr->status)) {
702         CAIRO_TRACE_END (__func__);
703         return;
704     }
705
706     status = cr->backend->set_source_rgba (cr, red, green, blue, 1.);
707     if (unlikely (status))
708         _cairo_set_error (cr, status);
709     CAIRO_TRACE_END (__func__);
710 }
711 slim_hidden_def (cairo_set_source_rgb);
712
713 /**
714  * cairo_set_source_rgba:
715  * @cr: a cairo context
716  * @red: red component of color
717  * @green: green component of color
718  * @blue: blue component of color
719  * @alpha: alpha component of color
720  *
721  * Sets the source pattern within @cr to a translucent color. This
722  * color will then be used for any subsequent drawing operation until
723  * a new source pattern is set.
724  *
725  * The color and alpha components are floating point numbers in the
726  * range 0 to 1. If the values passed in are outside that range, they
727  * will be clamped.
728  *
729  * The default source pattern is opaque black, (that is, it is
730  * equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)).
731  *
732  * Since: 1.0
733  **/
734 void
735 cairo_set_source_rgba (cairo_t *cr,
736                        double red, double green, double blue,
737                        double alpha)
738 {
739     cairo_status_t status;
740
741     if (unlikely (cr->status))
742         return;
743
744     status = cr->backend->set_source_rgba (cr, red, green, blue, alpha);
745     if (unlikely (status))
746         _cairo_set_error (cr, status);
747 }
748
749 /**
750  * cairo_set_source_surface:
751  * @cr: a cairo context
752  * @surface: a surface to be used to set the source pattern
753  * @x: User-space X coordinate for surface origin
754  * @y: User-space Y coordinate for surface origin
755  *
756  * This is a convenience function for creating a pattern from @surface
757  * and setting it as the source in @cr with cairo_set_source().
758  *
759  * The @x and @y parameters give the user-space coordinate at which
760  * the surface origin should appear. (The surface origin is its
761  * upper-left corner before any transformation has been applied.) The
762  * @x and @y parameters are negated and then set as translation values
763  * in the pattern matrix.
764  *
765  * Other than the initial translation pattern matrix, as described
766  * above, all other pattern attributes, (such as its extend mode), are
767  * set to the default values as in cairo_pattern_create_for_surface().
768  * The resulting pattern can be queried with cairo_get_source() so
769  * that these attributes can be modified if desired, (eg. to create a
770  * repeating pattern with cairo_pattern_set_extend()).
771  *
772  * Since: 1.0
773  **/
774 void
775 cairo_set_source_surface (cairo_t         *cr,
776                           cairo_surface_t *surface,
777                           double           x,
778                           double           y)
779 {
780     CAIRO_TRACE_BEGIN (__func__);
781     cairo_status_t status;
782
783     if (unlikely (cr->status)) {
784         CAIRO_TRACE_END (__func__);
785         return;
786     }
787
788     if (unlikely (surface == NULL)) {
789         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
790         CAIRO_TRACE_END (__func__);
791         return;
792     }
793
794     status = cr->backend->set_source_surface (cr, surface, x, y);
795     if (unlikely (status))
796         _cairo_set_error (cr, status);
797     CAIRO_TRACE_END (__func__);
798 }
799 slim_hidden_def (cairo_set_source_surface);
800
801 /**
802  * cairo_set_source:
803  * @cr: a cairo context
804  * @source: a #cairo_pattern_t to be used as the source for
805  * subsequent drawing operations.
806  *
807  * Sets the source pattern within @cr to @source. This pattern
808  * will then be used for any subsequent drawing operation until a new
809  * source pattern is set.
810  *
811  * Note: The pattern's transformation matrix will be locked to the
812  * user space in effect at the time of cairo_set_source(). This means
813  * that further modifications of the current transformation matrix
814  * will not affect the source pattern. See cairo_pattern_set_matrix().
815  *
816  * The default source pattern is a solid pattern that is opaque black,
817  * (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0,
818  * 0.0)).
819  *
820  * Since: 1.0
821  **/
822 void
823 cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
824 {
825     cairo_status_t status;
826
827     if (unlikely (cr->status))
828         return;
829
830     if (unlikely (source == NULL)) {
831         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
832         return;
833     }
834
835     if (unlikely (source->status)) {
836         _cairo_set_error (cr, source->status);
837         return;
838     }
839
840     status = cr->backend->set_source (cr, source);
841     if (unlikely (status))
842         _cairo_set_error (cr, status);
843 }
844 slim_hidden_def (cairo_set_source);
845
846 /**
847  * cairo_get_source:
848  * @cr: a cairo context
849  *
850  * Gets the current source pattern for @cr.
851  *
852  * Return value: the current source pattern. This object is owned by
853  * cairo. To keep a reference to it, you must call
854  * cairo_pattern_reference().
855  *
856  * Since: 1.0
857  **/
858 cairo_pattern_t *
859 cairo_get_source (cairo_t *cr)
860 {
861     if (unlikely (cr->status))
862         return _cairo_pattern_create_in_error (cr->status);
863
864     return cr->backend->get_source (cr);
865 }
866
867 /**
868  * cairo_set_tolerance:
869  * @cr: a #cairo_t
870  * @tolerance: the tolerance, in device units (typically pixels)
871  *
872  * Sets the tolerance used when converting paths into trapezoids.
873  * Curved segments of the path will be subdivided until the maximum
874  * deviation between the original path and the polygonal approximation
875  * is less than @tolerance. The default value is 0.1. A larger
876  * value will give better performance, a smaller value, better
877  * appearance. (Reducing the value from the default value of 0.1
878  * is unlikely to improve appearance significantly.)  The accuracy of paths
879  * within Cairo is limited by the precision of its internal arithmetic, and
880  * the prescribed @tolerance is restricted to the smallest
881  * representable internal value.
882  *
883  * Since: 1.0
884  **/
885 void
886 cairo_set_tolerance (cairo_t *cr, double tolerance)
887 {
888     cairo_status_t status;
889
890     if (unlikely (cr->status))
891         return;
892
893     status = cr->backend->set_tolerance (cr, tolerance);
894     if (unlikely (status))
895         _cairo_set_error (cr, status);
896 }
897 slim_hidden_def (cairo_set_tolerance);
898
899 /**
900  * cairo_set_antialias:
901  * @cr: a #cairo_t
902  * @antialias: the new antialiasing mode
903  *
904  * Set the antialiasing mode of the rasterizer used for drawing shapes.
905  * This value is a hint, and a particular backend may or may not support
906  * a particular value.  At the current time, no backend supports
907  * %CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes.
908  *
909  * Note that this option does not affect text rendering, instead see
910  * cairo_font_options_set_antialias().
911  *
912  * Since: 1.0
913  **/
914 void
915 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
916 {
917     cairo_status_t status;
918
919     if (unlikely (cr->status))
920         return;
921
922     status = cr->backend->set_antialias (cr, antialias);
923     if (unlikely (status))
924         _cairo_set_error (cr, status);
925 }
926
927 /**
928  * cairo_set_fill_rule:
929  * @cr: a #cairo_t
930  * @fill_rule: a fill rule, specified as a #cairo_fill_rule_t
931  *
932  * Set the current fill rule within the cairo context. The fill rule
933  * is used to determine which regions are inside or outside a complex
934  * (potentially self-intersecting) path. The current fill rule affects
935  * both cairo_fill() and cairo_clip(). See #cairo_fill_rule_t for details
936  * on the semantics of each available fill rule.
937  *
938  * The default fill rule is %CAIRO_FILL_RULE_WINDING.
939  *
940  * Since: 1.0
941  **/
942 void
943 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
944 {
945     cairo_status_t status;
946
947     if (unlikely (cr->status))
948         return;
949
950     status = cr->backend->set_fill_rule (cr, fill_rule);
951     if (unlikely (status))
952         _cairo_set_error (cr, status);
953 }
954
955 /**
956  * cairo_set_line_width:
957  * @cr: a #cairo_t
958  * @width: a line width
959  *
960  * Sets the current line width within the cairo context. The line
961  * width value specifies the diameter of a pen that is circular in
962  * user space, (though device-space pen may be an ellipse in general
963  * due to scaling/shear/rotation of the CTM).
964  *
965  * Note: When the description above refers to user space and CTM it
966  * refers to the user space and CTM in effect at the time of the
967  * stroking operation, not the user space and CTM in effect at the
968  * time of the call to cairo_set_line_width(). The simplest usage
969  * makes both of these spaces identical. That is, if there is no
970  * change to the CTM between a call to cairo_set_line_width() and the
971  * stroking operation, then one can just pass user-space values to
972  * cairo_set_line_width() and ignore this note.
973  *
974  * As with the other stroke parameters, the current line width is
975  * examined by cairo_stroke(), cairo_stroke_extents(), and
976  * cairo_stroke_to_path(), but does not have any effect during path
977  * construction.
978  *
979  * The default line width value is 2.0.
980  *
981  * Since: 1.0
982  **/
983 void
984 cairo_set_line_width (cairo_t *cr, double width)
985 {
986     cairo_status_t status;
987
988     if (unlikely (cr->status))
989         return;
990
991     if (width < 0.)
992         width = 0.;
993
994     status = cr->backend->set_line_width (cr, width);
995     if (unlikely (status))
996         _cairo_set_error (cr, status);
997 }
998 slim_hidden_def (cairo_set_line_width);
999
1000 /**
1001  * cairo_set_line_cap:
1002  * @cr: a cairo context
1003  * @line_cap: a line cap style
1004  *
1005  * Sets the current line cap style within the cairo context. See
1006  * #cairo_line_cap_t for details about how the available line cap
1007  * styles are drawn.
1008  *
1009  * As with the other stroke parameters, the current line cap style is
1010  * examined by cairo_stroke(), cairo_stroke_extents(), and
1011  * cairo_stroke_to_path(), but does not have any effect during path
1012  * construction.
1013  *
1014  * The default line cap style is %CAIRO_LINE_CAP_BUTT.
1015  *
1016  * Since: 1.0
1017  **/
1018 void
1019 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
1020 {
1021     cairo_status_t status;
1022
1023     if (unlikely (cr->status))
1024         return;
1025
1026     status = cr->backend->set_line_cap (cr, line_cap);
1027     if (unlikely (status))
1028         _cairo_set_error (cr, status);
1029 }
1030 slim_hidden_def (cairo_set_line_cap);
1031
1032 /**
1033  * cairo_set_line_join:
1034  * @cr: a cairo context
1035  * @line_join: a line join style
1036  *
1037  * Sets the current line join style within the cairo context. See
1038  * #cairo_line_join_t for details about how the available line join
1039  * styles are drawn.
1040  *
1041  * As with the other stroke parameters, the current line join style is
1042  * examined by cairo_stroke(), cairo_stroke_extents(), and
1043  * cairo_stroke_to_path(), but does not have any effect during path
1044  * construction.
1045  *
1046  * The default line join style is %CAIRO_LINE_JOIN_MITER.
1047  *
1048  * Since: 1.0
1049  **/
1050 void
1051 cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
1052 {
1053     cairo_status_t status;
1054
1055     if (unlikely (cr->status))
1056         return;
1057
1058     status = cr->backend->set_line_join (cr, line_join);
1059     if (unlikely (status))
1060         _cairo_set_error (cr, status);
1061 }
1062 slim_hidden_def (cairo_set_line_join);
1063
1064 /**
1065  * cairo_set_dash:
1066  * @cr: a cairo context
1067  * @dashes: an array specifying alternate lengths of on and off stroke portions
1068  * @num_dashes: the length of the dashes array
1069  * @offset: an offset into the dash pattern at which the stroke should start
1070  *
1071  * Sets the dash pattern to be used by cairo_stroke(). A dash pattern
1072  * is specified by @dashes, an array of positive values. Each value
1073  * provides the length of alternate "on" and "off" portions of the
1074  * stroke. The @offset specifies an offset into the pattern at which
1075  * the stroke begins.
1076  *
1077  * Each "on" segment will have caps applied as if the segment were a
1078  * separate sub-path. In particular, it is valid to use an "on" length
1079  * of 0.0 with %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE in order
1080  * to distributed dots or squares along a path.
1081  *
1082  * Note: The length values are in user-space units as evaluated at the
1083  * time of stroking. This is not necessarily the same as the user
1084  * space at the time of cairo_set_dash().
1085  *
1086  * If @num_dashes is 0 dashing is disabled.
1087  *
1088  * If @num_dashes is 1 a symmetric pattern is assumed with alternating
1089  * on and off portions of the size specified by the single value in
1090  * @dashes.
1091  *
1092  * If any value in @dashes is negative, or if all values are 0, then
1093  * @cr will be put into an error state with a status of
1094  * %CAIRO_STATUS_INVALID_DASH.
1095  *
1096  * Since: 1.0
1097  **/
1098 void
1099 cairo_set_dash (cairo_t      *cr,
1100                 const double *dashes,
1101                 int           num_dashes,
1102                 double        offset)
1103 {
1104     cairo_status_t status;
1105
1106     if (unlikely (cr->status))
1107         return;
1108
1109     status = cr->backend->set_dash (cr, dashes, num_dashes, offset);
1110     if (unlikely (status))
1111         _cairo_set_error (cr, status);
1112 }
1113
1114 /**
1115  * cairo_get_dash_count:
1116  * @cr: a #cairo_t
1117  *
1118  * This function returns the length of the dash array in @cr (0 if dashing
1119  * is not currently in effect).
1120  *
1121  * See also cairo_set_dash() and cairo_get_dash().
1122  *
1123  * Return value: the length of the dash array, or 0 if no dash array set.
1124  *
1125  * Since: 1.4
1126  **/
1127 int
1128 cairo_get_dash_count (cairo_t *cr)
1129 {
1130     int num_dashes;
1131
1132     if (unlikely (cr->status))
1133         return 0;
1134
1135     cr->backend->get_dash (cr, NULL, &num_dashes, NULL);
1136
1137     return num_dashes;
1138 }
1139
1140 /**
1141  * cairo_get_dash:
1142  * @cr: a #cairo_t
1143  * @dashes: return value for the dash array, or %NULL
1144  * @offset: return value for the current dash offset, or %NULL
1145  *
1146  * Gets the current dash array.  If not %NULL, @dashes should be big
1147  * enough to hold at least the number of values returned by
1148  * cairo_get_dash_count().
1149  *
1150  * Since: 1.4
1151  **/
1152 void
1153 cairo_get_dash (cairo_t *cr,
1154                 double  *dashes,
1155                 double  *offset)
1156 {
1157     if (unlikely (cr->status))
1158         return;
1159
1160     cr->backend->get_dash (cr, dashes, NULL, offset);
1161 }
1162
1163 /**
1164  * cairo_set_miter_limit:
1165  * @cr: a cairo context
1166  * @limit: miter limit to set
1167  *
1168  * Sets the current miter limit within the cairo context.
1169  *
1170  * If the current line join style is set to %CAIRO_LINE_JOIN_MITER
1171  * (see cairo_set_line_join()), the miter limit is used to determine
1172  * whether the lines should be joined with a bevel instead of a miter.
1173  * Cairo divides the length of the miter by the line width.
1174  * If the result is greater than the miter limit, the style is
1175  * converted to a bevel.
1176  *
1177  * As with the other stroke parameters, the current line miter limit is
1178  * examined by cairo_stroke(), cairo_stroke_extents(), and
1179  * cairo_stroke_to_path(), but does not have any effect during path
1180  * construction.
1181  *
1182  * The default miter limit value is 10.0, which will convert joins
1183  * with interior angles less than 11 degrees to bevels instead of
1184  * miters. For reference, a miter limit of 2.0 makes the miter cutoff
1185  * at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90
1186  * degrees.
1187  *
1188  * A miter limit for a desired angle can be computed as: miter limit =
1189  * 1/sin(angle/2)
1190  *
1191  * Since: 1.0
1192  **/
1193 void
1194 cairo_set_miter_limit (cairo_t *cr, double limit)
1195 {
1196     cairo_status_t status;
1197
1198     if (unlikely (cr->status))
1199         return;
1200
1201     status = cr->backend->set_miter_limit (cr, limit);
1202     if (unlikely (status))
1203         _cairo_set_error (cr, status);
1204 }
1205
1206 /**
1207  * cairo_translate:
1208  * @cr: a cairo context
1209  * @tx: amount to translate in the X direction
1210  * @ty: amount to translate in the Y direction
1211  *
1212  * Modifies the current transformation matrix (CTM) by translating the
1213  * user-space origin by (@tx, @ty). This offset is interpreted as a
1214  * user-space coordinate according to the CTM in place before the new
1215  * call to cairo_translate(). In other words, the translation of the
1216  * user-space origin takes place after any existing transformation.
1217  *
1218  * Since: 1.0
1219  **/
1220 void
1221 cairo_translate (cairo_t *cr, double tx, double ty)
1222 {
1223     CAIRO_TRACE_BEGIN (__func__);
1224     cairo_status_t status;
1225
1226     if (unlikely (cr->status)) {
1227         CAIRO_TRACE_END (__func__);
1228         return;
1229     }
1230
1231     status = cr->backend->translate (cr, tx, ty);
1232     if (unlikely (status))
1233         _cairo_set_error (cr, status);
1234     CAIRO_TRACE_END (__func__);
1235 }
1236 slim_hidden_def (cairo_translate);
1237
1238 /**
1239  * cairo_scale:
1240  * @cr: a cairo context
1241  * @sx: scale factor for the X dimension
1242  * @sy: scale factor for the Y dimension
1243  *
1244  * Modifies the current transformation matrix (CTM) by scaling the X
1245  * and Y user-space axes by @sx and @sy respectively. The scaling of
1246  * the axes takes place after any existing transformation of user
1247  * space.
1248  *
1249  * Since: 1.0
1250  **/
1251 void
1252 cairo_scale (cairo_t *cr, double sx, double sy)
1253 {
1254     CAIRO_TRACE_BEGIN (__func__);
1255     cairo_status_t status;
1256
1257     if (unlikely (cr->status)) {
1258         CAIRO_TRACE_END (__func__);
1259         return;
1260     }
1261
1262     status = cr->backend->scale (cr, sx, sy);
1263     if (unlikely (status))
1264         _cairo_set_error (cr, status);
1265     CAIRO_TRACE_END (__func__);
1266 }
1267 slim_hidden_def (cairo_scale);
1268
1269 /**
1270  * cairo_rotate:
1271  * @cr: a cairo context
1272  * @angle: angle (in radians) by which the user-space axes will be
1273  * rotated
1274  *
1275  * Modifies the current transformation matrix (CTM) by rotating the
1276  * user-space axes by @angle radians. The rotation of the axes takes
1277  * places after any existing transformation of user space. The
1278  * rotation direction for positive angles is from the positive X axis
1279  * toward the positive Y axis.
1280  *
1281  * Since: 1.0
1282  **/
1283 void
1284 cairo_rotate (cairo_t *cr, double angle)
1285 {
1286     CAIRO_TRACE_BEGIN (__func__);
1287     cairo_status_t status;
1288
1289     if (unlikely (cr->status)) {
1290         CAIRO_TRACE_END (__func__);
1291         return;
1292     }
1293
1294     status = cr->backend->rotate (cr, angle);
1295     if (unlikely (status))
1296         _cairo_set_error (cr, status);
1297     CAIRO_TRACE_END (__func__);
1298 }
1299
1300 /**
1301  * cairo_transform:
1302  * @cr: a cairo context
1303  * @matrix: a transformation to be applied to the user-space axes
1304  *
1305  * Modifies the current transformation matrix (CTM) by applying
1306  * @matrix as an additional transformation. The new transformation of
1307  * user space takes place after any existing transformation.
1308  *
1309  * Since: 1.0
1310  **/
1311 void
1312 cairo_transform (cairo_t              *cr,
1313                  const cairo_matrix_t *matrix)
1314 {
1315     cairo_status_t status;
1316
1317     if (unlikely (cr->status))
1318         return;
1319
1320     status = cr->backend->transform (cr, matrix);
1321     if (unlikely (status))
1322         _cairo_set_error (cr, status);
1323 }
1324 slim_hidden_def (cairo_transform);
1325
1326 /**
1327  * cairo_set_matrix:
1328  * @cr: a cairo context
1329  * @matrix: a transformation matrix from user space to device space
1330  *
1331  * Modifies the current transformation matrix (CTM) by setting it
1332  * equal to @matrix.
1333  *
1334  * Since: 1.0
1335  **/
1336 void
1337 cairo_set_matrix (cairo_t              *cr,
1338                   const cairo_matrix_t *matrix)
1339 {
1340     cairo_status_t status;
1341
1342     if (unlikely (cr->status))
1343         return;
1344
1345     status = cr->backend->set_matrix (cr, matrix);
1346     if (unlikely (status))
1347         _cairo_set_error (cr, status);
1348 }
1349 slim_hidden_def (cairo_set_matrix);
1350
1351 /**
1352  * cairo_identity_matrix:
1353  * @cr: a cairo context
1354  *
1355  * Resets the current transformation matrix (CTM) by setting it equal
1356  * to the identity matrix. That is, the user-space and device-space
1357  * axes will be aligned and one user-space unit will transform to one
1358  * device-space unit.
1359  *
1360  * Since: 1.0
1361  **/
1362 void
1363 cairo_identity_matrix (cairo_t *cr)
1364 {
1365     cairo_status_t status;
1366
1367     if (unlikely (cr->status))
1368         return;
1369
1370     status = cr->backend->set_identity_matrix (cr);
1371     if (unlikely (status))
1372         _cairo_set_error (cr, status);
1373 }
1374
1375 /**
1376  * cairo_user_to_device:
1377  * @cr: a cairo context
1378  * @x: X value of coordinate (in/out parameter)
1379  * @y: Y value of coordinate (in/out parameter)
1380  *
1381  * Transform a coordinate from user space to device space by
1382  * multiplying the given point by the current transformation matrix
1383  * (CTM).
1384  *
1385  * Since: 1.0
1386  **/
1387 void
1388 cairo_user_to_device (cairo_t *cr, double *x, double *y)
1389 {
1390     CAIRO_TRACE_BEGIN (__func__);
1391     if (unlikely (cr->status)) {
1392         CAIRO_TRACE_END (__func__);
1393         return;
1394     }
1395
1396     cr->backend->user_to_device (cr, x, y);
1397     CAIRO_TRACE_END (__func__);
1398 }
1399 slim_hidden_def (cairo_user_to_device);
1400
1401 /**
1402  * cairo_user_to_device_distance:
1403  * @cr: a cairo context
1404  * @dx: X component of a distance vector (in/out parameter)
1405  * @dy: Y component of a distance vector (in/out parameter)
1406  *
1407  * Transform a distance vector from user space to device space. This
1408  * function is similar to cairo_user_to_device() except that the
1409  * translation components of the CTM will be ignored when transforming
1410  * (@dx,@dy).
1411  *
1412  * Since: 1.0
1413  **/
1414 void
1415 cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy)
1416 {
1417     CAIRO_TRACE_BEGIN (__func__);
1418     if (unlikely (cr->status)) {
1419         CAIRO_TRACE_END (__func__);
1420         return;
1421     }
1422
1423     cr->backend->user_to_device_distance (cr, dx, dy);
1424     CAIRO_TRACE_END (__func__);
1425 }
1426 slim_hidden_def (cairo_user_to_device_distance);
1427
1428 /**
1429  * cairo_device_to_user:
1430  * @cr: a cairo
1431  * @x: X value of coordinate (in/out parameter)
1432  * @y: Y value of coordinate (in/out parameter)
1433  *
1434  * Transform a coordinate from device space to user space by
1435  * multiplying the given point by the inverse of the current
1436  * transformation matrix (CTM).
1437  *
1438  * Since: 1.0
1439  **/
1440 void
1441 cairo_device_to_user (cairo_t *cr, double *x, double *y)
1442 {
1443     CAIRO_TRACE_BEGIN (__func__);
1444     if (unlikely (cr->status)) {
1445         CAIRO_TRACE_END (__func__);
1446         return;
1447     }
1448
1449     cr->backend->device_to_user (cr, x, y);
1450     CAIRO_TRACE_END (__func__);
1451 }
1452 slim_hidden_def (cairo_device_to_user);
1453
1454 /**
1455  * cairo_device_to_user_distance:
1456  * @cr: a cairo context
1457  * @dx: X component of a distance vector (in/out parameter)
1458  * @dy: Y component of a distance vector (in/out parameter)
1459  *
1460  * Transform a distance vector from device space to user space. This
1461  * function is similar to cairo_device_to_user() except that the
1462  * translation components of the inverse CTM will be ignored when
1463  * transforming (@dx,@dy).
1464  *
1465  * Since: 1.0
1466  **/
1467 void
1468 cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy)
1469 {
1470     if (unlikely (cr->status))
1471         return;
1472
1473     cr->backend->device_to_user_distance (cr, dx, dy);
1474 }
1475
1476 /**
1477  * cairo_new_path:
1478  * @cr: a cairo context
1479  *
1480  * Clears the current path. After this call there will be no path and
1481  * no current point.
1482  *
1483  * Since: 1.0
1484  **/
1485 void
1486 cairo_new_path (cairo_t *cr)
1487 {
1488     cairo_status_t status;
1489
1490     if (unlikely (cr->status))
1491         return;
1492
1493     status = cr->backend->new_path (cr);
1494     if (unlikely (status))
1495         _cairo_set_error (cr, status);
1496 }
1497 slim_hidden_def(cairo_new_path);
1498
1499 /**
1500  * cairo_new_sub_path:
1501  * @cr: a cairo context
1502  *
1503  * Begin a new sub-path. Note that the existing path is not
1504  * affected. After this call there will be no current point.
1505  *
1506  * In many cases, this call is not needed since new sub-paths are
1507  * frequently started with cairo_move_to().
1508  *
1509  * A call to cairo_new_sub_path() is particularly useful when
1510  * beginning a new sub-path with one of the cairo_arc() calls. This
1511  * makes things easier as it is no longer necessary to manually
1512  * compute the arc's initial coordinates for a call to
1513  * cairo_move_to().
1514  *
1515  * Since: 1.2
1516  **/
1517 void
1518 cairo_new_sub_path (cairo_t *cr)
1519 {
1520     cairo_status_t status;
1521
1522     if (unlikely (cr->status))
1523         return;
1524
1525     status = cr->backend->new_sub_path (cr);
1526     if (unlikely (status))
1527         _cairo_set_error (cr, status);
1528 }
1529
1530 /**
1531  * cairo_move_to:
1532  * @cr: a cairo context
1533  * @x: the X coordinate of the new position
1534  * @y: the Y coordinate of the new position
1535  *
1536  * Begin a new sub-path. After this call the current point will be (@x,
1537  * @y).
1538  *
1539  * Since: 1.0
1540  **/
1541 void
1542 cairo_move_to (cairo_t *cr, double x, double y)
1543 {
1544     cairo_status_t status;
1545
1546     if (unlikely (cr->status))
1547         return;
1548
1549     status = cr->backend->move_to (cr, x, y);
1550     if (unlikely (status))
1551         _cairo_set_error (cr, status);
1552 }
1553 slim_hidden_def(cairo_move_to);
1554
1555
1556 /**
1557  * cairo_line_to:
1558  * @cr: a cairo context
1559  * @x: the X coordinate of the end of the new line
1560  * @y: the Y coordinate of the end of the new line
1561  *
1562  * Adds a line to the path from the current point to position (@x, @y)
1563  * in user-space coordinates. After this call the current point
1564  * will be (@x, @y).
1565  *
1566  * If there is no current point before the call to cairo_line_to()
1567  * this function will behave as cairo_move_to(@cr, @x, @y).
1568  *
1569  * Since: 1.0
1570  **/
1571 void
1572 cairo_line_to (cairo_t *cr, double x, double y)
1573 {
1574     cairo_status_t status;
1575
1576     if (unlikely (cr->status))
1577         return;
1578
1579     status = cr->backend->line_to (cr, x, y);
1580     if (unlikely (status))
1581         _cairo_set_error (cr, status);
1582 }
1583 slim_hidden_def (cairo_line_to);
1584
1585 /**
1586  * cairo_curve_to:
1587  * @cr: a cairo context
1588  * @x1: the X coordinate of the first control point
1589  * @y1: the Y coordinate of the first control point
1590  * @x2: the X coordinate of the second control point
1591  * @y2: the Y coordinate of the second control point
1592  * @x3: the X coordinate of the end of the curve
1593  * @y3: the Y coordinate of the end of the curve
1594  *
1595  * Adds a cubic Bézier spline to the path from the current point to
1596  * position (@x3, @y3) in user-space coordinates, using (@x1, @y1) and
1597  * (@x2, @y2) as the control points. After this call the current point
1598  * will be (@x3, @y3).
1599  *
1600  * If there is no current point before the call to cairo_curve_to()
1601  * this function will behave as if preceded by a call to
1602  * cairo_move_to(@cr, @x1, @y1).
1603  *
1604  * Since: 1.0
1605  **/
1606 void
1607 cairo_curve_to (cairo_t *cr,
1608                 double x1, double y1,
1609                 double x2, double y2,
1610                 double x3, double y3)
1611 {
1612     cairo_status_t status;
1613
1614     if (unlikely (cr->status))
1615         return;
1616
1617     status = cr->backend->curve_to (cr,
1618                                     x1, y1,
1619                                     x2, y2,
1620                                     x3, y3);
1621     if (unlikely (status))
1622         _cairo_set_error (cr, status);
1623 }
1624 slim_hidden_def (cairo_curve_to);
1625
1626 /**
1627  * cairo_arc:
1628  * @cr: a cairo context
1629  * @xc: X position of the center of the arc
1630  * @yc: Y position of the center of the arc
1631  * @radius: the radius of the arc
1632  * @angle1: the start angle, in radians
1633  * @angle2: the end angle, in radians
1634  *
1635  * Adds a circular arc of the given @radius to the current path.  The
1636  * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in
1637  * the direction of increasing angles to end at @angle2. If @angle2 is
1638  * less than @angle1 it will be progressively increased by
1639  * <literal>2*M_PI</literal> until it is greater than @angle1.
1640  *
1641  * If there is a current point, an initial line segment will be added
1642  * to the path to connect the current point to the beginning of the
1643  * arc. If this initial line is undesired, it can be avoided by
1644  * calling cairo_new_sub_path() before calling cairo_arc().
1645  *
1646  * Angles are measured in radians. An angle of 0.0 is in the direction
1647  * of the positive X axis (in user space). An angle of
1648  * <literal>M_PI/2.0</literal> radians (90 degrees) is in the
1649  * direction of the positive Y axis (in user space). Angles increase
1650  * in the direction from the positive X axis toward the positive Y
1651  * axis. So with the default transformation matrix, angles increase in
1652  * a clockwise direction.
1653  *
1654  * (To convert from degrees to radians, use <literal>degrees * (M_PI /
1655  * 180.)</literal>.)
1656  *
1657  * This function gives the arc in the direction of increasing angles;
1658  * see cairo_arc_negative() to get the arc in the direction of
1659  * decreasing angles.
1660  *
1661  * The arc is circular in user space. To achieve an elliptical arc,
1662  * you can scale the current transformation matrix by different
1663  * amounts in the X and Y directions. For example, to draw an ellipse
1664  * in the box given by @x, @y, @width, @height:
1665  *
1666  * <informalexample><programlisting>
1667  * cairo_save (cr);
1668  * cairo_translate (cr, x + width / 2., y + height / 2.);
1669  * cairo_scale (cr, width / 2., height / 2.);
1670  * cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
1671  * cairo_restore (cr);
1672  * </programlisting></informalexample>
1673  *
1674  * Since: 1.0
1675  **/
1676 void
1677 cairo_arc (cairo_t *cr,
1678            double xc, double yc,
1679            double radius,
1680            double angle1, double angle2)
1681 {
1682     CAIRO_TRACE_BEGIN (__func__);
1683     cairo_status_t status;
1684
1685     if (unlikely (cr->status)) {
1686         CAIRO_TRACE_END (__func__);
1687         return;
1688     }
1689
1690     if (angle2 < angle1) {
1691         /* increase angle2 by multiples of full circle until it
1692          * satisfies angle2 >= angle1 */
1693         angle2 = fmod (angle2 - angle1, 2 * M_PI);
1694         if (angle2 < 0)
1695             angle2 += 2 * M_PI;
1696         angle2 += angle1;
1697     }
1698
1699     status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, TRUE);
1700     if (unlikely (status))
1701         _cairo_set_error (cr, status);
1702     CAIRO_TRACE_END (__func__);
1703 }
1704
1705 /**
1706  * cairo_arc_negative:
1707  * @cr: a cairo context
1708  * @xc: X position of the center of the arc
1709  * @yc: Y position of the center of the arc
1710  * @radius: the radius of the arc
1711  * @angle1: the start angle, in radians
1712  * @angle2: the end angle, in radians
1713  *
1714  * Adds a circular arc of the given @radius to the current path.  The
1715  * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in
1716  * the direction of decreasing angles to end at @angle2. If @angle2 is
1717  * greater than @angle1 it will be progressively decreased by
1718  * <literal>2*M_PI</literal> until it is less than @angle1.
1719  *
1720  * See cairo_arc() for more details. This function differs only in the
1721  * direction of the arc between the two angles.
1722  *
1723  * Since: 1.0
1724  **/
1725 void
1726 cairo_arc_negative (cairo_t *cr,
1727                     double xc, double yc,
1728                     double radius,
1729                     double angle1, double angle2)
1730 {
1731     CAIRO_TRACE_BEGIN (__func__);
1732     cairo_status_t status;
1733
1734     if (unlikely (cr->status)) {
1735         CAIRO_TRACE_END (__func__);
1736         return;
1737     }
1738
1739     if (angle2 > angle1) {
1740         /* decrease angle2 by multiples of full circle until it
1741          * satisfies angle2 <= angle1 */
1742         angle2 = fmod (angle2 - angle1, 2 * M_PI);
1743         if (angle2 > 0)
1744             angle2 -= 2 * M_PI;
1745         angle2 += angle1;
1746     }
1747
1748     status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, FALSE);
1749     if (unlikely (status))
1750         _cairo_set_error (cr, status);
1751     CAIRO_TRACE_END (__func__);
1752 }
1753
1754 /* XXX: NYI
1755 void
1756 cairo_arc_to (cairo_t *cr,
1757               double x1, double y1,
1758               double x2, double y2,
1759               double radius)
1760 {
1761     cairo_status_t status;
1762
1763     if (unlikely (cr->status))
1764         return;
1765
1766     status = cr->backend->arc_to (cr, x1, y1, x2, y2, radius);
1767     if (unlikely (status))
1768         _cairo_set_error (cr, status);
1769 }
1770
1771 void
1772 cairo_rel_arc_to (cairo_t *cr,
1773               double dx1, double dy1,
1774               double dx2, double dy2,
1775               double radius)
1776 {
1777     cairo_status_t status;
1778
1779     if (unlikely (cr->status))
1780         return;
1781
1782     status = cr->backend->rel_arc_to (cr, dx1, dy1, dx2, dy2, radius);
1783     if (unlikely (status))
1784         _cairo_set_error (cr, status);
1785 }
1786 */
1787
1788 /**
1789  * cairo_rel_move_to:
1790  * @cr: a cairo context
1791  * @dx: the X offset
1792  * @dy: the Y offset
1793  *
1794  * Begin a new sub-path. After this call the current point will offset
1795  * by (@x, @y).
1796  *
1797  * Given a current point of (x, y), cairo_rel_move_to(@cr, @dx, @dy)
1798  * is logically equivalent to cairo_move_to(@cr, x + @dx, y + @dy).
1799  *
1800  * It is an error to call this function with no current point. Doing
1801  * so will cause @cr to shutdown with a status of
1802  * %CAIRO_STATUS_NO_CURRENT_POINT.
1803  *
1804  * Since: 1.0
1805  **/
1806 void
1807 cairo_rel_move_to (cairo_t *cr, double dx, double dy)
1808 {
1809     cairo_status_t status;
1810
1811     if (unlikely (cr->status))
1812         return;
1813
1814     status = cr->backend->rel_move_to (cr, dx, dy);
1815     if (unlikely (status))
1816         _cairo_set_error (cr, status);
1817 }
1818
1819 /**
1820  * cairo_rel_line_to:
1821  * @cr: a cairo context
1822  * @dx: the X offset to the end of the new line
1823  * @dy: the Y offset to the end of the new line
1824  *
1825  * Relative-coordinate version of cairo_line_to(). Adds a line to the
1826  * path from the current point to a point that is offset from the
1827  * current point by (@dx, @dy) in user space. After this call the
1828  * current point will be offset by (@dx, @dy).
1829  *
1830  * Given a current point of (x, y), cairo_rel_line_to(@cr, @dx, @dy)
1831  * is logically equivalent to cairo_line_to(@cr, x + @dx, y + @dy).
1832  *
1833  * It is an error to call this function with no current point. Doing
1834  * so will cause @cr to shutdown with a status of
1835  * %CAIRO_STATUS_NO_CURRENT_POINT.
1836  *
1837  * Since: 1.0
1838  **/
1839 void
1840 cairo_rel_line_to (cairo_t *cr, double dx, double dy)
1841 {
1842     cairo_status_t status;
1843
1844     if (unlikely (cr->status))
1845         return;
1846
1847     status = cr->backend->rel_line_to (cr, dx, dy);
1848     if (unlikely (status))
1849         _cairo_set_error (cr, status);
1850 }
1851 slim_hidden_def(cairo_rel_line_to);
1852
1853 /**
1854  * cairo_rel_curve_to:
1855  * @cr: a cairo context
1856  * @dx1: the X offset to the first control point
1857  * @dy1: the Y offset to the first control point
1858  * @dx2: the X offset to the second control point
1859  * @dy2: the Y offset to the second control point
1860  * @dx3: the X offset to the end of the curve
1861  * @dy3: the Y offset to the end of the curve
1862  *
1863  * Relative-coordinate version of cairo_curve_to(). All offsets are
1864  * relative to the current point. Adds a cubic Bézier spline to the
1865  * path from the current point to a point offset from the current
1866  * point by (@dx3, @dy3), using points offset by (@dx1, @dy1) and
1867  * (@dx2, @dy2) as the control points. After this call the current
1868  * point will be offset by (@dx3, @dy3).
1869  *
1870  * Given a current point of (x, y), cairo_rel_curve_to(@cr, @dx1,
1871  * @dy1, @dx2, @dy2, @dx3, @dy3) is logically equivalent to
1872  * cairo_curve_to(@cr, x+@dx1, y+@dy1, x+@dx2, y+@dy2, x+@dx3, y+@dy3).
1873  *
1874  * It is an error to call this function with no current point. Doing
1875  * so will cause @cr to shutdown with a status of
1876  * %CAIRO_STATUS_NO_CURRENT_POINT.
1877  *
1878  * Since: 1.0
1879  **/
1880 void
1881 cairo_rel_curve_to (cairo_t *cr,
1882                     double dx1, double dy1,
1883                     double dx2, double dy2,
1884                     double dx3, double dy3)
1885 {
1886     cairo_status_t status;
1887
1888     if (unlikely (cr->status))
1889         return;
1890
1891     status = cr->backend->rel_curve_to (cr,
1892                                         dx1, dy1,
1893                                         dx2, dy2,
1894                                         dx3, dy3);
1895     if (unlikely (status))
1896         _cairo_set_error (cr, status);
1897 }
1898
1899 /**
1900  * cairo_rectangle:
1901  * @cr: a cairo context
1902  * @x: the X coordinate of the top left corner of the rectangle
1903  * @y: the Y coordinate to the top left corner of the rectangle
1904  * @width: the width of the rectangle
1905  * @height: the height of the rectangle
1906  *
1907  * Adds a closed sub-path rectangle of the given size to the current
1908  * path at position (@x, @y) in user-space coordinates.
1909  *
1910  * This function is logically equivalent to:
1911  * <informalexample><programlisting>
1912  * cairo_move_to (cr, x, y);
1913  * cairo_rel_line_to (cr, width, 0);
1914  * cairo_rel_line_to (cr, 0, height);
1915  * cairo_rel_line_to (cr, -width, 0);
1916  * cairo_close_path (cr);
1917  * </programlisting></informalexample>
1918  *
1919  * Since: 1.0
1920  **/
1921 void
1922 cairo_rectangle (cairo_t *cr,
1923                  double x, double y,
1924                  double width, double height)
1925 {
1926     CAIRO_TRACE_BEGIN (__func__);
1927     cairo_status_t status;
1928
1929     if (unlikely (cr->status)) {
1930         CAIRO_TRACE_END (__func__);
1931         return;
1932     }
1933
1934     status = cr->backend->rectangle (cr, x, y, width, height);
1935     if (unlikely (status))
1936         _cairo_set_error (cr, status);
1937     CAIRO_TRACE_END (__func__);
1938 }
1939
1940 #if 0
1941 /* XXX: NYI */
1942 void
1943 cairo_stroke_to_path (cairo_t *cr)
1944 {
1945     cairo_status_t status;
1946
1947     if (unlikely (cr->status))
1948         return;
1949
1950     /* The code in _cairo_recording_surface_get_path has a poorman's stroke_to_path */
1951
1952     status = _cairo_gstate_stroke_path (cr->gstate);
1953     if (unlikely (status))
1954         _cairo_set_error (cr, status);
1955 }
1956 #endif
1957
1958 /**
1959  * cairo_close_path:
1960  * @cr: a cairo context
1961  *
1962  * Adds a line segment to the path from the current point to the
1963  * beginning of the current sub-path, (the most recent point passed to
1964  * cairo_move_to()), and closes this sub-path. After this call the
1965  * current point will be at the joined endpoint of the sub-path.
1966  *
1967  * The behavior of cairo_close_path() is distinct from simply calling
1968  * cairo_line_to() with the equivalent coordinate in the case of
1969  * stroking. When a closed sub-path is stroked, there are no caps on
1970  * the ends of the sub-path. Instead, there is a line join connecting
1971  * the final and initial segments of the sub-path.
1972  *
1973  * If there is no current point before the call to cairo_close_path(),
1974  * this function will have no effect.
1975  *
1976  * Note: As of cairo version 1.2.4 any call to cairo_close_path() will
1977  * place an explicit MOVE_TO element into the path immediately after
1978  * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for
1979  * example). This can simplify path processing in some cases as it may
1980  * not be necessary to save the "last move_to point" during processing
1981  * as the MOVE_TO immediately after the CLOSE_PATH will provide that
1982  * point.
1983  *
1984  * Since: 1.0
1985  **/
1986 void
1987 cairo_close_path (cairo_t *cr)
1988 {
1989     cairo_status_t status;
1990
1991     if (unlikely (cr->status))
1992         return;
1993
1994     status = cr->backend->close_path (cr);
1995     if (unlikely (status))
1996         _cairo_set_error (cr, status);
1997 }
1998 slim_hidden_def(cairo_close_path);
1999
2000 /**
2001  * cairo_path_extents:
2002  * @cr: a cairo context
2003  * @x1: left of the resulting extents
2004  * @y1: top of the resulting extents
2005  * @x2: right of the resulting extents
2006  * @y2: bottom of the resulting extents
2007  *
2008  * Computes a bounding box in user-space coordinates covering the
2009  * points on the current path. If the current path is empty, returns
2010  * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule,
2011  * surface dimensions and clipping are not taken into account.
2012  *
2013  * Contrast with cairo_fill_extents() and cairo_stroke_extents() which
2014  * return the extents of only the area that would be "inked" by
2015  * the corresponding drawing operations.
2016  *
2017  * The result of cairo_path_extents() is defined as equivalent to the
2018  * limit of cairo_stroke_extents() with %CAIRO_LINE_CAP_ROUND as the
2019  * line width approaches 0.0, (but never reaching the empty-rectangle
2020  * returned by cairo_stroke_extents() for a line width of 0.0).
2021  *
2022  * Specifically, this means that zero-area sub-paths such as
2023  * cairo_move_to();cairo_line_to() segments, (even degenerate cases
2024  * where the coordinates to both calls are identical), will be
2025  * considered as contributing to the extents. However, a lone
2026  * cairo_move_to() will not contribute to the results of
2027  * cairo_path_extents().
2028  *
2029  * Since: 1.6
2030  **/
2031 void
2032 cairo_path_extents (cairo_t *cr,
2033                     double *x1, double *y1, double *x2, double *y2)
2034 {
2035     if (unlikely (cr->status)) {
2036         if (x1)
2037             *x1 = 0.0;
2038         if (y1)
2039             *y1 = 0.0;
2040         if (x2)
2041             *x2 = 0.0;
2042         if (y2)
2043             *y2 = 0.0;
2044
2045         return;
2046     }
2047
2048     cr->backend->path_extents (cr, x1, y1, x2, y2);
2049 }
2050
2051 /**
2052  * cairo_paint:
2053  * @cr: a cairo context
2054  *
2055  * A drawing operator that paints the current source everywhere within
2056  * the current clip region.
2057  *
2058  * Since: 1.0
2059  **/
2060 void
2061 cairo_paint (cairo_t *cr)
2062 {
2063     CAIRO_TRACE_BEGIN (__func__);
2064     cairo_status_t status;
2065
2066     if (unlikely (cr->status)) {
2067         CAIRO_TRACE_END (__func__);
2068         return;
2069     }
2070
2071     status = cr->backend->paint (cr);
2072     if (unlikely (status))
2073         _cairo_set_error (cr, status);
2074     CAIRO_TRACE_END (__func__);
2075 }
2076 slim_hidden_def (cairo_paint);
2077
2078 /**
2079  * cairo_paint_with_alpha:
2080  * @cr: a cairo context
2081  * @alpha: alpha value, between 0 (transparent) and 1 (opaque)
2082  *
2083  * A drawing operator that paints the current source everywhere within
2084  * the current clip region using a mask of constant alpha value
2085  * @alpha. The effect is similar to cairo_paint(), but the drawing
2086  * is faded out using the alpha value.
2087  *
2088  * Since: 1.0
2089  **/
2090 void
2091 cairo_paint_with_alpha (cairo_t *cr,
2092                         double   alpha)
2093 {
2094     CAIRO_TRACE_BEGIN (__func__);
2095     cairo_status_t status;
2096
2097     if (unlikely (cr->status)) {
2098         CAIRO_TRACE_END (__func__);
2099         return;
2100     }
2101
2102     status = cr->backend->paint_with_alpha (cr, alpha);
2103     if (unlikely (status))
2104         _cairo_set_error (cr, status);
2105     CAIRO_TRACE_END (__func__);
2106 }
2107
2108 /**
2109  * cairo_mask:
2110  * @cr: a cairo context
2111  * @pattern: a #cairo_pattern_t
2112  *
2113  * A drawing operator that paints the current source
2114  * using the alpha channel of @pattern as a mask. (Opaque
2115  * areas of @pattern are painted with the source, transparent
2116  * areas are not painted.)
2117  *
2118  * Since: 1.0
2119  **/
2120 void
2121 cairo_mask (cairo_t         *cr,
2122             cairo_pattern_t *pattern)
2123 {
2124     CAIRO_TRACE_BEGIN (__func__);
2125     cairo_status_t status;
2126
2127     if (unlikely (cr->status)) {
2128         CAIRO_TRACE_END (__func__);
2129         return;
2130     }
2131
2132     if (unlikely (pattern == NULL)) {
2133         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
2134         CAIRO_TRACE_END (__func__);
2135         return;
2136     }
2137
2138     if (unlikely (pattern->status)) {
2139         _cairo_set_error (cr, pattern->status);
2140         CAIRO_TRACE_END (__func__);
2141         return;
2142     }
2143
2144     status = cr->backend->mask (cr, pattern);
2145     if (unlikely (status))
2146         _cairo_set_error (cr, status);
2147     CAIRO_TRACE_END (__func__);
2148 }
2149 slim_hidden_def (cairo_mask);
2150
2151 /**
2152  * cairo_mask_surface:
2153  * @cr: a cairo context
2154  * @surface: a #cairo_surface_t
2155  * @surface_x: X coordinate at which to place the origin of @surface
2156  * @surface_y: Y coordinate at which to place the origin of @surface
2157  *
2158  * A drawing operator that paints the current source
2159  * using the alpha channel of @surface as a mask. (Opaque
2160  * areas of @surface are painted with the source, transparent
2161  * areas are not painted.)
2162  *
2163  * Since: 1.0
2164  **/
2165 void
2166 cairo_mask_surface (cairo_t         *cr,
2167                     cairo_surface_t *surface,
2168                     double           surface_x,
2169                     double           surface_y)
2170 {
2171     CAIRO_TRACE_BEGIN (__func__);
2172     cairo_pattern_t *pattern;
2173     cairo_matrix_t matrix;
2174
2175     if (unlikely (cr->status)) {
2176         CAIRO_TRACE_END (__func__);
2177         return;
2178     }
2179
2180     pattern = cairo_pattern_create_for_surface (surface);
2181
2182     cairo_matrix_init_translate (&matrix, - surface_x, - surface_y);
2183     cairo_pattern_set_matrix (pattern, &matrix);
2184
2185     cairo_mask (cr, pattern);
2186
2187     cairo_pattern_destroy (pattern);
2188     CAIRO_TRACE_END (__func__);
2189 }
2190
2191 /**
2192  * cairo_stroke:
2193  * @cr: a cairo context
2194  *
2195  * A drawing operator that strokes the current path according to the
2196  * current line width, line join, line cap, and dash settings. After
2197  * cairo_stroke(), the current path will be cleared from the cairo
2198  * context. See cairo_set_line_width(), cairo_set_line_join(),
2199  * cairo_set_line_cap(), cairo_set_dash(), and
2200  * cairo_stroke_preserve().
2201  *
2202  * Note: Degenerate segments and sub-paths are treated specially and
2203  * provide a useful result. These can result in two different
2204  * situations:
2205  *
2206  * 1. Zero-length "on" segments set in cairo_set_dash(). If the cap
2207  * style is %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE then these
2208  * segments will be drawn as circular dots or squares respectively. In
2209  * the case of %CAIRO_LINE_CAP_SQUARE, the orientation of the squares
2210  * is determined by the direction of the underlying path.
2211  *
2212  * 2. A sub-path created by cairo_move_to() followed by either a
2213  * cairo_close_path() or one or more calls to cairo_line_to() to the
2214  * same coordinate as the cairo_move_to(). If the cap style is
2215  * %CAIRO_LINE_CAP_ROUND then these sub-paths will be drawn as circular
2216  * dots. Note that in the case of %CAIRO_LINE_CAP_SQUARE a degenerate
2217  * sub-path will not be drawn at all, (since the correct orientation
2218  * is indeterminate).
2219  *
2220  * In no case will a cap style of %CAIRO_LINE_CAP_BUTT cause anything
2221  * to be drawn in the case of either degenerate segments or sub-paths.
2222  *
2223  * Since: 1.0
2224  **/
2225 void
2226 cairo_stroke (cairo_t *cr)
2227 {
2228     CAIRO_TRACE_BEGIN (__func__);
2229     cairo_status_t status;
2230
2231     if (unlikely (cr->status)) {
2232         CAIRO_TRACE_END (__func__);
2233         return;
2234     }
2235
2236     status = cr->backend->stroke (cr);
2237     if (unlikely (status))
2238         _cairo_set_error (cr, status);
2239     CAIRO_TRACE_END (__func__);
2240 }
2241 slim_hidden_def(cairo_stroke);
2242
2243 /**
2244  * cairo_stroke_preserve:
2245  * @cr: a cairo context
2246  *
2247  * A drawing operator that strokes the current path according to the
2248  * current line width, line join, line cap, and dash settings. Unlike
2249  * cairo_stroke(), cairo_stroke_preserve() preserves the path within the
2250  * cairo context.
2251  *
2252  * See cairo_set_line_width(), cairo_set_line_join(),
2253  * cairo_set_line_cap(), cairo_set_dash(), and
2254  * cairo_stroke_preserve().
2255  *
2256  * Since: 1.0
2257  **/
2258 void
2259 cairo_stroke_preserve (cairo_t *cr)
2260 {
2261     CAIRO_TRACE_BEGIN (__func__);
2262     cairo_status_t status;
2263
2264     if (unlikely (cr->status)) {
2265         CAIRO_TRACE_END (__func__);
2266         return;
2267     }
2268
2269     status = cr->backend->stroke_preserve (cr);
2270     if (unlikely (status))
2271         _cairo_set_error (cr, status);
2272     CAIRO_TRACE_END (__func__);
2273 }
2274 slim_hidden_def(cairo_stroke_preserve);
2275
2276 /**
2277  * cairo_fill:
2278  * @cr: a cairo context
2279  *
2280  * A drawing operator that fills the current path according to the
2281  * current fill rule, (each sub-path is implicitly closed before being
2282  * filled). After cairo_fill(), the current path will be cleared from
2283  * the cairo context. See cairo_set_fill_rule() and
2284  * cairo_fill_preserve().
2285  *
2286  * Since: 1.0
2287  **/
2288 void
2289 cairo_fill (cairo_t *cr)
2290 {
2291     CAIRO_TRACE_BEGIN (__func__);
2292     cairo_status_t status;
2293
2294     if (unlikely (cr->status)) {
2295         CAIRO_TRACE_END (__func__);
2296         return;
2297     }
2298
2299     status = cr->backend->fill (cr);
2300     if (unlikely (status))
2301         _cairo_set_error (cr, status);
2302     CAIRO_TRACE_END (__func__);
2303 }
2304
2305 /**
2306  * cairo_fill_preserve:
2307  * @cr: a cairo context
2308  *
2309  * A drawing operator that fills the current path according to the
2310  * current fill rule, (each sub-path is implicitly closed before being
2311  * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the
2312  * path within the cairo context.
2313  *
2314  * See cairo_set_fill_rule() and cairo_fill().
2315  *
2316  * Since: 1.0
2317  **/
2318 void
2319 cairo_fill_preserve (cairo_t *cr)
2320 {
2321     CAIRO_TRACE_BEGIN (__func__);
2322     cairo_status_t status;
2323
2324     if (unlikely (cr->status)) {
2325         CAIRO_TRACE_END (__func__);
2326         return;
2327     }
2328
2329     status = cr->backend->fill_preserve (cr);
2330     if (unlikely (status))
2331         _cairo_set_error (cr, status);
2332     CAIRO_TRACE_END (__func__);
2333 }
2334 slim_hidden_def(cairo_fill_preserve);
2335
2336 /**
2337  * cairo_copy_page:
2338  * @cr: a cairo context
2339  *
2340  * Emits the current page for backends that support multiple pages, but
2341  * doesn't clear it, so, the contents of the current page will be retained
2342  * for the next page too.  Use cairo_show_page() if you want to get an
2343  * empty page after the emission.
2344  *
2345  * This is a convenience function that simply calls
2346  * cairo_surface_copy_page() on @cr's target.
2347  *
2348  * Since: 1.0
2349  **/
2350 void
2351 cairo_copy_page (cairo_t *cr)
2352 {
2353     cairo_status_t status;
2354
2355     if (unlikely (cr->status))
2356         return;
2357
2358     status = cr->backend->copy_page (cr);
2359     if (unlikely (status))
2360         _cairo_set_error (cr, status);
2361 }
2362
2363 /**
2364  * cairo_show_page:
2365  * @cr: a cairo context
2366  *
2367  * Emits and clears the current page for backends that support multiple
2368  * pages.  Use cairo_copy_page() if you don't want to clear the page.
2369  *
2370  * This is a convenience function that simply calls
2371  * cairo_surface_show_page() on @cr's target.
2372  *
2373  * Since: 1.0
2374  **/
2375 void
2376 cairo_show_page (cairo_t *cr)
2377 {
2378     cairo_status_t status;
2379
2380     if (unlikely (cr->status))
2381         return;
2382
2383     status = cr->backend->show_page (cr);
2384     if (unlikely (status))
2385         _cairo_set_error (cr, status);
2386 }
2387
2388 /**
2389  * cairo_in_stroke:
2390  * @cr: a cairo context
2391  * @x: X coordinate of the point to test
2392  * @y: Y coordinate of the point to test
2393  *
2394  * Tests whether the given point is inside the area that would be
2395  * affected by a cairo_stroke() operation given the current path and
2396  * stroking parameters. Surface dimensions and clipping are not taken
2397  * into account.
2398  *
2399  * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(),
2400  * cairo_set_line_cap(), cairo_set_dash(), and
2401  * cairo_stroke_preserve().
2402  *
2403  * Return value: A non-zero value if the point is inside, or zero if
2404  * outside.
2405  *
2406  * Since: 1.0
2407  **/
2408 cairo_bool_t
2409 cairo_in_stroke (cairo_t *cr, double x, double y)
2410 {
2411     cairo_status_t status;
2412     cairo_bool_t inside = FALSE;
2413
2414     if (unlikely (cr->status))
2415         return FALSE;
2416
2417     status = cr->backend->in_stroke (cr, x, y, &inside);
2418     if (unlikely (status))
2419         _cairo_set_error (cr, status);
2420
2421     return inside;
2422 }
2423
2424 /**
2425  * cairo_in_fill:
2426  * @cr: a cairo context
2427  * @x: X coordinate of the point to test
2428  * @y: Y coordinate of the point to test
2429  *
2430  * Tests whether the given point is inside the area that would be
2431  * affected by a cairo_fill() operation given the current path and
2432  * filling parameters. Surface dimensions and clipping are not taken
2433  * into account.
2434  *
2435  * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
2436  *
2437  * Return value: A non-zero value if the point is inside, or zero if
2438  * outside.
2439  *
2440  * Since: 1.0
2441  **/
2442 cairo_bool_t
2443 cairo_in_fill (cairo_t *cr, double x, double y)
2444 {
2445     cairo_status_t status;
2446     cairo_bool_t inside = FALSE;
2447
2448     if (unlikely (cr->status))
2449         return FALSE;
2450
2451     status = cr->backend->in_fill (cr, x, y, &inside);
2452     if (unlikely (status))
2453         _cairo_set_error (cr, status);
2454
2455     return inside;
2456 }
2457
2458 /**
2459  * cairo_stroke_extents:
2460  * @cr: a cairo context
2461  * @x1: left of the resulting extents
2462  * @y1: top of the resulting extents
2463  * @x2: right of the resulting extents
2464  * @y2: bottom of the resulting extents
2465  *
2466  * Computes a bounding box in user coordinates covering the area that
2467  * would be affected, (the "inked" area), by a cairo_stroke()
2468  * operation given the current path and stroke parameters.
2469  * If the current path is empty, returns an empty rectangle ((0,0), (0,0)).
2470  * Surface dimensions and clipping are not taken into account.
2471  *
2472  * Note that if the line width is set to exactly zero, then
2473  * cairo_stroke_extents() will return an empty rectangle. Contrast with
2474  * cairo_path_extents() which can be used to compute the non-empty
2475  * bounds as the line width approaches zero.
2476  *
2477  * Note that cairo_stroke_extents() must necessarily do more work to
2478  * compute the precise inked areas in light of the stroke parameters,
2479  * so cairo_path_extents() may be more desirable for sake of
2480  * performance if non-inked path extents are desired.
2481  *
2482  * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(),
2483  * cairo_set_line_cap(), cairo_set_dash(), and
2484  * cairo_stroke_preserve().
2485  *
2486  * Since: 1.0
2487  **/
2488 void
2489 cairo_stroke_extents (cairo_t *cr,
2490                       double *x1, double *y1, double *x2, double *y2)
2491 {
2492     CAIRO_TRACE_BEGIN (__func__);
2493     cairo_status_t status;
2494
2495     if (unlikely (cr->status)) {
2496         if (x1)
2497             *x1 = 0.0;
2498         if (y1)
2499             *y1 = 0.0;
2500         if (x2)
2501             *x2 = 0.0;
2502         if (y2)
2503             *y2 = 0.0;
2504
2505         CAIRO_TRACE_END (__func__);
2506         return;
2507     }
2508
2509     status = cr->backend->stroke_extents (cr, x1, y1, x2, y2);
2510     if (unlikely (status))
2511         _cairo_set_error (cr, status);
2512     CAIRO_TRACE_END (__func__);
2513 }
2514
2515 /**
2516  * cairo_fill_extents:
2517  * @cr: a cairo context
2518  * @x1: left of the resulting extents
2519  * @y1: top of the resulting extents
2520  * @x2: right of the resulting extents
2521  * @y2: bottom of the resulting extents
2522  *
2523  * Computes a bounding box in user coordinates covering the area that
2524  * would be affected, (the "inked" area), by a cairo_fill() operation
2525  * given the current path and fill parameters. If the current path is
2526  * empty, returns an empty rectangle ((0,0), (0,0)). Surface
2527  * dimensions and clipping are not taken into account.
2528  *
2529  * Contrast with cairo_path_extents(), which is similar, but returns
2530  * non-zero extents for some paths with no inked area, (such as a
2531  * simple line segment).
2532  *
2533  * Note that cairo_fill_extents() must necessarily do more work to
2534  * compute the precise inked areas in light of the fill rule, so
2535  * cairo_path_extents() may be more desirable for sake of performance
2536  * if the non-inked path extents are desired.
2537  *
2538  * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
2539  *
2540  * Since: 1.0
2541  **/
2542 void
2543 cairo_fill_extents (cairo_t *cr,
2544                     double *x1, double *y1, double *x2, double *y2)
2545 {
2546     CAIRO_TRACE_BEGIN (__func__);
2547     cairo_status_t status;
2548
2549     if (unlikely (cr->status)) {
2550         if (x1)
2551             *x1 = 0.0;
2552         if (y1)
2553             *y1 = 0.0;
2554         if (x2)
2555             *x2 = 0.0;
2556         if (y2)
2557             *y2 = 0.0;
2558
2559         CAIRO_TRACE_END (__func__);
2560         return;
2561     }
2562
2563     status = cr->backend->fill_extents (cr, x1, y1, x2, y2);
2564     if (unlikely (status))
2565         _cairo_set_error (cr, status);
2566     CAIRO_TRACE_END (__func__);
2567 }
2568
2569 /**
2570  * cairo_clip:
2571  * @cr: a cairo context
2572  *
2573  * Establishes a new clip region by intersecting the current clip
2574  * region with the current path as it would be filled by cairo_fill()
2575  * and according to the current fill rule (see cairo_set_fill_rule()).
2576  *
2577  * After cairo_clip(), the current path will be cleared from the cairo
2578  * context.
2579  *
2580  * The current clip region affects all drawing operations by
2581  * effectively masking out any changes to the surface that are outside
2582  * the current clip region.
2583  *
2584  * Calling cairo_clip() can only make the clip region smaller, never
2585  * larger. But the current clip is part of the graphics state, so a
2586  * temporary restriction of the clip region can be achieved by
2587  * calling cairo_clip() within a cairo_save()/cairo_restore()
2588  * pair. The only other means of increasing the size of the clip
2589  * region is cairo_reset_clip().
2590  *
2591  * Since: 1.0
2592  **/
2593 void
2594 cairo_clip (cairo_t *cr)
2595 {
2596     cairo_status_t status;
2597
2598     if (unlikely (cr->status))
2599         return;
2600
2601     status = cr->backend->clip (cr);
2602     if (unlikely (status))
2603         _cairo_set_error (cr, status);
2604 }
2605
2606 /**
2607  * cairo_clip_preserve:
2608  * @cr: a cairo context
2609  *
2610  * Establishes a new clip region by intersecting the current clip
2611  * region with the current path as it would be filled by cairo_fill()
2612  * and according to the current fill rule (see cairo_set_fill_rule()).
2613  *
2614  * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within
2615  * the cairo context.
2616  *
2617  * The current clip region affects all drawing operations by
2618  * effectively masking out any changes to the surface that are outside
2619  * the current clip region.
2620  *
2621  * Calling cairo_clip_preserve() can only make the clip region smaller, never
2622  * larger. But the current clip is part of the graphics state, so a
2623  * temporary restriction of the clip region can be achieved by
2624  * calling cairo_clip_preserve() within a cairo_save()/cairo_restore()
2625  * pair. The only other means of increasing the size of the clip
2626  * region is cairo_reset_clip().
2627  *
2628  * Since: 1.0
2629  **/
2630 void
2631 cairo_clip_preserve (cairo_t *cr)
2632 {
2633     cairo_status_t status;
2634
2635     if (unlikely (cr->status))
2636         return;
2637
2638     status = cr->backend->clip_preserve (cr);
2639     if (unlikely (status))
2640         _cairo_set_error (cr, status);
2641 }
2642 slim_hidden_def(cairo_clip_preserve);
2643
2644 /**
2645  * cairo_reset_clip:
2646  * @cr: a cairo context
2647  *
2648  * Reset the current clip region to its original, unrestricted
2649  * state. That is, set the clip region to an infinitely large shape
2650  * containing the target surface. Equivalently, if infinity is too
2651  * hard to grasp, one can imagine the clip region being reset to the
2652  * exact bounds of the target surface.
2653  *
2654  * Note that code meant to be reusable should not call
2655  * cairo_reset_clip() as it will cause results unexpected by
2656  * higher-level code which calls cairo_clip(). Consider using
2657  * cairo_save() and cairo_restore() around cairo_clip() as a more
2658  * robust means of temporarily restricting the clip region.
2659  *
2660  * Since: 1.0
2661  **/
2662 void
2663 cairo_reset_clip (cairo_t *cr)
2664 {
2665     cairo_status_t status;
2666
2667     if (unlikely (cr->status))
2668         return;
2669
2670     status = cr->backend->reset_clip (cr);
2671     if (unlikely (status))
2672         _cairo_set_error (cr, status);
2673 }
2674
2675 /**
2676  * cairo_clip_extents:
2677  * @cr: a cairo context
2678  * @x1: left of the resulting extents
2679  * @y1: top of the resulting extents
2680  * @x2: right of the resulting extents
2681  * @y2: bottom of the resulting extents
2682  *
2683  * Computes a bounding box in user coordinates covering the area inside the
2684  * current clip.
2685  *
2686  * Since: 1.4
2687  **/
2688 void
2689 cairo_clip_extents (cairo_t *cr,
2690                     double *x1, double *y1,
2691                     double *x2, double *y2)
2692 {
2693     CAIRO_TRACE_BEGIN (__func__);
2694     cairo_status_t status;
2695
2696     if (x1)
2697         *x1 = 0.0;
2698     if (y1)
2699         *y1 = 0.0;
2700     if (x2)
2701         *x2 = 0.0;
2702     if (y2)
2703         *y2 = 0.0;
2704
2705     if (unlikely (cr->status)) {
2706         CAIRO_TRACE_END (__func__);
2707         return;
2708     }
2709
2710     status = cr->backend->clip_extents (cr, x1, y1, x2, y2);
2711     if (unlikely (status))
2712         _cairo_set_error (cr, status);
2713     CAIRO_TRACE_END (__func__);
2714 }
2715
2716 /**
2717  * cairo_in_clip:
2718  * @cr: a cairo context
2719  * @x: X coordinate of the point to test
2720  * @y: Y coordinate of the point to test
2721  *
2722  * Tests whether the given point is inside the area that would be
2723  * visible through the current clip, i.e. the area that would be filled by
2724  * a cairo_paint() operation.
2725  *
2726  * See cairo_clip(), and cairo_clip_preserve().
2727  *
2728  * Return value: A non-zero value if the point is inside, or zero if
2729  * outside.
2730  *
2731  * Since: 1.10
2732  **/
2733 cairo_bool_t
2734 cairo_in_clip (cairo_t *cr, double x, double y)
2735 {
2736     cairo_status_t status;
2737     cairo_bool_t inside = FALSE;
2738
2739     if (unlikely (cr->status))
2740         return FALSE;
2741
2742     status = cr->backend->in_clip (cr, x, y, &inside);
2743     if (unlikely (status))
2744         _cairo_set_error (cr, status);
2745
2746     return inside;
2747 }
2748
2749 /**
2750  * cairo_copy_clip_rectangle_list:
2751  * @cr: a cairo context
2752  *
2753  * Gets the current clip region as a list of rectangles in user coordinates.
2754  * Never returns %NULL.
2755  *
2756  * The status in the list may be %CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to
2757  * indicate that the clip region cannot be represented as a list of
2758  * user-space rectangles. The status may have other values to indicate
2759  * other errors.
2760  *
2761  * Returns: the current clip region as a list of rectangles in user coordinates,
2762  * which should be destroyed using cairo_rectangle_list_destroy().
2763  *
2764  * Since: 1.4
2765  **/
2766 cairo_rectangle_list_t *
2767 cairo_copy_clip_rectangle_list (cairo_t *cr)
2768 {
2769     if (unlikely (cr->status))
2770         return _cairo_rectangle_list_create_in_error (cr->status);
2771
2772     return cr->backend->clip_copy_rectangle_list (cr);
2773 }
2774
2775 /**
2776  * cairo_select_font_face:
2777  * @cr: a #cairo_t
2778  * @family: a font family name, encoded in UTF-8
2779  * @slant: the slant for the font
2780  * @weight: the weight for the font
2781  *
2782  * Note: The cairo_select_font_face() function call is part of what
2783  * the cairo designers call the "toy" text API. It is convenient for
2784  * short demos and simple programs, but it is not expected to be
2785  * adequate for serious text-using applications.
2786  *
2787  * Selects a family and style of font from a simplified description as
2788  * a family name, slant and weight. Cairo provides no operation to
2789  * list available family names on the system (this is a "toy",
2790  * remember), but the standard CSS2 generic family names, ("serif",
2791  * "sans-serif", "cursive", "fantasy", "monospace"), are likely to
2792  * work as expected.
2793  *
2794  * If @family starts with the string "@cairo:", or if no native font
2795  * backends are compiled in, cairo will use an internal font family.
2796  * The internal font family recognizes many modifiers in the @family
2797  * string, most notably, it recognizes the string "monospace".  That is,
2798  * the family name "@cairo:monospace" will use the monospace version of
2799  * the internal font family.
2800  *
2801  * For "real" font selection, see the font-backend-specific
2802  * font_face_create functions for the font backend you are using. (For
2803  * example, if you are using the freetype-based cairo-ft font backend,
2804  * see cairo_ft_font_face_create_for_ft_face() or
2805  * cairo_ft_font_face_create_for_pattern().) The resulting font face
2806  * could then be used with cairo_scaled_font_create() and
2807  * cairo_set_scaled_font().
2808  *
2809  * Similarly, when using the "real" font support, you can call
2810  * directly into the underlying font system, (such as fontconfig or
2811  * freetype), for operations such as listing available fonts, etc.
2812  *
2813  * It is expected that most applications will need to use a more
2814  * comprehensive font handling and text layout library, (for example,
2815  * pango), in conjunction with cairo.
2816  *
2817  * If text is drawn without a call to cairo_select_font_face(), (nor
2818  * cairo_set_font_face() nor cairo_set_scaled_font()), the default
2819  * family is platform-specific, but is essentially "sans-serif".
2820  * Default slant is %CAIRO_FONT_SLANT_NORMAL, and default weight is
2821  * %CAIRO_FONT_WEIGHT_NORMAL.
2822  *
2823  * This function is equivalent to a call to cairo_toy_font_face_create()
2824  * followed by cairo_set_font_face().
2825  *
2826  * Since: 1.0
2827  **/
2828 void
2829 cairo_select_font_face (cairo_t              *cr,
2830                         const char           *family,
2831                         cairo_font_slant_t    slant,
2832                         cairo_font_weight_t   weight)
2833 {
2834     cairo_font_face_t *font_face;
2835     cairo_status_t status;
2836
2837     if (unlikely (cr->status))
2838         return;
2839
2840     font_face = cairo_toy_font_face_create (family, slant, weight);
2841     if (unlikely (font_face->status)) {
2842         _cairo_set_error (cr, font_face->status);
2843         return;
2844     }
2845
2846     status = cr->backend->set_font_face (cr, font_face);
2847     cairo_font_face_destroy (font_face);
2848
2849     if (unlikely (status))
2850         _cairo_set_error (cr, status);
2851 }
2852
2853 /**
2854  * cairo_font_extents:
2855  * @cr: a #cairo_t
2856  * @extents: a #cairo_font_extents_t object into which the results
2857  * will be stored.
2858  *
2859  * Gets the font extents for the currently selected font.
2860  *
2861  * Since: 1.0
2862  **/
2863 void
2864 cairo_font_extents (cairo_t              *cr,
2865                     cairo_font_extents_t *extents)
2866 {
2867     cairo_status_t status;
2868
2869     extents->ascent = 0.0;
2870     extents->descent = 0.0;
2871     extents->height = 0.0;
2872     extents->max_x_advance = 0.0;
2873     extents->max_y_advance = 0.0;
2874
2875     if (unlikely (cr->status))
2876         return;
2877
2878     status = cr->backend->font_extents (cr, extents);
2879     if (unlikely (status))
2880         _cairo_set_error (cr, status);
2881 }
2882
2883 /**
2884  * cairo_set_font_face:
2885  * @cr: a #cairo_t
2886  * @font_face: a #cairo_font_face_t, or %NULL to restore to the default font
2887  *
2888  * Replaces the current #cairo_font_face_t object in the #cairo_t with
2889  * @font_face. The replaced font face in the #cairo_t will be
2890  * destroyed if there are no other references to it.
2891  *
2892  * Since: 1.0
2893  **/
2894 void
2895 cairo_set_font_face (cairo_t           *cr,
2896                      cairo_font_face_t *font_face)
2897 {
2898     cairo_status_t status;
2899
2900     if (unlikely (cr->status))
2901         return;
2902
2903     status = cr->backend->set_font_face (cr, font_face);
2904     if (unlikely (status))
2905         _cairo_set_error (cr, status);
2906 }
2907
2908 /**
2909  * cairo_get_font_face:
2910  * @cr: a #cairo_t
2911  *
2912  * Gets the current font face for a #cairo_t.
2913  *
2914  * Return value: the current font face.  This object is owned by
2915  * cairo. To keep a reference to it, you must call
2916  * cairo_font_face_reference().
2917  *
2918  * This function never returns %NULL. If memory cannot be allocated, a
2919  * special "nil" #cairo_font_face_t object will be returned on which
2920  * cairo_font_face_status() returns %CAIRO_STATUS_NO_MEMORY. Using
2921  * this nil object will cause its error state to propagate to other
2922  * objects it is passed to, (for example, calling
2923  * cairo_set_font_face() with a nil font will trigger an error that
2924  * will shutdown the #cairo_t object).
2925  *
2926  * Since: 1.0
2927  **/
2928 cairo_font_face_t *
2929 cairo_get_font_face (cairo_t *cr)
2930 {
2931     if (unlikely (cr->status))
2932         return (cairo_font_face_t*) &_cairo_font_face_nil;
2933
2934     return cr->backend->get_font_face (cr);
2935 }
2936
2937 /**
2938  * cairo_set_font_size:
2939  * @cr: a #cairo_t
2940  * @size: the new font size, in user space units
2941  *
2942  * Sets the current font matrix to a scale by a factor of @size, replacing
2943  * any font matrix previously set with cairo_set_font_size() or
2944  * cairo_set_font_matrix(). This results in a font size of @size user space
2945  * units. (More precisely, this matrix will result in the font's
2946  * em-square being a @size by @size square in user space.)
2947  *
2948  * If text is drawn without a call to cairo_set_font_size(), (nor
2949  * cairo_set_font_matrix() nor cairo_set_scaled_font()), the default
2950  * font size is 10.0.
2951  *
2952  * Since: 1.0
2953  **/
2954 void
2955 cairo_set_font_size (cairo_t *cr, double size)
2956 {
2957     cairo_status_t status;
2958
2959     if (unlikely (cr->status))
2960         return;
2961
2962     status = cr->backend->set_font_size (cr, size);
2963     if (unlikely (status))
2964         _cairo_set_error (cr, status);
2965 }
2966 slim_hidden_def (cairo_set_font_size);
2967
2968 /**
2969  * cairo_set_font_matrix:
2970  * @cr: a #cairo_t
2971  * @matrix: a #cairo_matrix_t describing a transform to be applied to
2972  * the current font.
2973  *
2974  * Sets the current font matrix to @matrix. The font matrix gives a
2975  * transformation from the design space of the font (in this space,
2976  * the em-square is 1 unit by 1 unit) to user space. Normally, a
2977  * simple scale is used (see cairo_set_font_size()), but a more
2978  * complex font matrix can be used to shear the font
2979  * or stretch it unequally along the two axes
2980  *
2981  * Since: 1.0
2982  **/
2983 void
2984 cairo_set_font_matrix (cairo_t              *cr,
2985                        const cairo_matrix_t *matrix)
2986 {
2987     cairo_status_t status;
2988
2989     if (unlikely (cr->status))
2990         return;
2991
2992     status = cr->backend->set_font_matrix (cr, matrix);
2993     if (unlikely (status))
2994         _cairo_set_error (cr, status);
2995 }
2996 slim_hidden_def (cairo_set_font_matrix);
2997
2998 /**
2999  * cairo_get_font_matrix:
3000  * @cr: a #cairo_t
3001  * @matrix: return value for the matrix
3002  *
3003  * Stores the current font matrix into @matrix. See
3004  * cairo_set_font_matrix().
3005  *
3006  * Since: 1.0
3007  **/
3008 void
3009 cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix)
3010 {
3011     if (unlikely (cr->status)) {
3012         cairo_matrix_init_identity (matrix);
3013         return;
3014     }
3015
3016     cr->backend->get_font_matrix (cr, matrix);
3017 }
3018
3019 /**
3020  * cairo_set_font_options:
3021  * @cr: a #cairo_t
3022  * @options: font options to use
3023  *
3024  * Sets a set of custom font rendering options for the #cairo_t.
3025  * Rendering options are derived by merging these options with the
3026  * options derived from underlying surface; if the value in @options
3027  * has a default value (like %CAIRO_ANTIALIAS_DEFAULT), then the value
3028  * from the surface is used.
3029  *
3030  * Since: 1.0
3031  **/
3032 void
3033 cairo_set_font_options (cairo_t                    *cr,
3034                         const cairo_font_options_t *options)
3035 {
3036     cairo_status_t status;
3037
3038     if (unlikely (cr->status))
3039         return;
3040
3041     status = cairo_font_options_status ((cairo_font_options_t *) options);
3042     if (unlikely (status)) {
3043         _cairo_set_error (cr, status);
3044         return;
3045     }
3046
3047     status = cr->backend->set_font_options (cr, options);
3048     if (unlikely (status))
3049         _cairo_set_error (cr, status);
3050 }
3051 slim_hidden_def (cairo_set_font_options);
3052
3053 /**
3054  * cairo_get_font_options:
3055  * @cr: a #cairo_t
3056  * @options: a #cairo_font_options_t object into which to store
3057  *   the retrieved options. All existing values are overwritten
3058  *
3059  * Retrieves font rendering options set via #cairo_set_font_options.
3060  * Note that the returned options do not include any options derived
3061  * from the underlying surface; they are literally the options
3062  * passed to cairo_set_font_options().
3063  *
3064  * Since: 1.0
3065  **/
3066 void
3067 cairo_get_font_options (cairo_t              *cr,
3068                         cairo_font_options_t *options)
3069 {
3070     /* check that we aren't trying to overwrite the nil object */
3071     if (cairo_font_options_status (options))
3072         return;
3073
3074     if (unlikely (cr->status)) {
3075         _cairo_font_options_init_default (options);
3076         return;
3077     }
3078
3079     cr->backend->get_font_options (cr, options);
3080 }
3081
3082 /**
3083  * cairo_set_scaled_font:
3084  * @cr: a #cairo_t
3085  * @scaled_font: a #cairo_scaled_font_t
3086  *
3087  * Replaces the current font face, font matrix, and font options in
3088  * the #cairo_t with those of the #cairo_scaled_font_t.  Except for
3089  * some translation, the current CTM of the #cairo_t should be the
3090  * same as that of the #cairo_scaled_font_t, which can be accessed
3091  * using cairo_scaled_font_get_ctm().
3092  *
3093  * Since: 1.2
3094  **/
3095 void
3096 cairo_set_scaled_font (cairo_t                   *cr,
3097                        const cairo_scaled_font_t *scaled_font)
3098 {
3099     cairo_status_t status;
3100
3101     if (unlikely (cr->status))
3102         return;
3103
3104     if ((scaled_font == NULL)) {
3105         _cairo_set_error (cr, _cairo_error (CAIRO_STATUS_NULL_POINTER));
3106         return;
3107     }
3108
3109     status = scaled_font->status;
3110     if (unlikely (status)) {
3111         _cairo_set_error (cr, status);
3112         return;
3113     }
3114
3115     status = cr->backend->set_scaled_font (cr, (cairo_scaled_font_t *) scaled_font);
3116     if (unlikely (status))
3117         _cairo_set_error (cr, status);
3118 }
3119
3120 /**
3121  * cairo_get_scaled_font:
3122  * @cr: a #cairo_t
3123  *
3124  * Gets the current scaled font for a #cairo_t.
3125  *
3126  * Return value: the current scaled font. This object is owned by
3127  * cairo. To keep a reference to it, you must call
3128  * cairo_scaled_font_reference().
3129  *
3130  * This function never returns %NULL. If memory cannot be allocated, a
3131  * special "nil" #cairo_scaled_font_t object will be returned on which
3132  * cairo_scaled_font_status() returns %CAIRO_STATUS_NO_MEMORY. Using
3133  * this nil object will cause its error state to propagate to other
3134  * objects it is passed to, (for example, calling
3135  * cairo_set_scaled_font() with a nil font will trigger an error that
3136  * will shutdown the #cairo_t object).
3137  *
3138  * Since: 1.4
3139  **/
3140 cairo_scaled_font_t *
3141 cairo_get_scaled_font (cairo_t *cr)
3142 {
3143     if (unlikely (cr->status))
3144         return _cairo_scaled_font_create_in_error (cr->status);
3145
3146     return cr->backend->get_scaled_font (cr);
3147 }
3148 slim_hidden_def (cairo_get_scaled_font);
3149
3150 /**
3151  * cairo_text_extents:
3152  * @cr: a #cairo_t
3153  * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3154  * @extents: a #cairo_text_extents_t object into which the results
3155  * will be stored
3156  *
3157  * Gets the extents for a string of text. The extents describe a
3158  * user-space rectangle that encloses the "inked" portion of the text,
3159  * (as it would be drawn by cairo_show_text()). Additionally, the
3160  * x_advance and y_advance values indicate the amount by which the
3161  * current point would be advanced by cairo_show_text().
3162  *
3163  * Note that whitespace characters do not directly contribute to the
3164  * size of the rectangle (extents.width and extents.height). They do
3165  * contribute indirectly by changing the position of non-whitespace
3166  * characters. In particular, trailing whitespace characters are
3167  * likely to not affect the size of the rectangle, though they will
3168  * affect the x_advance and y_advance values.
3169  *
3170  * Since: 1.0
3171  **/
3172 void
3173 cairo_text_extents (cairo_t              *cr,
3174                     const char           *utf8,
3175                     cairo_text_extents_t *extents)
3176 {
3177     cairo_status_t status;
3178     cairo_scaled_font_t *scaled_font;
3179     cairo_glyph_t *glyphs = NULL;
3180     int num_glyphs = 0;
3181     double x, y;
3182
3183     extents->x_bearing = 0.0;
3184     extents->y_bearing = 0.0;
3185     extents->width  = 0.0;
3186     extents->height = 0.0;
3187     extents->x_advance = 0.0;
3188     extents->y_advance = 0.0;
3189
3190     if (unlikely (cr->status))
3191         return;
3192
3193     if (utf8 == NULL)
3194         return;
3195
3196     scaled_font = cairo_get_scaled_font (cr);
3197     if (unlikely (scaled_font->status)) {
3198         _cairo_set_error (cr, scaled_font->status);
3199         return;
3200     }
3201
3202     cairo_get_current_point (cr, &x, &y);
3203     status = cairo_scaled_font_text_to_glyphs (scaled_font,
3204                                                x, y,
3205                                                utf8, -1,
3206                                                &glyphs, &num_glyphs,
3207                                                NULL, NULL, NULL);
3208
3209     if (likely (status == CAIRO_STATUS_SUCCESS)) {
3210         status = cr->backend->glyph_extents (cr,
3211                                              glyphs, num_glyphs,
3212                                              extents);
3213     }
3214     cairo_glyph_free (glyphs);
3215
3216     if (unlikely (status))
3217         _cairo_set_error (cr, status);
3218 }
3219
3220 /**
3221  * cairo_glyph_extents:
3222  * @cr: a #cairo_t
3223  * @glyphs: an array of #cairo_glyph_t objects
3224  * @num_glyphs: the number of elements in @glyphs
3225  * @extents: a #cairo_text_extents_t object into which the results
3226  * will be stored
3227  *
3228  * Gets the extents for an array of glyphs. The extents describe a
3229  * user-space rectangle that encloses the "inked" portion of the
3230  * glyphs, (as they would be drawn by cairo_show_glyphs()).
3231  * Additionally, the x_advance and y_advance values indicate the
3232  * amount by which the current point would be advanced by
3233  * cairo_show_glyphs().
3234  *
3235  * Note that whitespace glyphs do not contribute to the size of the
3236  * rectangle (extents.width and extents.height).
3237  *
3238  * Since: 1.0
3239  **/
3240 void
3241 cairo_glyph_extents (cairo_t                *cr,
3242                      const cairo_glyph_t    *glyphs,
3243                      int                    num_glyphs,
3244                      cairo_text_extents_t   *extents)
3245 {
3246     cairo_status_t status;
3247
3248     extents->x_bearing = 0.0;
3249     extents->y_bearing = 0.0;
3250     extents->width  = 0.0;
3251     extents->height = 0.0;
3252     extents->x_advance = 0.0;
3253     extents->y_advance = 0.0;
3254
3255     if (unlikely (cr->status))
3256         return;
3257
3258     if (num_glyphs == 0)
3259         return;
3260
3261     if (unlikely (num_glyphs < 0)) {
3262         _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3263         return;
3264     }
3265
3266     if (unlikely (glyphs == NULL)) {
3267         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3268         return;
3269     }
3270
3271     status = cr->backend->glyph_extents (cr, glyphs, num_glyphs, extents);
3272     if (unlikely (status))
3273         _cairo_set_error (cr, status);
3274 }
3275
3276 /**
3277  * cairo_show_text:
3278  * @cr: a cairo context
3279  * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3280  *
3281  * A drawing operator that generates the shape from a string of UTF-8
3282  * characters, rendered according to the current font_face, font_size
3283  * (font_matrix), and font_options.
3284  *
3285  * This function first computes a set of glyphs for the string of
3286  * text. The first glyph is placed so that its origin is at the
3287  * current point. The origin of each subsequent glyph is offset from
3288  * that of the previous glyph by the advance values of the previous
3289  * glyph.
3290  *
3291  * After this call the current point is moved to the origin of where
3292  * the next glyph would be placed in this same progression. That is,
3293  * the current point will be at the origin of the final glyph offset
3294  * by its advance values. This allows for easy display of a single
3295  * logical string with multiple calls to cairo_show_text().
3296  *
3297  * Note: The cairo_show_text() function call is part of what the cairo
3298  * designers call the "toy" text API. It is convenient for short demos
3299  * and simple programs, but it is not expected to be adequate for
3300  * serious text-using applications. See cairo_show_glyphs() for the
3301  * "real" text display API in cairo.
3302  *
3303  * Since: 1.0
3304  **/
3305 void
3306 cairo_show_text (cairo_t *cr, const char *utf8)
3307 {
3308     CAIRO_TRACE_BEGIN (__func__);
3309     cairo_text_extents_t extents;
3310     cairo_status_t status;
3311     cairo_glyph_t *glyphs, *last_glyph;
3312     cairo_text_cluster_t *clusters;
3313     int utf8_len, num_glyphs, num_clusters;
3314     cairo_text_cluster_flags_t cluster_flags;
3315     double x, y;
3316     cairo_bool_t has_show_text_glyphs;
3317     cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
3318     cairo_text_cluster_t stack_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)];
3319     cairo_scaled_font_t *scaled_font;
3320     cairo_glyph_text_info_t info, *i;
3321
3322     if (unlikely (cr->status)) {
3323         CAIRO_TRACE_END (__func__);
3324         return;
3325     }
3326
3327     if (utf8 == NULL) {
3328         CAIRO_TRACE_END (__func__);
3329         return;
3330     }
3331
3332     scaled_font = cairo_get_scaled_font (cr);
3333     if (unlikely (scaled_font->status)) {
3334         _cairo_set_error (cr, scaled_font->status);
3335         CAIRO_TRACE_END (__func__);
3336         return;
3337     }
3338
3339     utf8_len = strlen (utf8);
3340
3341     has_show_text_glyphs =
3342         cairo_surface_has_show_text_glyphs (cairo_get_target (cr));
3343
3344     glyphs = stack_glyphs;
3345     num_glyphs = ARRAY_LENGTH (stack_glyphs);
3346
3347     if (has_show_text_glyphs) {
3348         clusters = stack_clusters;
3349         num_clusters = ARRAY_LENGTH (stack_clusters);
3350     } else {
3351         clusters = NULL;
3352         num_clusters = 0;
3353     }
3354
3355     cairo_get_current_point (cr, &x, &y);
3356     status = cairo_scaled_font_text_to_glyphs (scaled_font,
3357                                                x, y,
3358                                                utf8, utf8_len,
3359                                                &glyphs, &num_glyphs,
3360                                                has_show_text_glyphs ? &clusters : NULL, &num_clusters,
3361                                                &cluster_flags);
3362     if (unlikely (status))
3363         goto BAIL;
3364
3365     if (num_glyphs == 0) {
3366         CAIRO_TRACE_END (__func__);
3367         return;
3368     }
3369
3370     i = NULL;
3371     if (has_show_text_glyphs) {
3372         info.utf8 = utf8;
3373         info.utf8_len = utf8_len;
3374         info.clusters = clusters;
3375         info.num_clusters = num_clusters;
3376         info.cluster_flags = cluster_flags;
3377         i = &info;
3378     }
3379
3380     status = cr->backend->glyphs (cr, glyphs, num_glyphs, i);
3381     if (unlikely (status))
3382         goto BAIL;
3383
3384     last_glyph = &glyphs[num_glyphs - 1];
3385     status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents);
3386     if (unlikely (status))
3387         goto BAIL;
3388
3389     x = last_glyph->x + extents.x_advance;
3390     y = last_glyph->y + extents.y_advance;
3391     cr->backend->move_to (cr, x, y);
3392
3393  BAIL:
3394     if (glyphs != stack_glyphs)
3395         cairo_glyph_free (glyphs);
3396     if (clusters != stack_clusters)
3397         cairo_text_cluster_free (clusters);
3398
3399     if (unlikely (status))
3400         _cairo_set_error (cr, status);
3401     CAIRO_TRACE_END (__func__);
3402 }
3403
3404 /**
3405  * cairo_show_glyphs:
3406  * @cr: a cairo context
3407  * @glyphs: array of glyphs to show
3408  * @num_glyphs: number of glyphs to show
3409  *
3410  * A drawing operator that generates the shape from an array of glyphs,
3411  * rendered according to the current font face, font size
3412  * (font matrix), and font options.
3413  *
3414  * Since: 1.0
3415  **/
3416 void
3417 cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
3418 {
3419     CAIRO_TRACE_BEGIN (__func__);
3420     cairo_status_t status;
3421
3422     if (unlikely (cr->status)) {
3423         CAIRO_TRACE_END (__func__);
3424         return;
3425     }
3426
3427     if (num_glyphs == 0) {
3428         CAIRO_TRACE_END (__func__);
3429         return;
3430     }
3431
3432     if (num_glyphs < 0) {
3433         _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3434         CAIRO_TRACE_END (__func__);
3435         return;
3436     }
3437
3438     if (glyphs == NULL) {
3439         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3440         CAIRO_TRACE_END (__func__);
3441         return;
3442     }
3443
3444     status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL);
3445     if (unlikely (status))
3446         _cairo_set_error (cr, status);
3447     CAIRO_TRACE_END (__func__);
3448 }
3449
3450 /**
3451  * cairo_show_text_glyphs:
3452  * @cr: a cairo context
3453  * @utf8: a string of text encoded in UTF-8
3454  * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated
3455  * @glyphs: array of glyphs to show
3456  * @num_glyphs: number of glyphs to show
3457  * @clusters: array of cluster mapping information
3458  * @num_clusters: number of clusters in the mapping
3459  * @cluster_flags: cluster mapping flags
3460  *
3461  * This operation has rendering effects similar to cairo_show_glyphs()
3462  * but, if the target surface supports it, uses the provided text and
3463  * cluster mapping to embed the text for the glyphs shown in the output.
3464  * If the target does not support the extended attributes, this function
3465  * acts like the basic cairo_show_glyphs() as if it had been passed
3466  * @glyphs and @num_glyphs.
3467  *
3468  * The mapping between @utf8 and @glyphs is provided by an array of
3469  * <firstterm>clusters</firstterm>.  Each cluster covers a number of
3470  * text bytes and glyphs, and neighboring clusters cover neighboring
3471  * areas of @utf8 and @glyphs.  The clusters should collectively cover @utf8
3472  * and @glyphs in entirety.
3473  *
3474  * The first cluster always covers bytes from the beginning of @utf8.
3475  * If @cluster_flags do not have the %CAIRO_TEXT_CLUSTER_FLAG_BACKWARD
3476  * set, the first cluster also covers the beginning
3477  * of @glyphs, otherwise it covers the end of the @glyphs array and
3478  * following clusters move backward.
3479  *
3480  * See #cairo_text_cluster_t for constraints on valid clusters.
3481  *
3482  * Since: 1.8
3483  **/
3484 void
3485 cairo_show_text_glyphs (cairo_t                    *cr,
3486                         const char                 *utf8,
3487                         int                         utf8_len,
3488                         const cairo_glyph_t        *glyphs,
3489                         int                         num_glyphs,
3490                         const cairo_text_cluster_t *clusters,
3491                         int                         num_clusters,
3492                         cairo_text_cluster_flags_t  cluster_flags)
3493 {
3494     CAIRO_TRACE_BEGIN (__func__);
3495     cairo_status_t status;
3496
3497     if (unlikely (cr->status)) {
3498         CAIRO_TRACE_END (__func__);
3499         return;
3500     }
3501
3502     /* A slew of sanity checks */
3503
3504     /* Special case for NULL and -1 */
3505     if (utf8 == NULL && utf8_len == -1)
3506         utf8_len = 0;
3507
3508     /* No NULLs for non-zeros */
3509     if ((num_glyphs   && glyphs   == NULL) ||
3510         (utf8_len     && utf8     == NULL) ||
3511         (num_clusters && clusters == NULL)) {
3512         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3513         CAIRO_TRACE_END (__func__);
3514         return;
3515     }
3516
3517     /* A -1 for utf8_len means NUL-terminated */
3518     if (utf8_len == -1)
3519         utf8_len = strlen (utf8);
3520
3521     /* Apart from that, no negatives */
3522     if (num_glyphs < 0 || utf8_len < 0 || num_clusters < 0) {
3523         _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3524         CAIRO_TRACE_END (__func__);
3525         return;
3526     }
3527
3528     if (num_glyphs == 0 && utf8_len == 0) {
3529         CAIRO_TRACE_END (__func__);
3530         return;
3531     }
3532
3533     if (utf8) {
3534         /* Make sure clusters cover the entire glyphs and utf8 arrays,
3535          * and that cluster boundaries are UTF-8 boundaries. */
3536         status = _cairo_validate_text_clusters (utf8, utf8_len,
3537                                                 glyphs, num_glyphs,
3538                                                 clusters, num_clusters, cluster_flags);
3539         if (status == CAIRO_STATUS_INVALID_CLUSTERS) {
3540             /* Either got invalid UTF-8 text, or cluster mapping is bad.
3541              * Differentiate those. */
3542
3543             cairo_status_t status2;
3544
3545             status2 = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL);
3546             if (status2)
3547                 status = status2;
3548         } else {
3549             cairo_glyph_text_info_t info;
3550
3551             info.utf8 = utf8;
3552             info.utf8_len = utf8_len;
3553             info.clusters = clusters;
3554             info.num_clusters = num_clusters;
3555             info.cluster_flags = cluster_flags;
3556
3557             status = cr->backend->glyphs (cr, glyphs, num_glyphs, &info);
3558         }
3559     } else {
3560         status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL);
3561     }
3562     if (unlikely (status))
3563         _cairo_set_error (cr, status);
3564     CAIRO_TRACE_END (__func__);
3565 }
3566
3567 /**
3568  * cairo_text_path:
3569  * @cr: a cairo context
3570  * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3571  *
3572  * Adds closed paths for text to the current path.  The generated
3573  * path if filled, achieves an effect similar to that of
3574  * cairo_show_text().
3575  *
3576  * Text conversion and positioning is done similar to cairo_show_text().
3577  *
3578  * Like cairo_show_text(), After this call the current point is
3579  * moved to the origin of where the next glyph would be placed in
3580  * this same progression.  That is, the current point will be at
3581  * the origin of the final glyph offset by its advance values.
3582  * This allows for chaining multiple calls to to cairo_text_path()
3583  * without having to set current point in between.
3584  *
3585  * Note: The cairo_text_path() function call is part of what the cairo
3586  * designers call the "toy" text API. It is convenient for short demos
3587  * and simple programs, but it is not expected to be adequate for
3588  * serious text-using applications. See cairo_glyph_path() for the
3589  * "real" text path API in cairo.
3590  *
3591  * Since: 1.0
3592  **/
3593 void
3594 cairo_text_path (cairo_t *cr, const char *utf8)
3595 {
3596     CAIRO_TRACE_BEGIN (__func__);
3597     cairo_status_t status;
3598     cairo_text_extents_t extents;
3599     cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
3600     cairo_glyph_t *glyphs, *last_glyph;
3601     cairo_scaled_font_t *scaled_font;
3602     int num_glyphs;
3603     double x, y;
3604
3605     if (unlikely (cr->status)) {
3606         CAIRO_TRACE_END (__func__);
3607         return;
3608     }
3609
3610     if (utf8 == NULL) {
3611         CAIRO_TRACE_END (__func__);
3612         return;
3613     }
3614
3615
3616     glyphs = stack_glyphs;
3617     num_glyphs = ARRAY_LENGTH (stack_glyphs);
3618
3619     scaled_font = cairo_get_scaled_font (cr);
3620     if (unlikely (scaled_font->status)) {
3621         _cairo_set_error (cr, scaled_font->status);
3622         CAIRO_TRACE_END (__func__);
3623         return;
3624     }
3625
3626     cairo_get_current_point (cr, &x, &y);
3627     status = cairo_scaled_font_text_to_glyphs (scaled_font,
3628                                                x, y,
3629                                                utf8, -1,
3630                                                &glyphs, &num_glyphs,
3631                                                NULL, NULL, NULL);
3632
3633     if (num_glyphs == 0) {
3634         CAIRO_TRACE_END (__func__);
3635         return;
3636     }
3637
3638     status = cr->backend->glyph_path (cr, glyphs, num_glyphs);
3639
3640     if (unlikely (status))
3641         goto BAIL;
3642
3643     last_glyph = &glyphs[num_glyphs - 1];
3644     status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents);
3645
3646     if (unlikely (status))
3647         goto BAIL;
3648
3649     x = last_glyph->x + extents.x_advance;
3650     y = last_glyph->y + extents.y_advance;
3651     cr->backend->move_to (cr, x, y);
3652
3653  BAIL:
3654     if (glyphs != stack_glyphs)
3655         cairo_glyph_free (glyphs);
3656
3657     if (unlikely (status))
3658         _cairo_set_error (cr, status);
3659     CAIRO_TRACE_END (__func__);
3660 }
3661
3662 /**
3663  * cairo_glyph_path:
3664  * @cr: a cairo context
3665  * @glyphs: array of glyphs to show
3666  * @num_glyphs: number of glyphs to show
3667  *
3668  * Adds closed paths for the glyphs to the current path.  The generated
3669  * path if filled, achieves an effect similar to that of
3670  * cairo_show_glyphs().
3671  *
3672  * Since: 1.0
3673  **/
3674 void
3675 cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
3676 {
3677     CAIRO_TRACE_BEGIN (__func__);
3678     cairo_status_t status;
3679
3680     if (unlikely (cr->status)) {
3681         CAIRO_TRACE_END (__func__);
3682         return;
3683     }
3684
3685     if (num_glyphs == 0) {
3686         CAIRO_TRACE_END (__func__);
3687         return;
3688     }
3689
3690     if (unlikely (num_glyphs < 0)) {
3691         _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3692         CAIRO_TRACE_END (__func__);
3693         return;
3694     }
3695
3696     if (unlikely (glyphs == NULL)) {
3697         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3698         CAIRO_TRACE_END (__func__);
3699         return;
3700     }
3701
3702     status = cr->backend->glyph_path (cr, glyphs, num_glyphs);
3703     if (unlikely (status))
3704         _cairo_set_error (cr, status);
3705     CAIRO_TRACE_END (__func__);
3706 }
3707
3708 /**
3709  * cairo_get_operator:
3710  * @cr: a cairo context
3711  *
3712  * Gets the current compositing operator for a cairo context.
3713  *
3714  * Return value: the current compositing operator.
3715  *
3716  * Since: 1.0
3717  **/
3718 cairo_operator_t
3719 cairo_get_operator (cairo_t *cr)
3720 {
3721     if (unlikely (cr->status))
3722         return CAIRO_GSTATE_OPERATOR_DEFAULT;
3723
3724     return cr->backend->get_operator (cr);
3725 }
3726
3727 #if 0
3728 /**
3729  * cairo_get_opacity:
3730  * @cr: a cairo context
3731  *
3732  * Gets the current compositing opacity for a cairo context.
3733  *
3734  * Return value: the current compositing opacity.
3735  *
3736  * Since: TBD
3737  **/
3738 double
3739 cairo_get_opacity (cairo_t *cr)
3740 {
3741     if (unlikely (cr->status))
3742         return 1.;
3743
3744     return cr->backend->get_opacity (cr);
3745 }
3746 #endif
3747
3748 /**
3749  * cairo_get_tolerance:
3750  * @cr: a cairo context
3751  *
3752  * Gets the current tolerance value, as set by cairo_set_tolerance().
3753  *
3754  * Return value: the current tolerance value.
3755  *
3756  * Since: 1.0
3757  **/
3758 double
3759 cairo_get_tolerance (cairo_t *cr)
3760 {
3761     if (unlikely (cr->status))
3762         return CAIRO_GSTATE_TOLERANCE_DEFAULT;
3763
3764     return cr->backend->get_tolerance (cr);
3765 }
3766 slim_hidden_def (cairo_get_tolerance);
3767
3768 /**
3769  * cairo_get_antialias:
3770  * @cr: a cairo context
3771  *
3772  * Gets the current shape antialiasing mode, as set by
3773  * cairo_set_antialias().
3774  *
3775  * Return value: the current shape antialiasing mode.
3776  *
3777  * Since: 1.0
3778  **/
3779 cairo_antialias_t
3780 cairo_get_antialias (cairo_t *cr)
3781 {
3782     if (unlikely (cr->status))
3783         return CAIRO_ANTIALIAS_DEFAULT;
3784
3785     return cr->backend->get_antialias (cr);
3786 }
3787
3788 /**
3789  * cairo_has_current_point:
3790  * @cr: a cairo context
3791  *
3792  * Returns whether a current point is defined on the current path.
3793  * See cairo_get_current_point() for details on the current point.
3794  *
3795  * Return value: whether a current point is defined.
3796  *
3797  * Since: 1.6
3798  **/
3799 cairo_bool_t
3800 cairo_has_current_point (cairo_t *cr)
3801 {
3802     if (unlikely (cr->status))
3803         return FALSE;
3804
3805     return cr->backend->has_current_point (cr);
3806 }
3807
3808 /**
3809  * cairo_get_current_point:
3810  * @cr: a cairo context
3811  * @x: return value for X coordinate of the current point
3812  * @y: return value for Y coordinate of the current point
3813  *
3814  * Gets the current point of the current path, which is
3815  * conceptually the final point reached by the path so far.
3816  *
3817  * The current point is returned in the user-space coordinate
3818  * system. If there is no defined current point or if @cr is in an
3819  * error status, @x and @y will both be set to 0.0. It is possible to
3820  * check this in advance with cairo_has_current_point().
3821  *
3822  * Most path construction functions alter the current point. See the
3823  * following for details on how they affect the current point:
3824  * cairo_new_path(), cairo_new_sub_path(),
3825  * cairo_append_path(), cairo_close_path(),
3826  * cairo_move_to(), cairo_line_to(), cairo_curve_to(),
3827  * cairo_rel_move_to(), cairo_rel_line_to(), cairo_rel_curve_to(),
3828  * cairo_arc(), cairo_arc_negative(), cairo_rectangle(),
3829  * cairo_text_path(), cairo_glyph_path(), cairo_stroke_to_path().
3830  *
3831  * Some functions use and alter the current point but do not
3832  * otherwise change current path:
3833  * cairo_show_text().
3834  *
3835  * Some functions unset the current path and as a result, current point:
3836  * cairo_fill(), cairo_stroke().
3837  *
3838  * Since: 1.0
3839  **/
3840 void
3841 cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret)
3842 {
3843     double x, y;
3844
3845     x = y = 0;
3846     if (cr->status == CAIRO_STATUS_SUCCESS &&
3847         cr->backend->has_current_point (cr))
3848     {
3849         cr->backend->get_current_point (cr, &x, &y);
3850     }
3851
3852     if (x_ret)
3853         *x_ret = x;
3854     if (y_ret)
3855         *y_ret = y;
3856 }
3857 slim_hidden_def(cairo_get_current_point);
3858
3859 /**
3860  * cairo_get_fill_rule:
3861  * @cr: a cairo context
3862  *
3863  * Gets the current fill rule, as set by cairo_set_fill_rule().
3864  *
3865  * Return value: the current fill rule.
3866  *
3867  * Since: 1.0
3868  **/
3869 cairo_fill_rule_t
3870 cairo_get_fill_rule (cairo_t *cr)
3871 {
3872     if (unlikely (cr->status))
3873         return CAIRO_GSTATE_FILL_RULE_DEFAULT;
3874
3875     return cr->backend->get_fill_rule (cr);
3876 }
3877
3878 /**
3879  * cairo_get_line_width:
3880  * @cr: a cairo context
3881  *
3882  * This function returns the current line width value exactly as set by
3883  * cairo_set_line_width(). Note that the value is unchanged even if
3884  * the CTM has changed between the calls to cairo_set_line_width() and
3885  * cairo_get_line_width().
3886  *
3887  * Return value: the current line width.
3888  *
3889  * Since: 1.0
3890  **/
3891 double
3892 cairo_get_line_width (cairo_t *cr)
3893 {
3894     if (unlikely (cr->status))
3895         return CAIRO_GSTATE_LINE_WIDTH_DEFAULT;
3896
3897     return cr->backend->get_line_width (cr);
3898 }
3899 slim_hidden_def (cairo_get_line_width);
3900
3901 /**
3902  * cairo_get_line_cap:
3903  * @cr: a cairo context
3904  *
3905  * Gets the current line cap style, as set by cairo_set_line_cap().
3906  *
3907  * Return value: the current line cap style.
3908  *
3909  * Since: 1.0
3910  **/
3911 cairo_line_cap_t
3912 cairo_get_line_cap (cairo_t *cr)
3913 {
3914     if (unlikely (cr->status))
3915         return CAIRO_GSTATE_LINE_CAP_DEFAULT;
3916
3917     return cr->backend->get_line_cap (cr);
3918 }
3919
3920 /**
3921  * cairo_get_line_join:
3922  * @cr: a cairo context
3923  *
3924  * Gets the current line join style, as set by cairo_set_line_join().
3925  *
3926  * Return value: the current line join style.
3927  *
3928  * Since: 1.0
3929  **/
3930 cairo_line_join_t
3931 cairo_get_line_join (cairo_t *cr)
3932 {
3933     if (unlikely (cr->status))
3934         return CAIRO_GSTATE_LINE_JOIN_DEFAULT;
3935
3936     return cr->backend->get_line_join (cr);
3937 }
3938
3939 /**
3940  * cairo_get_miter_limit:
3941  * @cr: a cairo context
3942  *
3943  * Gets the current miter limit, as set by cairo_set_miter_limit().
3944  *
3945  * Return value: the current miter limit.
3946  *
3947  * Since: 1.0
3948  **/
3949 double
3950 cairo_get_miter_limit (cairo_t *cr)
3951 {
3952     if (unlikely (cr->status))
3953         return CAIRO_GSTATE_MITER_LIMIT_DEFAULT;
3954
3955     return cr->backend->get_miter_limit (cr);
3956 }
3957
3958 /**
3959  * cairo_get_matrix:
3960  * @cr: a cairo context
3961  * @matrix: return value for the matrix
3962  *
3963  * Stores the current transformation matrix (CTM) into @matrix.
3964  *
3965  * Since: 1.0
3966  **/
3967 void
3968 cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix)
3969 {
3970     if (unlikely (cr->status)) {
3971         cairo_matrix_init_identity (matrix);
3972         return;
3973     }
3974
3975     cr->backend->get_matrix (cr, matrix);
3976 }
3977 slim_hidden_def (cairo_get_matrix);
3978
3979 /**
3980  * cairo_get_target:
3981  * @cr: a cairo context
3982  *
3983  * Gets the target surface for the cairo context as passed to
3984  * cairo_create().
3985  *
3986  * This function will always return a valid pointer, but the result
3987  * can be a "nil" surface if @cr is already in an error state,
3988  * (ie. cairo_status() <literal>!=</literal> %CAIRO_STATUS_SUCCESS).
3989  * A nil surface is indicated by cairo_surface_status()
3990  * <literal>!=</literal> %CAIRO_STATUS_SUCCESS.
3991  *
3992  * Return value: the target surface. This object is owned by cairo. To
3993  * keep a reference to it, you must call cairo_surface_reference().
3994  *
3995  * Since: 1.0
3996  **/
3997 cairo_surface_t *
3998 cairo_get_target (cairo_t *cr)
3999 {
4000     if (unlikely (cr->status))
4001         return _cairo_surface_create_in_error (cr->status);
4002
4003     return cr->backend->get_original_target (cr);
4004 }
4005 slim_hidden_def (cairo_get_target);
4006
4007 /**
4008  * cairo_get_group_target:
4009  * @cr: a cairo context
4010  *
4011  * Gets the current destination surface for the context. This is either
4012  * the original target surface as passed to cairo_create() or the target
4013  * surface for the current group as started by the most recent call to
4014  * cairo_push_group() or cairo_push_group_with_content().
4015  *
4016  * This function will always return a valid pointer, but the result
4017  * can be a "nil" surface if @cr is already in an error state,
4018  * (ie. cairo_status() <literal>!=</literal> %CAIRO_STATUS_SUCCESS).
4019  * A nil surface is indicated by cairo_surface_status()
4020  * <literal>!=</literal> %CAIRO_STATUS_SUCCESS.
4021  *
4022  * Return value: the target surface. This object is owned by cairo. To
4023  * keep a reference to it, you must call cairo_surface_reference().
4024  *
4025  * Since: 1.2
4026  **/
4027 cairo_surface_t *
4028 cairo_get_group_target (cairo_t *cr)
4029 {
4030     if (unlikely (cr->status))
4031         return _cairo_surface_create_in_error (cr->status);
4032
4033     return cr->backend->get_current_target (cr);
4034 }
4035
4036 /**
4037  * cairo_copy_path:
4038  * @cr: a cairo context
4039  *
4040  * Creates a copy of the current path and returns it to the user as a
4041  * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate
4042  * over the returned data structure.
4043  *
4044  * This function will always return a valid pointer, but the result
4045  * will have no data (<literal>data==%NULL</literal> and
4046  * <literal>num_data==0</literal>), if either of the following
4047  * conditions hold:
4048  *
4049  * <orderedlist>
4050  * <listitem>If there is insufficient memory to copy the path. In this
4051  *     case <literal>path->status</literal> will be set to
4052  *     %CAIRO_STATUS_NO_MEMORY.</listitem>
4053  * <listitem>If @cr is already in an error state. In this case
4054  *    <literal>path->status</literal> will contain the same status that
4055  *    would be returned by cairo_status().</listitem>
4056  * </orderedlist>
4057  *
4058  * Return value: the copy of the current path. The caller owns the
4059  * returned object and should call cairo_path_destroy() when finished
4060  * with it.
4061  *
4062  * Since: 1.0
4063  **/
4064 cairo_path_t *
4065 cairo_copy_path (cairo_t *cr)
4066 {
4067     if (unlikely (cr->status))
4068         return _cairo_path_create_in_error (cr->status);
4069
4070     return cr->backend->copy_path (cr);
4071 }
4072
4073 /**
4074  * cairo_copy_path_flat:
4075  * @cr: a cairo context
4076  *
4077  * Gets a flattened copy of the current path and returns it to the
4078  * user as a #cairo_path_t. See #cairo_path_data_t for hints on
4079  * how to iterate over the returned data structure.
4080  *
4081  * This function is like cairo_copy_path() except that any curves
4082  * in the path will be approximated with piecewise-linear
4083  * approximations, (accurate to within the current tolerance
4084  * value). That is, the result is guaranteed to not have any elements
4085  * of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a
4086  * series of %CAIRO_PATH_LINE_TO elements.
4087  *
4088  * This function will always return a valid pointer, but the result
4089  * will have no data (<literal>data==%NULL</literal> and
4090  * <literal>num_data==0</literal>), if either of the following
4091  * conditions hold:
4092  *
4093  * <orderedlist>
4094  * <listitem>If there is insufficient memory to copy the path. In this
4095  *     case <literal>path->status</literal> will be set to
4096  *     %CAIRO_STATUS_NO_MEMORY.</listitem>
4097  * <listitem>If @cr is already in an error state. In this case
4098  *    <literal>path->status</literal> will contain the same status that
4099  *    would be returned by cairo_status().</listitem>
4100  * </orderedlist>
4101  *
4102  * Return value: the copy of the current path. The caller owns the
4103  * returned object and should call cairo_path_destroy() when finished
4104  * with it.
4105  *
4106  * Since: 1.0
4107  **/
4108 cairo_path_t *
4109 cairo_copy_path_flat (cairo_t *cr)
4110 {
4111     if (unlikely (cr->status))
4112         return _cairo_path_create_in_error (cr->status);
4113
4114     return cr->backend->copy_path_flat (cr);
4115 }
4116
4117 /**
4118  * cairo_append_path:
4119  * @cr: a cairo context
4120  * @path: path to be appended
4121  *
4122  * Append the @path onto the current path. The @path may be either the
4123  * return value from one of cairo_copy_path() or
4124  * cairo_copy_path_flat() or it may be constructed manually.  See
4125  * #cairo_path_t for details on how the path data structure should be
4126  * initialized, and note that <literal>path->status</literal> must be
4127  * initialized to %CAIRO_STATUS_SUCCESS.
4128  *
4129  * Since: 1.0
4130  **/
4131 void
4132 cairo_append_path (cairo_t              *cr,
4133                    const cairo_path_t   *path)
4134 {
4135     cairo_status_t status;
4136
4137     if (unlikely (cr->status))
4138         return;
4139
4140     if (unlikely (path == NULL)) {
4141         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
4142         return;
4143     }
4144
4145     if (unlikely (path->status)) {
4146         if (path->status > CAIRO_STATUS_SUCCESS &&
4147             path->status <= CAIRO_STATUS_LAST_STATUS)
4148             _cairo_set_error (cr, path->status);
4149         else
4150             _cairo_set_error (cr, CAIRO_STATUS_INVALID_STATUS);
4151         return;
4152     }
4153
4154     if (path->num_data == 0)
4155         return;
4156
4157     if (unlikely (path->data == NULL)) {
4158         _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
4159         return;
4160     }
4161
4162     status = cr->backend->append_path (cr, path);
4163     if (unlikely (status))
4164         _cairo_set_error (cr, status);
4165 }
4166
4167 /**
4168  * cairo_status:
4169  * @cr: a cairo context
4170  *
4171  * Checks whether an error has previously occurred for this context.
4172  *
4173  * Returns: the current status of this context, see #cairo_status_t
4174  *
4175  * Since: 1.0
4176  **/
4177 cairo_status_t
4178 cairo_status (cairo_t *cr)
4179 {
4180     return cr->status;
4181 }
4182 slim_hidden_def (cairo_status);
4183
4184 void
4185 cairo_set_shadow (cairo_t *cr, cairo_shadow_type_t shadow)
4186 {
4187     cairo_status_t status;
4188
4189     if (unlikely (cr->status))
4190         return;
4191
4192     status = cr->backend->set_shadow (cr, shadow);
4193     if (unlikely (status))
4194         _cairo_set_error (cr, status);
4195 }
4196 slim_hidden_def (cairo_set_shadow);
4197
4198 void
4199 cairo_set_shadow_offset (cairo_t *cr, double x_offset, double y_offset)
4200 {
4201     cairo_status_t status;
4202
4203     if (unlikely (cr->status))
4204         return;
4205
4206     status = cr->backend->set_shadow_offset (cr, x_offset, y_offset);
4207     if (unlikely (status))
4208         _cairo_set_error (cr, status);
4209 }
4210 slim_hidden_def (cairo_set_shadow_offset);
4211
4212 void
4213 cairo_set_shadow_rgb (cairo_t *cr, double red, double green, double blue)
4214 {
4215     cairo_status_t status;
4216
4217     if (unlikely (cr->status))
4218         return;
4219
4220     status = cr->backend->set_shadow_rgba (cr, red, green, blue, 1.0);
4221     if (unlikely (status))
4222         _cairo_set_error (cr, status);
4223 }
4224 slim_hidden_def (cairo_set_shadow_rgb);
4225
4226 void
4227 cairo_set_shadow_rgba (cairo_t *cr, double red, double green,
4228                        double blue, double alpha)
4229 {
4230     cairo_status_t status;
4231
4232     if (unlikely (cr->status))
4233         return;
4234
4235     status = cr->backend->set_shadow_rgba (cr, red, green, blue, alpha);
4236     if (unlikely (status))
4237         _cairo_set_error (cr, status);
4238 }
4239 slim_hidden_def (cairo_set_shadow_rgba);
4240
4241 void
4242 cairo_set_shadow_blur (cairo_t *cr, double x_blur, double y_blur)
4243 {
4244     cairo_status_t status;
4245
4246     if (unlikely (cr->status))
4247         return;
4248
4249     status = cr->backend->set_shadow_blur (cr, x_blur, y_blur);
4250     if (unlikely (status))
4251         _cairo_set_error (cr, status);
4252 }
4253 slim_hidden_def (cairo_set_shadow_blur);
4254
4255 void
4256 cairo_set_draw_shadow_only (cairo_t *cr, cairo_bool_t draw_shadow_only)
4257 {
4258     if (unlikely (cr->status))
4259         return;
4260
4261     cr->backend->set_draw_shadow_only (cr, draw_shadow_only);
4262 }
4263 slim_hidden_def (cairo_set_draw_shadow_only);
4264
4265 void
4266 cairo_shadow_enable_cache (cairo_t *cr, cairo_bool_t enable)
4267 {
4268     if (unlikely (cr->status))
4269         return;
4270
4271     cr->backend->shadow_enable_cache (cr, enable);
4272 }
4273 slim_hidden_def (cairo_shadow_enable_cache);
4274
4275 void
4276 cairo_set_path_is_inset_shadow_with_spread (cairo_t *cr,
4277                                             cairo_bool_t is_spread_path)
4278 {
4279     if (unlikely (cr->status))
4280         return;
4281     cr->backend->set_path_is_inset_shadow_with_spread (cr, is_spread_path);}
4282 slim_hidden_def (cairo_set_path_is_inset_shadow_with_spread);