Coverage Report

Created: 2025-07-07 10:01

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