forked from gtkforphp/cairo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cairo_context.c
3136 lines (2697 loc) · 119 KB
/
cairo_context.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
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2011 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Elizabeth Smith <[email protected]> |
| Michael Maclean <[email protected]> |
| Akshat Gupta <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_cairo.h"
zend_class_entry *cairo_ce_cairocontext;
zend_class_entry *cairo_ce_cairoantialias;
zend_class_entry *cairo_ce_cairosubpixelorder;
zend_class_entry *cairo_ce_cairofillrule;
zend_class_entry *cairo_ce_cairolinecap;
zend_class_entry *cairo_ce_cairolinejoin;
zend_class_entry *cairo_ce_cairooperator;
/* Basic Context */
ZEND_BEGIN_ARG_INFO(CairoContext___construct_args, ZEND_SEND_BY_VAL)
/* ZEND_ARG_OBJ_INFO(0, surface, CairoSurface, 0) */
ZEND_ARG_INFO(0, surface)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_pushGroupWithContent_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, content)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setSourceRGB_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, red)
ZEND_ARG_INFO(0, green)
ZEND_ARG_INFO(0, blue)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setSourceRGBA_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, red)
ZEND_ARG_INFO(0, green)
ZEND_ARG_INFO(0, blue)
ZEND_ARG_INFO(0, alpha)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setSource_args, ZEND_SEND_BY_VAL)
/* ZEND_ARG_OBJ_INFO(0, pattern, CairoPattern, 0) */
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(CairoContext_setSourceSurface_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
/* ZEND_ARG_OBJ_INFO(0, surface, CairoSurface, 0) */
ZEND_ARG_INFO(0, surface)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(CairoContext_setAntialias_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, antialias)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(CairoContext_setDash_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, dashes)
ZEND_ARG_INFO(0, offset)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setFillRule_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, setting)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setLineWidth_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, width)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setMiterLimit_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, limit)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setTolerance_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, tolerance)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_paintWithAlpha_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, alpha)
ZEND_END_ARG_INFO()
/* Transformations */
ZEND_BEGIN_ARG_INFO(CairoContext_translate_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_transform_args, ZEND_SEND_BY_VAL)
/* ZEND_ARG_OBJ_INFO(0, matrix, CairoMatrix, 0) - STUPID E_RECOVERABLE FROM THIS */
ZEND_ARG_INFO(0, matrix)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_rotate_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, angle)
ZEND_END_ARG_INFO()
/* Path support */
ZEND_BEGIN_ARG_INFO(CairoContext_curveTo_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, x1)
ZEND_ARG_INFO(0, y1)
ZEND_ARG_INFO(0, x2)
ZEND_ARG_INFO(0, y2)
ZEND_ARG_INFO(0, x3)
ZEND_ARG_INFO(0, y3)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_textPath_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, string)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_appendPath_args, ZEND_SEND_BY_VAL)
/* ZEND_ARG_OBJ_INFO(0, path, CairoPath, 0) */
ZEND_ARG_INFO(0, path)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_arc_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_ARG_INFO(0, radius)
ZEND_ARG_INFO(0, angle1)
ZEND_ARG_INFO(0, angle2)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_rectangle_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_ARG_INFO(0, width)
ZEND_ARG_INFO(0, height)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_glyphPath_args, ZEND_SEND_BY_VAL)
ZEND_ARG_ARRAY_INFO(0, glyphs, 0)
ZEND_END_ARG_INFO()
/* Text related methods */
ZEND_BEGIN_ARG_INFO_EX(CairoContext_selectFontFace_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, family)
ZEND_ARG_INFO(0, slant)
ZEND_ARG_INFO(0, weight)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setFontSize_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, size)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setFontMatrix_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, matrix)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setFontOptions_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, fontoptions)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setFontFace_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, fontface)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_setScaledFont_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, scaledfont)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoContext_text_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
/* Basic Context Methods */
/* {{{ proto CairoContext cairo_create(CairoSurface surface)
Returns new CairoContext object on the requested surface */
PHP_FUNCTION(cairo_create)
{
zval *surface_zval = NULL;
cairo_context_object *context_object;
cairo_surface_object *surface_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &surface_zval, cairo_ce_cairosurface) == FAILURE) {
return;
}
surface_object = (cairo_surface_object *)zend_object_store_get_object(surface_zval TSRMLS_CC);
object_init_ex(return_value, cairo_ce_cairocontext);
context_object = (cairo_context_object *)zend_object_store_get_object(return_value TSRMLS_CC);
context_object->context = cairo_create(surface_object->surface);
php_cairo_trigger_error(cairo_status(context_object->context) TSRMLS_CC);
/* we need to be able to get this zval out later, so ref and store */
context_object->surface = surface_zval;
Z_ADDREF_P(surface_zval);
}
/* }}} */
/* {{{ proto void __construct(object surface)
Returns new CairoContext object on the requested surface */
PHP_METHOD(CairoContext, __construct)
{
zval *surface_zval = NULL;
cairo_context_object *context_object;
cairo_surface_object *surface_object;
PHP_CAIRO_ERROR_HANDLING(TRUE)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &surface_zval, cairo_ce_cairosurface) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(TRUE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(TRUE)
surface_object = (cairo_surface_object *)zend_object_store_get_object(surface_zval TSRMLS_CC);
context_object = (cairo_context_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
context_object->context = cairo_create(surface_object->surface);
php_cairo_throw_exception(cairo_status(context_object->context) TSRMLS_CC);
/* we need to be able to get this zval out later, so ref and store */
context_object->surface = surface_zval;
Z_ADDREF_P(surface_zval);
}
/* }}} */
/* {{{ proto long cairo_status(CairoContext object)
proto long CairoContext->status()
Returns the current integer status of the CairoContext */
PHP_FUNCTION(cairo_status)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *) cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_save(CairoContext object)
proto void CairoContext->save()
Makes a copy of the current state of the context and saves it on an internal stack of saved states */
PHP_FUNCTION(cairo_save)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *) cairo_context_object_get(context_zval TSRMLS_CC);
cairo_save(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_restore(CairoContext object)
proto void CairoContext->restore()
Restores the context to the state saved and removes that state from the stack of saved states */
PHP_FUNCTION(cairo_restore)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *) cairo_context_object_get(context_zval TSRMLS_CC);
cairo_restore(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto CairoSurface object cairo_get_target(CairoContext object)
proto CairoSurface object CairoContext->getTarget()
Gets the target surface for the cairo context that was set on creation */
PHP_FUNCTION(cairo_get_target)
{
zend_class_entry *ce;
zval *context_zval = NULL;
cairo_surface_t *surface;
cairo_context_object *context_object;
cairo_surface_object *surface_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *) cairo_context_object_get(context_zval TSRMLS_CC);
/* Grab the surface properly */
surface = cairo_get_target(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
/* If we have a surface object stored, grab that zval to use */
if(context_object->surface) {
zval_dtor(return_value);
*return_value = *context_object->surface;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
ce = php_cairo_get_surface_ce(surface TSRMLS_CC);
object_init_ex(return_value, ce);
}
/* Get the surface_object and replace the internal surface pointer with what we fetched (should be the same) */
surface_object = (cairo_surface_object *)zend_object_store_get_object(return_value TSRMLS_CC);
/* if there IS a value in surface, destroy it cause we're getting a new one */
if (surface_object->surface != NULL) {
cairo_surface_destroy(surface_object->surface);
}
/* Grab the surface properly */
surface_object->surface = surface;
cairo_surface_reference(surface_object->surface);
}
/* }}} */
/* {{{ proto void cairo_push_group(CairoContext object)
proto void CairoContext->pushGroup()
Temporarily redirects drawing to an intermediate surface known as a group. */
PHP_FUNCTION(cairo_push_group)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_push_group(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_push_group_with_content(CairoContext object, int content)
proto void CairoContext->pushGroupWithContent(int content)
Temporarily redirects drawing to an intermediate surface known as a group. */
PHP_FUNCTION(cairo_push_group_with_content)
{
zval *context_zval = NULL;
/* should be cairo_content_t but we need a long */
long content;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, cairo_ce_cairocontext, &content) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_push_group_with_content(context_object->context, content);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto CairoPattern object cairo_pop_group(CairoContext object)
proto CairoPattern object CairoContext->popGroup()
Terminates the redirection and returns a new pattern containing the results of all drawing operations performed to the group. */
PHP_FUNCTION(cairo_pop_group)
{
zend_class_entry *ce;
zval *context_zval = NULL;
cairo_pattern_t *pattern;
cairo_context_object *context_object;
cairo_pattern_object *pattern_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
pattern = cairo_pop_group(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
ce = php_cairo_get_pattern_ce(pattern TSRMLS_CC);
object_init_ex(return_value, ce);
pattern_object = (cairo_pattern_object *)zend_object_store_get_object(return_value TSRMLS_CC);
pattern_object->pattern = pattern;
}
/* }}} */
/* {{{ proto void cairo_pop_group_to_source(CairoContext object)
proto void CairoContext->popGroupToSource()
Terminates the redirection and installs the resulting pattern as the source pattern in the given cairo context. */
PHP_FUNCTION(cairo_pop_group_to_source)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_pop_group_to_source(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto CairoSurface object cairo_get_group_target(CairoContext object)
proto CairoSurface object CairoContext->getGroupTarget()
Gets the current destination surface for the context */
PHP_FUNCTION(cairo_get_group_target)
{
zend_class_entry *ce;
zval *context_zval = NULL;
cairo_surface_t *surface;
cairo_context_object *context_object;
cairo_surface_object *surface_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
surface = cairo_get_group_target(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
ce = php_cairo_get_surface_ce(surface TSRMLS_CC);
object_init_ex(return_value, ce);
surface_object = (cairo_surface_object *)zend_object_store_get_object(return_value TSRMLS_CC);
surface_object->surface = cairo_get_group_target(context_object->context);
cairo_surface_reference(surface_object->surface);
}
/* }}} */
/* {{{ proto void cairo_set_source_rgb(CairoContext object, float red, float green, float blue)
proto void CairoContext->setSourceRGB(float red, float green, float blue)
Sets the source pattern within context to an opaque color. This opaque color will then be used for any subsequent drawing operation until a new source pattern is set. */
PHP_FUNCTION(cairo_set_source_rgb)
{
zval * context_zval = NULL;
double red = 0.0, green = 0.0, blue = 0.0;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oddd", &context_zval, cairo_ce_cairocontext, &red, &green, &blue) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_source_rgb(context_object->context, red, green, blue);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_source_rgba(CairoContext object, float red, float green, float blue, float alpha)
proto void CairoContext->setSourceRGBA(float red, float green, float blue, float alpha)
Sets the source pattern within context to an translucent color. This opaque color will then be used for any subsequent drawing operation until a new source pattern is set. */
PHP_FUNCTION(cairo_set_source_rgba)
{
zval * context_zval = NULL;
double red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odddd", &context_zval, cairo_ce_cairocontext, &red, &green, &blue, &alpha) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_source_rgba(context_object->context, red, green, blue, alpha);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_source(CairoContext object, CairoPattern object)
proto void CairoContext->setSource(CairoPattern object)
Sets the source pattern within context to source. This pattern will then be used for any subsequent drawing operation until a new source pattern is set. */
PHP_FUNCTION(cairo_set_source)
{
zval *context_zval = NULL, *pattern_zval = NULL;
cairo_context_object *context_object;
cairo_pattern_object *pattern_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &context_zval, cairo_ce_cairocontext, &pattern_zval, cairo_ce_cairopattern) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
pattern_object = (cairo_pattern_object *)cairo_pattern_object_get(pattern_zval TSRMLS_CC);
cairo_set_source(context_object->context, pattern_object->pattern);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
/* If there's already a pattern, then we deref and remove it */
if(context_object->pattern) {
Z_DELREF_P(context_object->pattern);
context_object->pattern = NULL;
}
/* we need to be able to get this zval out later, so ref and store */
context_object->pattern = pattern_zval;
Z_ADDREF_P(pattern_zval);
}
/* }}} */
/* {{{ proto void cairo_set_source_surface(CairoContext object, CairoSurface object [,float x, float y])
proto void CairoContext->setSourceSurface(object surface [,float x, float y])
This is a convenience function for creating a pattern from surface and setting it as the source
*/
PHP_FUNCTION(cairo_set_source_surface)
{
zval *context_zval = NULL, *surface_zval = NULL;
cairo_context_object *context_object;
cairo_surface_object *surface_object;
double x = 0.0, y = 0.0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|dd", &context_zval, cairo_ce_cairocontext, &surface_zval, cairo_ce_cairosurface, &x, &y) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
surface_object = (cairo_surface_object *)cairo_surface_object_get(surface_zval TSRMLS_CC);
cairo_set_source_surface(context_object->context, surface_object->surface, x, y);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
/* If there's already a pattern, then we deref and remove it because we just overwrote it */
if(context_object->pattern) {
Z_DELREF_P(context_object->pattern);
context_object->pattern = NULL;
}
}
/* }}} */
/* {{{ proto CairoPattern object cairo_get_source(CairoContext object)
proto CairoPattern object CairoContext->getSource()
Gets the current source pattern for the context. */
PHP_FUNCTION(cairo_get_source)
{
zend_class_entry *ce;
zval *context_zval = NULL;
cairo_pattern_t *pattern;
cairo_context_object *context_object;
cairo_pattern_object *pattern_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
pattern = cairo_get_source(context_object->context);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
/* If we have a patter/source object stored, grab that zval to use */
if(context_object->pattern) {
zval_dtor(return_value);
*return_value = *context_object->pattern;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
ce = php_cairo_get_pattern_ce(pattern TSRMLS_CC);
object_init_ex(return_value, ce);
}
/* Get the pattern object and replace the internal pattern pointer with what we fetched (should be the same) */
pattern_object = (cairo_pattern_object *)zend_object_store_get_object(return_value TSRMLS_CC);
/* if there IS a value in pattern, destroy it cause we're getting a new one */
if (pattern_object->pattern != NULL) {
cairo_pattern_destroy(pattern_object->pattern);
}
pattern_object->pattern = pattern;
cairo_pattern_reference(pattern_object->pattern);
}
/* }}} */
/* {{{ proto void cairo_set_antialias(CairoContext object[, int antialias])
proto void CairoContext->setAntialias([int antialias])
Set the antialiasing mode of the rasterizer used for drawing shapes. */
PHP_FUNCTION(cairo_set_antialias)
{
zval *context_zval = NULL;
long antialias = CAIRO_ANTIALIAS_DEFAULT;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &context_zval, cairo_ce_cairocontext, &antialias) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_antialias(context_object->context, antialias);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto int cairo_get_antialias(CairoContext object)
proto int CairoContext->getAntialias()
Gets the current shape antialiasing mode */
PHP_FUNCTION(cairo_get_antialias)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_get_antialias(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_dash(CairoContext object, array dashes [, float offset])
proto void CairoContext->setDash(array dashes [, float offset])
Sets the dash pattern to be used by cairo_stroke() */
PHP_FUNCTION(cairo_set_dash)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
double offset = 0.0;
long num_dashes = 0;
double *dashes_array;
zval * dashes = NULL, **ppzval;
HashTable *dashes_hash = NULL;
int i = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa/|d", &context_zval, cairo_ce_cairocontext, &dashes, &offset) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
/* Grab the zend hash and see how big our array will be */
dashes_hash = Z_ARRVAL_P(dashes);
num_dashes = zend_hash_num_elements(dashes_hash);
dashes_array = emalloc(num_dashes * sizeof(double));
/* iterate the array, make sure we JUGGLE the value to a double */
for(zend_hash_internal_pointer_reset(dashes_hash); zend_hash_has_more_elements(dashes_hash) == SUCCESS; zend_hash_move_forward(dashes_hash)) {
if (zend_hash_get_current_data(dashes_hash, (void **)&ppzval) == FAILURE) {
continue;
}
if (Z_TYPE_PP(ppzval) != IS_DOUBLE) {
convert_to_double(*ppzval);
}
dashes_array[i++] = Z_DVAL_PP(ppzval);
}
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
/* we use i in case we had a bad issue while iterating the array */
cairo_set_dash(context_object->context, dashes_array, i, offset);
efree(dashes_array);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 4, 0)
/* {{{ proto int cairo_get_dash_count(CairoContext object)
proto int CairoContext->getDashCount()
This function returns the length of the dash array or 0 */
PHP_FUNCTION(cairo_get_dash_count)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_get_dash_count(context_object->context));
}
/* }}} */
/* {{{ proto array cairo_get_dash(CairoContext object)
proto array CairoContext->getDash()
Gets the current dash array and offset */
PHP_FUNCTION(cairo_get_dash)
{
zval *sub_array, *context_zval = NULL;
cairo_context_object *context_object;
double *dashes = NULL;
double offset = 0;
int num_dashes, i;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
/* Setup container for dashes */
num_dashes = cairo_get_dash_count(context_object->context);
dashes = emalloc(num_dashes * sizeof(double));
/* Get dashes and push into PHP array */
cairo_get_dash(context_object->context, dashes, &offset);
MAKE_STD_ZVAL(sub_array);
array_init(sub_array);
for(i = 0; i < num_dashes; i++) {
add_next_index_double(sub_array, dashes[i]);
}
efree(dashes);
/* Put dashes and offset into return */
array_init(return_value);
add_assoc_zval(return_value, "dashes", sub_array);
add_assoc_double(return_value, "offset", offset);
}
/* }}} */
#endif
/* {{{ proto void cairo_set_fill_rule(CairoContext object, int setting)
proto void CairoContext->setFillRule(int setting)
Set the current fill rule within the cairo context. The fill rule is used
to determine which regions are inside or outside a complex path */
PHP_FUNCTION(cairo_set_fill_rule)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
long fill_rule = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, cairo_ce_cairocontext, &fill_rule) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_fill_rule(context_object->context, fill_rule);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto int cairo_get_fill_rule(CairoContext object)
proto int CairoContext->getFillRule()
Gets the current fill rule */
PHP_FUNCTION(cairo_get_fill_rule)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_get_fill_rule(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_line_cap(CairoContext object, int setting)
proto void CairoContext->setLineCap(int setting)
Sets the current line cap style within the cairo context. */
PHP_FUNCTION(cairo_set_line_cap)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
long line_cap = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, cairo_ce_cairocontext, &line_cap) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_line_cap(context_object->context, line_cap);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto int cairo_get_line_cap(CairoContext object)
proto int CairoContext->getLineCap()
Gets the current line cap style */
PHP_FUNCTION(cairo_get_line_cap)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_get_line_cap(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_line_join(CairoContext object, int setting)
proto void CairoContext->setLineJoin(int setting)
Sets the current line join style within the cairo context. */
PHP_FUNCTION(cairo_set_line_join)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
long line_join = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, cairo_ce_cairocontext, &line_join) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_line_join(context_object->context, line_join);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto int cairo_get_line_join(CairoContext object)
proto int CairoContext->getLineJoin()
Gets the current line join style */
PHP_FUNCTION(cairo_get_line_join)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_LONG(cairo_get_line_join(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_line_width(CairoContext object, float width)
proto void CairoContext->setLineWidth(float 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 */
PHP_FUNCTION(cairo_set_line_width)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
double width = 0.0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", &context_zval, cairo_ce_cairocontext, &width) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_line_width(context_object->context, width);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto double cairo_get_line_width(CairoContext object)
proto double CairoContext->getLineWidth()
This function returns the current line width value exactly as set by cairo_set_line_width() */
PHP_FUNCTION(cairo_get_line_width)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_DOUBLE(cairo_get_line_width(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_miter_limit(CairoContext object, float limit)
proto void CairoContext->setMiterLimit(float limit)
Sets the current miter limit within the cairo context. */
PHP_FUNCTION(cairo_set_miter_limit)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
double limit = 0.0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", &context_zval, cairo_ce_cairocontext, &limit) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
cairo_set_miter_limit(context_object->context, limit);
PHP_CAIRO_ERROR(cairo_status(context_object->context));
}
/* }}} */
/* {{{ proto double cairo_get_miter_limit(CairoContext object)
proto double CairoContext->getMiterLimit()
Gets the current miter limit */
PHP_FUNCTION(cairo_get_miter_limit)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, cairo_ce_cairocontext) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
context_object = (cairo_context_object *)cairo_context_object_get(context_zval TSRMLS_CC);
RETURN_DOUBLE(cairo_get_miter_limit(context_object->context));
}
/* }}} */
/* {{{ proto void cairo_set_operator(CairoContext object, int setting)
proto void CairoContext->setOperator(int setting)
Sets the compositing operator to be used for all drawing operations. */
PHP_FUNCTION(cairo_set_operator)
{
zval *context_zval = NULL;
cairo_context_object *context_object;
long op = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, cairo_ce_cairocontext, &op) == FAILURE) {