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