1 #include "php_cairo_api.h"
2 #include "CairoSurface.h"
3 #include "CairoExceptionMacro.h"
4 #include "php_cairo_ce_ptr.h"
6 /* {{{ Class CairoSurface */
8 static zend_class_entry
* CairoSurface_ce_ptr
= NULL
;
9 static zend_object_handlers CairoSurface_handlers
;
12 _write_func(void *closure
, const unsigned char *data
, unsigned int length
)
15 php_stream
*zs
= (php_stream
*)closure
;
16 written
= php_stream_write(zs
, data
, length
);
18 return CAIRO_STATUS_SUCCESS
;
20 printf("is it an error ?");
25 _read_func(void *closure
, const unsigned char *data
, unsigned int length
)
28 php_stream
*zs
= (php_stream
*)closure
;
29 read
= php_stream_read(zs
, data
, length
);
31 return CAIRO_STATUS_SUCCESS
;
33 printf("is it an error");
40 typedef struct _surface_object {
42 cairo_surface_t *surface;
49 /* {{{ proto void construct()
51 PHP_METHOD(CairoSurface
, __construct
)
57 if (ZEND_NUM_ARGS()>0) {
63 php_print("No direct call for this constructor");
71 /* {{{ proto object createSimilar(int content, int width, int height)
73 PHP_METHOD(CairoSurface
, createSimilar
)
76 zval
* _this_zval
= NULL
;
82 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Olll", &_this_zval
, CairoSurface_ce_ptr
, &content
, &width
, &height
) == FAILURE
) {
86 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
87 sur
= cairo_surface_create_similar(curr
->surface
, content
, width
, height
);
88 ce
= get_CairoSurface_ce_ptr(sur
);
89 object_init_ex(return_value
, ce
);
90 surface_object
*sobj
= (surface_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
94 /* }}} createSimilar */
97 /* {{{ proto void finish()
99 PHP_METHOD(CairoSurface
, finish
)
102 zval
* _this_zval
= NULL
;
104 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoSurface_ce_ptr
) == FAILURE
) {
108 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
109 cairo_surface_finish(curr
->surface
);
115 /* {{{ proto void flush()
117 PHP_METHOD(CairoSurface
, flush
)
120 zval
* _this_zval
= NULL
;
122 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoSurface_ce_ptr
) == FAILURE
) {
126 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
128 cairo_surface_flush(curr
->surface
);
135 /* {{{ proto int getContent()
137 PHP_METHOD(CairoSurface
, getContent
)
140 zval
* _this_zval
= NULL
;
141 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoSurface_ce_ptr
) == FAILURE
) {
145 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
147 RETURN_LONG(cairo_surface_get_content(curr
->surface
));
153 /* {{{ proto array getDeviceOffset()
155 PHP_METHOD(CairoSurface
, getDeviceOffset
)
158 zval
* _this_zval
= NULL
;
159 double x_offset
, y_offset
;
161 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoSurface_ce_ptr
) == FAILURE
) {
165 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
167 cairo_surface_get_device_offset(curr
->surface
, &x_offset
, &y_offset
);
169 array_init(return_value
);
170 add_assoc_double(return_value
, "x", x_offset
);
171 add_assoc_double(return_value
, "y", y_offset
);
174 /* }}} getDeviceOffset */
178 /* {{{ proto object getFontOptions()
180 PHP_METHOD(CairoSurface
, getFontOptions
)
183 zval
* _this_zval
= NULL
;
185 cairo_font_options_t
*options
= cairo_font_options_create();
188 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoSurface_ce_ptr
) == FAILURE
) {
192 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
194 cairo_surface_get_font_options(curr
->surface
, options
);
195 object_init_ex(return_value
, CairoFontOptions_ce_ptr
);
196 fontoptions_object
*fobj
= (fontoptions_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
197 fobj
->fontoptions
= options
;
200 /* }}} getFontOptions */
204 /* {{{ proto void markDirtyRectangle([int x, int y, int width, int height])
206 PHP_METHOD(CairoSurface
, markDirtyRectangle
)
209 zval
* _this_zval
= NULL
;
217 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|llll", &_this_zval
, CairoSurface_ce_ptr
, &x
, &y
, &width
, &height
) == FAILURE
) {
220 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
221 cairo_surface_mark_dirty_rectangle(curr
->surface
, x
, y
, width
, height
);
224 /* }}} markDirtyRectangle */
228 /* {{{ proto void setDeviceOffset(float x_offset, float y_offset)
230 PHP_METHOD(CairoSurface
, setDeviceOffset
)
233 zval
* _this_zval
= NULL
;
234 double x_offset
= 0.0;
235 double y_offset
= 0.0;
237 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoSurface_ce_ptr
, &x_offset
, &y_offset
) == FAILURE
) {
241 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
242 cairo_surface_set_device_offset(curr
->surface
, x_offset
, y_offset
);
245 /* }}} setDeviceOffset */
249 /* {{{ proto void setFallbackResolution(float x_ppi, float y_ppi)
251 PHP_METHOD(CairoSurface
, setFallbackResolution
)
254 zval
* _this_zval
= NULL
;
258 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoSurface_ce_ptr
, &x_ppi
, &y_ppi
) == FAILURE
) {
262 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
263 cairo_surface_set_fallback_resolution(curr
->surface
, x_ppi
, y_ppi
);
266 /* }}} setFallbackResolution */
270 /* {{{ proto void writeToPng(string file)
272 PHP_METHOD(CairoSurface
, writeToPng
)
275 zval
* _this_zval
= NULL
;
276 const char * file
= NULL
;
278 cairo_status_t status
;
280 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Os", &_this_zval
, CairoSurface_ce_ptr
, &file
, &file_len
) == FAILURE
) {
284 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
285 status
= cairo_surface_write_to_png(curr
->surface
, file
);
291 /* {{{ proto void writeToPngStream(stream file)
293 PHP_METHOD(CairoSurface
, writeToPngStream
)
296 zval
*_this_zval
= NULL
;
297 cairo_status_t status
;
302 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Or", &_this_zval
, CairoSurface_ce_ptr
, &zstream
)) {
306 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
307 php_stream_from_zval(stream
, &zstream
);
308 status
= cairo_surface_write_to_png_stream(curr
->surface
, _write_func
, stream
);
312 /* }}} writeToPngStream*/
315 static zend_function_entry CairoSurface_methods
[] = {
316 PHP_ME(CairoSurface
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
317 PHP_ME(CairoSurface
, createSimilar
, CairoSurface__create_similar_args
, /**/ZEND_ACC_PUBLIC
)
318 PHP_ME(CairoSurface
, finish
, NULL
, /**/ZEND_ACC_PUBLIC
)
319 PHP_ME(CairoSurface
, flush
, NULL
, /**/ZEND_ACC_PUBLIC
)
320 PHP_ME(CairoSurface
, getContent
, NULL
, /**/ZEND_ACC_PUBLIC
)
321 PHP_ME(CairoSurface
, getDeviceOffset
, NULL
, /**/ZEND_ACC_PUBLIC
)
322 PHP_ME(CairoSurface
, getFontOptions
, NULL
, /**/ZEND_ACC_PUBLIC
)
323 PHP_ME(CairoSurface
, markDirtyRectangle
, CairoSurface__mark_dirty_rectangle_args
, /**/ZEND_ACC_PUBLIC
)
324 PHP_ME(CairoSurface
, setDeviceOffset
, CairoSurface__set_device_offset_args
, /**/ZEND_ACC_PUBLIC
)
325 PHP_ME(CairoSurface
, setFallbackResolution
, CairoSurface__set_fallback_resolution_args
, /**/ZEND_ACC_PUBLIC
)
326 PHP_ME(CairoSurface
, writeToPng
, CairoSurface__write_to_png_args
, /**/ZEND_ACC_PUBLIC
)
327 PHP_ME(CairoSurface
, writeToPngStream
, CairoSurface__write_to_png_stream_args
, /**/ZEND_ACC_PUBLIC
)
334 static void CairoSurface_object_dtor(void *object
)
336 surface_object
*surface
= (surface_object
*)object
;
337 zend_hash_destroy(surface
->std
.properties
);
338 FREE_HASHTABLE(surface
->std
.properties
);
339 if(surface
->surface
){
340 cairo_surface_finish(surface
->surface
);
341 cairo_surface_destroy(surface
->surface
);
347 static zend_object_value
CairoSurface_object_new(zend_class_entry
*ce
)
349 zend_object_value retval
;
350 surface_object
*surface
;
353 surface
= emalloc(sizeof(surface_object
));
354 memset(surface
,0,sizeof(surface_object
));
356 surface
->std
.ce
= ce
;
358 ALLOC_HASHTABLE(surface
->std
.properties
);
359 zend_hash_init(surface
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
, 0);
360 zend_hash_copy(surface
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
,(void *) &temp
, sizeof(zval
*));
361 retval
.handle
= zend_objects_store_put(surface
, NULL
, (zend_objects_free_object_storage_t
)CairoSurface_object_dtor
, NULL TSRMLS_CC
);
362 retval
.handlers
= &CairoSurface_handlers
;
366 void class_init_CairoSurface(void)
370 INIT_CLASS_ENTRY(ce
, "CairoSurface", CairoSurface_methods
);
371 CairoSurface_ce_ptr
= zend_register_internal_class(&ce
);
372 CairoSurface_ce_ptr
->create_object
= CairoSurface_object_new
;
373 memcpy(&CairoSurface_handlers
, zend_get_std_object_handlers(),sizeof(zend_object_handlers
));
374 CairoSurface_handlers
.clone_obj
= NULL
;
377 /* }}} Class CairoSurface */
379 /* {{{ Class CairoImageSurface -- done :)*/
381 static zend_class_entry
* CairoImageSurface_ce_ptr
= NULL
;
382 static zend_object_handlers CairoImageSurface_handlers
;
388 /* {{{ proto void construct(int format, int widthm, int height)
390 PHP_METHOD(CairoImageSurface
, __construct
)
394 cairo_format_t format
= 0;
400 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "lll", &format
, &widthm
, &height
) == FAILURE
) {
404 _this_zval
= getThis();
405 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
406 curr
->surface
= cairo_image_surface_create(format
, widthm
, height
);
409 /* }}} __construct */
413 /* {{{ proto void createFromData(string obj, int format, int width, int height [, int stride])
415 PHP_METHOD(CairoImageSurface
, createFromData
)
418 zval
* _this_zval
= NULL
;
419 const char * buffer
= NULL
;
428 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Oslll|l", &_this_zval
, CairoImageSurface_ce_ptr
, &buffer
, &buffer_len
, &format
, &width
, &height
, &stride
) == FAILURE
) {
432 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
433 cairo_surface_finish(curr
->surface
);
434 cairo_surface_destroy(curr
->surface
);
438 case CAIRO_FORMAT_ARGB32
:
439 case CAIRO_FORMAT_RGB24
:
442 case CAIRO_FORMAT_RGB16_565
:
445 case CAIRO_FORMAT_A8
:
448 case CAIRO_FORMAT_A1
:
449 stride
= (width
+ 1) / 8;
452 php_error(E_WARNING
, "Unknown format");
458 if (height * stride > buffer_len) {
459 php_error(E_WARNING,"buffer is not long enough");
463 curr
->surface
= cairo_image_surface_create_for_data(buffer
, format
, width
, height
, stride
);
466 /* }}} createFromData */
470 /* {{{ proto void createFromPng(string file)
472 PHP_METHOD(CairoImageSurface
, createFromPng
)
475 zval
* _this_zval
= NULL
;
476 const char * file
= NULL
;
479 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Os", &_this_zval
, CairoImageSurface_ce_ptr
, &file
, &file_len
) == FAILURE
) {
483 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
485 curr
->surface
= cairo_image_surface_create_from_png(file
);
488 /* }}} createFromPng */
492 /* {{{ proto void createFromPngStream(stream zstream)
495 PHP_METHOD(CairoImageSurface
, createFromPngStream
)
498 zval
*_this_zval
= NULL
;
499 cairo_status_t status
;
504 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Or", &_this_zval
, CairoImageSurface_ce_ptr
, &zstream
)) {
508 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
510 php_stream_from_zval(stream
, &zstream
);
511 curr
->surface
= cairo_image_surface_create_from_png_stream( _read_func
, stream
);
516 /* }}} createFromPngStream*/
520 /* {{{ proto string getData() -- not required
522 PHP_METHOD(CairoImageSurface
, getData
)
525 zval
* _this_zval
= NULL
;
529 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoImageSurface_ce_ptr
) == FAILURE
) {
533 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
536 str
= cairo_image_surface_get_data(curr
->surface
);
537 RETURN_STRING(str
, 0);
543 /* {{{ proto int getFormat()
545 PHP_METHOD(CairoImageSurface
, getFormat
)
547 zval
* _this_zval
= NULL
;
549 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoImageSurface_ce_ptr
) == FAILURE
) {
552 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
554 RETURN_LONG(cairo_image_surface_get_format(curr
->surface
));
560 /* {{{ proto int getHeight()
562 PHP_METHOD(CairoImageSurface
, getHeight
)
564 zval
* _this_zval
= NULL
;
566 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoImageSurface_ce_ptr
) == FAILURE
) {
570 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
571 RETURN_LONG(cairo_image_surface_get_height(curr
->surface
));
578 /* {{{ proto int getStride()
580 PHP_METHOD(CairoImageSurface
, getStride
)
582 zval
* _this_zval
= NULL
;
584 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoImageSurface_ce_ptr
) == FAILURE
) {
588 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
589 RETURN_LONG(cairo_image_surface_get_stride(curr
->surface
));
596 /* {{{ proto int getWidth()
598 PHP_METHOD(CairoImageSurface
, getWidth
)
600 zval
* _this_zval
= NULL
;
602 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoImageSurface_ce_ptr
) == FAILURE
) {
607 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
609 RETURN_LONG(cairo_image_surface_get_width(curr
->surface
));
614 static zend_function_entry CairoImageSurface_methods
[] = {
615 PHP_ME(CairoImageSurface
, __construct
, CairoImageSurface____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
616 PHP_ME(CairoImageSurface
, createFromData
, CairoImageSurface__create_from_data_args
, /**/ZEND_ACC_PUBLIC
)
617 PHP_ME(CairoImageSurface
, createFromPng
, CairoImageSurface__create_from_png_args
, /**/ZEND_ACC_PUBLIC
)
618 PHP_ME(CairoImageSurface
, createFromPngStream
, CairoImageSurface__create_from_png_stream_args
, /**/ZEND_ACC_PUBLIC
)
619 PHP_ME(CairoImageSurface
, getData
, NULL
, /**/ZEND_ACC_PUBLIC
)
620 PHP_ME(CairoImageSurface
, getFormat
, NULL
, /**/ZEND_ACC_PUBLIC
)
621 PHP_ME(CairoImageSurface
, getHeight
, NULL
, /**/ZEND_ACC_PUBLIC
)
622 PHP_ME(CairoImageSurface
, getStride
, NULL
, /**/ZEND_ACC_PUBLIC
)
623 PHP_ME(CairoImageSurface
, getWidth
, NULL
, /**/ZEND_ACC_PUBLIC
)
629 static zend_object_value
CairoImageSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
631 zend_object_value retval
;
632 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
633 retval
.handlers
= &CairoImageSurface_handlers
;
638 void class_init_CairoImageSurface(void)
642 INIT_CLASS_ENTRY(ce
, "CairoImageSurface", CairoImageSurface_methods
);
643 CairoImageSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
644 CairoImageSurface_ce_ptr
->create_object
= CairoImageSurface_object_new
;
645 memcpy(&CairoImageSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
648 /* }}} Class CairoImageSurface */
650 /* {{{ Class CairoPDFSurface */
652 static zend_class_entry
* CairoPDFSurface_ce_ptr
= NULL
;
653 static zend_object_handlers CairoPDFSurface_handlers
;
657 /* {{{ proto void construct(string file, float wpts, float hpts)
659 PHP_METHOD(CairoPDFSurface
, __construct
)
662 zval
*zstream
= NULL
;
663 const char * file
= NULL
;
668 int argc
= ZEND_NUM_ARGS();
671 args
= (zval
***)safe_emalloc(argc
, sizeof(zval
*),0);
672 if(ZEND_NUM_ARGS() == 0 ||
673 zend_get_parameters_array_ex(argc
, args
) == FAILURE
) {
680 switch(Z_TYPE_P(obj
)) {
682 wpts
= Z_DVAL_P(obj
);
685 wpts
= Z_LVAL_P(obj
);
694 switch(Z_TYPE_P(obj
)) {
696 hpts
= Z_DVAL_P(obj
);
699 hpts
= Z_LVAL_P(obj
);
707 _this_zval
= getThis();
709 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
712 if(Z_TYPE_P(obj
) == IS_STRING
) {
713 file
= Z_STRVAL_P(obj
);
714 curr
->surface
= cairo_pdf_surface_create(file
, wpts
, hpts
);
716 else if(Z_TYPE_P(obj
) == IS_RESOURCE
) {
718 php_stream_from_zval(stream
, &zstream
);
719 curr
->surface
= cairo_pdf_surface_create_for_stream(_write_func
, stream
, wpts
, hpts
);
727 /* }}} __construct */
731 /* {{{ proto void setSize(float wptd, float hpts)
733 PHP_METHOD(CairoPDFSurface
, setSize
)
736 zval
* _this_zval
= NULL
;
742 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoPDFSurface_ce_ptr
, &wpts
, &hpts
) == FAILURE
) {
746 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
747 cairo_pdf_surface_set_size(curr
->surface
, wpts
, hpts
);
753 static zend_function_entry CairoPDFSurface_methods
[] = {
754 PHP_ME(CairoPDFSurface
, __construct
, CairoPDFSurface____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
755 PHP_ME(CairoPDFSurface
, setSize
, CairoPDFSurface__set_size_args
, /**/ZEND_ACC_PUBLIC
)
761 static zend_object_value
CairoPDFSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
763 zend_object_value retval
;
764 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
765 retval
.handlers
= &CairoPDFSurface_handlers
;
769 void class_init_CairoPDFSurface(void)
773 INIT_CLASS_ENTRY(ce
, "CairoPDFSurface", CairoPDFSurface_methods
);
774 CairoPDFSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
775 CairoPDFSurface_ce_ptr
->create_object
= CairoPDFSurface_object_new
;
776 memcpy(&CairoPDFSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
780 /* }}} Class CairoPDFSurface */
782 /* {{{ Class CairoPSSurface */
784 static zend_class_entry
* CairoPSSurface_ce_ptr
= NULL
;
785 static zend_object_handlers CairoPSSurface_handlers
;
789 /* {{{ proto void construct(string file | stream stream, float wpts, float hpts)
791 PHP_METHOD(CairoPSSurface
, __construct
)
794 zval
*zstream
= NULL
;
795 const char * file
= NULL
;
800 int argc
= ZEND_NUM_ARGS();
803 args
= (zval
**)safe_emalloc(argc
, sizeof(zval
*),0);
804 if(ZEND_NUM_ARGS() == 0 ||
805 zend_get_parameters_array_ex(argc
, args
) == FAILURE
) {
812 switch(Z_TYPE_P(obj
)) {
814 wpts
= Z_DVAL_P(obj
);
817 wpts
= Z_LVAL_P(obj
);
826 switch(Z_TYPE_P(obj
)) {
828 hpts
= Z_DVAL_P(obj
);
831 hpts
= Z_LVAL_P(obj
);
839 _this_zval
= getThis();
840 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
843 if(Z_TYPE_P(obj
) == IS_STRING
) {
844 file
= Z_STRVAL_P(obj
);
845 curr
->surface
= cairo_ps_surface_create(file
, wpts
, hpts
);
847 else if(Z_TYPE_P(obj
) == IS_RESOURCE
) {
849 php_stream_from_zval(stream
, &zstream
);
850 curr
->surface
= cairo_ps_surface_create_for_stream(_write_func
, stream
, wpts
, hpts
);
862 /* }}} __construct */
866 /* {{{ proto void dscBeginPageSetup()
868 PHP_METHOD(CairoPSSurface
, dscBeginPageSetup
)
871 zval
* _this_zval
= NULL
;
875 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
878 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
879 cairo_ps_surface_dsc_begin_page_setup(curr
->surface
);
880 PHP_CAIRO_SURFACE_ERROR(curr
->surface
);
885 /* }}} dscBeginPageSetup */
889 /* {{{ proto void dscBeginSetup()
891 PHP_METHOD(CairoPSSurface
, dscBeginSetup
)
894 zval
* _this_zval
= NULL
;
898 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
902 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
903 cairo_ps_surface_dsc_begin_setup(curr
->surface
);
904 PHP_CAIRO_SURFACE_ERROR(curr
->surface
);
907 /* }}} dscBeginSetup */
911 /* {{{ proto void dscComment()
913 PHP_METHOD(CairoPSSurface
, dscComment
)
916 zval
* _this_zval
= NULL
;
920 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
924 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
925 cairo_ps_surface_dsc_comment(curr
->surface
);
926 PHP_CAIRO_SURFACE_ERROR(curr
->surface
);
933 /* {{{ proto array getLevels() -- cairo 1.6
935 PHP_METHOD(CairoPSSurface
, getLevels
)
938 zval
* _this_zval
= NULL
;
942 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
946 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
949 array_init(return_value
);
952 /* ONLY for CAIRO 1.6 */
959 /* {{{ proto string getLevelString() --cairo 1.6
961 PHP_METHOD(CairoPSSurface
, getLevelString
)
964 zval
* _this_zval
= NULL
;
968 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
972 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
976 /* ONLY for CAIRO 1.6*/
979 /* }}} getLevelString */
983 /* {{{ proto void restrictToLevel(int level) --cairo 1.6
985 PHP_METHOD(CairoPSSurface
, restrictToLevel
)
988 zval
* _this_zval
= NULL
;
993 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Ol", &_this_zval
, CairoPSSurface_ce_ptr
, &level
) == FAILURE
) {
997 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1001 /* ONLY for CAIRO 1.6 */
1004 /* }}} restrictToLevel */
1008 /* {{{ proto void setEps() --cairo 1.6
1010 PHP_METHOD(CairoPSSurface
, setEps
)
1013 zval
* _this_zval
= NULL
;
1017 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoPSSurface_ce_ptr
) == FAILURE
) {
1021 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1025 /* ONLY for CAIRO 1.6 */
1032 /* {{{ proto void setSize(float wpts, float hpts)
1034 PHP_METHOD(CairoPSSurface
, setSize
)
1037 zval
* _this_zval
= NULL
;
1043 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoPSSurface_ce_ptr
, &wpts
, &hpts
) == FAILURE
) {
1047 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1048 cairo_ps_surface_set_size(curr
->surface
, wpts
, hpts
);
1054 static zend_function_entry CairoPSSurface_methods
[] = {
1055 PHP_ME(CairoPSSurface
, __construct
, CairoPSSurface____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
1056 PHP_ME(CairoPSSurface
, dscBeginPageSetup
, NULL
, /**/ZEND_ACC_PUBLIC
)
1057 PHP_ME(CairoPSSurface
, dscBeginSetup
, NULL
, /**/ZEND_ACC_PUBLIC
)
1058 PHP_ME(CairoPSSurface
, dscComment
, NULL
, /**/ZEND_ACC_PUBLIC
)
1059 PHP_ME(CairoPSSurface
, getLevels
, NULL
, /**/ZEND_ACC_PUBLIC
)
1060 PHP_ME(CairoPSSurface
, getLevelString
, NULL
, /**/ZEND_ACC_PUBLIC
)
1061 PHP_ME(CairoPSSurface
, restrictToLevel
, CairoPSSurface__restrict_to_level_args
, /**/ZEND_ACC_PUBLIC
)
1062 PHP_ME(CairoPSSurface
, setEps
, NULL
, /**/ZEND_ACC_PUBLIC
)
1063 PHP_ME(CairoPSSurface
, setSize
, CairoPSSurface__set_size_args
, /**/ZEND_ACC_PUBLIC
)
1064 { NULL
, NULL
, NULL
}
1069 static zend_object_value
CairoPSSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
1071 zend_object_value retval
;
1072 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
1073 retval
.handlers
= &CairoPSSurface_handlers
;
1077 void class_init_CairoPSSurface(void)
1079 zend_class_entry ce
;
1081 INIT_CLASS_ENTRY(ce
, "CairoPSSurface", CairoPSSurface_methods
);
1082 CairoPSSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
1083 CairoPSSurface_ce_ptr
->create_object
= CairoPSSurface_object_new
;
1084 memcpy(&CairoPSSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1087 /* }}} Class CairoPSSurface */
1089 /* {{{ Class CairoQuartzSurface */
1091 static zend_class_entry
* CairoQuartzSurface_ce_ptr
= NULL
;
1092 static zend_object_handlers CairoQuartzSurface_handlers
;
1096 /* {{{ proto void construct(float wpixels, float hpixels [, int format])
1098 PHP_METHOD(CairoQuartzSurface
, __construct
)
1102 double wpixels
= 0.0;
1103 double hpixels
= 0.0;
1108 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "dd|l", &wpixels
, &hpixels
, &format
) == FAILURE
) {
1112 _this_zval
= getThis();
1113 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1116 php_error(E_WARNING
, "CANNOT BE CALLED"); RETURN_FALSE
;
1119 /* }}} __construct */
1122 static zend_function_entry CairoQuartzSurface_methods
[] = {
1123 PHP_ME(CairoQuartzSurface
, __construct
, CairoQuartzSurface____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
1124 { NULL
, NULL
, NULL
}
1129 static zend_object_value
CairoQuartzSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
1131 zend_object_value retval
;
1132 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
1133 retval
.handlers
= &CairoQuartzSurface_handlers
;
1137 void class_init_CairoQuartzSurface(void)
1139 zend_class_entry ce
;
1141 INIT_CLASS_ENTRY(ce
, "CairoQuartzSurface", CairoQuartzSurface_methods
);
1142 CairoQuartzSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
1143 CairoQuartzSurface_ce_ptr
->create_object
= CairoQuartzSurface_object_new
;
1144 memcpy(&CairoQuartzSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1148 /* }}} Class CairoQuartzSurface */
1150 /* {{{ Class CairoSVGSurface */
1152 static zend_class_entry
* CairoSVGSurface_ce_ptr
= NULL
;
1153 static zend_object_handlers CairoSVGSurface_handlers
;
1159 /* {{{ proto void construct(string file, float wpts, float hpts)
1161 PHP_METHOD(CairoSVGSurface
, __construct
)
1164 zval
*zstream
= NULL
;
1165 const char * file
= NULL
;
1170 int argc
= ZEND_NUM_ARGS();
1173 args
= (zval
**)safe_emalloc(argc
, sizeof(zval
*),0);
1174 if(ZEND_NUM_ARGS() == 0 ||
1175 zend_get_parameters_array_ex(argc
, args
) == FAILURE
) {
1182 switch(Z_TYPE_P(obj
)) {
1184 wpts
= Z_DVAL_P(obj
);
1187 wpts
= Z_LVAL_P(obj
);
1196 switch(Z_TYPE_P(obj
)) {
1198 hpts
= Z_DVAL_P(obj
);
1201 hpts
= Z_LVAL_P(obj
);
1209 _this_zval
= getThis();
1210 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1213 if(Z_TYPE_P(obj
) == IS_STRING
) {
1214 file
= Z_STRVAL_P(obj
);
1215 curr
->surface
= cairo_svg_surface_create(file
, wpts
, hpts
);
1217 else if(Z_TYPE_P(obj
) == IS_RESOURCE
) {
1219 php_stream_from_zval(stream
, &zstream
);
1220 curr
->surface
= cairo_svg_surface_create_for_stream(_write_func
, stream
, wpts
, hpts
);
1230 /* }}} __construct */
1233 static zend_function_entry CairoSVGSurface_methods
[] = {
1234 PHP_ME(CairoSVGSurface
, __construct
, CairoSVGSurface____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
1235 { NULL
, NULL
, NULL
}
1240 static zend_object_value
CairoSVGSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
1242 zend_object_value retval
;
1243 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
1244 retval
.handlers
= &CairoSVGSurface_handlers
;
1248 void class_init_CairoSVGSurface(void)
1250 zend_class_entry ce
;
1252 INIT_CLASS_ENTRY(ce
, "CairoSVGSurface", CairoSVGSurface_methods
);
1253 CairoSVGSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
1254 CairoSVGSurface_ce_ptr
->create_object
= CairoSVGSurface_object_new
;
1255 memcpy(&CairoSVGSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1259 /* }}} Class CairoSVGSurface */
1261 /* {{{ Class CairoWin32Surface*/
1263 static zend_class_entry
* CairoWin32Surface_ce_ptr
= NULL
;
1264 static zend_object_handlers CairoWin32Surface_handlers
;
1269 /* {{{ proto void construct(int hdc)
1271 PHP_METHOD(CairoWin32Surface
, __construct
)
1279 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &hdc
) == FAILURE
) {
1283 _this_zval
= getThis();
1284 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1285 curr
->surface
= cairo_win32_surface_create(hdc
, NULL
);
1287 /* }}} __construct */
1290 static zend_function_entry CairoWin32Surface_methods
[] = {
1291 PHP_ME(CairoWin32Surface
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
1292 { NULL
, NULL
, NULL
}
1297 static zend_object_value
CairoWin32Surface_object_new(zend_class_entry
*ce TSRMLS_DC
)
1299 zend_object_value retval
;
1300 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
1301 retval
.handlers
= &CairoWin32Surface_handlers
;
1305 void class_init_CairoWin32Surface(void)
1307 zend_class_entry ce
;
1309 INIT_CLASS_ENTRY(ce
, "CairoWin32Surface", CairoWin32Surface_methods
);
1310 CairoWin32Surface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
1311 CairoWin32Surface_ce_ptr
->create_object
= CairoWin32Surface_object_new
;
1312 memcpy(&CairoWin32Surface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1316 /* }}} Class CairoWin32Surface */
1318 /* {{{ Class CairoXlibSurface */
1320 static zend_class_entry
* CairoXlibSurface_ce_ptr
= NULL
;
1321 static zend_object_handlers CairoXlibSurface_handlers
;
1325 /* {{{ proto void construct()
1327 PHP_METHOD(CairoXlibSurface
, __construct
)
1333 if (ZEND_NUM_ARGS()>0) {
1337 _this_zval
= getThis();
1338 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1340 php_error(E_WARNING
, "Cannot Be Initialized"); RETURN_FALSE
;
1343 /* }}} __construct */
1347 /* {{{ proto int getDepth()
1349 PHP_METHOD(CairoXlibSurface
, getDepth
)
1352 zval
* _this_zval
= NULL
;
1355 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoXlibSurface_ce_ptr
) == FAILURE
) {
1359 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1361 RETURN_LONG(cairo_xlib_surface_get_depth(curr
->surface
));
1368 /* {{{ proto int getHeight()
1370 PHP_METHOD(CairoXlibSurface
, getHeight
)
1373 zval
* _this_zval
= NULL
;
1376 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoXlibSurface_ce_ptr
) == FAILURE
) {
1380 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1381 RETURN_LONG(cairo_xlib_surface_get_height(curr
->surface
));
1388 /* {{{ proto int getWidth()
1390 PHP_METHOD(CairoXlibSurface
, getWidth
)
1393 zval
* _this_zval
= NULL
;
1396 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoXlibSurface_ce_ptr
) == FAILURE
) {
1400 surface_object
*curr
= (surface_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
1401 RETURN_LONG(cairo_xlib_surface_get_width(curr
->surface
));
1407 static zend_function_entry CairoXlibSurface_methods
[] = {
1408 PHP_ME(CairoXlibSurface
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
1409 PHP_ME(CairoXlibSurface
, getDepth
, NULL
, /**/ZEND_ACC_PUBLIC
)
1410 PHP_ME(CairoXlibSurface
, getHeight
, NULL
, /**/ZEND_ACC_PUBLIC
)
1411 PHP_ME(CairoXlibSurface
, getWidth
, NULL
, /**/ZEND_ACC_PUBLIC
)
1412 { NULL
, NULL
, NULL
}
1417 static zend_object_value
CairoXlibSurface_object_new(zend_class_entry
*ce TSRMLS_DC
)
1419 zend_object_value retval
;
1420 retval
= CairoSurface_object_new(ce TSRMLS_CC
);
1421 retval
.handlers
= &CairoXlibSurface_handlers
;
1425 void class_init_CairoXlibSurface(void)
1427 zend_class_entry ce
;
1429 INIT_CLASS_ENTRY(ce
, "CairoXlibSurface", CairoXlibSurface_methods
);
1430 CairoXlibSurface_ce_ptr
= zend_register_internal_class_ex(&ce
, CairoSurface_ce_ptr
, "CairoSurface" TSRMLS_CC
);
1431 CairoXlibSurface_ce_ptr
->create_object
= CairoXlibSurface_object_new
;
1432 memcpy(&CairoXlibSurface_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
1436 /* }}} Class CairoXlibSurface */
1438 /* {{{ Helper Functions */
1440 get_CairoSurface_ce_ptr(cairo_surface_t
*surface
)
1442 zend_class_entry
*type
;
1446 switch(cairo_surface_get_type(surface
)) {
1447 case CAIRO_SURFACE_TYPE_IMAGE
:
1448 type
= CairoImageSurface_ce_ptr
;
1450 case CAIRO_SURFACE_TYPE_PDF
:
1451 type
= CairoPDFSurface_ce_ptr
;
1453 case CAIRO_SURFACE_TYPE_PS
:
1454 type
= CairoPSSurface_ce_ptr
;
1456 case CAIRO_SURFACE_TYPE_SVG
:
1457 type
= CairoSVGSurface_ce_ptr
;
1459 case CAIRO_SURFACE_TYPE_WIN32
:
1460 type
= CairoWin32Surface_ce_ptr
;
1462 case CAIRO_SURFACE_TYPE_XLIB
:
1463 type
= CairoXlibSurface_ce_ptr
;
1465 case CAIRO_SURFACE_TYPE_QUARTZ
:
1466 type
= CairoQuartzSurface_ce_ptr
;
1469 php_error(E_WARNING
,"Unsupported Surface Type");
1475 /* }}} Helper Function*/