-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcairo.c
4027 lines (3627 loc) · 110 KB
/
cairo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
* Copyright © 2005 Red Hat, Inc.
* Copyright © 2011 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is University of Southern
* California.
*
* Contributor(s):
* Carl D. Worth <[email protected]>
* Chris Wilson <[email protected]>
*/
#include "cairoint.h"
#include "cairo-private.h"
#include "cairo-backend-private.h"
#include "cairo-error-private.h"
#include "cairo-path-private.h"
#include "cairo-pattern-private.h"
#include "cairo-surface-private.h"
#include "cairo-surface-backend-private.h"
#include <assert.h>
/**
* SECTION:cairo
* @Title: cairo_t
* @Short_Description: The cairo drawing context
* @See_Also: #cairo_surface_t
*
* #cairo_t is the main object used when drawing with cairo. To
* draw with cairo, you create a #cairo_t, set the target surface,
* and drawing options for the #cairo_t, create shapes with
* functions like cairo_move_to() and cairo_line_to(), and then
* draw shapes with cairo_stroke() or cairo_fill().
*
* #cairo_t<!-- -->'s can be pushed to a stack via cairo_save().
* They may then safely be changed, without losing the current state.
* Use cairo_restore() to restore to the saved state.
**/
/**
* SECTION:cairo-text
* @Title: text
* @Short_Description: Rendering text and glyphs
* @See_Also: #cairo_font_face_t, #cairo_scaled_font_t, cairo_text_path(),
* cairo_glyph_path()
*
* The functions with <emphasis>text</emphasis> in their name form cairo's
* <firstterm>toy</firstterm> text API. The toy API takes UTF-8 encoded
* text and is limited in its functionality to rendering simple
* left-to-right text with no advanced features. That means for example
* that most complex scripts like Hebrew, Arabic, and Indic scripts are
* out of question. No kerning or correct positioning of diacritical marks
* either. The font selection is pretty limited too and doesn't handle the
* case that the selected font does not cover the characters in the text.
* This set of functions are really that, a toy text API, for testing and
* demonstration purposes. Any serious application should avoid them.
*
* The functions with <emphasis>glyphs</emphasis> in their name form cairo's
* <firstterm>low-level</firstterm> text API. The low-level API relies on
* the user to convert text to a set of glyph indexes and positions. This
* is a very hard problem and is best handled by external libraries, like
* the pangocairo that is part of the Pango text layout and rendering library.
* Pango is available from <ulink
* url="http://www.pango.org/">http://www.pango.org/</ulink>.
**/
/**
* SECTION:cairo-transforms
* @Title: Transformations
* @Short_Description: Manipulating the current transformation matrix
* @See_Also: #cairo_matrix_t
*
* The current transformation matrix, <firstterm>ctm</firstterm>, is a
* two-dimensional affine transformation that maps all coordinates and other
* drawing instruments from the <firstterm>user space</firstterm> into the
* surface's canonical coordinate system, also known as the <firstterm>device
* space</firstterm>.
**/
#define DEFINE_NIL_CONTEXT(status) \
{ \
CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \
status, /* status */ \
{ 0, 0, 0, NULL }, /* user_data */ \
NULL \
}
static const cairo_t _cairo_nil[] = {
DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_MEMORY),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_RESTORE),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_POP_GROUP),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_CURRENT_POINT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MATRIX),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STATUS),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_NULL_POINTER),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRING),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_PATH_DATA),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_READ_ERROR),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_WRITE_ERROR),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_FINISHED),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_TYPE_MISMATCH),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_PATTERN_TYPE_MISMATCH),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CONTENT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_FORMAT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_VISUAL),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_FILE_NOT_FOUND),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DASH),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DSC_COMMENT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_INDEX),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_TEMP_FILE_ERROR),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRIDE),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_FONT_TYPE_MISMATCH),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_IMMUTABLE),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_ERROR),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_NEGATIVE_COUNT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CLUSTERS),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SLANT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_WEIGHT),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SIZE),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_TYPE_MISMATCH),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_ERROR),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MESH_CONSTRUCTION),
DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_FINISHED)
};
COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1);
/**
* _cairo_set_error:
* @cr: a cairo context
* @status: a status value indicating an error
*
* Atomically sets cr->status to @status and calls _cairo_error;
* Does nothing if status is %CAIRO_STATUS_SUCCESS.
*
* All assignments of an error status to cr->status should happen
* through _cairo_set_error(). Note that due to the nature of the atomic
* operation, it is not safe to call this function on the nil objects.
*
* The purpose of this function is to allow the user to set a
* breakpoint in _cairo_error() to generate a stack trace for when the
* user causes cairo to detect an error.
**/
static void
_cairo_set_error (cairo_t *cr, cairo_status_t status)
{
/* Don't overwrite an existing error. This preserves the first
* error, which is the most significant. */
_cairo_status_set_error (&cr->status, _cairo_error (status));
}
cairo_t *
_cairo_create_in_error (cairo_status_t status)
{
cairo_t *cr;
assert (status != CAIRO_STATUS_SUCCESS);
cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY];
assert (status == cr->status);
return cr;
}
/**
* cairo_create:
* @target: target surface for the context
*
* Creates a new #cairo_t with all graphics state parameters set to
* default values and with @target as a target surface. The target
* surface should be constructed with a backend-specific function such
* as cairo_image_surface_create() (or any other
* <function>cairo_<emphasis>backend</emphasis>_surface_create(<!-- -->)</function>
* variant).
*
* This function references @target, so you can immediately
* call cairo_surface_destroy() on it if you don't need to
* maintain a separate reference to it.
*
* Return value: a newly allocated #cairo_t with a reference
* count of 1. The initial reference count should be released
* with cairo_destroy() when you are done using the #cairo_t.
* This function never returns %NULL. If memory cannot be
* allocated, a special #cairo_t object will be returned on
* which cairo_status() returns %CAIRO_STATUS_NO_MEMORY. If
* you attempt to target a surface which does not support
* writing (such as #cairo_mime_surface_t) then a
* %CAIRO_STATUS_WRITE_ERROR will be raised. You can use this
* object normally, but no drawing will be done.
*
* Since: 1.0
**/
cairo_t *
cairo_create (cairo_surface_t *target)
{
if (unlikely (target == NULL))
return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER));
if (unlikely (target->status))
return _cairo_create_in_error (target->status);
if (target->backend->create_context == NULL)
return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_WRITE_ERROR));
return target->backend->create_context (target);
}
slim_hidden_def (cairo_create);
void
_cairo_init (cairo_t *cr,
const cairo_backend_t *backend)
{
CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1);
cr->status = CAIRO_STATUS_SUCCESS;
_cairo_user_data_array_init (&cr->user_data);
cr->backend = backend;
}
/**
* cairo_reference:
* @cr: a #cairo_t
*
* Increases the reference count on @cr by one. This prevents
* @cr from being destroyed until a matching call to cairo_destroy()
* is made.
*
* The number of references to a #cairo_t can be get using
* cairo_get_reference_count().
*
* Return value: the referenced #cairo_t.
*
* Since: 1.0
**/
cairo_t *
cairo_reference (cairo_t *cr)
{
if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
return cr;
assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
_cairo_reference_count_inc (&cr->ref_count);
return cr;
}
void
_cairo_fini (cairo_t *cr)
{
_cairo_user_data_array_fini (&cr->user_data);
}
/**
* cairo_destroy:
* @cr: a #cairo_t
*
* Decreases the reference count on @cr by one. If the result
* is zero, then @cr and all associated resources are freed.
* See cairo_reference().
*
* Since: 1.0
**/
void
cairo_destroy (cairo_t *cr)
{
if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
return;
assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count));
if (! _cairo_reference_count_dec_and_test (&cr->ref_count))
return;
cr->backend->destroy (cr);
}
slim_hidden_def (cairo_destroy);
/**
* cairo_get_user_data:
* @cr: a #cairo_t
* @key: the address of the #cairo_user_data_key_t the user data was
* attached to
*
* Return user data previously attached to @cr using the specified
* key. If no user data has been attached with the given key this
* function returns %NULL.
*
* Return value: the user data previously attached or %NULL.
*
* Since: 1.4
**/
void *
cairo_get_user_data (cairo_t *cr,
const cairo_user_data_key_t *key)
{
return _cairo_user_data_array_get_data (&cr->user_data, key);
}
/**
* cairo_set_user_data:
* @cr: a #cairo_t
* @key: the address of a #cairo_user_data_key_t to attach the user data to
* @user_data: the user data to attach to the #cairo_t
* @destroy: a #cairo_destroy_func_t which will be called when the
* #cairo_t is destroyed or when new user data is attached using the
* same key.
*
* Attach user data to @cr. To remove user data from a surface,
* call this function with the key that was used to set it and %NULL
* for @data.
*
* Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a
* slot could not be allocated for the user data.
*
* Since: 1.4
**/
cairo_status_t
cairo_set_user_data (cairo_t *cr,
const cairo_user_data_key_t *key,
void *user_data,
cairo_destroy_func_t destroy)
{
if (CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
return cr->status;
return _cairo_user_data_array_set_data (&cr->user_data,
key, user_data, destroy);
}
/**
* cairo_get_reference_count:
* @cr: a #cairo_t
*
* Returns the current reference count of @cr.
*
* Return value: the current reference count of @cr. If the
* object is a nil object, 0 will be returned.
*
* Since: 1.4
**/
unsigned int
cairo_get_reference_count (cairo_t *cr)
{
if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count))
return 0;
return CAIRO_REFERENCE_COUNT_GET_VALUE (&cr->ref_count);
}
/**
* cairo_save:
* @cr: a #cairo_t
*
* Makes a copy of the current state of @cr and saves it
* on an internal stack of saved states for @cr. When
* cairo_restore() is called, @cr will be restored to
* the saved state. Multiple calls to cairo_save() and
* cairo_restore() can be nested; each call to cairo_restore()
* restores the state from the matching paired cairo_save().
*
* It isn't necessary to clear all saved states before
* a #cairo_t is freed. If the reference count of a #cairo_t
* drops to zero in response to a call to cairo_destroy(),
* any saved states will be freed along with the #cairo_t.
*
* Since: 1.0
**/
void
cairo_save (cairo_t *cr)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->save (cr);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def(cairo_save);
/**
* cairo_restore:
* @cr: a #cairo_t
*
* Restores @cr to the state saved by a preceding call to
* cairo_save() and removes that state from the stack of
* saved states.
*
* Since: 1.0
**/
void
cairo_restore (cairo_t *cr)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->restore (cr);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def(cairo_restore);
/**
* cairo_push_group:
* @cr: a cairo context
*
* Temporarily redirects drawing to an intermediate surface known as a
* group. The redirection lasts until the group is completed by a call
* to cairo_pop_group() or cairo_pop_group_to_source(). These calls
* provide the result of any drawing to the group as a pattern,
* (either as an explicit object, or set as the source pattern).
*
* This group functionality can be convenient for performing
* intermediate compositing. One common use of a group is to render
* objects as opaque within the group, (so that they occlude each
* other), and then blend the result with translucence onto the
* destination.
*
* Groups can be nested arbitrarily deep by making balanced calls to
* cairo_push_group()/cairo_pop_group(). Each call pushes/pops the new
* target group onto/from a stack.
*
* The cairo_push_group() function calls cairo_save() so that any
* changes to the graphics state will not be visible outside the
* group, (the pop_group functions call cairo_restore()).
*
* By default the intermediate group will have a content type of
* %CAIRO_CONTENT_COLOR_ALPHA. Other content types can be chosen for
* the group by using cairo_push_group_with_content() instead.
*
* As an example, here is how one might fill and stroke a path with
* translucence, but without any portion of the fill being visible
* under the stroke:
*
* <informalexample><programlisting>
* cairo_push_group (cr);
* cairo_set_source (cr, fill_pattern);
* cairo_fill_preserve (cr);
* cairo_set_source (cr, stroke_pattern);
* cairo_stroke (cr);
* cairo_pop_group_to_source (cr);
* cairo_paint_with_alpha (cr, alpha);
* </programlisting></informalexample>
*
* Since: 1.2
**/
void
cairo_push_group (cairo_t *cr)
{
cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
}
/**
* cairo_push_group_with_content:
* @cr: a cairo context
* @content: a #cairo_content_t indicating the type of group that
* will be created
*
* Temporarily redirects drawing to an intermediate surface known as a
* group. The redirection lasts until the group is completed by a call
* to cairo_pop_group() or cairo_pop_group_to_source(). These calls
* provide the result of any drawing to the group as a pattern,
* (either as an explicit object, or set as the source pattern).
*
* The group will have a content type of @content. The ability to
* control this content type is the only distinction between this
* function and cairo_push_group() which you should see for a more
* detailed description of group rendering.
*
* Since: 1.2
**/
void
cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->push_group (cr, content);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def(cairo_push_group_with_content);
/**
* cairo_pop_group:
* @cr: a cairo context
*
* Terminates the redirection begun by a call to cairo_push_group() or
* cairo_push_group_with_content() and returns a new pattern
* containing the results of all drawing operations performed to the
* group.
*
* The cairo_pop_group() function calls cairo_restore(), (balancing a
* call to cairo_save() by the push_group function), so that any
* changes to the graphics state will not be visible outside the
* group.
*
* Return value: a newly created (surface) pattern containing the
* results of all drawing operations performed to the group. The
* caller owns the returned object and should call
* cairo_pattern_destroy() when finished with it.
*
* Since: 1.2
**/
cairo_pattern_t *
cairo_pop_group (cairo_t *cr)
{
cairo_pattern_t *group_pattern;
if (unlikely (cr->status))
return _cairo_pattern_create_in_error (cr->status);
group_pattern = cr->backend->pop_group (cr);
if (unlikely (group_pattern->status))
_cairo_set_error (cr, group_pattern->status);
return group_pattern;
}
slim_hidden_def(cairo_pop_group);
/**
* cairo_pop_group_to_source:
* @cr: a cairo context
*
* Terminates the redirection begun by a call to cairo_push_group() or
* cairo_push_group_with_content() and installs the resulting pattern
* as the source pattern in the given cairo context.
*
* The behavior of this function is equivalent to the sequence of
* operations:
*
* <informalexample><programlisting>
* cairo_pattern_t *group = cairo_pop_group (cr);
* cairo_set_source (cr, group);
* cairo_pattern_destroy (group);
* </programlisting></informalexample>
*
* but is more convenient as their is no need for a variable to store
* the short-lived pointer to the pattern.
*
* The cairo_pop_group() function calls cairo_restore(), (balancing a
* call to cairo_save() by the push_group function), so that any
* changes to the graphics state will not be visible outside the
* group.
*
* Since: 1.2
**/
void
cairo_pop_group_to_source (cairo_t *cr)
{
cairo_pattern_t *group_pattern;
group_pattern = cairo_pop_group (cr);
cairo_set_source (cr, group_pattern);
cairo_pattern_destroy (group_pattern);
}
/**
* cairo_set_operator:
* @cr: a #cairo_t
* @op: a compositing operator, specified as a #cairo_operator_t
*
* Sets the compositing operator to be used for all drawing
* operations. See #cairo_operator_t for details on the semantics of
* each available compositing operator.
*
* The default operator is %CAIRO_OPERATOR_OVER.
*
* Since: 1.0
**/
void
cairo_set_operator (cairo_t *cr, cairo_operator_t op)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_operator (cr, op);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_operator);
#if 0
/**
* cairo_set_opacity:
* @cr: a #cairo_t
* @opacity: the level of opacity to use when compositing
*
* Sets the compositing opacity to be used for all drawing
* operations. The effect is to fade out the operations
* using the alpha value.
*
* The default opacity is 1.
*
* Since: TBD
**/
void
cairo_set_opacity (cairo_t *cr, double opacity)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_opacity (cr, opacity);
if (unlikely (status))
_cairo_set_error (cr, status);
}
#endif
/**
* cairo_set_source_rgb:
* @cr: a cairo context
* @red: red component of color
* @green: green component of color
* @blue: blue component of color
*
* Sets the source pattern within @cr to an opaque color. This opaque
* color will then be used for any subsequent drawing operation until
* a new source pattern is set.
*
* The color components are floating point numbers in the range 0 to
* 1. If the values passed in are outside that range, they will be
* clamped.
*
* The default source pattern is opaque black, (that is, it is
* equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)).
*
* Since: 1.0
**/
void
cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_source_rgba (cr, red, green, blue, 1.);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_source_rgb);
/**
* cairo_set_source_rgba:
* @cr: a cairo context
* @red: red component of color
* @green: green component of color
* @blue: blue component of color
* @alpha: alpha component of color
*
* Sets the source pattern within @cr to a translucent color. This
* color will then be used for any subsequent drawing operation until
* a new source pattern is set.
*
* The color and alpha components are floating point numbers in the
* range 0 to 1. If the values passed in are outside that range, they
* will be clamped.
*
* The default source pattern is opaque black, (that is, it is
* equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)).
*
* Since: 1.0
**/
void
cairo_set_source_rgba (cairo_t *cr,
double red, double green, double blue,
double alpha)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_source_rgba (cr, red, green, blue, alpha);
if (unlikely (status))
_cairo_set_error (cr, status);
}
/**
* cairo_set_source_surface:
* @cr: a cairo context
* @surface: a surface to be used to set the source pattern
* @x: User-space X coordinate for surface origin
* @y: User-space Y coordinate for surface origin
*
* This is a convenience function for creating a pattern from @surface
* and setting it as the source in @cr with cairo_set_source().
*
* The @x and @y parameters give the user-space coordinate at which
* the surface origin should appear. (The surface origin is its
* upper-left corner before any transformation has been applied.) The
* @x and @y parameters are negated and then set as translation values
* in the pattern matrix.
*
* Other than the initial translation pattern matrix, as described
* above, all other pattern attributes, (such as its extend mode), are
* set to the default values as in cairo_pattern_create_for_surface().
* The resulting pattern can be queried with cairo_get_source() so
* that these attributes can be modified if desired, (eg. to create a
* repeating pattern with cairo_pattern_set_extend()).
*
* Since: 1.0
**/
void
cairo_set_source_surface (cairo_t *cr,
cairo_surface_t *surface,
double x,
double y)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
if (unlikely (surface == NULL)) {
_cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
status = cr->backend->set_source_surface (cr, surface, x, y);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_source_surface);
/**
* cairo_set_source:
* @cr: a cairo context
* @source: a #cairo_pattern_t to be used as the source for
* subsequent drawing operations.
*
* Sets the source pattern within @cr to @source. This pattern
* will then be used for any subsequent drawing operation until a new
* source pattern is set.
*
* Note: The pattern's transformation matrix will be locked to the
* user space in effect at the time of cairo_set_source(). This means
* that further modifications of the current transformation matrix
* will not affect the source pattern. See cairo_pattern_set_matrix().
*
* The default source pattern is a solid pattern that is opaque black,
* (that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0,
* 0.0)).
*
* Since: 1.0
**/
void
cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
if (unlikely (source == NULL)) {
_cairo_set_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
if (unlikely (source->status)) {
_cairo_set_error (cr, source->status);
return;
}
status = cr->backend->set_source (cr, source);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_source);
/**
* cairo_get_source:
* @cr: a cairo context
*
* Gets the current source pattern for @cr.
*
* Return value: the current source pattern. This object is owned by
* cairo. To keep a reference to it, you must call
* cairo_pattern_reference().
*
* Since: 1.0
**/
cairo_pattern_t *
cairo_get_source (cairo_t *cr)
{
if (unlikely (cr->status))
return _cairo_pattern_create_in_error (cr->status);
return cr->backend->get_source (cr);
}
/**
* cairo_set_tolerance:
* @cr: a #cairo_t
* @tolerance: the tolerance, in device units (typically pixels)
*
* Sets the tolerance used when converting paths into trapezoids.
* Curved segments of the path will be subdivided until the maximum
* deviation between the original path and the polygonal approximation
* is less than @tolerance. The default value is 0.1. A larger
* value will give better performance, a smaller value, better
* appearance. (Reducing the value from the default value of 0.1
* is unlikely to improve appearance significantly.) The accuracy of paths
* within Cairo is limited by the precision of its internal arithmetic, and
* the prescribed @tolerance is restricted to the smallest
* representable internal value.
*
* Since: 1.0
**/
void
cairo_set_tolerance (cairo_t *cr, double tolerance)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_tolerance (cr, tolerance);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_tolerance);
/**
* cairo_set_antialias:
* @cr: a #cairo_t
* @antialias: the new antialiasing mode
*
* Set the antialiasing mode of the rasterizer used for drawing shapes.
* This value is a hint, and a particular backend may or may not support
* a particular value. At the current time, no backend supports
* %CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes.
*
* Note that this option does not affect text rendering, instead see
* cairo_font_options_set_antialias().
*
* Since: 1.0
**/
void
cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_antialias (cr, antialias);
if (unlikely (status))
_cairo_set_error (cr, status);
}
/**
* cairo_set_fill_rule:
* @cr: a #cairo_t
* @fill_rule: a fill rule, specified as a #cairo_fill_rule_t
*
* Set the current fill rule within the cairo context. The fill rule
* is used to determine which regions are inside or outside a complex
* (potentially self-intersecting) path. The current fill rule affects
* both cairo_fill() and cairo_clip(). See #cairo_fill_rule_t for details
* on the semantics of each available fill rule.
*
* The default fill rule is %CAIRO_FILL_RULE_WINDING.
*
* Since: 1.0
**/
void
cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_fill_rule (cr, fill_rule);
if (unlikely (status))
_cairo_set_error (cr, status);
}
/**
* cairo_set_line_width:
* @cr: a #cairo_t
* @width: a line width
*
* Sets the current line width within the cairo context. The line
* width value specifies the diameter of a pen that is circular in
* user space, (though device-space pen may be an ellipse in general
* due to scaling/shear/rotation of the CTM).
*
* Note: When the description above refers to user space and CTM it
* refers to the user space and CTM in effect at the time of the
* stroking operation, not the user space and CTM in effect at the
* time of the call to cairo_set_line_width(). The simplest usage
* makes both of these spaces identical. That is, if there is no
* change to the CTM between a call to cairo_set_line_width() and the
* stroking operation, then one can just pass user-space values to
* cairo_set_line_width() and ignore this note.
*
* As with the other stroke parameters, the current line width is
* examined by cairo_stroke(), cairo_stroke_extents(), and
* cairo_stroke_to_path(), but does not have any effect during path
* construction.
*
* The default line width value is 2.0.
*
* Since: 1.0
**/
void
cairo_set_line_width (cairo_t *cr, double width)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
if (width < 0.)
width = 0.;
status = cr->backend->set_line_width (cr, width);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_line_width);
/**
* cairo_set_line_cap:
* @cr: a cairo context
* @line_cap: a line cap style
*
* Sets the current line cap style within the cairo context. See
* #cairo_line_cap_t for details about how the available line cap
* styles are drawn.
*
* As with the other stroke parameters, the current line cap style is
* examined by cairo_stroke(), cairo_stroke_extents(), and
* cairo_stroke_to_path(), but does not have any effect during path
* construction.
*
* The default line cap style is %CAIRO_LINE_CAP_BUTT.
*
* Since: 1.0
**/
void
cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
{
cairo_status_t status;
if (unlikely (cr->status))
return;
status = cr->backend->set_line_cap (cr, line_cap);
if (unlikely (status))
_cairo_set_error (cr, status);
}
slim_hidden_def (cairo_set_line_cap);
/**
* cairo_set_line_join: