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
4 * Copyright © 2002 University of Southern California
5 * Copyright © 2005 Red Hat, Inc.
6 * Copyright © 2011 Intel Corporation
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.
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
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/
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.
31 * The Original Code is the cairo graphics library.
33 * The Initial Developer of the Original Code is University of Southern
37 * Carl D. Worth <cworth@cworth.org>
38 * Chris Wilson <chris@chris-wilson.co.uk>
42 #include "cairo-private.h"
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"
52 #include "cairo-ttrace.h"
57 * @Short_Description: The cairo drawing context
58 * @See_Also: #cairo_surface_t
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().
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.
74 * @Short_Description: Rendering text and glyphs
75 * @See_Also: #cairo_font_face_t, #cairo_scaled_font_t, cairo_text_path(),
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.
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>.
99 * SECTION:cairo-transforms
100 * @Title: Transformations
101 * @Short_Description: Manipulating the current transformation matrix
102 * @See_Also: #cairo_matrix_t
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
111 #define DEFINE_NIL_CONTEXT(status) \
113 CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \
114 status, /* status */ \
115 { 0, 0, 0, NULL }, /* user_data */ \
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)
158 COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1);
162 * @cr: a cairo context
163 * @status: a status value indicating an error
165 * Atomically sets cr->status to @status and calls _cairo_error;
166 * Does nothing if status is %CAIRO_STATUS_SUCCESS.
168 * All assignments of an error status to cr->status should happen
169 * through _cairo_set_error(). Note that due to the nature of the atomic
170 * operation, it is not safe to call this function on the nil objects.
172 * The purpose of this function is to allow the user to set a
173 * breakpoint in _cairo_error() to generate a stack trace for when the
174 * user causes cairo to detect an error.
177 _cairo_set_error (cairo_t *cr, cairo_status_t status)
179 /* Don't overwrite an existing error. This preserves the first
180 * error, which is the most significant. */
181 _cairo_status_set_error (&cr->status, _cairo_error (status));
185 _cairo_create_in_error (cairo_status_t status)
189 assert (status != CAIRO_STATUS_SUCCESS);
191 cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY];
192 assert (status == cr->status);
199 * @target: target surface for the context
201 * Creates a new #cairo_t with all graphics state parameters set to
202 * default values and with @target as a target surface. The target
203 * surface should be constructed with a backend-specific function such
204 * as cairo_image_surface_create() (or any other
205 * <function>cairo_<emphasis>backend</emphasis>_surface_create(<!-- -->)</function>
208 * This function references @target, so you can immediately
209 * call cairo_surface_destroy() on it if you don't need to
210 * maintain a separate reference to it.
212 * Return value: a newly allocated #cairo_t with a reference
213 * count of 1. The initial reference count should be released
214 * with cairo_destroy() when you are done using the #cairo_t.
215 * This function never returns %NULL. If memory cannot be
216 * allocated, a special #cairo_t object will be returned on
217 * which cairo_status() returns %CAIRO_STATUS_NO_MEMORY. If
218 * you attempt to target a surface which does not support
219 * writing (such as #cairo_mime_surface_t) then a
220 * %CAIRO_STATUS_WRITE_ERROR will be raised. You can use this
221 * object normally, but no drawing will be done.
226 cairo_create (cairo_surface_t *target)
228 CAIRO_TRACE_BEGIN (__func__);
229 if (unlikely (target == NULL)) {
230 CAIRO_TRACE_END (__func__);
231 return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER));
233 if (unlikely (target->status)) {
234 CAIRO_TRACE_END (__func__);
235 return _cairo_create_in_error (target->status);
238 if (target->backend->create_context == NULL) {
239 CAIRO_TRACE_END (__func__);
240 return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR));
243 cairo_t *cr = target->backend->create_context (target);
244 CAIRO_TRACE_END (__func__);
248 slim_hidden_def (cairo_create);
251 _cairo_init (cairo_t *cr,
252 const cairo_backend_t *backend)
254 CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1);
255 cr->status = CAIRO_STATUS_SUCCESS;
256 _cairo_user_data_array_init (&cr->user_data);
258 cr->backend = backend;
265 * Increases the reference count on @cr by one. This prevents
266 * @cr from being destroyed until a matching call to cairo_destroy()
269 * The number of references to a #cairo_t can be get using
270 * cairo_get_reference_count().
272 * Return value: the referenced #cairo_t.
277 cairo_reference (cairo_t *cr)
279 if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
282 assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
284 _cairo_reference_count_inc (&cr->ref_count);
290 _cairo_fini (cairo_t *cr)
292 _cairo_user_data_array_fini (&cr->user_data);
299 * Decreases the reference count on @cr by one. If the result
300 * is zero, then @cr and all associated resources are freed.
301 * See cairo_reference().
306 cairo_destroy (cairo_t *cr)
308 CAIRO_TRACE_BEGIN (__func__);
309 if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) {
310 CAIRO_TRACE_END (__func__);
314 assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
316 if (! _cairo_reference_count_dec_and_test (&cr->ref_count)) {
317 CAIRO_TRACE_END (__func__);
321 cr->backend->destroy (cr);
322 CAIRO_TRACE_END (__func__);
324 slim_hidden_def (cairo_destroy);
327 * cairo_get_user_data:
329 * @key: the address of the #cairo_user_data_key_t the user data was
332 * Return user data previously attached to @cr using the specified
333 * key. If no user data has been attached with the given key this
334 * function returns %NULL.
336 * Return value: the user data previously attached or %NULL.
341 cairo_get_user_data (cairo_t *cr,
342 const cairo_user_data_key_t *key)
344 return _cairo_user_data_array_get_data (&cr->user_data, key);
348 * cairo_set_user_data:
350 * @key: the address of a #cairo_user_data_key_t to attach the user data to
351 * @user_data: the user data to attach to the #cairo_t
352 * @destroy: a #cairo_destroy_func_t which will be called when the
353 * #cairo_t is destroyed or when new user data is attached using the
356 * Attach user data to @cr. To remove user data from a surface,
357 * call this function with the key that was used to set it and %NULL
360 * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a
361 * slot could not be allocated for the user data.
366 cairo_set_user_data (cairo_t *cr,
367 const cairo_user_data_key_t *key,
369 cairo_destroy_func_t destroy)
371 if (CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
374 return _cairo_user_data_array_set_data (&cr->user_data,
375 key, user_data, destroy);
379 * cairo_get_reference_count:
382 * Returns the current reference count of @cr.
384 * Return value: the current reference count of @cr. If the
385 * object is a nil object, 0 will be returned.
390 cairo_get_reference_count (cairo_t *cr)
392 if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
395 return CAIRO_REFERENCE_COUNT_GET_VALUE (&cr->ref_count);
402 * Makes a copy of the current state of @cr and saves it
403 * on an internal stack of saved states for @cr. When
404 * cairo_restore() is called, @cr will be restored to
405 * the saved state. Multiple calls to cairo_save() and
406 * cairo_restore() can be nested; each call to cairo_restore()
407 * restores the state from the matching paired cairo_save().
409 * It isn't necessary to clear all saved states before
410 * a #cairo_t is freed. If the reference count of a #cairo_t
411 * drops to zero in response to a call to cairo_destroy(),
412 * any saved states will be freed along with the #cairo_t.
417 cairo_save (cairo_t *cr)
419 CAIRO_TRACE_BEGIN (__func__);
420 cairo_status_t status;
422 if (unlikely (cr->status)) {
423 CAIRO_TRACE_END (__func__);
427 status = cr->backend->save (cr);
428 if (unlikely (status))
429 _cairo_set_error (cr, status);
430 CAIRO_TRACE_END (__func__);
432 slim_hidden_def(cairo_save);
438 * Restores @cr to the state saved by a preceding call to
439 * cairo_save() and removes that state from the stack of
445 cairo_restore (cairo_t *cr)
447 CAIRO_TRACE_BEGIN (__func__);
448 cairo_status_t status;
450 if (unlikely (cr->status)) {
451 CAIRO_TRACE_END (__func__);
455 status = cr->backend->restore (cr);
456 if (unlikely (status))
457 _cairo_set_error (cr, status);
458 CAIRO_TRACE_END (__func__);
460 slim_hidden_def(cairo_restore);
464 * @cr: a cairo context
466 * Temporarily redirects drawing to an intermediate surface known as a
467 * group. The redirection lasts until the group is completed by a call
468 * to cairo_pop_group() or cairo_pop_group_to_source(). These calls
469 * provide the result of any drawing to the group as a pattern,
470 * (either as an explicit object, or set as the source pattern).
472 * This group functionality can be convenient for performing
473 * intermediate compositing. One common use of a group is to render
474 * objects as opaque within the group, (so that they occlude each
475 * other), and then blend the result with translucence onto the
478 * Groups can be nested arbitrarily deep by making balanced calls to
479 * cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new
480 * target group onto/from a stack.
482 * The cairo_push_group() function calls cairo_save() so that any
483 * changes to the graphics state will not be visible outside the
484 * group, (the pop_group functions call cairo_restore()).
486 * By default the intermediate group will have a content type of
487 * %CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for
488 * the group by using cairo_push_group_with_content() instead.
490 * As an example, here is how one might fill and stroke a path with
491 * translucence, but without any portion of the fill being visible
494 * <informalexample><programlisting>
495 * cairo_push_group (cr);
496 * cairo_set_source (cr, fill_pattern);
497 * cairo_fill_preserve (cr);
498 * cairo_set_source (cr, stroke_pattern);
500 * cairo_pop_group_to_source (cr);
501 * cairo_paint_with_alpha (cr, alpha);
502 * </programlisting></informalexample>
507 cairo_push_group (cairo_t *cr)
509 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
513 * cairo_push_group_with_content:
514 * @cr: a cairo context
515 * @content: a #cairo_content_t indicating the type of group that
518 * Temporarily redirects drawing to an intermediate surface known as a
519 * group. The redirection lasts until the group is completed by a call
520 * to cairo_pop_group() or cairo_pop_group_to_source(). These calls
521 * provide the result of any drawing to the group as a pattern,
522 * (either as an explicit object, or set as the source pattern).
524 * The group will have a content type of @content. The ability to
525 * control this content type is the only distinction between this
526 * function and cairo_push_group() which you should see for a more
527 * detailed description of group rendering.
532 cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
534 cairo_status_t status;
536 if (unlikely (cr->status))
539 status = cr->backend->push_group (cr, content);
540 if (unlikely (status))
541 _cairo_set_error (cr, status);
543 slim_hidden_def(cairo_push_group_with_content);
547 * @cr: a cairo context
549 * Terminates the redirection begun by a call to cairo_push_group() or
550 * cairo_push_group_with_content() and returns a new pattern
551 * containing the results of all drawing operations performed to the
554 * The cairo_pop_group() function calls cairo_restore(), (balancing a
555 * call to cairo_save() by the push_group function), so that any
556 * changes to the graphics state will not be visible outside the
559 * Return value: a newly created (surface) pattern containing the
560 * results of all drawing operations performed to the group. The
561 * caller owns the returned object and should call
562 * cairo_pattern_destroy() when finished with it.
567 cairo_pop_group (cairo_t *cr)
569 cairo_pattern_t *group_pattern;
571 if (unlikely (cr->status))
572 return _cairo_pattern_create_in_error (cr->status);
574 group_pattern = cr->backend->pop_group (cr);
575 if (unlikely (group_pattern->status))
576 _cairo_set_error (cr, group_pattern->status);
578 return group_pattern;
580 slim_hidden_def(cairo_pop_group);
583 * cairo_pop_group_to_source:
584 * @cr: a cairo context
586 * Terminates the redirection begun by a call to cairo_push_group() or
587 * cairo_push_group_with_content() and installs the resulting pattern
588 * as the source pattern in the given cairo context.
590 * The behavior of this function is equivalent to the sequence of
593 * <informalexample><programlisting>
594 * cairo_pattern_t *group = cairo_pop_group (cr);
595 * cairo_set_source (cr, group);
596 * cairo_pattern_destroy (group);
597 * </programlisting></informalexample>
599 * but is more convenient as their is no need for a variable to store
600 * the short-lived pointer to the pattern.
602 * The cairo_pop_group() function calls cairo_restore(), (balancing a
603 * call to cairo_save() by the push_group function), so that any
604 * changes to the graphics state will not be visible outside the
610 cairo_pop_group_to_source (cairo_t *cr)
612 cairo_pattern_t *group_pattern;
614 group_pattern = cairo_pop_group (cr);
615 cairo_set_source (cr, group_pattern);
616 cairo_pattern_destroy (group_pattern);
620 * cairo_set_operator:
622 * @op: a compositing operator, specified as a #cairo_operator_t
624 * Sets the compositing operator to be used for all drawing
625 * operations. See #cairo_operator_t for details on the semantics of
626 * each available compositing operator.
628 * The default operator is %CAIRO_OPERATOR_OVER.
633 cairo_set_operator (cairo_t *cr, cairo_operator_t op)
635 cairo_status_t status;
637 if (unlikely (cr->status))
640 status = cr->backend->set_operator (cr, op);
641 if (unlikely (status))
642 _cairo_set_error (cr, status);
644 slim_hidden_def (cairo_set_operator);
651 * @opacity: the level of opacity to use when compositing
653 * Sets the compositing opacity to be used for all drawing
654 * operations. The effect is to fade out the operations
655 * using the alpha value.
657 * The default opacity is 1.
662 cairo_set_opacity (cairo_t *cr, double opacity)
664 cairo_status_t status;
666 if (unlikely (cr->status))
669 status = cr->backend->set_opacity (cr, opacity);
670 if (unlikely (status))
671 _cairo_set_error (cr, status);
676 * cairo_set_source_rgb:
677 * @cr: a cairo context
678 * @red: red component of color
679 * @green: green component of color
680 * @blue: blue component of color
682 * Sets the source pattern within @cr to an opaque color. This opaque
683 * color will then be used for any subsequent drawing operation until
684 * a new source pattern is set.
686 * The color components are floating point numbers in the range 0 to
687 * 1. If the values passed in are outside that range, they will be
690 * The default source pattern is opaque black, (that is, it is
691 * equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)).
696 cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
698 CAIRO_TRACE_BEGIN (__func__);
699 cairo_status_t status;
701 if (unlikely (cr->status)) {
702 CAIRO_TRACE_END (__func__);
706 status = cr->backend->set_source_rgba (cr, red, green, blue, 1.);
707 if (unlikely (status))
708 _cairo_set_error (cr, status);
709 CAIRO_TRACE_END (__func__);
711 slim_hidden_def (cairo_set_source_rgb);
714 * cairo_set_source_rgba:
715 * @cr: a cairo context
716 * @red: red component of color
717 * @green: green component of color
718 * @blue: blue component of color
719 * @alpha: alpha component of color
721 * Sets the source pattern within @cr to a translucent color. This
722 * color will then be used for any subsequent drawing operation until
723 * a new source pattern is set.
725 * The color and alpha components are floating point numbers in the
726 * range 0 to 1. If the values passed in are outside that range, they
729 * The default source pattern is opaque black, (that is, it is
730 * equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)).
735 cairo_set_source_rgba (cairo_t *cr,
736 double red, double green, double blue,
739 cairo_status_t status;
741 if (unlikely (cr->status))
744 status = cr->backend->set_source_rgba (cr, red, green, blue, alpha);
745 if (unlikely (status))
746 _cairo_set_error (cr, status);
750 * cairo_set_source_surface:
751 * @cr: a cairo context
752 * @surface: a surface to be used to set the source pattern
753 * @x: User-space X coordinate for surface origin
754 * @y: User-space Y coordinate for surface origin
756 * This is a convenience function for creating a pattern from @surface
757 * and setting it as the source in @cr with cairo_set_source().
759 * The @x and @y parameters give the user-space coordinate at which
760 * the surface origin should appear. (The surface origin is its
761 * upper-left corner before any transformation has been applied.) The
762 * @x and @y parameters are negated and then set as translation values
763 * in the pattern matrix.
765 * Other than the initial translation pattern matrix, as described
766 * above, all other pattern attributes, (such as its extend mode), are
767 * set to the default values as in cairo_pattern_create_for_surface().
768 * The resulting pattern can be queried with cairo_get_source() so
769 * that these attributes can be modified if desired, (eg. to create a
770 * repeating pattern with cairo_pattern_set_extend()).
775 cairo_set_source_surface (cairo_t *cr,
776 cairo_surface_t *surface,
780 CAIRO_TRACE_BEGIN (__func__);
781 cairo_status_t status;
783 if (unlikely (cr->status)) {
784 CAIRO_TRACE_END (__func__);
788 if (unlikely (surface == NULL)) {
789 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
790 CAIRO_TRACE_END (__func__);
794 status = cr->backend->set_source_surface (cr, surface, x, y);
795 if (unlikely (status))
796 _cairo_set_error (cr, status);
797 CAIRO_TRACE_END (__func__);
799 slim_hidden_def (cairo_set_source_surface);
803 * @cr: a cairo context
804 * @source: a #cairo_pattern_t to be used as the source for
805 * subsequent drawing operations.
807 * Sets the source pattern within @cr to @source. This pattern
808 * will then be used for any subsequent drawing operation until a new
809 * source pattern is set.
811 * Note: The pattern's transformation matrix will be locked to the
812 * user space in effect at the time of cairo_set_source(). This means
813 * that further modifications of the current transformation matrix
814 * will not affect the source pattern. See cairo_pattern_set_matrix().
816 * The default source pattern is a solid pattern that is opaque black,
817 * (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0,
823 cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
825 cairo_status_t status;
827 if (unlikely (cr->status))
830 if (unlikely (source == NULL)) {
831 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
835 if (unlikely (source->status)) {
836 _cairo_set_error (cr, source->status);
840 status = cr->backend->set_source (cr, source);
841 if (unlikely (status))
842 _cairo_set_error (cr, status);
844 slim_hidden_def (cairo_set_source);
848 * @cr: a cairo context
850 * Gets the current source pattern for @cr.
852 * Return value: the current source pattern. This object is owned by
853 * cairo. To keep a reference to it, you must call
854 * cairo_pattern_reference().
859 cairo_get_source (cairo_t *cr)
861 if (unlikely (cr->status))
862 return _cairo_pattern_create_in_error (cr->status);
864 return cr->backend->get_source (cr);
868 * cairo_set_tolerance:
870 * @tolerance: the tolerance, in device units (typically pixels)
872 * Sets the tolerance used when converting paths into trapezoids.
873 * Curved segments of the path will be subdivided until the maximum
874 * deviation between the original path and the polygonal approximation
875 * is less than @tolerance. The default value is 0.1. A larger
876 * value will give better performance, a smaller value, better
877 * appearance. (Reducing the value from the default value of 0.1
878 * is unlikely to improve appearance significantly.) The accuracy of paths
879 * within Cairo is limited by the precision of its internal arithmetic, and
880 * the prescribed @tolerance is restricted to the smallest
881 * representable internal value.
886 cairo_set_tolerance (cairo_t *cr, double tolerance)
888 cairo_status_t status;
890 if (unlikely (cr->status))
893 status = cr->backend->set_tolerance (cr, tolerance);
894 if (unlikely (status))
895 _cairo_set_error (cr, status);
897 slim_hidden_def (cairo_set_tolerance);
900 * cairo_set_antialias:
902 * @antialias: the new antialiasing mode
904 * Set the antialiasing mode of the rasterizer used for drawing shapes.
905 * This value is a hint, and a particular backend may or may not support
906 * a particular value. At the current time, no backend supports
907 * %CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes.
909 * Note that this option does not affect text rendering, instead see
910 * cairo_font_options_set_antialias().
915 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
917 cairo_status_t status;
919 if (unlikely (cr->status))
922 status = cr->backend->set_antialias (cr, antialias);
923 if (unlikely (status))
924 _cairo_set_error (cr, status);
928 * cairo_set_fill_rule:
930 * @fill_rule: a fill rule, specified as a #cairo_fill_rule_t
932 * Set the current fill rule within the cairo context. The fill rule
933 * is used to determine which regions are inside or outside a complex
934 * (potentially self-intersecting) path. The current fill rule affects
935 * both cairo_fill() and cairo_clip(). See #cairo_fill_rule_t for details
936 * on the semantics of each available fill rule.
938 * The default fill rule is %CAIRO_FILL_RULE_WINDING.
943 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
945 cairo_status_t status;
947 if (unlikely (cr->status))
950 status = cr->backend->set_fill_rule (cr, fill_rule);
951 if (unlikely (status))
952 _cairo_set_error (cr, status);
956 * cairo_set_line_width:
958 * @width: a line width
960 * Sets the current line width within the cairo context. The line
961 * width value specifies the diameter of a pen that is circular in
962 * user space, (though device-space pen may be an ellipse in general
963 * due to scaling/shear/rotation of the CTM).
965 * Note: When the description above refers to user space and CTM it
966 * refers to the user space and CTM in effect at the time of the
967 * stroking operation, not the user space and CTM in effect at the
968 * time of the call to cairo_set_line_width(). The simplest usage
969 * makes both of these spaces identical. That is, if there is no
970 * change to the CTM between a call to cairo_set_line_width() and the
971 * stroking operation, then one can just pass user-space values to
972 * cairo_set_line_width() and ignore this note.
974 * As with the other stroke parameters, the current line width is
975 * examined by cairo_stroke(), cairo_stroke_extents(), and
976 * cairo_stroke_to_path(), but does not have any effect during path
979 * The default line width value is 2.0.
984 cairo_set_line_width (cairo_t *cr, double width)
986 cairo_status_t status;
988 if (unlikely (cr->status))
994 status = cr->backend->set_line_width (cr, width);
995 if (unlikely (status))
996 _cairo_set_error (cr, status);
998 slim_hidden_def (cairo_set_line_width);
1001 * cairo_set_line_cap:
1002 * @cr: a cairo context
1003 * @line_cap: a line cap style
1005 * Sets the current line cap style within the cairo context. See
1006 * #cairo_line_cap_t for details about how the available line cap
1009 * As with the other stroke parameters, the current line cap style is
1010 * examined by cairo_stroke(), cairo_stroke_extents(), and
1011 * cairo_stroke_to_path(), but does not have any effect during path
1014 * The default line cap style is %CAIRO_LINE_CAP_BUTT.
1019 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
1021 cairo_status_t status;
1023 if (unlikely (cr->status))
1026 status = cr->backend->set_line_cap (cr, line_cap);
1027 if (unlikely (status))
1028 _cairo_set_error (cr, status);
1030 slim_hidden_def (cairo_set_line_cap);
1033 * cairo_set_line_join:
1034 * @cr: a cairo context
1035 * @line_join: a line join style
1037 * Sets the current line join style within the cairo context. See
1038 * #cairo_line_join_t for details about how the available line join
1041 * As with the other stroke parameters, the current line join style is
1042 * examined by cairo_stroke(), cairo_stroke_extents(), and
1043 * cairo_stroke_to_path(), but does not have any effect during path
1046 * The default line join style is %CAIRO_LINE_JOIN_MITER.
1051 cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
1053 cairo_status_t status;
1055 if (unlikely (cr->status))
1058 status = cr->backend->set_line_join (cr, line_join);
1059 if (unlikely (status))
1060 _cairo_set_error (cr, status);
1062 slim_hidden_def (cairo_set_line_join);
1066 * @cr: a cairo context
1067 * @dashes: an array specifying alternate lengths of on and off stroke portions
1068 * @num_dashes: the length of the dashes array
1069 * @offset: an offset into the dash pattern at which the stroke should start
1071 * Sets the dash pattern to be used by cairo_stroke(). A dash pattern
1072 * is specified by @dashes, an array of positive values. Each value
1073 * provides the length of alternate "on" and "off" portions of the
1074 * stroke. The @offset specifies an offset into the pattern at which
1075 * the stroke begins.
1077 * Each "on" segment will have caps applied as if the segment were a
1078 * separate sub-path. In particular, it is valid to use an "on" length
1079 * of 0.0 with %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE in order
1080 * to distributed dots or squares along a path.
1082 * Note: The length values are in user-space units as evaluated at the
1083 * time of stroking. This is not necessarily the same as the user
1084 * space at the time of cairo_set_dash().
1086 * If @num_dashes is 0 dashing is disabled.
1088 * If @num_dashes is 1 a symmetric pattern is assumed with alternating
1089 * on and off portions of the size specified by the single value in
1092 * If any value in @dashes is negative, or if all values are 0, then
1093 * @cr will be put into an error state with a status of
1094 * %CAIRO_STATUS_INVALID_DASH.
1099 cairo_set_dash (cairo_t *cr,
1100 const double *dashes,
1104 cairo_status_t status;
1106 if (unlikely (cr->status))
1109 status = cr->backend->set_dash (cr, dashes, num_dashes, offset);
1110 if (unlikely (status))
1111 _cairo_set_error (cr, status);
1115 * cairo_get_dash_count:
1118 * This function returns the length of the dash array in @cr (0 if dashing
1119 * is not currently in effect).
1121 * See also cairo_set_dash() and cairo_get_dash().
1123 * Return value: the length of the dash array, or 0 if no dash array set.
1128 cairo_get_dash_count (cairo_t *cr)
1132 if (unlikely (cr->status))
1135 cr->backend->get_dash (cr, NULL, &num_dashes, NULL);
1143 * @dashes: return value for the dash array, or %NULL
1144 * @offset: return value for the current dash offset, or %NULL
1146 * Gets the current dash array. If not %NULL, @dashes should be big
1147 * enough to hold at least the number of values returned by
1148 * cairo_get_dash_count().
1153 cairo_get_dash (cairo_t *cr,
1157 if (unlikely (cr->status))
1160 cr->backend->get_dash (cr, dashes, NULL, offset);
1164 * cairo_set_miter_limit:
1165 * @cr: a cairo context
1166 * @limit: miter limit to set
1168 * Sets the current miter limit within the cairo context.
1170 * If the current line join style is set to %CAIRO_LINE_JOIN_MITER
1171 * (see cairo_set_line_join()), the miter limit is used to determine
1172 * whether the lines should be joined with a bevel instead of a miter.
1173 * Cairo divides the length of the miter by the line width.
1174 * If the result is greater than the miter limit, the style is
1175 * converted to a bevel.
1177 * As with the other stroke parameters, the current line miter limit is
1178 * examined by cairo_stroke(), cairo_stroke_extents(), and
1179 * cairo_stroke_to_path(), but does not have any effect during path
1182 * The default miter limit value is 10.0, which will convert joins
1183 * with interior angles less than 11 degrees to bevels instead of
1184 * miters. For reference, a miter limit of 2.0 makes the miter cutoff
1185 * at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90
1188 * A miter limit for a desired angle can be computed as: miter limit =
1194 cairo_set_miter_limit (cairo_t *cr, double limit)
1196 cairo_status_t status;
1198 if (unlikely (cr->status))
1201 status = cr->backend->set_miter_limit (cr, limit);
1202 if (unlikely (status))
1203 _cairo_set_error (cr, status);
1208 * @cr: a cairo context
1209 * @tx: amount to translate in the X direction
1210 * @ty: amount to translate in the Y direction
1212 * Modifies the current transformation matrix (CTM) by translating the
1213 * user-space origin by (@tx, @ty). This offset is interpreted as a
1214 * user-space coordinate according to the CTM in place before the new
1215 * call to cairo_translate(). In other words, the translation of the
1216 * user-space origin takes place after any existing transformation.
1221 cairo_translate (cairo_t *cr, double tx, double ty)
1223 CAIRO_TRACE_BEGIN (__func__);
1224 cairo_status_t status;
1226 if (unlikely (cr->status)) {
1227 CAIRO_TRACE_END (__func__);
1231 status = cr->backend->translate (cr, tx, ty);
1232 if (unlikely (status))
1233 _cairo_set_error (cr, status);
1234 CAIRO_TRACE_END (__func__);
1236 slim_hidden_def (cairo_translate);
1240 * @cr: a cairo context
1241 * @sx: scale factor for the X dimension
1242 * @sy: scale factor for the Y dimension
1244 * Modifies the current transformation matrix (CTM) by scaling the X
1245 * and Y user-space axes by @sx and @sy respectively. The scaling of
1246 * the axes takes place after any existing transformation of user
1252 cairo_scale (cairo_t *cr, double sx, double sy)
1254 CAIRO_TRACE_BEGIN (__func__);
1255 cairo_status_t status;
1257 if (unlikely (cr->status)) {
1258 CAIRO_TRACE_END (__func__);
1262 status = cr->backend->scale (cr, sx, sy);
1263 if (unlikely (status))
1264 _cairo_set_error (cr, status);
1265 CAIRO_TRACE_END (__func__);
1267 slim_hidden_def (cairo_scale);
1271 * @cr: a cairo context
1272 * @angle: angle (in radians) by which the user-space axes will be
1275 * Modifies the current transformation matrix (CTM) by rotating the
1276 * user-space axes by @angle radians. The rotation of the axes takes
1277 * places after any existing transformation of user space. The
1278 * rotation direction for positive angles is from the positive X axis
1279 * toward the positive Y axis.
1284 cairo_rotate (cairo_t *cr, double angle)
1286 CAIRO_TRACE_BEGIN (__func__);
1287 cairo_status_t status;
1289 if (unlikely (cr->status)) {
1290 CAIRO_TRACE_END (__func__);
1294 status = cr->backend->rotate (cr, angle);
1295 if (unlikely (status))
1296 _cairo_set_error (cr, status);
1297 CAIRO_TRACE_END (__func__);
1302 * @cr: a cairo context
1303 * @matrix: a transformation to be applied to the user-space axes
1305 * Modifies the current transformation matrix (CTM) by applying
1306 * @matrix as an additional transformation. The new transformation of
1307 * user space takes place after any existing transformation.
1312 cairo_transform (cairo_t *cr,
1313 const cairo_matrix_t *matrix)
1315 cairo_status_t status;
1317 if (unlikely (cr->status))
1320 status = cr->backend->transform (cr, matrix);
1321 if (unlikely (status))
1322 _cairo_set_error (cr, status);
1324 slim_hidden_def (cairo_transform);
1328 * @cr: a cairo context
1329 * @matrix: a transformation matrix from user space to device space
1331 * Modifies the current transformation matrix (CTM) by setting it
1337 cairo_set_matrix (cairo_t *cr,
1338 const cairo_matrix_t *matrix)
1340 cairo_status_t status;
1342 if (unlikely (cr->status))
1345 status = cr->backend->set_matrix (cr, matrix);
1346 if (unlikely (status))
1347 _cairo_set_error (cr, status);
1349 slim_hidden_def (cairo_set_matrix);
1352 * cairo_identity_matrix:
1353 * @cr: a cairo context
1355 * Resets the current transformation matrix (CTM) by setting it equal
1356 * to the identity matrix. That is, the user-space and device-space
1357 * axes will be aligned and one user-space unit will transform to one
1358 * device-space unit.
1363 cairo_identity_matrix (cairo_t *cr)
1365 cairo_status_t status;
1367 if (unlikely (cr->status))
1370 status = cr->backend->set_identity_matrix (cr);
1371 if (unlikely (status))
1372 _cairo_set_error (cr, status);
1376 * cairo_user_to_device:
1377 * @cr: a cairo context
1378 * @x: X value of coordinate (in/out parameter)
1379 * @y: Y value of coordinate (in/out parameter)
1381 * Transform a coordinate from user space to device space by
1382 * multiplying the given point by the current transformation matrix
1388 cairo_user_to_device (cairo_t *cr, double *x, double *y)
1390 CAIRO_TRACE_BEGIN (__func__);
1391 if (unlikely (cr->status)) {
1392 CAIRO_TRACE_END (__func__);
1396 cr->backend->user_to_device (cr, x, y);
1397 CAIRO_TRACE_END (__func__);
1399 slim_hidden_def (cairo_user_to_device);
1402 * cairo_user_to_device_distance:
1403 * @cr: a cairo context
1404 * @dx: X component of a distance vector (in/out parameter)
1405 * @dy: Y component of a distance vector (in/out parameter)
1407 * Transform a distance vector from user space to device space. This
1408 * function is similar to cairo_user_to_device() except that the
1409 * translation components of the CTM will be ignored when transforming
1415 cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy)
1417 CAIRO_TRACE_BEGIN (__func__);
1418 if (unlikely (cr->status)) {
1419 CAIRO_TRACE_END (__func__);
1423 cr->backend->user_to_device_distance (cr, dx, dy);
1424 CAIRO_TRACE_END (__func__);
1426 slim_hidden_def (cairo_user_to_device_distance);
1429 * cairo_device_to_user:
1431 * @x: X value of coordinate (in/out parameter)
1432 * @y: Y value of coordinate (in/out parameter)
1434 * Transform a coordinate from device space to user space by
1435 * multiplying the given point by the inverse of the current
1436 * transformation matrix (CTM).
1441 cairo_device_to_user (cairo_t *cr, double *x, double *y)
1443 CAIRO_TRACE_BEGIN (__func__);
1444 if (unlikely (cr->status)) {
1445 CAIRO_TRACE_END (__func__);
1449 cr->backend->device_to_user (cr, x, y);
1450 CAIRO_TRACE_END (__func__);
1452 slim_hidden_def (cairo_device_to_user);
1455 * cairo_device_to_user_distance:
1456 * @cr: a cairo context
1457 * @dx: X component of a distance vector (in/out parameter)
1458 * @dy: Y component of a distance vector (in/out parameter)
1460 * Transform a distance vector from device space to user space. This
1461 * function is similar to cairo_device_to_user() except that the
1462 * translation components of the inverse CTM will be ignored when
1463 * transforming (@dx,@dy).
1468 cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy)
1470 if (unlikely (cr->status))
1473 cr->backend->device_to_user_distance (cr, dx, dy);
1478 * @cr: a cairo context
1480 * Clears the current path. After this call there will be no path and
1486 cairo_new_path (cairo_t *cr)
1488 cairo_status_t status;
1490 if (unlikely (cr->status))
1493 status = cr->backend->new_path (cr);
1494 if (unlikely (status))
1495 _cairo_set_error (cr, status);
1497 slim_hidden_def(cairo_new_path);
1500 * cairo_new_sub_path:
1501 * @cr: a cairo context
1503 * Begin a new sub-path. Note that the existing path is not
1504 * affected. After this call there will be no current point.
1506 * In many cases, this call is not needed since new sub-paths are
1507 * frequently started with cairo_move_to().
1509 * A call to cairo_new_sub_path() is particularly useful when
1510 * beginning a new sub-path with one of the cairo_arc() calls. This
1511 * makes things easier as it is no longer necessary to manually
1512 * compute the arc's initial coordinates for a call to
1518 cairo_new_sub_path (cairo_t *cr)
1520 cairo_status_t status;
1522 if (unlikely (cr->status))
1525 status = cr->backend->new_sub_path (cr);
1526 if (unlikely (status))
1527 _cairo_set_error (cr, status);
1532 * @cr: a cairo context
1533 * @x: the X coordinate of the new position
1534 * @y: the Y coordinate of the new position
1536 * Begin a new sub-path. After this call the current point will be (@x,
1542 cairo_move_to (cairo_t *cr, double x, double y)
1544 cairo_status_t status;
1546 if (unlikely (cr->status))
1549 status = cr->backend->move_to (cr, x, y);
1550 if (unlikely (status))
1551 _cairo_set_error (cr, status);
1553 slim_hidden_def(cairo_move_to);
1558 * @cr: a cairo context
1559 * @x: the X coordinate of the end of the new line
1560 * @y: the Y coordinate of the end of the new line
1562 * Adds a line to the path from the current point to position (@x, @y)
1563 * in user-space coordinates. After this call the current point
1566 * If there is no current point before the call to cairo_line_to()
1567 * this function will behave as cairo_move_to(@cr, @x, @y).
1572 cairo_line_to (cairo_t *cr, double x, double y)
1574 cairo_status_t status;
1576 if (unlikely (cr->status))
1579 status = cr->backend->line_to (cr, x, y);
1580 if (unlikely (status))
1581 _cairo_set_error (cr, status);
1583 slim_hidden_def (cairo_line_to);
1587 * @cr: a cairo context
1588 * @x1: the X coordinate of the first control point
1589 * @y1: the Y coordinate of the first control point
1590 * @x2: the X coordinate of the second control point
1591 * @y2: the Y coordinate of the second control point
1592 * @x3: the X coordinate of the end of the curve
1593 * @y3: the Y coordinate of the end of the curve
1595 * Adds a cubic Bézier spline to the path from the current point to
1596 * position (@x3, @y3) in user-space coordinates, using (@x1, @y1) and
1597 * (@x2, @y2) as the control points. After this call the current point
1598 * will be (@x3, @y3).
1600 * If there is no current point before the call to cairo_curve_to()
1601 * this function will behave as if preceded by a call to
1602 * cairo_move_to(@cr, @x1, @y1).
1607 cairo_curve_to (cairo_t *cr,
1608 double x1, double y1,
1609 double x2, double y2,
1610 double x3, double y3)
1612 cairo_status_t status;
1614 if (unlikely (cr->status))
1617 status = cr->backend->curve_to (cr,
1621 if (unlikely (status))
1622 _cairo_set_error (cr, status);
1624 slim_hidden_def (cairo_curve_to);
1628 * @cr: a cairo context
1629 * @xc: X position of the center of the arc
1630 * @yc: Y position of the center of the arc
1631 * @radius: the radius of the arc
1632 * @angle1: the start angle, in radians
1633 * @angle2: the end angle, in radians
1635 * Adds a circular arc of the given @radius to the current path. The
1636 * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in
1637 * the direction of increasing angles to end at @angle2. If @angle2 is
1638 * less than @angle1 it will be progressively increased by
1639 * <literal>2*M_PI</literal> until it is greater than @angle1.
1641 * If there is a current point, an initial line segment will be added
1642 * to the path to connect the current point to the beginning of the
1643 * arc. If this initial line is undesired, it can be avoided by
1644 * calling cairo_new_sub_path() before calling cairo_arc().
1646 * Angles are measured in radians. An angle of 0.0 is in the direction
1647 * of the positive X axis (in user space). An angle of
1648 * <literal>M_PI/2.0</literal> radians (90 degrees) is in the
1649 * direction of the positive Y axis (in user space). Angles increase
1650 * in the direction from the positive X axis toward the positive Y
1651 * axis. So with the default transformation matrix, angles increase in
1652 * a clockwise direction.
1654 * (To convert from degrees to radians, use <literal>degrees * (M_PI /
1657 * This function gives the arc in the direction of increasing angles;
1658 * see cairo_arc_negative() to get the arc in the direction of
1659 * decreasing angles.
1661 * The arc is circular in user space. To achieve an elliptical arc,
1662 * you can scale the current transformation matrix by different
1663 * amounts in the X and Y directions. For example, to draw an ellipse
1664 * in the box given by @x, @y, @width, @height:
1666 * <informalexample><programlisting>
1668 * cairo_translate (cr, x + width / 2., y + height / 2.);
1669 * cairo_scale (cr, width / 2., height / 2.);
1670 * cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
1671 * cairo_restore (cr);
1672 * </programlisting></informalexample>
1677 cairo_arc (cairo_t *cr,
1678 double xc, double yc,
1680 double angle1, double angle2)
1682 CAIRO_TRACE_BEGIN (__func__);
1683 cairo_status_t status;
1685 if (unlikely (cr->status)) {
1686 CAIRO_TRACE_END (__func__);
1690 if (angle2 < angle1) {
1691 /* increase angle2 by multiples of full circle until it
1692 * satisfies angle2 >= angle1 */
1693 angle2 = fmod (angle2 - angle1, 2 * M_PI);
1699 status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, TRUE);
1700 if (unlikely (status))
1701 _cairo_set_error (cr, status);
1702 CAIRO_TRACE_END (__func__);
1706 * cairo_arc_negative:
1707 * @cr: a cairo context
1708 * @xc: X position of the center of the arc
1709 * @yc: Y position of the center of the arc
1710 * @radius: the radius of the arc
1711 * @angle1: the start angle, in radians
1712 * @angle2: the end angle, in radians
1714 * Adds a circular arc of the given @radius to the current path. The
1715 * arc is centered at (@xc, @yc), begins at @angle1 and proceeds in
1716 * the direction of decreasing angles to end at @angle2. If @angle2 is
1717 * greater than @angle1 it will be progressively decreased by
1718 * <literal>2*M_PI</literal> until it is less than @angle1.
1720 * See cairo_arc() for more details. This function differs only in the
1721 * direction of the arc between the two angles.
1726 cairo_arc_negative (cairo_t *cr,
1727 double xc, double yc,
1729 double angle1, double angle2)
1731 CAIRO_TRACE_BEGIN (__func__);
1732 cairo_status_t status;
1734 if (unlikely (cr->status)) {
1735 CAIRO_TRACE_END (__func__);
1739 if (angle2 > angle1) {
1740 /* decrease angle2 by multiples of full circle until it
1741 * satisfies angle2 <= angle1 */
1742 angle2 = fmod (angle2 - angle1, 2 * M_PI);
1748 status = cr->backend->arc (cr, xc, yc, radius, angle1, angle2, FALSE);
1749 if (unlikely (status))
1750 _cairo_set_error (cr, status);
1751 CAIRO_TRACE_END (__func__);
1756 cairo_arc_to (cairo_t *cr,
1757 double x1, double y1,
1758 double x2, double y2,
1761 cairo_status_t status;
1763 if (unlikely (cr->status))
1766 status = cr->backend->arc_to (cr, x1, y1, x2, y2, radius);
1767 if (unlikely (status))
1768 _cairo_set_error (cr, status);
1772 cairo_rel_arc_to (cairo_t *cr,
1773 double dx1, double dy1,
1774 double dx2, double dy2,
1777 cairo_status_t status;
1779 if (unlikely (cr->status))
1782 status = cr->backend->rel_arc_to (cr, dx1, dy1, dx2, dy2, radius);
1783 if (unlikely (status))
1784 _cairo_set_error (cr, status);
1789 * cairo_rel_move_to:
1790 * @cr: a cairo context
1794 * Begin a new sub-path. After this call the current point will offset
1797 * Given a current point of (x, y), cairo_rel_move_to(@cr, @dx, @dy)
1798 * is logically equivalent to cairo_move_to(@cr, x + @dx, y + @dy).
1800 * It is an error to call this function with no current point. Doing
1801 * so will cause @cr to shutdown with a status of
1802 * %CAIRO_STATUS_NO_CURRENT_POINT.
1807 cairo_rel_move_to (cairo_t *cr, double dx, double dy)
1809 cairo_status_t status;
1811 if (unlikely (cr->status))
1814 status = cr->backend->rel_move_to (cr, dx, dy);
1815 if (unlikely (status))
1816 _cairo_set_error (cr, status);
1820 * cairo_rel_line_to:
1821 * @cr: a cairo context
1822 * @dx: the X offset to the end of the new line
1823 * @dy: the Y offset to the end of the new line
1825 * Relative-coordinate version of cairo_line_to(). Adds a line to the
1826 * path from the current point to a point that is offset from the
1827 * current point by (@dx, @dy) in user space. After this call the
1828 * current point will be offset by (@dx, @dy).
1830 * Given a current point of (x, y), cairo_rel_line_to(@cr, @dx, @dy)
1831 * is logically equivalent to cairo_line_to(@cr, x + @dx, y + @dy).
1833 * It is an error to call this function with no current point. Doing
1834 * so will cause @cr to shutdown with a status of
1835 * %CAIRO_STATUS_NO_CURRENT_POINT.
1840 cairo_rel_line_to (cairo_t *cr, double dx, double dy)
1842 cairo_status_t status;
1844 if (unlikely (cr->status))
1847 status = cr->backend->rel_line_to (cr, dx, dy);
1848 if (unlikely (status))
1849 _cairo_set_error (cr, status);
1851 slim_hidden_def(cairo_rel_line_to);
1854 * cairo_rel_curve_to:
1855 * @cr: a cairo context
1856 * @dx1: the X offset to the first control point
1857 * @dy1: the Y offset to the first control point
1858 * @dx2: the X offset to the second control point
1859 * @dy2: the Y offset to the second control point
1860 * @dx3: the X offset to the end of the curve
1861 * @dy3: the Y offset to the end of the curve
1863 * Relative-coordinate version of cairo_curve_to(). All offsets are
1864 * relative to the current point. Adds a cubic Bézier spline to the
1865 * path from the current point to a point offset from the current
1866 * point by (@dx3, @dy3), using points offset by (@dx1, @dy1) and
1867 * (@dx2, @dy2) as the control points. After this call the current
1868 * point will be offset by (@dx3, @dy3).
1870 * Given a current point of (x, y), cairo_rel_curve_to(@cr, @dx1,
1871 * @dy1, @dx2, @dy2, @dx3, @dy3) is logically equivalent to
1872 * cairo_curve_to(@cr, x+@dx1, y+@dy1, x+@dx2, y+@dy2, x+@dx3, y+@dy3).
1874 * It is an error to call this function with no current point. Doing
1875 * so will cause @cr to shutdown with a status of
1876 * %CAIRO_STATUS_NO_CURRENT_POINT.
1881 cairo_rel_curve_to (cairo_t *cr,
1882 double dx1, double dy1,
1883 double dx2, double dy2,
1884 double dx3, double dy3)
1886 cairo_status_t status;
1888 if (unlikely (cr->status))
1891 status = cr->backend->rel_curve_to (cr,
1895 if (unlikely (status))
1896 _cairo_set_error (cr, status);
1901 * @cr: a cairo context
1902 * @x: the X coordinate of the top left corner of the rectangle
1903 * @y: the Y coordinate to the top left corner of the rectangle
1904 * @width: the width of the rectangle
1905 * @height: the height of the rectangle
1907 * Adds a closed sub-path rectangle of the given size to the current
1908 * path at position (@x, @y) in user-space coordinates.
1910 * This function is logically equivalent to:
1911 * <informalexample><programlisting>
1912 * cairo_move_to (cr, x, y);
1913 * cairo_rel_line_to (cr, width, 0);
1914 * cairo_rel_line_to (cr, 0, height);
1915 * cairo_rel_line_to (cr, -width, 0);
1916 * cairo_close_path (cr);
1917 * </programlisting></informalexample>
1922 cairo_rectangle (cairo_t *cr,
1924 double width, double height)
1926 CAIRO_TRACE_BEGIN (__func__);
1927 cairo_status_t status;
1929 if (unlikely (cr->status)) {
1930 CAIRO_TRACE_END (__func__);
1934 status = cr->backend->rectangle (cr, x, y, width, height);
1935 if (unlikely (status))
1936 _cairo_set_error (cr, status);
1937 CAIRO_TRACE_END (__func__);
1943 cairo_stroke_to_path (cairo_t *cr)
1945 cairo_status_t status;
1947 if (unlikely (cr->status))
1950 /* The code in _cairo_recording_surface_get_path has a poorman's stroke_to_path */
1952 status = _cairo_gstate_stroke_path (cr->gstate);
1953 if (unlikely (status))
1954 _cairo_set_error (cr, status);
1960 * @cr: a cairo context
1962 * Adds a line segment to the path from the current point to the
1963 * beginning of the current sub-path, (the most recent point passed to
1964 * cairo_move_to()), and closes this sub-path. After this call the
1965 * current point will be at the joined endpoint of the sub-path.
1967 * The behavior of cairo_close_path() is distinct from simply calling
1968 * cairo_line_to() with the equivalent coordinate in the case of
1969 * stroking. When a closed sub-path is stroked, there are no caps on
1970 * the ends of the sub-path. Instead, there is a line join connecting
1971 * the final and initial segments of the sub-path.
1973 * If there is no current point before the call to cairo_close_path(),
1974 * this function will have no effect.
1976 * Note: As of cairo version 1.2.4 any call to cairo_close_path() will
1977 * place an explicit MOVE_TO element into the path immediately after
1978 * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for
1979 * example). This can simplify path processing in some cases as it may
1980 * not be necessary to save the "last move_to point" during processing
1981 * as the MOVE_TO immediately after the CLOSE_PATH will provide that
1987 cairo_close_path (cairo_t *cr)
1989 cairo_status_t status;
1991 if (unlikely (cr->status))
1994 status = cr->backend->close_path (cr);
1995 if (unlikely (status))
1996 _cairo_set_error (cr, status);
1998 slim_hidden_def(cairo_close_path);
2001 * cairo_path_extents:
2002 * @cr: a cairo context
2003 * @x1: left of the resulting extents
2004 * @y1: top of the resulting extents
2005 * @x2: right of the resulting extents
2006 * @y2: bottom of the resulting extents
2008 * Computes a bounding box in user-space coordinates covering the
2009 * points on the current path. If the current path is empty, returns
2010 * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule,
2011 * surface dimensions and clipping are not taken into account.
2013 * Contrast with cairo_fill_extents() and cairo_stroke_extents() which
2014 * return the extents of only the area that would be "inked" by
2015 * the corresponding drawing operations.
2017 * The result of cairo_path_extents() is defined as equivalent to the
2018 * limit of cairo_stroke_extents() with %CAIRO_LINE_CAP_ROUND as the
2019 * line width approaches 0.0, (but never reaching the empty-rectangle
2020 * returned by cairo_stroke_extents() for a line width of 0.0).
2022 * Specifically, this means that zero-area sub-paths such as
2023 * cairo_move_to();cairo_line_to() segments, (even degenerate cases
2024 * where the coordinates to both calls are identical), will be
2025 * considered as contributing to the extents. However, a lone
2026 * cairo_move_to() will not contribute to the results of
2027 * cairo_path_extents().
2032 cairo_path_extents (cairo_t *cr,
2033 double *x1, double *y1, double *x2, double *y2)
2035 if (unlikely (cr->status)) {
2048 cr->backend->path_extents (cr, x1, y1, x2, y2);
2053 * @cr: a cairo context
2055 * A drawing operator that paints the current source everywhere within
2056 * the current clip region.
2061 cairo_paint (cairo_t *cr)
2063 CAIRO_TRACE_BEGIN (__func__);
2064 cairo_status_t status;
2066 if (unlikely (cr->status)) {
2067 CAIRO_TRACE_END (__func__);
2071 status = cr->backend->paint (cr);
2072 if (unlikely (status))
2073 _cairo_set_error (cr, status);
2074 CAIRO_TRACE_END (__func__);
2076 slim_hidden_def (cairo_paint);
2079 * cairo_paint_with_alpha:
2080 * @cr: a cairo context
2081 * @alpha: alpha value, between 0 (transparent) and 1 (opaque)
2083 * A drawing operator that paints the current source everywhere within
2084 * the current clip region using a mask of constant alpha value
2085 * @alpha. The effect is similar to cairo_paint(), but the drawing
2086 * is faded out using the alpha value.
2091 cairo_paint_with_alpha (cairo_t *cr,
2094 CAIRO_TRACE_BEGIN (__func__);
2095 cairo_status_t status;
2097 if (unlikely (cr->status)) {
2098 CAIRO_TRACE_END (__func__);
2102 status = cr->backend->paint_with_alpha (cr, alpha);
2103 if (unlikely (status))
2104 _cairo_set_error (cr, status);
2105 CAIRO_TRACE_END (__func__);
2110 * @cr: a cairo context
2111 * @pattern: a #cairo_pattern_t
2113 * A drawing operator that paints the current source
2114 * using the alpha channel of @pattern as a mask. (Opaque
2115 * areas of @pattern are painted with the source, transparent
2116 * areas are not painted.)
2121 cairo_mask (cairo_t *cr,
2122 cairo_pattern_t *pattern)
2124 CAIRO_TRACE_BEGIN (__func__);
2125 cairo_status_t status;
2127 if (unlikely (cr->status)) {
2128 CAIRO_TRACE_END (__func__);
2132 if (unlikely (pattern == NULL)) {
2133 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
2134 CAIRO_TRACE_END (__func__);
2138 if (unlikely (pattern->status)) {
2139 _cairo_set_error (cr, pattern->status);
2140 CAIRO_TRACE_END (__func__);
2144 status = cr->backend->mask (cr, pattern);
2145 if (unlikely (status))
2146 _cairo_set_error (cr, status);
2147 CAIRO_TRACE_END (__func__);
2149 slim_hidden_def (cairo_mask);
2152 * cairo_mask_surface:
2153 * @cr: a cairo context
2154 * @surface: a #cairo_surface_t
2155 * @surface_x: X coordinate at which to place the origin of @surface
2156 * @surface_y: Y coordinate at which to place the origin of @surface
2158 * A drawing operator that paints the current source
2159 * using the alpha channel of @surface as a mask. (Opaque
2160 * areas of @surface are painted with the source, transparent
2161 * areas are not painted.)
2166 cairo_mask_surface (cairo_t *cr,
2167 cairo_surface_t *surface,
2171 CAIRO_TRACE_BEGIN (__func__);
2172 cairo_pattern_t *pattern;
2173 cairo_matrix_t matrix;
2175 if (unlikely (cr->status)) {
2176 CAIRO_TRACE_END (__func__);
2180 pattern = cairo_pattern_create_for_surface (surface);
2182 cairo_matrix_init_translate (&matrix, - surface_x, - surface_y);
2183 cairo_pattern_set_matrix (pattern, &matrix);
2185 cairo_mask (cr, pattern);
2187 cairo_pattern_destroy (pattern);
2188 CAIRO_TRACE_END (__func__);
2193 * @cr: a cairo context
2195 * A drawing operator that strokes the current path according to the
2196 * current line width, line join, line cap, and dash settings. After
2197 * cairo_stroke(), the current path will be cleared from the cairo
2198 * context. See cairo_set_line_width(), cairo_set_line_join(),
2199 * cairo_set_line_cap(), cairo_set_dash(), and
2200 * cairo_stroke_preserve().
2202 * Note: Degenerate segments and sub-paths are treated specially and
2203 * provide a useful result. These can result in two different
2206 * 1. Zero-length "on" segments set in cairo_set_dash(). If the cap
2207 * style is %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE then these
2208 * segments will be drawn as circular dots or squares respectively. In
2209 * the case of %CAIRO_LINE_CAP_SQUARE, the orientation of the squares
2210 * is determined by the direction of the underlying path.
2212 * 2. A sub-path created by cairo_move_to() followed by either a
2213 * cairo_close_path() or one or more calls to cairo_line_to() to the
2214 * same coordinate as the cairo_move_to(). If the cap style is
2215 * %CAIRO_LINE_CAP_ROUND then these sub-paths will be drawn as circular
2216 * dots. Note that in the case of %CAIRO_LINE_CAP_SQUARE a degenerate
2217 * sub-path will not be drawn at all, (since the correct orientation
2218 * is indeterminate).
2220 * In no case will a cap style of %CAIRO_LINE_CAP_BUTT cause anything
2221 * to be drawn in the case of either degenerate segments or sub-paths.
2226 cairo_stroke (cairo_t *cr)
2228 CAIRO_TRACE_BEGIN (__func__);
2229 cairo_status_t status;
2231 if (unlikely (cr->status)) {
2232 CAIRO_TRACE_END (__func__);
2236 status = cr->backend->stroke (cr);
2237 if (unlikely (status))
2238 _cairo_set_error (cr, status);
2239 CAIRO_TRACE_END (__func__);
2241 slim_hidden_def(cairo_stroke);
2244 * cairo_stroke_preserve:
2245 * @cr: a cairo context
2247 * A drawing operator that strokes the current path according to the
2248 * current line width, line join, line cap, and dash settings. Unlike
2249 * cairo_stroke(), cairo_stroke_preserve() preserves the path within the
2252 * See cairo_set_line_width(), cairo_set_line_join(),
2253 * cairo_set_line_cap(), cairo_set_dash(), and
2254 * cairo_stroke_preserve().
2259 cairo_stroke_preserve (cairo_t *cr)
2261 CAIRO_TRACE_BEGIN (__func__);
2262 cairo_status_t status;
2264 if (unlikely (cr->status)) {
2265 CAIRO_TRACE_END (__func__);
2269 status = cr->backend->stroke_preserve (cr);
2270 if (unlikely (status))
2271 _cairo_set_error (cr, status);
2272 CAIRO_TRACE_END (__func__);
2274 slim_hidden_def(cairo_stroke_preserve);
2278 * @cr: a cairo context
2280 * A drawing operator that fills the current path according to the
2281 * current fill rule, (each sub-path is implicitly closed before being
2282 * filled). After cairo_fill(), the current path will be cleared from
2283 * the cairo context. See cairo_set_fill_rule() and
2284 * cairo_fill_preserve().
2289 cairo_fill (cairo_t *cr)
2291 CAIRO_TRACE_BEGIN (__func__);
2292 cairo_status_t status;
2294 if (unlikely (cr->status)) {
2295 CAIRO_TRACE_END (__func__);
2299 status = cr->backend->fill (cr);
2300 if (unlikely (status))
2301 _cairo_set_error (cr, status);
2302 CAIRO_TRACE_END (__func__);
2306 * cairo_fill_preserve:
2307 * @cr: a cairo context
2309 * A drawing operator that fills the current path according to the
2310 * current fill rule, (each sub-path is implicitly closed before being
2311 * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the
2312 * path within the cairo context.
2314 * See cairo_set_fill_rule() and cairo_fill().
2319 cairo_fill_preserve (cairo_t *cr)
2321 CAIRO_TRACE_BEGIN (__func__);
2322 cairo_status_t status;
2324 if (unlikely (cr->status)) {
2325 CAIRO_TRACE_END (__func__);
2329 status = cr->backend->fill_preserve (cr);
2330 if (unlikely (status))
2331 _cairo_set_error (cr, status);
2332 CAIRO_TRACE_END (__func__);
2334 slim_hidden_def(cairo_fill_preserve);
2338 * @cr: a cairo context
2340 * Emits the current page for backends that support multiple pages, but
2341 * doesn't clear it, so, the contents of the current page will be retained
2342 * for the next page too. Use cairo_show_page() if you want to get an
2343 * empty page after the emission.
2345 * This is a convenience function that simply calls
2346 * cairo_surface_copy_page() on @cr's target.
2351 cairo_copy_page (cairo_t *cr)
2353 cairo_status_t status;
2355 if (unlikely (cr->status))
2358 status = cr->backend->copy_page (cr);
2359 if (unlikely (status))
2360 _cairo_set_error (cr, status);
2365 * @cr: a cairo context
2367 * Emits and clears the current page for backends that support multiple
2368 * pages. Use cairo_copy_page() if you don't want to clear the page.
2370 * This is a convenience function that simply calls
2371 * cairo_surface_show_page() on @cr's target.
2376 cairo_show_page (cairo_t *cr)
2378 cairo_status_t status;
2380 if (unlikely (cr->status))
2383 status = cr->backend->show_page (cr);
2384 if (unlikely (status))
2385 _cairo_set_error (cr, status);
2390 * @cr: a cairo context
2391 * @x: X coordinate of the point to test
2392 * @y: Y coordinate of the point to test
2394 * Tests whether the given point is inside the area that would be
2395 * affected by a cairo_stroke() operation given the current path and
2396 * stroking parameters. Surface dimensions and clipping are not taken
2399 * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(),
2400 * cairo_set_line_cap(), cairo_set_dash(), and
2401 * cairo_stroke_preserve().
2403 * Return value: A non-zero value if the point is inside, or zero if
2409 cairo_in_stroke (cairo_t *cr, double x, double y)
2411 cairo_status_t status;
2412 cairo_bool_t inside = FALSE;
2414 if (unlikely (cr->status))
2417 status = cr->backend->in_stroke (cr, x, y, &inside);
2418 if (unlikely (status))
2419 _cairo_set_error (cr, status);
2426 * @cr: a cairo context
2427 * @x: X coordinate of the point to test
2428 * @y: Y coordinate of the point to test
2430 * Tests whether the given point is inside the area that would be
2431 * affected by a cairo_fill() operation given the current path and
2432 * filling parameters. Surface dimensions and clipping are not taken
2435 * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
2437 * Return value: A non-zero value if the point is inside, or zero if
2443 cairo_in_fill (cairo_t *cr, double x, double y)
2445 cairo_status_t status;
2446 cairo_bool_t inside = FALSE;
2448 if (unlikely (cr->status))
2451 status = cr->backend->in_fill (cr, x, y, &inside);
2452 if (unlikely (status))
2453 _cairo_set_error (cr, status);
2459 * cairo_stroke_extents:
2460 * @cr: a cairo context
2461 * @x1: left of the resulting extents
2462 * @y1: top of the resulting extents
2463 * @x2: right of the resulting extents
2464 * @y2: bottom of the resulting extents
2466 * Computes a bounding box in user coordinates covering the area that
2467 * would be affected, (the "inked" area), by a cairo_stroke()
2468 * operation given the current path and stroke parameters.
2469 * If the current path is empty, returns an empty rectangle ((0,0), (0,0)).
2470 * Surface dimensions and clipping are not taken into account.
2472 * Note that if the line width is set to exactly zero, then
2473 * cairo_stroke_extents() will return an empty rectangle. Contrast with
2474 * cairo_path_extents() which can be used to compute the non-empty
2475 * bounds as the line width approaches zero.
2477 * Note that cairo_stroke_extents() must necessarily do more work to
2478 * compute the precise inked areas in light of the stroke parameters,
2479 * so cairo_path_extents() may be more desirable for sake of
2480 * performance if non-inked path extents are desired.
2482 * See cairo_stroke(), cairo_set_line_width(), cairo_set_line_join(),
2483 * cairo_set_line_cap(), cairo_set_dash(), and
2484 * cairo_stroke_preserve().
2489 cairo_stroke_extents (cairo_t *cr,
2490 double *x1, double *y1, double *x2, double *y2)
2492 CAIRO_TRACE_BEGIN (__func__);
2493 cairo_status_t status;
2495 if (unlikely (cr->status)) {
2505 CAIRO_TRACE_END (__func__);
2509 status = cr->backend->stroke_extents (cr, x1, y1, x2, y2);
2510 if (unlikely (status))
2511 _cairo_set_error (cr, status);
2512 CAIRO_TRACE_END (__func__);
2516 * cairo_fill_extents:
2517 * @cr: a cairo context
2518 * @x1: left of the resulting extents
2519 * @y1: top of the resulting extents
2520 * @x2: right of the resulting extents
2521 * @y2: bottom of the resulting extents
2523 * Computes a bounding box in user coordinates covering the area that
2524 * would be affected, (the "inked" area), by a cairo_fill() operation
2525 * given the current path and fill parameters. If the current path is
2526 * empty, returns an empty rectangle ((0,0), (0,0)). Surface
2527 * dimensions and clipping are not taken into account.
2529 * Contrast with cairo_path_extents(), which is similar, but returns
2530 * non-zero extents for some paths with no inked area, (such as a
2531 * simple line segment).
2533 * Note that cairo_fill_extents() must necessarily do more work to
2534 * compute the precise inked areas in light of the fill rule, so
2535 * cairo_path_extents() may be more desirable for sake of performance
2536 * if the non-inked path extents are desired.
2538 * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
2543 cairo_fill_extents (cairo_t *cr,
2544 double *x1, double *y1, double *x2, double *y2)
2546 CAIRO_TRACE_BEGIN (__func__);
2547 cairo_status_t status;
2549 if (unlikely (cr->status)) {
2559 CAIRO_TRACE_END (__func__);
2563 status = cr->backend->fill_extents (cr, x1, y1, x2, y2);
2564 if (unlikely (status))
2565 _cairo_set_error (cr, status);
2566 CAIRO_TRACE_END (__func__);
2571 * @cr: a cairo context
2573 * Establishes a new clip region by intersecting the current clip
2574 * region with the current path as it would be filled by cairo_fill()
2575 * and according to the current fill rule (see cairo_set_fill_rule()).
2577 * After cairo_clip(), the current path will be cleared from the cairo
2580 * The current clip region affects all drawing operations by
2581 * effectively masking out any changes to the surface that are outside
2582 * the current clip region.
2584 * Calling cairo_clip() can only make the clip region smaller, never
2585 * larger. But the current clip is part of the graphics state, so a
2586 * temporary restriction of the clip region can be achieved by
2587 * calling cairo_clip() within a cairo_save()/cairo_restore()
2588 * pair. The only other means of increasing the size of the clip
2589 * region is cairo_reset_clip().
2594 cairo_clip (cairo_t *cr)
2596 cairo_status_t status;
2598 if (unlikely (cr->status))
2601 status = cr->backend->clip (cr);
2602 if (unlikely (status))
2603 _cairo_set_error (cr, status);
2607 * cairo_clip_preserve:
2608 * @cr: a cairo context
2610 * Establishes a new clip region by intersecting the current clip
2611 * region with the current path as it would be filled by cairo_fill()
2612 * and according to the current fill rule (see cairo_set_fill_rule()).
2614 * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within
2615 * the cairo context.
2617 * The current clip region affects all drawing operations by
2618 * effectively masking out any changes to the surface that are outside
2619 * the current clip region.
2621 * Calling cairo_clip_preserve() can only make the clip region smaller, never
2622 * larger. But the current clip is part of the graphics state, so a
2623 * temporary restriction of the clip region can be achieved by
2624 * calling cairo_clip_preserve() within a cairo_save()/cairo_restore()
2625 * pair. The only other means of increasing the size of the clip
2626 * region is cairo_reset_clip().
2631 cairo_clip_preserve (cairo_t *cr)
2633 cairo_status_t status;
2635 if (unlikely (cr->status))
2638 status = cr->backend->clip_preserve (cr);
2639 if (unlikely (status))
2640 _cairo_set_error (cr, status);
2642 slim_hidden_def(cairo_clip_preserve);
2646 * @cr: a cairo context
2648 * Reset the current clip region to its original, unrestricted
2649 * state. That is, set the clip region to an infinitely large shape
2650 * containing the target surface. Equivalently, if infinity is too
2651 * hard to grasp, one can imagine the clip region being reset to the
2652 * exact bounds of the target surface.
2654 * Note that code meant to be reusable should not call
2655 * cairo_reset_clip() as it will cause results unexpected by
2656 * higher-level code which calls cairo_clip(). Consider using
2657 * cairo_save() and cairo_restore() around cairo_clip() as a more
2658 * robust means of temporarily restricting the clip region.
2663 cairo_reset_clip (cairo_t *cr)
2665 cairo_status_t status;
2667 if (unlikely (cr->status))
2670 status = cr->backend->reset_clip (cr);
2671 if (unlikely (status))
2672 _cairo_set_error (cr, status);
2676 * cairo_clip_extents:
2677 * @cr: a cairo context
2678 * @x1: left of the resulting extents
2679 * @y1: top of the resulting extents
2680 * @x2: right of the resulting extents
2681 * @y2: bottom of the resulting extents
2683 * Computes a bounding box in user coordinates covering the area inside the
2689 cairo_clip_extents (cairo_t *cr,
2690 double *x1, double *y1,
2691 double *x2, double *y2)
2693 CAIRO_TRACE_BEGIN (__func__);
2694 cairo_status_t status;
2705 if (unlikely (cr->status)) {
2706 CAIRO_TRACE_END (__func__);
2710 status = cr->backend->clip_extents (cr, x1, y1, x2, y2);
2711 if (unlikely (status))
2712 _cairo_set_error (cr, status);
2713 CAIRO_TRACE_END (__func__);
2718 * @cr: a cairo context
2719 * @x: X coordinate of the point to test
2720 * @y: Y coordinate of the point to test
2722 * Tests whether the given point is inside the area that would be
2723 * visible through the current clip, i.e. the area that would be filled by
2724 * a cairo_paint() operation.
2726 * See cairo_clip(), and cairo_clip_preserve().
2728 * Return value: A non-zero value if the point is inside, or zero if
2734 cairo_in_clip (cairo_t *cr, double x, double y)
2736 cairo_status_t status;
2737 cairo_bool_t inside = FALSE;
2739 if (unlikely (cr->status))
2742 status = cr->backend->in_clip (cr, x, y, &inside);
2743 if (unlikely (status))
2744 _cairo_set_error (cr, status);
2750 * cairo_copy_clip_rectangle_list:
2751 * @cr: a cairo context
2753 * Gets the current clip region as a list of rectangles in user coordinates.
2754 * Never returns %NULL.
2756 * The status in the list may be %CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to
2757 * indicate that the clip region cannot be represented as a list of
2758 * user-space rectangles. The status may have other values to indicate
2761 * Returns: the current clip region as a list of rectangles in user coordinates,
2762 * which should be destroyed using cairo_rectangle_list_destroy().
2766 cairo_rectangle_list_t *
2767 cairo_copy_clip_rectangle_list (cairo_t *cr)
2769 if (unlikely (cr->status))
2770 return _cairo_rectangle_list_create_in_error (cr->status);
2772 return cr->backend->clip_copy_rectangle_list (cr);
2776 * cairo_select_font_face:
2778 * @family: a font family name, encoded in UTF-8
2779 * @slant: the slant for the font
2780 * @weight: the weight for the font
2782 * Note: The cairo_select_font_face() function call is part of what
2783 * the cairo designers call the "toy" text API. It is convenient for
2784 * short demos and simple programs, but it is not expected to be
2785 * adequate for serious text-using applications.
2787 * Selects a family and style of font from a simplified description as
2788 * a family name, slant and weight. Cairo provides no operation to
2789 * list available family names on the system (this is a "toy",
2790 * remember), but the standard CSS2 generic family names, ("serif",
2791 * "sans-serif", "cursive", "fantasy", "monospace"), are likely to
2794 * If @family starts with the string "@cairo:", or if no native font
2795 * backends are compiled in, cairo will use an internal font family.
2796 * The internal font family recognizes many modifiers in the @family
2797 * string, most notably, it recognizes the string "monospace". That is,
2798 * the family name "@cairo:monospace" will use the monospace version of
2799 * the internal font family.
2801 * For "real" font selection, see the font-backend-specific
2802 * font_face_create functions for the font backend you are using. (For
2803 * example, if you are using the freetype-based cairo-ft font backend,
2804 * see cairo_ft_font_face_create_for_ft_face() or
2805 * cairo_ft_font_face_create_for_pattern().) The resulting font face
2806 * could then be used with cairo_scaled_font_create() and
2807 * cairo_set_scaled_font().
2809 * Similarly, when using the "real" font support, you can call
2810 * directly into the underlying font system, (such as fontconfig or
2811 * freetype), for operations such as listing available fonts, etc.
2813 * It is expected that most applications will need to use a more
2814 * comprehensive font handling and text layout library, (for example,
2815 * pango), in conjunction with cairo.
2817 * If text is drawn without a call to cairo_select_font_face(), (nor
2818 * cairo_set_font_face() nor cairo_set_scaled_font()), the default
2819 * family is platform-specific, but is essentially "sans-serif".
2820 * Default slant is %CAIRO_FONT_SLANT_NORMAL, and default weight is
2821 * %CAIRO_FONT_WEIGHT_NORMAL.
2823 * This function is equivalent to a call to cairo_toy_font_face_create()
2824 * followed by cairo_set_font_face().
2829 cairo_select_font_face (cairo_t *cr,
2831 cairo_font_slant_t slant,
2832 cairo_font_weight_t weight)
2834 cairo_font_face_t *font_face;
2835 cairo_status_t status;
2837 if (unlikely (cr->status))
2840 font_face = cairo_toy_font_face_create (family, slant, weight);
2841 if (unlikely (font_face->status)) {
2842 _cairo_set_error (cr, font_face->status);
2846 status = cr->backend->set_font_face (cr, font_face);
2847 cairo_font_face_destroy (font_face);
2849 if (unlikely (status))
2850 _cairo_set_error (cr, status);
2854 * cairo_font_extents:
2856 * @extents: a #cairo_font_extents_t object into which the results
2859 * Gets the font extents for the currently selected font.
2864 cairo_font_extents (cairo_t *cr,
2865 cairo_font_extents_t *extents)
2867 cairo_status_t status;
2869 extents->ascent = 0.0;
2870 extents->descent = 0.0;
2871 extents->height = 0.0;
2872 extents->max_x_advance = 0.0;
2873 extents->max_y_advance = 0.0;
2875 if (unlikely (cr->status))
2878 status = cr->backend->font_extents (cr, extents);
2879 if (unlikely (status))
2880 _cairo_set_error (cr, status);
2884 * cairo_set_font_face:
2886 * @font_face: a #cairo_font_face_t, or %NULL to restore to the default font
2888 * Replaces the current #cairo_font_face_t object in the #cairo_t with
2889 * @font_face. The replaced font face in the #cairo_t will be
2890 * destroyed if there are no other references to it.
2895 cairo_set_font_face (cairo_t *cr,
2896 cairo_font_face_t *font_face)
2898 cairo_status_t status;
2900 if (unlikely (cr->status))
2903 status = cr->backend->set_font_face (cr, font_face);
2904 if (unlikely (status))
2905 _cairo_set_error (cr, status);
2909 * cairo_get_font_face:
2912 * Gets the current font face for a #cairo_t.
2914 * Return value: the current font face. This object is owned by
2915 * cairo. To keep a reference to it, you must call
2916 * cairo_font_face_reference().
2918 * This function never returns %NULL. If memory cannot be allocated, a
2919 * special "nil" #cairo_font_face_t object will be returned on which
2920 * cairo_font_face_status() returns %CAIRO_STATUS_NO_MEMORY. Using
2921 * this nil object will cause its error state to propagate to other
2922 * objects it is passed to, (for example, calling
2923 * cairo_set_font_face() with a nil font will trigger an error that
2924 * will shutdown the #cairo_t object).
2929 cairo_get_font_face (cairo_t *cr)
2931 if (unlikely (cr->status))
2932 return (cairo_font_face_t*) &_cairo_font_face_nil;
2934 return cr->backend->get_font_face (cr);
2938 * cairo_set_font_size:
2940 * @size: the new font size, in user space units
2942 * Sets the current font matrix to a scale by a factor of @size, replacing
2943 * any font matrix previously set with cairo_set_font_size() or
2944 * cairo_set_font_matrix(). This results in a font size of @size user space
2945 * units. (More precisely, this matrix will result in the font's
2946 * em-square being a @size by @size square in user space.)
2948 * If text is drawn without a call to cairo_set_font_size(), (nor
2949 * cairo_set_font_matrix() nor cairo_set_scaled_font()), the default
2950 * font size is 10.0.
2955 cairo_set_font_size (cairo_t *cr, double size)
2957 cairo_status_t status;
2959 if (unlikely (cr->status))
2962 status = cr->backend->set_font_size (cr, size);
2963 if (unlikely (status))
2964 _cairo_set_error (cr, status);
2966 slim_hidden_def (cairo_set_font_size);
2969 * cairo_set_font_matrix:
2971 * @matrix: a #cairo_matrix_t describing a transform to be applied to
2974 * Sets the current font matrix to @matrix. The font matrix gives a
2975 * transformation from the design space of the font (in this space,
2976 * the em-square is 1 unit by 1 unit) to user space. Normally, a
2977 * simple scale is used (see cairo_set_font_size()), but a more
2978 * complex font matrix can be used to shear the font
2979 * or stretch it unequally along the two axes
2984 cairo_set_font_matrix (cairo_t *cr,
2985 const cairo_matrix_t *matrix)
2987 cairo_status_t status;
2989 if (unlikely (cr->status))
2992 status = cr->backend->set_font_matrix (cr, matrix);
2993 if (unlikely (status))
2994 _cairo_set_error (cr, status);
2996 slim_hidden_def (cairo_set_font_matrix);
2999 * cairo_get_font_matrix:
3001 * @matrix: return value for the matrix
3003 * Stores the current font matrix into @matrix. See
3004 * cairo_set_font_matrix().
3009 cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix)
3011 if (unlikely (cr->status)) {
3012 cairo_matrix_init_identity (matrix);
3016 cr->backend->get_font_matrix (cr, matrix);
3020 * cairo_set_font_options:
3022 * @options: font options to use
3024 * Sets a set of custom font rendering options for the #cairo_t.
3025 * Rendering options are derived by merging these options with the
3026 * options derived from underlying surface; if the value in @options
3027 * has a default value (like %CAIRO_ANTIALIAS_DEFAULT), then the value
3028 * from the surface is used.
3033 cairo_set_font_options (cairo_t *cr,
3034 const cairo_font_options_t *options)
3036 cairo_status_t status;
3038 if (unlikely (cr->status))
3041 status = cairo_font_options_status ((cairo_font_options_t *) options);
3042 if (unlikely (status)) {
3043 _cairo_set_error (cr, status);
3047 status = cr->backend->set_font_options (cr, options);
3048 if (unlikely (status))
3049 _cairo_set_error (cr, status);
3051 slim_hidden_def (cairo_set_font_options);
3054 * cairo_get_font_options:
3056 * @options: a #cairo_font_options_t object into which to store
3057 * the retrieved options. All existing values are overwritten
3059 * Retrieves font rendering options set via #cairo_set_font_options.
3060 * Note that the returned options do not include any options derived
3061 * from the underlying surface; they are literally the options
3062 * passed to cairo_set_font_options().
3067 cairo_get_font_options (cairo_t *cr,
3068 cairo_font_options_t *options)
3070 /* check that we aren't trying to overwrite the nil object */
3071 if (cairo_font_options_status (options))
3074 if (unlikely (cr->status)) {
3075 _cairo_font_options_init_default (options);
3079 cr->backend->get_font_options (cr, options);
3083 * cairo_set_scaled_font:
3085 * @scaled_font: a #cairo_scaled_font_t
3087 * Replaces the current font face, font matrix, and font options in
3088 * the #cairo_t with those of the #cairo_scaled_font_t. Except for
3089 * some translation, the current CTM of the #cairo_t should be the
3090 * same as that of the #cairo_scaled_font_t, which can be accessed
3091 * using cairo_scaled_font_get_ctm().
3096 cairo_set_scaled_font (cairo_t *cr,
3097 const cairo_scaled_font_t *scaled_font)
3099 cairo_status_t status;
3101 if (unlikely (cr->status))
3104 if ((scaled_font == NULL)) {
3105 _cairo_set_error (cr, _cairo_error (CAIRO_STATUS_NULL_POINTER));
3109 status = scaled_font->status;
3110 if (unlikely (status)) {
3111 _cairo_set_error (cr, status);
3115 status = cr->backend->set_scaled_font (cr, (cairo_scaled_font_t *) scaled_font);
3116 if (unlikely (status))
3117 _cairo_set_error (cr, status);
3121 * cairo_get_scaled_font:
3124 * Gets the current scaled font for a #cairo_t.
3126 * Return value: the current scaled font. This object is owned by
3127 * cairo. To keep a reference to it, you must call
3128 * cairo_scaled_font_reference().
3130 * This function never returns %NULL. If memory cannot be allocated, a
3131 * special "nil" #cairo_scaled_font_t object will be returned on which
3132 * cairo_scaled_font_status() returns %CAIRO_STATUS_NO_MEMORY. Using
3133 * this nil object will cause its error state to propagate to other
3134 * objects it is passed to, (for example, calling
3135 * cairo_set_scaled_font() with a nil font will trigger an error that
3136 * will shutdown the #cairo_t object).
3140 cairo_scaled_font_t *
3141 cairo_get_scaled_font (cairo_t *cr)
3143 if (unlikely (cr->status))
3144 return _cairo_scaled_font_create_in_error (cr->status);
3146 return cr->backend->get_scaled_font (cr);
3148 slim_hidden_def (cairo_get_scaled_font);
3151 * cairo_text_extents:
3153 * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3154 * @extents: a #cairo_text_extents_t object into which the results
3157 * Gets the extents for a string of text. The extents describe a
3158 * user-space rectangle that encloses the "inked" portion of the text,
3159 * (as it would be drawn by cairo_show_text()). Additionally, the
3160 * x_advance and y_advance values indicate the amount by which the
3161 * current point would be advanced by cairo_show_text().
3163 * Note that whitespace characters do not directly contribute to the
3164 * size of the rectangle (extents.width and extents.height). They do
3165 * contribute indirectly by changing the position of non-whitespace
3166 * characters. In particular, trailing whitespace characters are
3167 * likely to not affect the size of the rectangle, though they will
3168 * affect the x_advance and y_advance values.
3173 cairo_text_extents (cairo_t *cr,
3175 cairo_text_extents_t *extents)
3177 cairo_status_t status;
3178 cairo_scaled_font_t *scaled_font;
3179 cairo_glyph_t *glyphs = NULL;
3183 extents->x_bearing = 0.0;
3184 extents->y_bearing = 0.0;
3185 extents->width = 0.0;
3186 extents->height = 0.0;
3187 extents->x_advance = 0.0;
3188 extents->y_advance = 0.0;
3190 if (unlikely (cr->status))
3196 scaled_font = cairo_get_scaled_font (cr);
3197 if (unlikely (scaled_font->status)) {
3198 _cairo_set_error (cr, scaled_font->status);
3202 cairo_get_current_point (cr, &x, &y);
3203 status = cairo_scaled_font_text_to_glyphs (scaled_font,
3206 &glyphs, &num_glyphs,
3209 if (likely (status == CAIRO_STATUS_SUCCESS)) {
3210 status = cr->backend->glyph_extents (cr,
3214 cairo_glyph_free (glyphs);
3216 if (unlikely (status))
3217 _cairo_set_error (cr, status);
3221 * cairo_glyph_extents:
3223 * @glyphs: an array of #cairo_glyph_t objects
3224 * @num_glyphs: the number of elements in @glyphs
3225 * @extents: a #cairo_text_extents_t object into which the results
3228 * Gets the extents for an array of glyphs. The extents describe a
3229 * user-space rectangle that encloses the "inked" portion of the
3230 * glyphs, (as they would be drawn by cairo_show_glyphs()).
3231 * Additionally, the x_advance and y_advance values indicate the
3232 * amount by which the current point would be advanced by
3233 * cairo_show_glyphs().
3235 * Note that whitespace glyphs do not contribute to the size of the
3236 * rectangle (extents.width and extents.height).
3241 cairo_glyph_extents (cairo_t *cr,
3242 const cairo_glyph_t *glyphs,
3244 cairo_text_extents_t *extents)
3246 cairo_status_t status;
3248 extents->x_bearing = 0.0;
3249 extents->y_bearing = 0.0;
3250 extents->width = 0.0;
3251 extents->height = 0.0;
3252 extents->x_advance = 0.0;
3253 extents->y_advance = 0.0;
3255 if (unlikely (cr->status))
3258 if (num_glyphs == 0)
3261 if (unlikely (num_glyphs < 0)) {
3262 _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3266 if (unlikely (glyphs == NULL)) {
3267 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3271 status = cr->backend->glyph_extents (cr, glyphs, num_glyphs, extents);
3272 if (unlikely (status))
3273 _cairo_set_error (cr, status);
3278 * @cr: a cairo context
3279 * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3281 * A drawing operator that generates the shape from a string of UTF-8
3282 * characters, rendered according to the current font_face, font_size
3283 * (font_matrix), and font_options.
3285 * This function first computes a set of glyphs for the string of
3286 * text. The first glyph is placed so that its origin is at the
3287 * current point. The origin of each subsequent glyph is offset from
3288 * that of the previous glyph by the advance values of the previous
3291 * After this call the current point is moved to the origin of where
3292 * the next glyph would be placed in this same progression. That is,
3293 * the current point will be at the origin of the final glyph offset
3294 * by its advance values. This allows for easy display of a single
3295 * logical string with multiple calls to cairo_show_text().
3297 * Note: The cairo_show_text() function call is part of what the cairo
3298 * designers call the "toy" text API. It is convenient for short demos
3299 * and simple programs, but it is not expected to be adequate for
3300 * serious text-using applications. See cairo_show_glyphs() for the
3301 * "real" text display API in cairo.
3306 cairo_show_text (cairo_t *cr, const char *utf8)
3308 CAIRO_TRACE_BEGIN (__func__);
3309 cairo_text_extents_t extents;
3310 cairo_status_t status;
3311 cairo_glyph_t *glyphs, *last_glyph;
3312 cairo_text_cluster_t *clusters;
3313 int utf8_len, num_glyphs, num_clusters;
3314 cairo_text_cluster_flags_t cluster_flags;
3316 cairo_bool_t has_show_text_glyphs;
3317 cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
3318 cairo_text_cluster_t stack_clusters[CAIRO_STACK_ARRAY_LENGTH (cairo_text_cluster_t)];
3319 cairo_scaled_font_t *scaled_font;
3320 cairo_glyph_text_info_t info, *i;
3322 if (unlikely (cr->status)) {
3323 CAIRO_TRACE_END (__func__);
3328 CAIRO_TRACE_END (__func__);
3332 scaled_font = cairo_get_scaled_font (cr);
3333 if (unlikely (scaled_font->status)) {
3334 _cairo_set_error (cr, scaled_font->status);
3335 CAIRO_TRACE_END (__func__);
3339 utf8_len = strlen (utf8);
3341 has_show_text_glyphs =
3342 cairo_surface_has_show_text_glyphs (cairo_get_target (cr));
3344 glyphs = stack_glyphs;
3345 num_glyphs = ARRAY_LENGTH (stack_glyphs);
3347 if (has_show_text_glyphs) {
3348 clusters = stack_clusters;
3349 num_clusters = ARRAY_LENGTH (stack_clusters);
3355 cairo_get_current_point (cr, &x, &y);
3356 status = cairo_scaled_font_text_to_glyphs (scaled_font,
3359 &glyphs, &num_glyphs,
3360 has_show_text_glyphs ? &clusters : NULL, &num_clusters,
3362 if (unlikely (status))
3365 if (num_glyphs == 0) {
3366 CAIRO_TRACE_END (__func__);
3371 if (has_show_text_glyphs) {
3373 info.utf8_len = utf8_len;
3374 info.clusters = clusters;
3375 info.num_clusters = num_clusters;
3376 info.cluster_flags = cluster_flags;
3380 status = cr->backend->glyphs (cr, glyphs, num_glyphs, i);
3381 if (unlikely (status))
3384 last_glyph = &glyphs[num_glyphs - 1];
3385 status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents);
3386 if (unlikely (status))
3389 x = last_glyph->x + extents.x_advance;
3390 y = last_glyph->y + extents.y_advance;
3391 cr->backend->move_to (cr, x, y);
3394 if (glyphs != stack_glyphs)
3395 cairo_glyph_free (glyphs);
3396 if (clusters != stack_clusters)
3397 cairo_text_cluster_free (clusters);
3399 if (unlikely (status))
3400 _cairo_set_error (cr, status);
3401 CAIRO_TRACE_END (__func__);
3405 * cairo_show_glyphs:
3406 * @cr: a cairo context
3407 * @glyphs: array of glyphs to show
3408 * @num_glyphs: number of glyphs to show
3410 * A drawing operator that generates the shape from an array of glyphs,
3411 * rendered according to the current font face, font size
3412 * (font matrix), and font options.
3417 cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
3419 CAIRO_TRACE_BEGIN (__func__);
3420 cairo_status_t status;
3422 if (unlikely (cr->status)) {
3423 CAIRO_TRACE_END (__func__);
3427 if (num_glyphs == 0) {
3428 CAIRO_TRACE_END (__func__);
3432 if (num_glyphs < 0) {
3433 _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3434 CAIRO_TRACE_END (__func__);
3438 if (glyphs == NULL) {
3439 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3440 CAIRO_TRACE_END (__func__);
3444 status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL);
3445 if (unlikely (status))
3446 _cairo_set_error (cr, status);
3447 CAIRO_TRACE_END (__func__);
3451 * cairo_show_text_glyphs:
3452 * @cr: a cairo context
3453 * @utf8: a string of text encoded in UTF-8
3454 * @utf8_len: length of @utf8 in bytes, or -1 if it is NUL-terminated
3455 * @glyphs: array of glyphs to show
3456 * @num_glyphs: number of glyphs to show
3457 * @clusters: array of cluster mapping information
3458 * @num_clusters: number of clusters in the mapping
3459 * @cluster_flags: cluster mapping flags
3461 * This operation has rendering effects similar to cairo_show_glyphs()
3462 * but, if the target surface supports it, uses the provided text and
3463 * cluster mapping to embed the text for the glyphs shown in the output.
3464 * If the target does not support the extended attributes, this function
3465 * acts like the basic cairo_show_glyphs() as if it had been passed
3466 * @glyphs and @num_glyphs.
3468 * The mapping between @utf8 and @glyphs is provided by an array of
3469 * <firstterm>clusters</firstterm>. Each cluster covers a number of
3470 * text bytes and glyphs, and neighboring clusters cover neighboring
3471 * areas of @utf8 and @glyphs. The clusters should collectively cover @utf8
3472 * and @glyphs in entirety.
3474 * The first cluster always covers bytes from the beginning of @utf8.
3475 * If @cluster_flags do not have the %CAIRO_TEXT_CLUSTER_FLAG_BACKWARD
3476 * set, the first cluster also covers the beginning
3477 * of @glyphs, otherwise it covers the end of the @glyphs array and
3478 * following clusters move backward.
3480 * See #cairo_text_cluster_t for constraints on valid clusters.
3485 cairo_show_text_glyphs (cairo_t *cr,
3488 const cairo_glyph_t *glyphs,
3490 const cairo_text_cluster_t *clusters,
3492 cairo_text_cluster_flags_t cluster_flags)
3494 CAIRO_TRACE_BEGIN (__func__);
3495 cairo_status_t status;
3497 if (unlikely (cr->status)) {
3498 CAIRO_TRACE_END (__func__);
3502 /* A slew of sanity checks */
3504 /* Special case for NULL and -1 */
3505 if (utf8 == NULL && utf8_len == -1)
3508 /* No NULLs for non-zeros */
3509 if ((num_glyphs && glyphs == NULL) ||
3510 (utf8_len && utf8 == NULL) ||
3511 (num_clusters && clusters == NULL)) {
3512 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3513 CAIRO_TRACE_END (__func__);
3517 /* A -1 for utf8_len means NUL-terminated */
3519 utf8_len = strlen (utf8);
3521 /* Apart from that, no negatives */
3522 if (num_glyphs < 0 || utf8_len < 0 || num_clusters < 0) {
3523 _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3524 CAIRO_TRACE_END (__func__);
3528 if (num_glyphs == 0 && utf8_len == 0) {
3529 CAIRO_TRACE_END (__func__);
3534 /* Make sure clusters cover the entire glyphs and utf8 arrays,
3535 * and that cluster boundaries are UTF-8 boundaries. */
3536 status = _cairo_validate_text_clusters (utf8, utf8_len,
3538 clusters, num_clusters, cluster_flags);
3539 if (status == CAIRO_STATUS_INVALID_CLUSTERS) {
3540 /* Either got invalid UTF-8 text, or cluster mapping is bad.
3541 * Differentiate those. */
3543 cairo_status_t status2;
3545 status2 = _cairo_utf8_to_ucs4 (utf8, utf8_len, NULL, NULL);
3549 cairo_glyph_text_info_t info;
3552 info.utf8_len = utf8_len;
3553 info.clusters = clusters;
3554 info.num_clusters = num_clusters;
3555 info.cluster_flags = cluster_flags;
3557 status = cr->backend->glyphs (cr, glyphs, num_glyphs, &info);
3560 status = cr->backend->glyphs (cr, glyphs, num_glyphs, NULL);
3562 if (unlikely (status))
3563 _cairo_set_error (cr, status);
3564 CAIRO_TRACE_END (__func__);
3569 * @cr: a cairo context
3570 * @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL
3572 * Adds closed paths for text to the current path. The generated
3573 * path if filled, achieves an effect similar to that of
3574 * cairo_show_text().
3576 * Text conversion and positioning is done similar to cairo_show_text().
3578 * Like cairo_show_text(), After this call the current point is
3579 * moved to the origin of where the next glyph would be placed in
3580 * this same progression. That is, the current point will be at
3581 * the origin of the final glyph offset by its advance values.
3582 * This allows for chaining multiple calls to to cairo_text_path()
3583 * without having to set current point in between.
3585 * Note: The cairo_text_path() function call is part of what the cairo
3586 * designers call the "toy" text API. It is convenient for short demos
3587 * and simple programs, but it is not expected to be adequate for
3588 * serious text-using applications. See cairo_glyph_path() for the
3589 * "real" text path API in cairo.
3594 cairo_text_path (cairo_t *cr, const char *utf8)
3596 CAIRO_TRACE_BEGIN (__func__);
3597 cairo_status_t status;
3598 cairo_text_extents_t extents;
3599 cairo_glyph_t stack_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
3600 cairo_glyph_t *glyphs, *last_glyph;
3601 cairo_scaled_font_t *scaled_font;
3605 if (unlikely (cr->status)) {
3606 CAIRO_TRACE_END (__func__);
3611 CAIRO_TRACE_END (__func__);
3616 glyphs = stack_glyphs;
3617 num_glyphs = ARRAY_LENGTH (stack_glyphs);
3619 scaled_font = cairo_get_scaled_font (cr);
3620 if (unlikely (scaled_font->status)) {
3621 _cairo_set_error (cr, scaled_font->status);
3622 CAIRO_TRACE_END (__func__);
3626 cairo_get_current_point (cr, &x, &y);
3627 status = cairo_scaled_font_text_to_glyphs (scaled_font,
3630 &glyphs, &num_glyphs,
3633 if (num_glyphs == 0) {
3634 CAIRO_TRACE_END (__func__);
3638 status = cr->backend->glyph_path (cr, glyphs, num_glyphs);
3640 if (unlikely (status))
3643 last_glyph = &glyphs[num_glyphs - 1];
3644 status = cr->backend->glyph_extents (cr, last_glyph, 1, &extents);
3646 if (unlikely (status))
3649 x = last_glyph->x + extents.x_advance;
3650 y = last_glyph->y + extents.y_advance;
3651 cr->backend->move_to (cr, x, y);
3654 if (glyphs != stack_glyphs)
3655 cairo_glyph_free (glyphs);
3657 if (unlikely (status))
3658 _cairo_set_error (cr, status);
3659 CAIRO_TRACE_END (__func__);
3664 * @cr: a cairo context
3665 * @glyphs: array of glyphs to show
3666 * @num_glyphs: number of glyphs to show
3668 * Adds closed paths for the glyphs to the current path. The generated
3669 * path if filled, achieves an effect similar to that of
3670 * cairo_show_glyphs().
3675 cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
3677 CAIRO_TRACE_BEGIN (__func__);
3678 cairo_status_t status;
3680 if (unlikely (cr->status)) {
3681 CAIRO_TRACE_END (__func__);
3685 if (num_glyphs == 0) {
3686 CAIRO_TRACE_END (__func__);
3690 if (unlikely (num_glyphs < 0)) {
3691 _cairo_set_error (cr, CAIRO_STATUS_NEGATIVE_COUNT);
3692 CAIRO_TRACE_END (__func__);
3696 if (unlikely (glyphs == NULL)) {
3697 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
3698 CAIRO_TRACE_END (__func__);
3702 status = cr->backend->glyph_path (cr, glyphs, num_glyphs);
3703 if (unlikely (status))
3704 _cairo_set_error (cr, status);
3705 CAIRO_TRACE_END (__func__);
3709 * cairo_get_operator:
3710 * @cr: a cairo context
3712 * Gets the current compositing operator for a cairo context.
3714 * Return value: the current compositing operator.
3719 cairo_get_operator (cairo_t *cr)
3721 if (unlikely (cr->status))
3722 return CAIRO_GSTATE_OPERATOR_DEFAULT;
3724 return cr->backend->get_operator (cr);
3729 * cairo_get_opacity:
3730 * @cr: a cairo context
3732 * Gets the current compositing opacity for a cairo context.
3734 * Return value: the current compositing opacity.
3739 cairo_get_opacity (cairo_t *cr)
3741 if (unlikely (cr->status))
3744 return cr->backend->get_opacity (cr);
3749 * cairo_get_tolerance:
3750 * @cr: a cairo context
3752 * Gets the current tolerance value, as set by cairo_set_tolerance().
3754 * Return value: the current tolerance value.
3759 cairo_get_tolerance (cairo_t *cr)
3761 if (unlikely (cr->status))
3762 return CAIRO_GSTATE_TOLERANCE_DEFAULT;
3764 return cr->backend->get_tolerance (cr);
3766 slim_hidden_def (cairo_get_tolerance);
3769 * cairo_get_antialias:
3770 * @cr: a cairo context
3772 * Gets the current shape antialiasing mode, as set by
3773 * cairo_set_antialias().
3775 * Return value: the current shape antialiasing mode.
3780 cairo_get_antialias (cairo_t *cr)
3782 if (unlikely (cr->status))
3783 return CAIRO_ANTIALIAS_DEFAULT;
3785 return cr->backend->get_antialias (cr);
3789 * cairo_has_current_point:
3790 * @cr: a cairo context
3792 * Returns whether a current point is defined on the current path.
3793 * See cairo_get_current_point() for details on the current point.
3795 * Return value: whether a current point is defined.
3800 cairo_has_current_point (cairo_t *cr)
3802 if (unlikely (cr->status))
3805 return cr->backend->has_current_point (cr);
3809 * cairo_get_current_point:
3810 * @cr: a cairo context
3811 * @x: return value for X coordinate of the current point
3812 * @y: return value for Y coordinate of the current point
3814 * Gets the current point of the current path, which is
3815 * conceptually the final point reached by the path so far.
3817 * The current point is returned in the user-space coordinate
3818 * system. If there is no defined current point or if @cr is in an
3819 * error status, @x and @y will both be set to 0.0. It is possible to
3820 * check this in advance with cairo_has_current_point().
3822 * Most path construction functions alter the current point. See the
3823 * following for details on how they affect the current point:
3824 * cairo_new_path(), cairo_new_sub_path(),
3825 * cairo_append_path(), cairo_close_path(),
3826 * cairo_move_to(), cairo_line_to(), cairo_curve_to(),
3827 * cairo_rel_move_to(), cairo_rel_line_to(), cairo_rel_curve_to(),
3828 * cairo_arc(), cairo_arc_negative(), cairo_rectangle(),
3829 * cairo_text_path(), cairo_glyph_path(), cairo_stroke_to_path().
3831 * Some functions use and alter the current point but do not
3832 * otherwise change current path:
3833 * cairo_show_text().
3835 * Some functions unset the current path and as a result, current point:
3836 * cairo_fill(), cairo_stroke().
3841 cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret)
3846 if (cr->status == CAIRO_STATUS_SUCCESS &&
3847 cr->backend->has_current_point (cr))
3849 cr->backend->get_current_point (cr, &x, &y);
3857 slim_hidden_def(cairo_get_current_point);
3860 * cairo_get_fill_rule:
3861 * @cr: a cairo context
3863 * Gets the current fill rule, as set by cairo_set_fill_rule().
3865 * Return value: the current fill rule.
3870 cairo_get_fill_rule (cairo_t *cr)
3872 if (unlikely (cr->status))
3873 return CAIRO_GSTATE_FILL_RULE_DEFAULT;
3875 return cr->backend->get_fill_rule (cr);
3879 * cairo_get_line_width:
3880 * @cr: a cairo context
3882 * This function returns the current line width value exactly as set by
3883 * cairo_set_line_width(). Note that the value is unchanged even if
3884 * the CTM has changed between the calls to cairo_set_line_width() and
3885 * cairo_get_line_width().
3887 * Return value: the current line width.
3892 cairo_get_line_width (cairo_t *cr)
3894 if (unlikely (cr->status))
3895 return CAIRO_GSTATE_LINE_WIDTH_DEFAULT;
3897 return cr->backend->get_line_width (cr);
3899 slim_hidden_def (cairo_get_line_width);
3902 * cairo_get_line_cap:
3903 * @cr: a cairo context
3905 * Gets the current line cap style, as set by cairo_set_line_cap().
3907 * Return value: the current line cap style.
3912 cairo_get_line_cap (cairo_t *cr)
3914 if (unlikely (cr->status))
3915 return CAIRO_GSTATE_LINE_CAP_DEFAULT;
3917 return cr->backend->get_line_cap (cr);
3921 * cairo_get_line_join:
3922 * @cr: a cairo context
3924 * Gets the current line join style, as set by cairo_set_line_join().
3926 * Return value: the current line join style.
3931 cairo_get_line_join (cairo_t *cr)
3933 if (unlikely (cr->status))
3934 return CAIRO_GSTATE_LINE_JOIN_DEFAULT;
3936 return cr->backend->get_line_join (cr);
3940 * cairo_get_miter_limit:
3941 * @cr: a cairo context
3943 * Gets the current miter limit, as set by cairo_set_miter_limit().
3945 * Return value: the current miter limit.
3950 cairo_get_miter_limit (cairo_t *cr)
3952 if (unlikely (cr->status))
3953 return CAIRO_GSTATE_MITER_LIMIT_DEFAULT;
3955 return cr->backend->get_miter_limit (cr);
3960 * @cr: a cairo context
3961 * @matrix: return value for the matrix
3963 * Stores the current transformation matrix (CTM) into @matrix.
3968 cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix)
3970 if (unlikely (cr->status)) {
3971 cairo_matrix_init_identity (matrix);
3975 cr->backend->get_matrix (cr, matrix);
3977 slim_hidden_def (cairo_get_matrix);
3981 * @cr: a cairo context
3983 * Gets the target surface for the cairo context as passed to
3986 * This function will always return a valid pointer, but the result
3987 * can be a "nil" surface if @cr is already in an error state,
3988 * (ie. cairo_status() <literal>!=</literal> %CAIRO_STATUS_SUCCESS).
3989 * A nil surface is indicated by cairo_surface_status()
3990 * <literal>!=</literal> %CAIRO_STATUS_SUCCESS.
3992 * Return value: the target surface. This object is owned by cairo. To
3993 * keep a reference to it, you must call cairo_surface_reference().
3998 cairo_get_target (cairo_t *cr)
4000 if (unlikely (cr->status))
4001 return _cairo_surface_create_in_error (cr->status);
4003 return cr->backend->get_original_target (cr);
4005 slim_hidden_def (cairo_get_target);
4008 * cairo_get_group_target:
4009 * @cr: a cairo context
4011 * Gets the current destination surface for the context. This is either
4012 * the original target surface as passed to cairo_create() or the target
4013 * surface for the current group as started by the most recent call to
4014 * cairo_push_group() or cairo_push_group_with_content().
4016 * This function will always return a valid pointer, but the result
4017 * can be a "nil" surface if @cr is already in an error state,
4018 * (ie. cairo_status() <literal>!=</literal> %CAIRO_STATUS_SUCCESS).
4019 * A nil surface is indicated by cairo_surface_status()
4020 * <literal>!=</literal> %CAIRO_STATUS_SUCCESS.
4022 * Return value: the target surface. This object is owned by cairo. To
4023 * keep a reference to it, you must call cairo_surface_reference().
4028 cairo_get_group_target (cairo_t *cr)
4030 if (unlikely (cr->status))
4031 return _cairo_surface_create_in_error (cr->status);
4033 return cr->backend->get_current_target (cr);
4038 * @cr: a cairo context
4040 * Creates a copy of the current path and returns it to the user as a
4041 * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate
4042 * over the returned data structure.
4044 * This function will always return a valid pointer, but the result
4045 * will have no data (<literal>data==%NULL</literal> and
4046 * <literal>num_data==0</literal>), if either of the following
4050 * <listitem>If there is insufficient memory to copy the path. In this
4051 * case <literal>path->status</literal> will be set to
4052 * %CAIRO_STATUS_NO_MEMORY.</listitem>
4053 * <listitem>If @cr is already in an error state. In this case
4054 * <literal>path->status</literal> will contain the same status that
4055 * would be returned by cairo_status().</listitem>
4058 * Return value: the copy of the current path. The caller owns the
4059 * returned object and should call cairo_path_destroy() when finished
4065 cairo_copy_path (cairo_t *cr)
4067 if (unlikely (cr->status))
4068 return _cairo_path_create_in_error (cr->status);
4070 return cr->backend->copy_path (cr);
4074 * cairo_copy_path_flat:
4075 * @cr: a cairo context
4077 * Gets a flattened copy of the current path and returns it to the
4078 * user as a #cairo_path_t. See #cairo_path_data_t for hints on
4079 * how to iterate over the returned data structure.
4081 * This function is like cairo_copy_path() except that any curves
4082 * in the path will be approximated with piecewise-linear
4083 * approximations, (accurate to within the current tolerance
4084 * value). That is, the result is guaranteed to not have any elements
4085 * of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a
4086 * series of %CAIRO_PATH_LINE_TO elements.
4088 * This function will always return a valid pointer, but the result
4089 * will have no data (<literal>data==%NULL</literal> and
4090 * <literal>num_data==0</literal>), if either of the following
4094 * <listitem>If there is insufficient memory to copy the path. In this
4095 * case <literal>path->status</literal> will be set to
4096 * %CAIRO_STATUS_NO_MEMORY.</listitem>
4097 * <listitem>If @cr is already in an error state. In this case
4098 * <literal>path->status</literal> will contain the same status that
4099 * would be returned by cairo_status().</listitem>
4102 * Return value: the copy of the current path. The caller owns the
4103 * returned object and should call cairo_path_destroy() when finished
4109 cairo_copy_path_flat (cairo_t *cr)
4111 if (unlikely (cr->status))
4112 return _cairo_path_create_in_error (cr->status);
4114 return cr->backend->copy_path_flat (cr);
4118 * cairo_append_path:
4119 * @cr: a cairo context
4120 * @path: path to be appended
4122 * Append the @path onto the current path. The @path may be either the
4123 * return value from one of cairo_copy_path() or
4124 * cairo_copy_path_flat() or it may be constructed manually. See
4125 * #cairo_path_t for details on how the path data structure should be
4126 * initialized, and note that <literal>path->status</literal> must be
4127 * initialized to %CAIRO_STATUS_SUCCESS.
4132 cairo_append_path (cairo_t *cr,
4133 const cairo_path_t *path)
4135 cairo_status_t status;
4137 if (unlikely (cr->status))
4140 if (unlikely (path == NULL)) {
4141 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
4145 if (unlikely (path->status)) {
4146 if (path->status > CAIRO_STATUS_SUCCESS &&
4147 path->status <= CAIRO_STATUS_LAST_STATUS)
4148 _cairo_set_error (cr, path->status);
4150 _cairo_set_error (cr, CAIRO_STATUS_INVALID_STATUS);
4154 if (path->num_data == 0)
4157 if (unlikely (path->data == NULL)) {
4158 _cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
4162 status = cr->backend->append_path (cr, path);
4163 if (unlikely (status))
4164 _cairo_set_error (cr, status);
4169 * @cr: a cairo context
4171 * Checks whether an error has previously occurred for this context.
4173 * Returns: the current status of this context, see #cairo_status_t
4178 cairo_status (cairo_t *cr)
4182 slim_hidden_def (cairo_status);
4185 cairo_set_shadow (cairo_t *cr, cairo_shadow_type_t shadow)
4187 cairo_status_t status;
4189 if (unlikely (cr->status))
4192 status = cr->backend->set_shadow (cr, shadow);
4193 if (unlikely (status))
4194 _cairo_set_error (cr, status);
4196 slim_hidden_def (cairo_set_shadow);
4199 cairo_set_shadow_offset (cairo_t *cr, double x_offset, double y_offset)
4201 cairo_status_t status;
4203 if (unlikely (cr->status))
4206 status = cr->backend->set_shadow_offset (cr, x_offset, y_offset);
4207 if (unlikely (status))
4208 _cairo_set_error (cr, status);
4210 slim_hidden_def (cairo_set_shadow_offset);
4213 cairo_set_shadow_rgb (cairo_t *cr, double red, double green, double blue)
4215 cairo_status_t status;
4217 if (unlikely (cr->status))
4220 status = cr->backend->set_shadow_rgba (cr, red, green, blue, 1.0);
4221 if (unlikely (status))
4222 _cairo_set_error (cr, status);
4224 slim_hidden_def (cairo_set_shadow_rgb);
4227 cairo_set_shadow_rgba (cairo_t *cr, double red, double green,
4228 double blue, double alpha)
4230 cairo_status_t status;
4232 if (unlikely (cr->status))
4235 status = cr->backend->set_shadow_rgba (cr, red, green, blue, alpha);
4236 if (unlikely (status))
4237 _cairo_set_error (cr, status);
4239 slim_hidden_def (cairo_set_shadow_rgba);
4242 cairo_set_shadow_blur (cairo_t *cr, double x_blur, double y_blur)
4244 cairo_status_t status;
4246 if (unlikely (cr->status))
4249 status = cr->backend->set_shadow_blur (cr, x_blur, y_blur);
4250 if (unlikely (status))
4251 _cairo_set_error (cr, status);
4253 slim_hidden_def (cairo_set_shadow_blur);
4256 cairo_set_draw_shadow_only (cairo_t *cr, cairo_bool_t draw_shadow_only)
4258 if (unlikely (cr->status))
4261 cr->backend->set_draw_shadow_only (cr, draw_shadow_only);
4263 slim_hidden_def (cairo_set_draw_shadow_only);
4266 cairo_shadow_enable_cache (cairo_t *cr, cairo_bool_t enable)
4268 if (unlikely (cr->status))
4271 cr->backend->shadow_enable_cache (cr, enable);
4273 slim_hidden_def (cairo_shadow_enable_cache);
4276 cairo_set_path_is_inset_shadow_with_spread (cairo_t *cr,
4277 cairo_bool_t is_spread_path)
4279 if (unlikely (cr->status))
4281 cr->backend->set_path_is_inset_shadow_with_spread (cr, is_spread_path);}
4282 slim_hidden_def (cairo_set_path_is_inset_shadow_with_spread);