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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
|
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
* Copyright © 2005 Red Hat, Inc.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <cworth@cworth.org>
*/
#include "cairoint.h"
#include "cairo-private.h"
#include "cairo-arc-private.h"
#include "cairo-path-data-private.h"
#define CAIRO_TOLERANCE_MINIMUM 0.0002 /* We're limited by 16 bits of sub-pixel precision */
static const cairo_t cairo_nil = {
(unsigned int)-1, /* ref_count */
CAIRO_STATUS_NO_MEMORY, /* status */
{ /* path */
NULL, NULL, /* op_buf_head, op_buf_tail */
NULL, NULL, /* arg_buf_head, arg_buf_tail */
{ 0, 0 }, /* last_move_point */
{ 0, 0 }, /* current point */
FALSE, /* has_current_point */
},
NULL /* gstate */
};
#include <assert.h>
/* This has to be updated whenever cairo_status_t is extended. That's
* a bit of a pain, but it should be easy to always catch as long as
* one adds a new test case to test a trigger of the new status value.
*/
#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_PATTERN_TYPE_MISMATCH
/**
* _cairo_error:
* @cr: a cairo context
* @status: a status value indicating an error, (eg. not
* CAIRO_STATUS_SUCCESS)
*
* Sets cr->status to @status.
*
* All assignments of an error status to cr->status should happen
* either inside of _cairo_error(), or else _cairo_error() should be
* called immediately after the assignment.
*
* 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.
*
* _cairo_error also calls the error notify callback function that the
* user may have set with cairo_set_error_notify.
**/
static void
_cairo_error (cairo_t *cr, cairo_status_t status)
{
assert (status > CAIRO_STATUS_SUCCESS &&
status <= CAIRO_STATUS_LAST_STATUS);
cr->status = status;
}
/**
* 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
* cairo_<backend>_surface_create 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.
*
* Note that there are restrictions on using the same surface in
* multiple contexts at the same time. If, after creating @cr_a with
* @surface you also create @cr_b with the same surface, you must
* ensure that @cr_b has finished using @surface before resuming use
* of @cr_a. Currently, the only way time at which this is guaranteed
* is when the the last reference to @cr_b is released with
* cairo_destroy(). (XXX: We need to add a cairo_finish() call to
* provide a way to achieve this explicitly). See also the
* %CAIRO_STATUS_BAD_NESTING status.
*
* 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.
* You can use this object normally, but no drawing will
* be done.
**/
cairo_t *
cairo_create (cairo_surface_t *target)
{
cairo_t *cr;
cr = malloc (sizeof (cairo_t));
if (cr == NULL)
return (cairo_t *) &cairo_nil;
cr->ref_count = 1;
cr->status = CAIRO_STATUS_SUCCESS;
_cairo_path_fixed_init (&cr->path);
if (target == NULL) {
cr->gstate = NULL;
_cairo_error (cr, CAIRO_STATUS_NULL_POINTER);
return cr;
}
cr->gstate = _cairo_gstate_create (target);
if (cr->gstate == NULL)
_cairo_error (cr, CAIRO_STATUS_NO_MEMORY);
return cr;
}
/**
* 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.
**/
void
cairo_reference (cairo_t *cr)
{
if (cr->ref_count == (unsigned int)-1)
return;
cr->ref_count++;
}
/**
* 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().
**/
void
cairo_destroy (cairo_t *cr)
{
if (cr->ref_count == (unsigned int)-1)
return;
cr->ref_count--;
if (cr->ref_count)
return;
while (cr->gstate) {
cairo_gstate_t *tmp = cr->gstate;
cr->gstate = tmp->next;
_cairo_gstate_destroy (tmp);
}
_cairo_path_fixed_fini (&cr->path);
free (cr);
}
/**
* 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.
**/
void
cairo_save (cairo_t *cr)
{
cairo_gstate_t *top;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
top = _cairo_gstate_clone (cr->gstate);
if (top == NULL) {
_cairo_error (cr, CAIRO_STATUS_NO_MEMORY);
return;
}
top->next = cr->gstate;
cr->gstate = top;
}
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.
**/
void
cairo_restore (cairo_t *cr)
{
cairo_gstate_t *top;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
top = cr->gstate;
cr->gstate = top->next;
_cairo_gstate_destroy (top);
if (cr->gstate == NULL)
_cairo_error (cr, CAIRO_STATUS_INVALID_RESTORE);
}
slim_hidden_def(cairo_restore);
/* XXX: I want to rethink this API
void
cairo_push_group (cairo_t *cr)
{
if (cr->status)
return;
cr->status = cairoPush (cr);
if (cr->status)
return;
cr->status = _cairo_gstate_begin_group (cr->gstate);
}
void
cairo_pop_group (cairo_t *cr)
{
if (cr->status)
return;
cr->status = _cairo_gstate_end_group (cr->gstate);
if (cr->status)
return;
cr->status = cairoPop (cr);
}
*/
/**
* 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 drawing operator.
*
* XXX: I'd also like to direct the reader's attention to some
* (not-yet-written) section on cairo's imaging model. How would I do
* that if such a section existed? (cworth).
**/
void
cairo_set_operator (cairo_t *cr, cairo_operator_t op)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_operator (cr->gstate, op);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* 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.
**/
void
cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
{
cairo_pattern_t *pattern;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
pattern = cairo_pattern_create_rgb (red, green, blue);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
/**
* 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.
**/
void
cairo_set_source_rgba (cairo_t *cr,
double red, double green, double blue,
double alpha)
{
cairo_pattern_t *pattern;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
pattern = cairo_pattern_create_rgba (red, green, blue, alpha);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
/**
* 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 patterns 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()).
**/
void
cairo_set_source_surface (cairo_t *cr,
cairo_surface_t *surface,
double x,
double y)
{
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
pattern = cairo_pattern_create_for_surface (surface);
cairo_matrix_init_translate (&matrix, -x, -y);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
/**
* 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.
*
* XXX: I'd also like to direct the reader's attention to some
* (not-yet-written) section on cairo's imaging model. How would I do
* that if such a section existed? (cworth).
**/
void
cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (source == NULL) {
_cairo_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
if (source->status) {
_cairo_error (cr, source->status);
return;
}
cr->status = _cairo_gstate_set_source (cr->gstate, source);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* 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().
**/
cairo_pattern_t *
cairo_get_source (cairo_t *cr)
{
if (cr->status) {
cairo_pattern_t *pattern;
pattern = _cairo_pattern_create_in_error (cr->status);
_cairo_error (cr, cr->status);
return pattern;
}
return _cairo_gstate_get_source (cr->gstate);
}
/**
* 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.)
**/
void
cairo_set_tolerance (cairo_t *cr, double tolerance)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance);
cr->status = _cairo_gstate_set_tolerance (cr->gstate, tolerance);
if (cr->status)
_cairo_error (cr, 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.
**/
void
cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_line_width:
* @cr: a #cairo_t
* @width: a line width, as a user-space value
*
* Sets the current line width within the cairo context. The line
* width specifies the diameter of a pen that is circular in
* user-space.
*
* 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.
**/
void
cairo_set_line_width (cairo_t *cr, double width)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_restrict_value (&width, 0.0, width);
cr->status = _cairo_gstate_set_line_width (cr->gstate, width);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_line_cap:
* @cr: a cairo context, as a #cairo_t
* @line_cap: a line cap style, as a #cairo_line_cap_t
*
* 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.
**/
void
cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_line_cap (cr->gstate, line_cap);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_line_join:
* @cr: a cairo context, as a #cairo_t
* @line_join: a line joint style, as a #cairo_line_join_t
*
* Sets the current line join style within the cairo context. See
* #cairo_line_join_t for details about how the available line join
* styles are drawn.
*
* As with the other stroke parameters, the current line join style is
* examined by cairo_stroke(), cairo_stroke_extents(), and
* cairo_stroke_to_path(), but does not have any effect during path
* construction.
**/
void
cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_line_join (cr->gstate, line_join);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_set_dash (cairo_t *cr, double *dashes, int ndash, double offset)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_dash (cr->gstate, dashes, ndash, offset);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_set_miter_limit (cairo_t *cr, double limit)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_miter_limit (cr->gstate, limit);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_translate:
* @cr: a cairo context
* @tx: amount to translate in the X direction
* @ty: amount to translate in the Y direction
*
* Modifies the current transformation matrix (CTM) by translating the
* user-space origin by (@tx, @ty). This offset is interpreted as a
* user-space coordinate according to the CTM in place before the new
* call to cairo_translate. In other words, the translation of the
* user-space origin takes place after any existing transformation.
**/
void
cairo_translate (cairo_t *cr, double tx, double ty)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_translate (cr->gstate, tx, ty);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_scale:
* @cr: a cairo context
* @sx: scale factor for the X dimension
* @sy: scale factor for the Y dimension
*
* Modifies the current transformation matrix (CTM) by scaling the X
* and Y user-space axes by @sx and @sy respectively. The scaling of
* the axes takes place after any existing transformation of user
* space.
**/
void
cairo_scale (cairo_t *cr, double sx, double sy)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_scale (cr->gstate, sx, sy);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_rotate:
* @cr: a cairo context
* @angle: angle (in radians) by which the user-space axes will be
* rotated
*
* Modifies the current transformation matrix (CTM) by rotating the
* user-space axes by @angle radians. The rotation of the axes takes
* places after any existing transformation of user space. The
* rotation direction for positive angles is from the positive X axis
* toward the positive Y axis.
**/
void
cairo_rotate (cairo_t *cr, double angle)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_rotate (cr->gstate, angle);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_transform:
* @cr: a cairo context
* @matrix: a transformation to be applied to the user-space axes
*
* Modifies the current transformation matrix (CTM) by applying
* @matrix as an additional transformation. The new transformation of
* user space takes place after any existing transformation.
**/
void
cairo_transform (cairo_t *cr,
const cairo_matrix_t *matrix)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_transform (cr->gstate, matrix);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_matrix:
* @cr: a cairo context
* @matrix: a transformation matrix from user space to device space
*
* Modifies the current transformation matrix (CTM) by setting it
* equal to @matrix.
**/
void
cairo_set_matrix (cairo_t *cr,
const cairo_matrix_t *matrix)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_matrix (cr->gstate, matrix);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_identity_matrix:
* @cr: a cairo context
*
* Resets the current transformation matrix (CTM) by setting it equal
* to the identity matrix. That is, the user-space and device-space
* axes will be aligned and one user-space unit will transform to one
* device-space unit.
**/
void
cairo_identity_matrix (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_identity_matrix (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_user_to_device:
* @cr: a cairo context
* @x: X value of coordinate (in/out parameter)
* @y: Y value of coordinate (in/out parameter)
*
* Transform a coordinate from user space to device space by
* multiplying the given point by the current transformation matrix
* (CTM).
**/
void
cairo_user_to_device (cairo_t *cr, double *x, double *y)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_user_to_device (cr->gstate, x, y);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_user_to_device_distance:
* @cr: a cairo context
* @dx: X component of a distance vector (in/out parameter)
* @dy: Y component of a distance vector (in/out parameter)
*
* Transform a distance vector from user space to device space. This
* function is similar to cairo_user_to_device() except that the
* translation components of the CTM will be ignored when transforming
* (@dx,@dy).
**/
void
cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_device_to_user:
* @cr: a cairo
* @x: X value of coordinate (in/out parameter)
* @y: Y value of coordinate (in/out parameter)
*
* Transform a coordinate from device space to user space by
* multiplying the given point by the inverse of the current
* transformation matrix (CTM).
**/
void
cairo_device_to_user (cairo_t *cr, double *x, double *y)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_device_to_user (cr->gstate, x, y);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_device_to_user_distance:
* @cr: a cairo context
* @dx: X component of a distance vector (in/out parameter)
* @dy: Y component of a distance vector (in/out parameter)
*
* Transform a distance vector from device space to user space. This
* function is similar to cairo_device_to_user() except that the
* translation components of the inverse CTM will be ignored when
* transforming (@dx,@dy).
**/
void
cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_new_path (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_path_fixed_fini (&cr->path);
}
slim_hidden_def(cairo_new_path);
void
cairo_move_to (cairo_t *cr, double x, double y)
{
cairo_fixed_t x_fixed, y_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_backend (cr->gstate, &x, &y);
x_fixed = _cairo_fixed_from_double (x);
y_fixed = _cairo_fixed_from_double (y);
cr->status = _cairo_path_fixed_move_to (&cr->path, x_fixed, y_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_move_to);
void
cairo_line_to (cairo_t *cr, double x, double y)
{
cairo_fixed_t x_fixed, y_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_backend (cr->gstate, &x, &y);
x_fixed = _cairo_fixed_from_double (x);
y_fixed = _cairo_fixed_from_double (y);
cr->status = _cairo_path_fixed_line_to (&cr->path, x_fixed, y_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_curve_to (cairo_t *cr,
double x1, double y1,
double x2, double y2,
double x3, double y3)
{
cairo_fixed_t x1_fixed, y1_fixed;
cairo_fixed_t x2_fixed, y2_fixed;
cairo_fixed_t x3_fixed, y3_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_backend (cr->gstate, &x1, &y1);
_cairo_gstate_user_to_backend (cr->gstate, &x2, &y2);
_cairo_gstate_user_to_backend (cr->gstate, &x3, &y3);
x1_fixed = _cairo_fixed_from_double (x1);
y1_fixed = _cairo_fixed_from_double (y1);
x2_fixed = _cairo_fixed_from_double (x2);
y2_fixed = _cairo_fixed_from_double (y2);
x3_fixed = _cairo_fixed_from_double (x3);
y3_fixed = _cairo_fixed_from_double (y3);
cr->status = _cairo_path_fixed_curve_to (&cr->path,
x1_fixed, y1_fixed,
x2_fixed, y2_fixed,
x3_fixed, y3_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_arc:
* @cr: a cairo context
* @xc: X position of the center of the arc
* @yc: Y position of the center of the arc
* @radius: the radius of the arc
* @angle1: the start angle, in radians
* @angle2: the end angle, in radians
*
* Adds an arc from @angle1 to @angle2 to the current path. If there
* is a current point, that point is connected to the start of the arc
* by a straight line segment. Angles are measured in radians with an
* angle of 0 along the X axis and an angle of %M_PI radians (90
* degrees) along the Y axis, so with the default transformation
* matrix, positive angles are clockwise. (To convert from degrees to
* radians, use <literal>degrees * (M_PI / 180.)</literal>.) This
* function gives the arc in the direction of increasing angle; see
* cairo_arc_negative() to get the arc in the direction of decreasing
* angle.
*
* A full arc is drawn as a circle. To make an oval arc, you can scale
* the current transformation matrix by different amounts in the X and
* Y directions. For example, to draw a full oval in the box given
* by @x, @y, @width, @height:
* <informalexample><programlisting>
* cairo_save (cr);
* cairo_translate (x + width / 2., y + height / 2.);
* cairo_scale (1. / (height / 2.), 1. / (width / 2.));
* cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
* cairo_restore (cr);
* </programlisting></informalexample>
**/
void
cairo_arc (cairo_t *cr,
double xc, double yc,
double radius,
double angle1, double angle2)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
/* Do nothing, successfully, if radius is <= 0 */
if (radius <= 0.0)
return;
while (angle2 < angle1)
angle2 += 2 * M_PI;
cairo_line_to (cr,
xc + radius * cos (angle1),
yc + radius * sin (angle1));
_cairo_arc_path (cr, xc, yc, radius,
angle1, angle2);
}
/**
* cairo_arc_negative:
* @cr: a cairo context
* @xc: X position of the center of the arc
* @yc: Y position of the center of the arc
* @radius: the radius of the arc
* @angle1: the start angle, in radians
* @angle2: the end angle, in radians
*
* Adds an arc from @angle1 to @angle2 to the current path. The
* function behaves identically to cairo_arc() except that instead of
* giving the arc in the direction of increasing angle, it gives
* the arc in the direction of decreasing angle.
**/
void
cairo_arc_negative (cairo_t *cr,
double xc, double yc,
double radius,
double angle1, double angle2)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
/* Do nothing, successfully, if radius is <= 0 */
if (radius <= 0.0)
return;
while (angle2 > angle1)
angle2 -= 2 * M_PI;
cairo_line_to (cr,
xc + radius * cos (angle1),
yc + radius * sin (angle1));
_cairo_arc_path_negative (cr, xc, yc, radius,
angle1, angle2);
}
/* XXX: NYI
void
cairo_arc_to (cairo_t *cr,
double x1, double y1,
double x2, double y2,
double radius)
{
if (cr->status)
return;
cr->status = _cairo_gstate_arc_to (cr->gstate,
x1, y1,
x2, y2,
radius);
}
*/
void
cairo_rel_move_to (cairo_t *cr, double dx, double dy)
{
cairo_fixed_t dx_fixed, dy_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
dx_fixed = _cairo_fixed_from_double (dx);
dy_fixed = _cairo_fixed_from_double (dy);
cr->status = _cairo_path_fixed_rel_move_to (&cr->path, dx_fixed, dy_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_rel_line_to (cairo_t *cr, double dx, double dy)
{
cairo_fixed_t dx_fixed, dy_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_device_distance (cr->gstate, &dx, &dy);
dx_fixed = _cairo_fixed_from_double (dx);
dy_fixed = _cairo_fixed_from_double (dy);
cr->status = _cairo_path_fixed_rel_line_to (&cr->path, dx_fixed, dy_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_rel_line_to);
void
cairo_rel_curve_to (cairo_t *cr,
double dx1, double dy1,
double dx2, double dy2,
double dx3, double dy3)
{
cairo_fixed_t dx1_fixed, dy1_fixed;
cairo_fixed_t dx2_fixed, dy2_fixed;
cairo_fixed_t dx3_fixed, dy3_fixed;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
_cairo_gstate_user_to_device_distance (cr->gstate, &dx1, &dy1);
_cairo_gstate_user_to_device_distance (cr->gstate, &dx2, &dy2);
_cairo_gstate_user_to_device_distance (cr->gstate, &dx3, &dy3);
dx1_fixed = _cairo_fixed_from_double (dx1);
dy1_fixed = _cairo_fixed_from_double (dy1);
dx2_fixed = _cairo_fixed_from_double (dx2);
dy2_fixed = _cairo_fixed_from_double (dy2);
dx3_fixed = _cairo_fixed_from_double (dx3);
dy3_fixed = _cairo_fixed_from_double (dy3);
cr->status = _cairo_path_fixed_rel_curve_to (&cr->path,
dx1_fixed, dy1_fixed,
dx2_fixed, dy2_fixed,
dx3_fixed, dy3_fixed);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_rectangle (cairo_t *cr,
double x, double y,
double width, double height)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cairo_move_to (cr, x, y);
cairo_rel_line_to (cr, width, 0);
cairo_rel_line_to (cr, 0, height);
cairo_rel_line_to (cr, -width, 0);
cairo_close_path (cr);
}
/* XXX: NYI
void
cairo_stroke_to_path (cairo_t *cr)
{
if (cr->status)
return;
cr->status = _cairo_gstate_stroke_path (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
*/
void
cairo_close_path (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_path_fixed_close_path (&cr->path);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_close_path);
/**
* cairo_paint:
* @cr: a cairo context
*
* A drawing operator that paints the current source everywhere within
* the current clip region.
**/
void
cairo_paint (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_paint (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_paint_with_alpha:
* @cr: a cairo context
* @alpha: alpha value, between 0 (transparent) and 1 (opaque)
*
* A drawing operator that paints the current source everywhere within
* the current clip region using a mask of constant alpha value
* @alpha. The effect is similar to cairo_paint(), but the drawing
* is faded out using the alpha value.
**/
void
cairo_paint_with_alpha (cairo_t *cr,
double alpha)
{
cairo_color_t color;
cairo_pattern_union_t pattern;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (CAIRO_ALPHA_IS_OPAQUE (alpha)) {
cairo_paint (cr);
return;
}
_cairo_color_init_rgba (&color, 1., 1., 1., alpha);
_cairo_pattern_init_solid (&pattern.solid, &color);
cr->status = _cairo_gstate_mask (cr->gstate, &pattern.base);
if (cr->status)
_cairo_error (cr, cr->status);
_cairo_pattern_fini (&pattern.base);
}
/**
* cairo_mask:
* @cr: a cairo context
* @pattern: a #cairo_pattern_t
*
* A drawing operator that paints the current source
* using the alpha channel of @pattern as a mask. (Opaque
* areas of @mask are painted with the source, transparent
* areas are not painted.)
*/
void
cairo_mask (cairo_t *cr,
cairo_pattern_t *pattern)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (pattern == NULL) {
_cairo_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
if (pattern->status) {
_cairo_error (cr, pattern->status);
return;
}
cr->status = _cairo_gstate_mask (cr->gstate, pattern);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_mask_surface:
* @cr: a cairo context
* @surface: a #cairo_surface_t
* @surface_x: X coordinate at which to place the origin of @surface
* @surface_y: Y coordinate at which to place the origin of @surface
*
* A drawing operator that paints the current source
* using the alpha channel of @surface as a mask. (Opaque
* areas of @surface are painted with the source, transparent
* areas are not painted.)
*/
void
cairo_mask_surface (cairo_t *cr,
cairo_surface_t *surface,
double surface_x,
double surface_y)
{
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
pattern = cairo_pattern_create_for_surface (surface);
cairo_matrix_init_translate (&matrix, - surface_x, - surface_y);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_mask (cr, pattern);
cairo_pattern_destroy (pattern);
}
/**
* cairo_stroke:
* @cr: a cairo context
*
* A drawing operator that strokes the current path according to the
* current line width, line join, line cap, and dash settings. After
* cairo_stroke, the current path will be cleared from the cairo
* context. See cairo_set_line_width(), cairo_set_line_join(),
* cairo_set_line_cap(), cairo_set_dash(), and
* cairo_stroke_preserve().
**/
void
cairo_stroke (cairo_t *cr)
{
cairo_stroke_preserve (cr);
cairo_new_path (cr);
}
/**
* cairo_stroke_preserve:
* @cr: a cairo context
*
* A drawing operator that strokes the current path according to the
* current line width, line join, line cap, and dash settings. Unlike
* cairo_stroke(), cairo_stroke_preserve preserves the path within the
* cairo context.
*
* See cairo_set_line_width(), cairo_set_line_join(),
* cairo_set_line_cap(), cairo_set_dash(), and
* cairo_stroke_preserve().
**/
void
cairo_stroke_preserve (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_stroke (cr->gstate, &cr->path);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_stroke_preserve);
/**
* cairo_fill:
* @cr: a cairo context
*
* A drawing operator that fills the current path according to the
* current fill rule. After cairo_fill, the current path will be
* cleared from the cairo context. See cairo_set_fill_rule() and
* cairo_fill_preserve().
**/
void
cairo_fill (cairo_t *cr)
{
cairo_fill_preserve (cr);
cairo_new_path (cr);
}
/**
* cairo_fill_preserve:
* @cr: a cairo context
*
* A drawing operator that fills the current path according to the
* current fill rule. Unlike cairo_fill(), cairo_fill_preserve
* preserves the path within the cairo context.
*
* See cairo_set_fill_rule() and cairo_fill().
**/
void
cairo_fill_preserve (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_fill (cr->gstate, &cr->path);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_fill_preserve);
void
cairo_copy_page (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_copy_page (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_show_page (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_show_page (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
cairo_bool_t
cairo_in_stroke (cairo_t *cr, double x, double y)
{
int inside;
if (cr->status) {
_cairo_error (cr, cr->status);
return 0;
}
cr->status = _cairo_gstate_in_stroke (cr->gstate,
&cr->path,
x, y, &inside);
if (cr->status) {
_cairo_error (cr, cr->status);
return 0;
}
return inside;
}
int
cairo_in_fill (cairo_t *cr, double x, double y)
{
int inside;
if (cr->status) {
_cairo_error (cr, cr->status);
return 0;
}
cr->status = _cairo_gstate_in_fill (cr->gstate,
&cr->path,
x, y, &inside);
if (cr->status) {
_cairo_error (cr, cr->status);
return 0;
}
return inside;
}
void
cairo_stroke_extents (cairo_t *cr,
double *x1, double *y1, double *x2, double *y2)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_stroke_extents (cr->gstate,
&cr->path,
x1, y1, x2, y2);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_fill_extents (cairo_t *cr,
double *x1, double *y1, double *x2, double *y2)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_fill_extents (cr->gstate,
&cr->path,
x1, y1, x2, y2);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_clip:
* @cr: a cairo context
*
* Establishes a new clip region by intersecting the current clip
* region with the current path as it would be filled by cairo_fill()
* and according to the current fill rule (see cairo_set_fill_rule()).
*
* After cairo_clip, the current path will be cleared from the cairo
* context.
*
* The current clip region affects all drawing operations by
* effectively masking out any changes to the surface that are outside
* the current clip region.
*
* Calling cairo_clip() can only make the clip region smaller, never
* larger. But the current clip is part of the graphics state, so a
* temporary restriction of the clip region can be achieved by
* calling cairo_clip() within a cairo_save()/cairo_restore()
* pair. The only other means of increasing the size of the clip
* region is cairo_reset_clip().
**/
void
cairo_clip (cairo_t *cr)
{
cairo_clip_preserve (cr);
cairo_new_path (cr);
}
/**
* cairo_clip_preserve:
* @cr: a cairo context
*
* Establishes a new clip region by intersecting the current clip
* region with the current path as it would be filled by cairo_fill()
* and according to the current fill rule (see cairo_set_fill_rule()).
*
* Unlike cairo_clip(), cairo_clip_preserve preserves the path within
* the cairo context.
*
* The current clip region affects all drawing operations by
* effectively masking out any changes to the surface that are outside
* the current clip region.
*
* Calling cairo_clip() can only make the clip region smaller, never
* larger. But the current clip is part of the graphics state, so a
* temporary restriction of the clip region can be achieved by
* calling cairo_clip() within a cairo_save()/cairo_restore()
* pair. The only other means of increasing the size of the clip
* region is cairo_reset_clip().
**/
void
cairo_clip_preserve (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_clip (cr->gstate, &cr->path);
if (cr->status)
_cairo_error (cr, cr->status);
}
slim_hidden_def(cairo_clip_preserve);
/**
* cairo_reset_clip:
* @cr: a cairo context
*
* Reset the current clip region to its original, unrestricted
* state. That is, set the clip region to an infinitely large shape
* containing the target surface. Equivalently, if infinity is too
* hard to grasp, one can imagine the clip region being reset to the
* exact bounds of the target surface.
*
* Note that code meant to be reusable should not call
* cairo_reset_clip() as it will cause results unexpected by
* higher-level code which calls cairo_clip(). Consider using
* cairo_save() and cairo_restore() around cairo_clip() as a more
* robust means of temporarily restricting the clip region.
**/
void
cairo_reset_clip (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_reset_clip (cr->gstate);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_select_font_face:
* @cr: a #cairo_t
* @family: a font family name, encoded in UTF-8
* @slant: the slant for the font
* @weight: the weight for the font
*
* Selects a family and style of font from a simplified description as
* a family name, slant and weight. This function is meant to be used
* only for applications with simple font needs: Cairo doesn't provide
* for operations such as listing all available fonts on the system,
* and it is expected that most applications will need to use a more
* comprehensive font handling and text layout library in addition to
* Cairo.
**/
void
cairo_select_font_face (cairo_t *cr,
const char *family,
cairo_font_slant_t slant,
cairo_font_weight_t weight)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_get_font_face:
* @cr: a #cairo_t
*
* Gets the current font face for a #cairo_t.
*
* Return value: the current font object. Can return %NULL
* on out-of-memory or if the context is already in
* an error state. This object is owned by cairo. To keep
* a reference to it, you must call cairo_font_face_reference().
**/
cairo_font_face_t *
cairo_get_font_face (cairo_t *cr)
{
cairo_font_face_t *font_face;
if (cr->status) {
_cairo_error (cr, cr->status);
return NULL;
}
cr->status = _cairo_gstate_get_font_face (cr->gstate, &font_face);
if (cr->status) {
_cairo_error (cr, cr->status);
/* XXX: When available:
return _cairo_font_face_create_in_error (cr->status);
*/
return NULL;
}
return font_face;
}
/**
* cairo_font_extents:
* @cr: a #cairo_t
* @extents: a #cairo_font_extents_t object into which the results
* will be stored.
*
* Gets the font extents for the currently selected font.
**/
void
cairo_font_extents (cairo_t *cr,
cairo_font_extents_t *extents)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_get_font_extents (cr->gstate, extents);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_font_face:
* @cr: a #cairo_t
* @font_face: a #cairo_font_face_t, or %NULL to restore to the default font
*
* Replaces the current #cairo_font_face_t object in the #cairo_t with
* @font_face. The replaced font face in the #cairo_t will be
* destroyed if there are no other references to it.
**/
void
cairo_set_font_face (cairo_t *cr,
cairo_font_face_t *font_face)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_font_face (cr->gstate, font_face);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_font_size:
* @cr: a #cairo_t
* @size: the new font size, in user space units
*
* Sets the current font matrix to a scale by a factor of @size, replacing
* any font matrix previously set with cairo_set_font_size() or
* cairo_set_font_matrix(). This results in a font size of @size user space
* units. (More precisely, this matrix will result in the font's
* em-square being a @size by @size square in user space.)
**/
void
cairo_set_font_size (cairo_t *cr, double size)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_font_size (cr->gstate, size);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_set_font_matrix
* @cr: a #cairo_t
* @matrix: a #cairo_matrix_t describing a transform to be applied to
* the current font.
*
* Sets the current font matrix to @matrix. The font matrix gives a
* transformation from the design space of the font (in this space,
* the em-square is 1 unit by 1 unit) to user space. Normally, a
* simple scale is used (see cairo_set_font_size()), but a more
* complex font matrix can be used to shear the font
* or stretch it unequally along the two axes
**/
void
cairo_set_font_matrix (cairo_t *cr,
const cairo_matrix_t *matrix)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_set_font_matrix (cr->gstate, matrix);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_get_font_matrix
* @cr: a #cairo_t
* @matrix: return value for the matrix
*
* Stores the current font matrix into @matrix. See
* cairo_set_font_matrix().
**/
void
cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix)
{
_cairo_gstate_get_font_matrix (cr->gstate, matrix);
}
/**
* cairo_text_extents:
* @cr: a #cairo_t
* @utf8: a string of text, encoded in utf-8
* @extents: a #cairo_text_extents_t object into which the results
* will be stored.
*
* Gets the extents for a string of text. The extents describe a
* user-space rectangle that encloses the "inked" portion of the text,
* (as it would be drawn by cairo_show_text). Additionally, the
* x_advance and y_advance values indicate the amount by which the
* current point would be advanced by cairo_show_text.
*
* Note that whitespace characters do not directly contribute to the
* size of the rectangle (extents.width and extents.height). They do
* contribute indirectly by changing the position of non-whitespace
* characters. In particular, trailing whitespace characters are
* likely to not affect the size of the rectangle, though they will
* affect the x_advance and y_advance values.
**/
void
cairo_text_extents (cairo_t *cr,
const char *utf8,
cairo_text_extents_t *extents)
{
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
double x, y;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (utf8 == NULL) {
extents->x_bearing = 0.0;
extents->y_bearing = 0.0;
extents->width = 0.0;
extents->height = 0.0;
extents->x_advance = 0.0;
extents->y_advance = 0.0;
return;
}
cairo_get_current_point (cr, &x, &y);
cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
x, y,
&glyphs, &num_glyphs);
if (cr->status) {
if (glyphs)
free (glyphs);
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents);
if (glyphs)
free (glyphs);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_glyph_extents:
* @cr: a #cairo_t
* @glyphs: an array of #cairo_glyph_t objects
* @num_glyphs: the number of elements in @glyphs
* @extents: a #cairo_text_extents_t object into which the results
* will be stored
*
* Gets the extents for an array of glyphs. The extents describe a
* user-space rectangle that encloses the "inked" portion of the
* glyphs, (as they would be drawn by cairo_show_glyphs).
* Additionally, the x_advance and y_advance values indicate the
* amount by which the current point would be advanced by
* cairo_show_glyphs.
*
* Note that whitespace glyphs do not contribute to the size of the
* rectangle (extents.width and extents.height).
**/
void
cairo_glyph_extents (cairo_t *cr,
cairo_glyph_t *glyphs,
int num_glyphs,
cairo_text_extents_t *extents)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs,
extents);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_show_text (cairo_t *cr, const char *utf8)
{
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
double x, y;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (utf8 == NULL)
return;
cairo_get_current_point (cr, &x, &y);
cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
x, y,
&glyphs, &num_glyphs);
if (cr->status) {
if (glyphs)
free (glyphs);
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs);
if (glyphs)
free (glyphs);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_show_glyphs (cairo_t *cr, cairo_glyph_t *glyphs, int num_glyphs)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_text_path (cairo_t *cr, const char *utf8)
{
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
double x, y;
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cairo_get_current_point (cr, &x, &y);
cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
x, y,
&glyphs, &num_glyphs);
if (cr->status) {
if (glyphs)
free (glyphs);
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_glyph_path (cr->gstate,
glyphs, num_glyphs,
&cr->path);
if (glyphs)
free (glyphs);
if (cr->status)
_cairo_error (cr, cr->status);
}
void
cairo_glyph_path (cairo_t *cr, cairo_glyph_t *glyphs, int num_glyphs)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
cr->status = _cairo_gstate_glyph_path (cr->gstate,
glyphs, num_glyphs,
&cr->path);
if (cr->status)
_cairo_error (cr, cr->status);
}
/**
* cairo_get_operator:
* @cr: a cairo context
*
* Gets the current compositing operator for a cairo context.
*
* Return value: the current compositing operator.
**/
cairo_operator_t
cairo_get_operator (cairo_t *cr)
{
return _cairo_gstate_get_operator (cr->gstate);
}
/**
* cairo_get_tolerance:
* @cr: a cairo context
*
* Gets the current tolerance value, as set by cairo_set_tolerance().
*
* Return value: the current tolerance value.
**/
double
cairo_get_tolerance (cairo_t *cr)
{
return _cairo_gstate_get_tolerance (cr->gstate);
}
/**
* cairo_get_current_point:
* @cr: a cairo context
* @x: return value for X coordinate of the current point
* @y: return value for Y coordinate of the current point
*
* Gets the current point of the current path, which is
* conceptually the final point reached by the path so far.
*
* The current point is returned in the user-space coordinate
* system. If there is no defined current point then @x and @y will
* both be set to 0.0.
*
* Most path construction functions alter the current point. See the
* following for details on how they affect the current point:
*
* cairo_new_path(), cairo_move_to(), cairo_line_to(),
* cairo_curve_to(), cairo_arc(), cairo_rel_move_to(),
* cairo_rel_line_to(), cairo_rel_curve_to(), cairo_arc(),
* cairo_text_path(), cairo_stroke_to_path()
**/
void
cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret)
{
cairo_status_t status;
cairo_fixed_t x_fixed, y_fixed;
double x, y;
status = _cairo_path_fixed_get_current_point (&cr->path, &x_fixed, &y_fixed);
if (status == CAIRO_STATUS_NO_CURRENT_POINT) {
x = 0.0;
y = 0.0;
} else {
x = _cairo_fixed_to_double (x_fixed);
y = _cairo_fixed_to_double (y_fixed);
_cairo_gstate_backend_to_user (cr->gstate, &x, &y);
}
if (x_ret)
*x_ret = x;
if (y_ret)
*y_ret = y;
}
slim_hidden_def(cairo_get_current_point);
/**
* cairo_get_fill_rule:
* @cr: a cairo context
*
* Gets the current fill rule, as set by cairo_set_fill_rule().
*
* Return value: the current fill rule.
**/
cairo_fill_rule_t
cairo_get_fill_rule (cairo_t *cr)
{
return _cairo_gstate_get_fill_rule (cr->gstate);
}
/**
* cairo_get_line_width:
* @cr: a cairo context
*
* Gets the current line width, as set by cairo_set_line_width().
*
* Return value: the current line width, in user-space units.
**/
double
cairo_get_line_width (cairo_t *cr)
{
return _cairo_gstate_get_line_width (cr->gstate);
}
/**
* cairo_get_line_cap:
* @cr: a cairo context
*
* Gets the current line cap style, as set by cairo_set_line_cap().
*
* Return value: the current line cap style.
**/
cairo_line_cap_t
cairo_get_line_cap (cairo_t *cr)
{
return _cairo_gstate_get_line_cap (cr->gstate);
}
/**
* cairo_get_line_join:
* @cr: a cairo context
*
* Gets the current line join style, as set by cairo_set_line_join().
*
* Return value: the current line join style.
**/
cairo_line_join_t
cairo_get_line_join (cairo_t *cr)
{
return _cairo_gstate_get_line_join (cr->gstate);
}
/**
* cairo_get_miter_limit:
* @cr: a cairo context
*
* Gets the current miter limit, as set by cairo_set_miter_limit().
*
* Return value: the current miter limit.
**/
double
cairo_get_miter_limit (cairo_t *cr)
{
return _cairo_gstate_get_miter_limit (cr->gstate);
}
/**
* cairo_get_matrix:
* @cr: a cairo context
* @matrix: return value for the matrix
*
* Stores the current transformation matrix (CTM) into @matrix.
**/
void
cairo_get_matrix (cairo_t *cr, cairo_matrix_t *matrix)
{
_cairo_gstate_get_matrix (cr->gstate, matrix);
}
/**
* cairo_get_target:
* @cr: a cairo context
*
* Gets the target surface for the cairo context as passed to
* cairo_create().
*
* Return value: the target surface, (or NULL if @cr is in an error
* state). This object is owned by cairo. To keep a reference to it,
* you must call cairo_surface_reference().
**/
cairo_surface_t *
cairo_get_target (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
/* XXX: Should be as follows when available:
return _cairo_surface_create_in_error ();
*/
return NULL;
}
return _cairo_gstate_get_target (cr->gstate);
}
/**
* cairo_copy_path:
* @cr: a cairo context
*
* Creates a copy of the current path and returns it to the user as a
* #cairo_path_t. See #cairo_path_data_t for hints on how to iterate
* over the returned data structure.
*
* Return value: the copy of the current path. The caller owns the
* returned object and should call cairo_path_destroy() when finished
* with it.
*
* This function will always return a valid pointer, but the result
* will have no data, (data==NULL and num_data==0), if either of the
* following conditions hold:
*
* 1) If there is insufficient memory to copy the path. In this case
* path->status will be set to CAIRO_STATUS_NO_MEMORY.
*
* 2) If @cr is already in an error state. In this case path->status
* will contain the same status that would be returned by
* cairo_status(cr).
**/
cairo_path_t *
cairo_copy_path (cairo_t *cr)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return _cairo_path_data_create_in_error (cr->status);
}
return _cairo_path_data_create (&cr->path, cr->gstate);
}
/**
* cairo_copy_path_flat:
* @cr: a cairo context
*
* Gets a flattened copy of the current path and returns it to the
* user as a #cairo_path_t. See #cairo_path_data_t for hints on
* how to iterate over the returned data structure.
*
* This function is like cairo_copy_path() except that any curves
* in the path will be approximated with piecewise-linear
* approximations, (accurate to within the current tolerance
* value). That is, the result is guaranteed to not have any elements
* of type CAIRO_PATH_CURVE_TO which will instead be replaced by a
* series of CAIRO_PATH_LINE_TO elements.
*
* Return value: the copy of the current path. The caller owns the
* returned object and should call cairo_path_destroy() when finished
* with it.
*
* This function will always return a valid pointer, but the result
* will have no data, (data==NULL and num_data==0), if either of the
* following conditions hold:
*
* 1) If there is insufficient memory to copy the path. In this case
* path->status will be set to CAIRO_STATUS_NO_MEMORY.
*
* 2) If @cr is already in an error state. In this case path->status
* will contain the same status that would be returned by
* cairo_status(cr).
**/
cairo_path_t *
cairo_copy_path_flat (cairo_t *cr)
{
if (cr->status)
return _cairo_path_data_create_in_error (cr->status);
else
return _cairo_path_data_create_flat (&cr->path, cr->gstate);
}
/**
* cairo_append_path:
* @cr: a cairo context
* @path: path to be appended
*
* Append the @path onto the current path. The @path may be either the
* return value from one of cairo_copy_path() or
* cairo_copy_path_flat() or it may be constructed manually. See
* #cairo_path_t for details on how the path data structure should be
* initialized, and note that path->status must be initialized to
* CAIRO_STATUS_SUCCESS.
**/
void
cairo_append_path (cairo_t *cr,
cairo_path_t *path)
{
if (cr->status) {
_cairo_error (cr, cr->status);
return;
}
if (path == NULL) {
_cairo_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
if (path->status) {
if (path->status <= CAIRO_STATUS_LAST_STATUS)
_cairo_error (cr, path->status);
else
_cairo_error (cr, CAIRO_STATUS_INVALID_STATUS);
return;
}
if (path->data == NULL) {
_cairo_error (cr, CAIRO_STATUS_NULL_POINTER);
return;
}
cr->status = _cairo_path_data_append_to_context (path, cr);
if (cr->status)
_cairo_error (cr, cr->status);
}
cairo_status_t
cairo_status (cairo_t *cr)
{
return cr->status;
}
const char *
cairo_status_to_string (cairo_status_t status)
{
switch (status) {
case CAIRO_STATUS_SUCCESS:
return "success";
case CAIRO_STATUS_NO_MEMORY:
return "out of memory";
case CAIRO_STATUS_INVALID_RESTORE:
return "cairo_restore without matching cairo_save";
case CAIRO_STATUS_INVALID_POP_GROUP:
return "cairo_pop_group without matching cairo_push_group";
case CAIRO_STATUS_NO_CURRENT_POINT:
return "no current point defined";
case CAIRO_STATUS_INVALID_MATRIX:
return "invalid matrix (not invertible)";
case CAIRO_STATUS_INVALID_STATUS:
return " invalid value for an input cairo_status_t";
case CAIRO_STATUS_NULL_POINTER:
return "NULL pointer";
case CAIRO_STATUS_INVALID_STRING:
return "input string not valid UTF-8";
case CAIRO_STATUS_INVALID_PATH_DATA:
return "input path data not valid";
case CAIRO_STATUS_READ_ERROR:
return "error while reading from input stream";
case CAIRO_STATUS_WRITE_ERROR:
return "error while writing to output stream";
case CAIRO_STATUS_SURFACE_FINISHED:
return "the target surface has been finished";
case CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
return "the surface type is not appropriate for the operation";
case CAIRO_STATUS_PATTERN_TYPE_MISMATCH:
return "the pattern type is not appropriate for the operation";
}
return "<unknown error status>";
}
void
_cairo_restrict_value (double *value, double min, double max)
{
if (*value < min)
*value = min;
else if (*value > max)
*value = max;
}
|