Added some test cases ....
[phpCairo.git] / individual_files / phpCairoSurface.c
blob7e2082550995fb2ba416fcd178146c294184590c
1 /* {{{ Class CairoSurface */
3 static zend_class_entry * CairoSurface_ce_ptr = NULL;
4 static zend_object_handlers CairoSurface_handlers;
6 static cairo_status_t
7 _write_func(void *closure, const unsigned char *data, unsigned int length)
9 int written;
10 php_stream *zs = (php_stream *)closure ;
11 written = php_stream_write(zs, data, length);
12 //written = php_stream_write_string(zs, data);
13 if(written == length)
14 return CAIRO_STATUS_SUCCESS;
15 else {
16 printf("is it an error ?");
17 // CAIRO_STATUS_WRITE_ERROR;
21 static cairo_status_t
22 _read_func(void *closure, const unsigned char *data, unsigned int length)
24 int read;
25 php_stream *zs = (php_stream *)closure;
26 //data = emalloc(length);
27 read = php_stream_read(zs, data, length);
28 if(read == length)
29 return CAIRO_STATUS_SUCCESS;
30 else {
31 printf("is it an error");
38 typedef struct _surface_object {
39 zend_object std;
40 cairo_surface_t *surface;
41 } surface_object;
44 /* {{{ Methods */
47 /* {{{ proto void construct()
49 PHP_METHOD(CairoSurface, __construct)
51 zend_class_entry * _this_ce;
52 zval * _this_zval;
56 if (ZEND_NUM_ARGS()>0) {
57 WRONG_PARAM_COUNT;
58 php_print("wtf");
59 return;
62 php_print("No direct call for this constructor");
66 /* }}} __construct */
70 /* {{{ proto object create_similar(int content, int width, int height)
72 PHP_METHOD(CairoSurface, create_similar)
74 zend_class_entry * _this_ce, *ce;
76 zval * _this_zval = NULL;
77 cairo_surface_t *sur;
78 int content;
79 long width = 0;
80 long height = 0;
82 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olll", &_this_zval, CairoSurface_ce_ptr, &content, &width, &height) == FAILURE) {
83 return;
86 _this_ce = Z_OBJCE_P(_this_zval);
87 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
88 sur = cairo_surface_create_similar(curr->surface, content, width, height);
89 ce = get_CairoSurface_ce_ptr(sur);
90 object_init_ex(return_value, ce);
91 surface_object *sobj = (surface_object *)zend_objects_get_address(return_value TSRMLS_CC);
92 sobj->surface=sur;
95 /* }}} create_similar */
98 /* {{{ proto void finish()
100 PHP_METHOD(CairoSurface, finish)
102 zend_class_entry * _this_ce;
104 zval * _this_zval = NULL;
106 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
107 return;
110 _this_ce = Z_OBJCE_P(_this_zval);
111 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
112 cairo_surface_finish(curr->surface);
114 /* }}} finish */
118 /* {{{ proto void flush()
120 PHP_METHOD(CairoSurface, flush)
122 zend_class_entry * _this_ce;
124 zval * _this_zval = NULL;
126 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
127 return;
130 _this_ce = Z_OBJCE_P(_this_zval);
131 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
133 cairo_surface_flush(curr->surface);
136 /* }}} flush */
140 /* {{{ proto int get_content()
142 PHP_METHOD(CairoSurface, get_content)
144 zend_class_entry * _this_ce;
146 zval * _this_zval = NULL;
147 long x;
148 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
149 return;
152 _this_ce = Z_OBJCE_P(_this_zval);
153 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
155 x=cairo_surface_get_content(curr->surface);
156 RETURN_LONG(x);
158 /* }}} get_content */
162 /* {{{ proto array get_device_offset()
164 PHP_METHOD(CairoSurface, get_device_offset)
166 zend_class_entry * _this_ce;
168 zval * _this_zval = NULL;
169 double x_offset, y_offset;
171 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
172 return;
175 _this_ce = Z_OBJCE_P(_this_zval);
176 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
178 cairo_surface_get_device_offset(curr->surface, &x_offset, &y_offset);
180 array_init(return_value);
181 add_assoc_double(return_value, "x_offset", x_offset);
182 add_assoc_double(return_value, "y_offset", y_offset);
185 /* }}} get_device_offset */
189 /* {{{ proto object get_font_options()
191 PHP_METHOD(CairoSurface, get_font_options)
193 zend_class_entry * _this_ce;
195 zval * _this_zval = NULL;
197 cairo_font_options_t *options = cairo_font_options_create();
200 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
201 return;
204 _this_ce = Z_OBJCE_P(_this_zval);
205 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
207 cairo_surface_get_font_options(curr->surface, options);
208 object_init_ex(return_value, CairoFontOptions_ce_ptr);
209 fontoptions_object *fobj = (fontoptions_object *)zend_objects_get_address(return_value TSRMLS_CC);
210 fobj->fontoptions=options;
213 /* }}} get_font_options */
217 /* {{{ proto void mark_dirty_rectangle([int x, int y, int width, int height])
219 PHP_METHOD(CairoSurface, mark_dirty_rectangle)
221 zend_class_entry * _this_ce;
223 zval * _this_zval = NULL;
224 long x = 0;
225 long y = 0;
226 long width = -1;
227 long height = -1;
231 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|llll", &_this_zval, CairoSurface_ce_ptr, &x, &y, &width, &height) == FAILURE) {
232 return;
234 _this_ce = Z_OBJCE_P(_this_zval);
235 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
236 cairo_surface_mark_dirty_rectangle(curr->surface, x, y, width, height);
239 /* }}} mark_dirty_rectangle */
243 /* {{{ proto void set_device_offset(float x_offset, float y_offset)
245 PHP_METHOD(CairoSurface, set_device_offset)
247 zend_class_entry * _this_ce;
249 zval * _this_zval = NULL;
250 double x_offset = 0.0;
251 double y_offset = 0.0;
253 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_offset, &y_offset) == FAILURE) {
254 return;
257 _this_ce = Z_OBJCE_P(_this_zval);
258 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
259 cairo_surface_set_device_offset(curr->surface, x_offset, y_offset);
262 /* }}} set_device_offset */
266 /* {{{ proto void set_fallback_resolution(float x_ppi, float y_ppi)
268 PHP_METHOD(CairoSurface, set_fallback_resolution)
270 zend_class_entry * _this_ce;
272 zval * _this_zval = NULL;
273 double x_ppi = 0.0;
274 double y_ppi = 0.0;
276 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_ppi, &y_ppi) == FAILURE) {
277 return;
280 _this_ce = Z_OBJCE_P(_this_zval);
281 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
282 cairo_surface_set_fallback_resolution(curr->surface, x_ppi, y_ppi);
285 /* }}} set_fallback_resolution */
289 /* {{{ proto void write_to_png(string file)
291 PHP_METHOD(CairoSurface, write_to_png)
293 zend_class_entry * _this_ce;
295 zval * _this_zval = NULL;
296 const char * file = NULL;
297 int file_len = 0;
298 cairo_status_t status;
300 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoSurface_ce_ptr, &file, &file_len) == FAILURE) {
301 return;
304 _this_ce = Z_OBJCE_P(_this_zval);
305 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
306 status = cairo_surface_write_to_png(curr->surface, file);
309 /* }}} write_to_png */
312 /* {{{ proto void write_to_png_stream(stream file)
314 PHP_METHOD(CairoSurface, write_to_png_stream)
316 zend_class_entry *_this_ce;
317 FILE *file;
318 zval *_this_zval = NULL;
319 cairo_status_t status;
320 zval *zstream;
321 php_stream *stream;
322 int err;
324 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoSurface_ce_ptr, &zstream)) {
325 return;
328 _this_ce = Z_OBJCE_P(_this_zval);
329 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
330 php_stream_from_zval(stream, &zstream);
331 status = cairo_surface_write_to_png_stream(curr->surface, _write_func, stream);
335 /* }}} */
338 static zend_function_entry CairoSurface_methods[] = {
339 PHP_ME(CairoSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
340 PHP_ME(CairoSurface, create_similar, CairoSurface__create_similar_args, /**/ZEND_ACC_PUBLIC)
341 PHP_ME(CairoSurface, finish, NULL, /**/ZEND_ACC_PUBLIC)
342 PHP_ME(CairoSurface, flush, NULL, /**/ZEND_ACC_PUBLIC)
343 PHP_ME(CairoSurface, get_content, NULL, /**/ZEND_ACC_PUBLIC)
344 PHP_ME(CairoSurface, get_device_offset, NULL, /**/ZEND_ACC_PUBLIC)
345 PHP_ME(CairoSurface, get_font_options, NULL, /**/ZEND_ACC_PUBLIC)
346 PHP_ME(CairoSurface, mark_dirty_rectangle, CairoSurface__mark_dirty_rectangle_args, /**/ZEND_ACC_PUBLIC)
347 PHP_ME(CairoSurface, set_device_offset, CairoSurface__set_device_offset_args, /**/ZEND_ACC_PUBLIC)
348 PHP_ME(CairoSurface, set_fallback_resolution, CairoSurface__set_fallback_resolution_args, /**/ZEND_ACC_PUBLIC)
349 PHP_ME(CairoSurface, write_to_png, CairoSurface__write_to_png_args, /**/ZEND_ACC_PUBLIC)
350 PHP_ME(CairoSurface, write_to_png_stream, CairoSurface__write_to_png_stream_args, /**/ZEND_ACC_PUBLIC)
351 { NULL, NULL, NULL }
354 /* }}} Methods */
357 static void CairoSurface_object_dtor(void *object)
359 surface_object *surface = (surface_object *)object;
360 zend_hash_destroy(surface->std.properties);
361 FREE_HASHTABLE(surface->std.properties);
362 if(surface->surface){
363 cairo_surface_finish(surface->surface);
364 cairo_surface_destroy(surface->surface);
367 efree(object);
370 static zend_object_value CairoSurface_object_new(zend_class_entry *ce)
372 zend_object_value retval;
373 surface_object *surface;
374 zval *temp;
376 surface = emalloc(sizeof(surface_object));
377 memset(surface,0,sizeof(surface_object));
379 surface->std.ce=ce;
381 ALLOC_HASHTABLE(surface->std.properties);
382 zend_hash_init(surface->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
383 zend_hash_copy(surface->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
384 retval.handle=zend_objects_store_put(surface, NULL, (zend_objects_free_object_storage_t)CairoSurface_object_dtor, NULL TSRMLS_CC);
385 retval.handlers = &CairoSurface_handlers;
386 return retval;
389 static void class_init_CairoSurface(void)
391 zend_class_entry ce;
393 INIT_CLASS_ENTRY(ce, "CairoSurface", CairoSurface_methods);
394 CairoSurface_ce_ptr = zend_register_internal_class(&ce);
395 CairoSurface_ce_ptr->create_object = CairoSurface_object_new;
396 memcpy(&CairoSurface_handlers, zend_get_std_object_handlers(),sizeof(zend_object_handlers));
397 CairoSurface_handlers.clone_obj = NULL;
400 /* }}} Class CairoSurface */
402 /* {{{ Class CairoImageSurface -- done :)*/
404 static zend_class_entry * CairoImageSurface_ce_ptr = NULL;
405 static zend_object_handlers CairoImageSurface_handlers;
406 /* {{{ Methods */
409 /* {{{ proto void construct(int format, int widthm, int height)
411 PHP_METHOD(CairoImageSurface, __construct)
413 zend_class_entry * _this_ce;
414 zval * _this_zval;
416 cairo_format_t format = 0;
417 long widthm = 0;
418 long height = 0;
422 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &format, &widthm, &height) == FAILURE) {
423 return;
426 _this_zval = getThis();
427 _this_ce = Z_OBJCE_P(_this_zval);
428 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
429 curr->surface = cairo_image_surface_create(format, widthm, height);
432 /* }}} __construct */
436 /* {{{ proto void create_from_data(string obj, int format, int width, int height [, int stride])
438 PHP_METHOD(CairoImageSurface, create_from_data)
440 zend_class_entry * _this_ce;
442 zval * _this_zval = NULL;
443 const char * buffer = NULL;
444 int buffer_len = 0;
445 long format = 0;
446 long width = 0;
447 long height = 0;
448 long stride = -1;
452 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) {
453 return;
456 _this_ce = Z_OBJCE_P(_this_zval);
457 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
458 cairo_surface_finish(curr->surface);
459 cairo_surface_destroy(curr->surface);
461 if(stride < 0 ){
462 switch(format) {
463 case CAIRO_FORMAT_ARGB32:
464 case CAIRO_FORMAT_RGB24:
465 stride = width * 4;
466 break;
467 case CAIRO_FORMAT_RGB16_565:
468 stride = width * 2;
469 break;
470 case CAIRO_FORMAT_A8:
471 stride = width;
472 break;
473 case CAIRO_FORMAT_A1:
474 stride = (width + 1) / 8;
475 break;
476 default:
477 php_error(E_ERROR, "Unknown format");
478 return;
483 if (height * stride > buffer_len) {
484 php_error(E_ERROR,"buffer is not long enough");
485 return;
488 curr->surface = cairo_image_surface_create_for_data(buffer, format, width, height, stride);
491 /* }}} create_from_data */
495 /* {{{ proto void create_from_png(string file)
497 PHP_METHOD(CairoImageSurface, create_from_png)
499 zend_class_entry * _this_ce;
501 zval * _this_zval = NULL;
502 const char * file = NULL;
503 int file_len = 0;
505 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoImageSurface_ce_ptr, &file, &file_len) == FAILURE) {
506 return;
509 _this_ce = Z_OBJCE_P(_this_zval);
510 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
512 curr->surface = cairo_image_surface_create_from_png(file);
515 /* }}} create_from_png */
519 /* {{{ proto void create_from_png_stream(stream zstream)
522 PHP_METHOD(CairoImageSurface, create_from_png_stream)
524 zend_class_entry *_this_ce;
525 FILE *file;
526 zval *_this_zval = NULL;
527 cairo_status_t status;
528 zval *zstream;
529 php_stream *stream;
530 int err;
532 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoImageSurface_ce_ptr, &zstream)) {
533 return;
536 _this_ce = Z_OBJCE_P(_this_zval);
537 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
539 php_stream_from_zval(stream, &zstream);
540 curr->surface = cairo_image_surface_create_from_png_stream( _read_func, stream);
545 /* }}} */
549 /* {{{ proto string get_data() -- not required
551 PHP_METHOD(CairoImageSurface, get_data)
553 zend_class_entry * _this_ce;
555 zval * _this_zval = NULL;
556 char *str;
559 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
560 return;
563 _this_ce = Z_OBJCE_P(_this_zval);
564 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
567 str = cairo_image_surface_get_data(curr->surface);
568 RETURN_STRING(str, 0);
570 /* }}} get_data */
574 /* {{{ proto int get_format()
576 PHP_METHOD(CairoImageSurface, get_format)
578 zend_class_entry * _this_ce;
579 long x;
580 zval * _this_zval = NULL;
582 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
583 return;
585 _this_ce = Z_OBJCE_P(_this_zval);
586 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
588 x = cairo_image_surface_get_format(curr->surface);
589 RETURN_LONG(x);
591 /* }}} get_format */
595 /* {{{ proto int get_height()
597 PHP_METHOD(CairoImageSurface, get_height)
599 zend_class_entry * _this_ce;
600 zval * _this_zval = NULL;
601 long x;
603 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
604 return;
607 _this_ce = Z_OBJCE_P(_this_zval);
608 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
609 x = cairo_image_surface_get_height(curr->surface);
611 RETURN_LONG(x);
613 /* }}} get_height */
617 /* {{{ proto int get_stride()
619 PHP_METHOD(CairoImageSurface, get_stride)
621 zend_class_entry * _this_ce;
622 zval * _this_zval = NULL;
623 long x;
625 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
626 return;
629 _this_ce = Z_OBJCE_P(_this_zval);
630 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
631 x = cairo_image_surface_get_stride(curr->surface);
633 RETURN_LONG(x);
635 /* }}} get_stride */
639 /* {{{ proto int get_width()
641 PHP_METHOD(CairoImageSurface, get_width)
643 zend_class_entry * _this_ce;
644 zval * _this_zval = NULL;
645 long x;
647 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
648 return;
651 _this_ce = Z_OBJCE_P(_this_zval);
653 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
655 x = cairo_image_surface_get_width(curr->surface);
656 RETURN_LONG(x);
658 /* }}} get_width */
661 static zend_function_entry CairoImageSurface_methods[] = {
662 PHP_ME(CairoImageSurface, __construct, CairoImageSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
663 PHP_ME(CairoImageSurface, create_from_data, CairoImageSurface__create_from_data_args, /**/ZEND_ACC_PUBLIC)
664 PHP_ME(CairoImageSurface, create_from_png, CairoImageSurface__create_from_png_args, /**/ZEND_ACC_PUBLIC)
665 PHP_ME(CairoImageSurface, create_from_png_stream, CairoImageSurface__create_from_png_stream_args, /**/ZEND_ACC_PUBLIC)
666 PHP_ME(CairoImageSurface, get_data, NULL, /**/ZEND_ACC_PUBLIC)
667 PHP_ME(CairoImageSurface, get_format, NULL, /**/ZEND_ACC_PUBLIC)
668 PHP_ME(CairoImageSurface, get_height, NULL, /**/ZEND_ACC_PUBLIC)
669 PHP_ME(CairoImageSurface, get_stride, NULL, /**/ZEND_ACC_PUBLIC)
670 PHP_ME(CairoImageSurface, get_width, NULL, /**/ZEND_ACC_PUBLIC)
671 { NULL, NULL, NULL }
674 /* }}} Methods */
676 static zend_object_value CairoImageSurface_object_new(zend_class_entry *ce TSRMLS_DC)
678 zend_object_value retval;
679 retval=CairoSurface_object_new(ce TSRMLS_CC);
680 retval.handlers = &CairoImageSurface_handlers;
681 return retval;
685 static void class_init_CairoImageSurface(void)
687 zend_class_entry ce;
689 INIT_CLASS_ENTRY(ce, "CairoImageSurface", CairoImageSurface_methods);
690 CairoImageSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
691 CairoImageSurface_ce_ptr->create_object = CairoImageSurface_object_new;
692 memcpy(&CairoImageSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
695 /* }}} Class CairoImageSurface */
697 /* {{{ Class CairoPDFSurface */
699 static zend_class_entry * CairoPDFSurface_ce_ptr = NULL;
700 static zend_object_handlers CairoPDFSurface_handlers;
701 /* {{{ Methods */
704 /* {{{ proto void construct(string file, float wpts, float hpts)
706 PHP_METHOD(CairoPDFSurface, __construct)
708 zend_class_entry * _this_ce;
709 zval * _this_zval;
710 zval *zstream = NULL;
711 const char * file = NULL;
712 int file_len = 0;
713 double wpts = 0.0;
714 double hpts = 0.0;
715 php_stream *stream;
716 int argc = ZEND_NUM_ARGS();
717 zval ***args, *obj;
719 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
720 if(ZEND_NUM_ARGS()== 0 ||
721 zend_get_parameters_array_ex(argc, args)== FAILURE) {
722 printf("ERROR");
723 efree(args);
724 WRONG_PARAM_COUNT;
727 obj = *(args[1]);
728 switch(Z_TYPE_P(obj)) {
729 case IS_DOUBLE:
730 wpts = Z_DVAL_P(obj);
731 break;
732 case IS_LONG:
733 wpts = Z_LVAL_P(obj);
734 break;
735 default :
736 printf("Error!!!");
737 return;
740 obj = *(args[2]);
742 switch(Z_TYPE_P(obj)) {
743 case IS_DOUBLE:
744 hpts = Z_DVAL_P(obj);
745 break;
746 case IS_LONG:
747 hpts = Z_LVAL_P(obj);
748 break;
749 default :
750 printf("Error!!!");
751 return;
755 _this_zval = getThis();
756 _this_ce = Z_OBJCE_P(_this_zval);
757 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
759 obj = *(args[0]);
760 if(Z_TYPE_P(obj)==IS_STRING) {
761 file = Z_STRVAL_P(obj);
762 curr->surface = cairo_pdf_surface_create(file, wpts, hpts);
764 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
765 zstream = obj;
766 php_stream_from_zval(stream, &zstream);
767 curr->surface = cairo_pdf_surface_create_for_stream(_write_func, stream, wpts, hpts);
769 else {
770 printf("ERROR\n");
773 efree(args);
775 /* }}} __construct */
779 /* {{{ proto void set_size(float wptd, float hpts)
781 PHP_METHOD(CairoPDFSurface, set_size)
783 zend_class_entry * _this_ce;
785 zval * _this_zval = NULL;
786 double wpts = 0.0;
787 double hpts = 0.0;
791 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPDFSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
792 return;
795 _this_ce = Z_OBJCE_P(_this_zval);
796 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
797 cairo_pdf_surface_set_size(curr->surface, wpts, hpts);
800 /* }}} set_size */
803 static zend_function_entry CairoPDFSurface_methods[] = {
804 PHP_ME(CairoPDFSurface, __construct, CairoPDFSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
805 PHP_ME(CairoPDFSurface, set_size, CairoPDFSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
806 { NULL, NULL, NULL }
809 /* }}} Methods */
811 static zend_object_value CairoPDFSurface_object_new(zend_class_entry *ce TSRMLS_DC)
813 zend_object_value retval;
814 retval=CairoSurface_object_new(ce TSRMLS_CC);
815 retval.handlers = &CairoPDFSurface_handlers;
816 return retval;
819 static void class_init_CairoPDFSurface(void)
821 zend_class_entry ce;
823 INIT_CLASS_ENTRY(ce, "CairoPDFSurface", CairoPDFSurface_methods);
824 CairoPDFSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
825 CairoPDFSurface_ce_ptr->create_object = CairoPDFSurface_object_new;
826 memcpy(&CairoPDFSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
830 /* }}} Class CairoPDFSurface */
832 /* {{{ Class CairoPSSurface */
834 static zend_class_entry * CairoPSSurface_ce_ptr = NULL;
835 static zend_object_handlers CairoPSSurface_handlers;
836 /* {{{ Methods */
839 /* {{{ proto void construct(string file | stream stream, float wpts, float hpts)
841 PHP_METHOD(CairoPSSurface, __construct)
843 zend_class_entry * _this_ce;
844 zval * _this_zval;
845 zval *zstream = NULL;
846 const char * file = NULL;
847 int file_len = 0;
848 double wpts = 0.0;
849 double hpts = 0.0;
850 php_stream *stream;
851 int argc = ZEND_NUM_ARGS();
852 zval ***args, *obj;
854 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
855 if(ZEND_NUM_ARGS()== 0 ||
856 zend_get_parameters_array_ex(argc, args)== FAILURE) {
857 printf("ERROR");
858 efree(args);
859 WRONG_PARAM_COUNT;
862 obj = *(args[1]);
863 switch(Z_TYPE_P(obj)) {
864 case IS_DOUBLE:
865 wpts = Z_DVAL_P(obj);
866 break;
867 case IS_LONG:
868 wpts = Z_LVAL_P(obj);
869 break;
870 default :
871 printf("Error!!!");
872 return;
875 obj = *(args[2]);
877 switch(Z_TYPE_P(obj)) {
878 case IS_DOUBLE:
879 hpts = Z_DVAL_P(obj);
880 break;
881 case IS_LONG:
882 hpts = Z_LVAL_P(obj);
883 break;
884 default :
885 printf("Error!!!");
886 return;
890 _this_zval = getThis();
891 _this_ce = Z_OBJCE_P(_this_zval);
892 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
894 obj = *(args[0]);
895 if(Z_TYPE_P(obj)==IS_STRING) {
896 file = Z_STRVAL_P(obj);
897 curr->surface = cairo_ps_surface_create(file, wpts, hpts);
899 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
900 zstream = obj;
901 php_stream_from_zval(stream, &zstream);
902 curr->surface = cairo_ps_surface_create_for_stream(_write_func, stream, wpts, hpts);
904 else {
905 printf("ERROR\n");
908 efree(args);
914 /* }}} __construct */
918 /* {{{ proto void dsc_begin_page_setup()
920 PHP_METHOD(CairoPSSurface, dsc_begin_page_setup)
922 zend_class_entry * _this_ce;
924 zval * _this_zval = NULL;
928 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
929 return;
931 _this_ce = Z_OBJCE_P(_this_zval);
932 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
933 cairo_ps_surface_dsc_begin_page_setup(curr->surface);
934 phpCAIRO_SURFACE_ERROR(curr->surface);
939 /* }}} dsc_begin_page_setup */
943 /* {{{ proto void dsc_begin_setup()
945 PHP_METHOD(CairoPSSurface, dsc_begin_setup)
947 zend_class_entry * _this_ce;
949 zval * _this_zval = NULL;
953 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
954 return;
957 _this_ce = Z_OBJCE_P(_this_zval);
958 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
959 cairo_ps_surface_dsc_begin_setup(curr->surface);
960 phpCAIRO_SURFACE_ERROR(curr->surface);
963 /* }}} dsc_begin_setup */
967 /* {{{ proto void dsc_comment()
969 PHP_METHOD(CairoPSSurface, dsc_comment)
971 zend_class_entry * _this_ce;
973 zval * _this_zval = NULL;
977 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
978 return;
981 _this_ce = Z_OBJCE_P(_this_zval);
982 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
983 cairo_ps_surface_dsc_comment(curr->surface);
984 phpCAIRO_SURFACE_ERROR(curr->surface);
987 /* }}} dsc_comment */
991 /* {{{ proto array get_levels() -- cairo 1.6
993 PHP_METHOD(CairoPSSurface, get_levels)
995 zend_class_entry * _this_ce;
997 zval * _this_zval = NULL;
1001 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1002 return;
1005 _this_ce = Z_OBJCE_P(_this_zval);
1006 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1009 array_init(return_value);
1011 do {
1012 /* ONLY for CAIRO 1.6 */
1013 } while (0);
1015 /* }}} get_levels */
1019 /* {{{ proto string get_level_string() --cairo 1.6
1021 PHP_METHOD(CairoPSSurface, get_level_string)
1023 zend_class_entry * _this_ce;
1025 zval * _this_zval = NULL;
1029 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1030 return;
1033 _this_ce = Z_OBJCE_P(_this_zval);
1034 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1037 do {
1038 /* ONLY for CAIRO 1.6*/
1039 } while (0);
1041 /* }}} get_level_string */
1045 /* {{{ proto void restrict_to_level(int level) --cairo 1.6
1047 PHP_METHOD(CairoPSSurface, restrict_to_level)
1049 zend_class_entry * _this_ce;
1051 zval * _this_zval = NULL;
1052 long level = 0;
1056 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoPSSurface_ce_ptr, &level) == FAILURE) {
1057 return;
1060 _this_ce = Z_OBJCE_P(_this_zval);
1061 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1064 do {
1065 /* ONLY for CAIRO 1.6 */
1066 } while (0);
1068 /* }}} restrict_to_level */
1072 /* {{{ proto void set_eps() --cairo 1.6
1074 PHP_METHOD(CairoPSSurface, set_eps)
1076 zend_class_entry * _this_ce;
1078 zval * _this_zval = NULL;
1082 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1083 return;
1086 _this_ce = Z_OBJCE_P(_this_zval);
1087 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1090 do {
1091 /* ONLY for CAIRO 1.6 */
1092 } while (0);
1094 /* }}} set_eps */
1098 /* {{{ proto void set_size(float wpts, float hpts)
1100 PHP_METHOD(CairoPSSurface, set_size)
1102 zend_class_entry * _this_ce;
1104 zval * _this_zval = NULL;
1105 double wpts = 0.0;
1106 double hpts = 0.0;
1110 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPSSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
1111 return;
1114 _this_ce = Z_OBJCE_P(_this_zval);
1115 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1116 cairo_ps_surface_set_size(curr->surface, wpts, hpts);
1119 /* }}} set_size */
1122 static zend_function_entry CairoPSSurface_methods[] = {
1123 PHP_ME(CairoPSSurface, __construct, CairoPSSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1124 PHP_ME(CairoPSSurface, dsc_begin_page_setup, NULL, /**/ZEND_ACC_PUBLIC)
1125 PHP_ME(CairoPSSurface, dsc_begin_setup, NULL, /**/ZEND_ACC_PUBLIC)
1126 PHP_ME(CairoPSSurface, dsc_comment, NULL, /**/ZEND_ACC_PUBLIC)
1127 PHP_ME(CairoPSSurface, get_levels, NULL, /**/ZEND_ACC_PUBLIC)
1128 PHP_ME(CairoPSSurface, get_level_string, NULL, /**/ZEND_ACC_PUBLIC)
1129 PHP_ME(CairoPSSurface, restrict_to_level, CairoPSSurface__restrict_to_level_args, /**/ZEND_ACC_PUBLIC)
1130 PHP_ME(CairoPSSurface, set_eps, NULL, /**/ZEND_ACC_PUBLIC)
1131 PHP_ME(CairoPSSurface, set_size, CairoPSSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
1132 { NULL, NULL, NULL }
1135 /* }}} Methods */
1137 static zend_object_value CairoPSSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1139 zend_object_value retval;
1140 retval=CairoSurface_object_new(ce TSRMLS_CC);
1141 retval.handlers = &CairoPSSurface_handlers;
1142 return retval;
1145 static void class_init_CairoPSSurface(void)
1147 zend_class_entry ce;
1149 INIT_CLASS_ENTRY(ce, "CairoPSSurface", CairoPSSurface_methods);
1150 CairoPSSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1151 CairoPSSurface_ce_ptr->create_object = CairoPSSurface_object_new;
1152 memcpy(&CairoPSSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1155 /* }}} Class CairoPSSurface */
1157 /* {{{ Class CairoQuartzSurface */
1159 static zend_class_entry * CairoQuartzSurface_ce_ptr = NULL;
1160 static zend_object_handlers CairoQuartzSurface_handlers;
1161 /* {{{ Methods */
1164 /* {{{ proto void construct(float wpixels, float hpixels [, int format])
1166 PHP_METHOD(CairoQuartzSurface, __construct)
1168 zend_class_entry * _this_ce;
1169 zval * _this_zval;
1171 double wpixels = 0.0;
1172 double hpixels = 0.0;
1173 long format = 0;
1177 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &wpixels, &hpixels, &format) == FAILURE) {
1178 return;
1181 _this_zval = getThis();
1182 _this_ce = Z_OBJCE_P(_this_zval);
1183 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1186 php_error(E_ERROR, "CANNOT BE CALLED"); RETURN_FALSE;
1189 /* }}} __construct */
1192 static zend_function_entry CairoQuartzSurface_methods[] = {
1193 PHP_ME(CairoQuartzSurface, __construct, CairoQuartzSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1194 { NULL, NULL, NULL }
1197 /* }}} Methods */
1199 static zend_object_value CairoQuartzSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1201 zend_object_value retval;
1202 retval=CairoSurface_object_new(ce TSRMLS_CC);
1203 retval.handlers = &CairoQuartzSurface_handlers;
1204 return retval;
1207 static void class_init_CairoQuartzSurface(void)
1209 zend_class_entry ce;
1211 INIT_CLASS_ENTRY(ce, "CairoQuartzSurface", CairoQuartzSurface_methods);
1212 CairoQuartzSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1213 CairoQuartzSurface_ce_ptr->create_object = CairoQuartzSurface_object_new;
1214 memcpy(&CairoQuartzSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1218 /* }}} Class CairoQuartzSurface */
1220 /* {{{ Class CairoSVGSurface */
1222 static zend_class_entry * CairoSVGSurface_ce_ptr = NULL;
1223 static zend_object_handlers CairoSVGSurface_handlers;
1226 /* {{{ Methods */
1229 /* {{{ proto void construct(string file, float wpts, float hpts)
1231 PHP_METHOD(CairoSVGSurface, __construct)
1233 zend_class_entry * _this_ce;
1234 zval * _this_zval;
1235 zval *zstream = NULL;
1236 const char * file = NULL;
1237 int file_len = 0;
1238 double wpts = 0.0;
1239 double hpts = 0.0;
1240 php_stream *stream;
1241 int argc = ZEND_NUM_ARGS();
1242 zval ***args, *obj;
1244 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
1245 if(ZEND_NUM_ARGS()== 0 ||
1246 zend_get_parameters_array_ex(argc, args)== FAILURE) {
1247 printf("ERROR");
1248 efree(args);
1249 WRONG_PARAM_COUNT;
1252 obj = *(args[1]);
1253 switch(Z_TYPE_P(obj)) {
1254 case IS_DOUBLE:
1255 wpts = Z_DVAL_P(obj);
1256 break;
1257 case IS_LONG:
1258 wpts = Z_LVAL_P(obj);
1259 break;
1260 default :
1261 printf("error!!!");
1262 return;
1265 obj = *(args[2]);
1267 switch(Z_TYPE_P(obj)) {
1268 case IS_DOUBLE:
1269 hpts = Z_DVAL_P(obj);
1270 break;
1271 case IS_LONG:
1272 hpts = Z_LVAL_P(obj);
1273 break;
1274 default :
1275 printf("Error!!!");
1276 return;
1280 _this_zval = getThis();
1281 _this_ce = Z_OBJCE_P(_this_zval);
1282 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1284 obj = *(args[0]);
1285 if(Z_TYPE_P(obj)==IS_STRING) {
1286 file = Z_STRVAL_P(obj);
1287 curr->surface = cairo_svg_surface_create(file, wpts, hpts);
1289 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
1290 zstream = obj;
1291 php_stream_from_zval(stream, &zstream);
1292 curr->surface = cairo_svg_surface_create_for_stream(_write_func, stream, wpts, hpts);
1294 else {
1295 printf("ERROR\n");
1298 efree(args);
1302 /* }}} __construct */
1305 static zend_function_entry CairoSVGSurface_methods[] = {
1306 PHP_ME(CairoSVGSurface, __construct, CairoSVGSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1307 { NULL, NULL, NULL }
1310 /* }}} Methods */
1312 static zend_object_value CairoSVGSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1314 zend_object_value retval;
1315 retval=CairoSurface_object_new(ce TSRMLS_CC);
1316 retval.handlers = &CairoSVGSurface_handlers;
1317 return retval;
1320 static void class_init_CairoSVGSurface(void)
1322 zend_class_entry ce;
1324 INIT_CLASS_ENTRY(ce, "CairoSVGSurface", CairoSVGSurface_methods);
1325 CairoSVGSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1326 CairoSVGSurface_ce_ptr->create_object = CairoSVGSurface_object_new;
1327 memcpy(&CairoSVGSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1331 /* }}} Class CairoSVGSurface */
1333 /* {{{ Class CairoWin32Surface -- Have to work on this aswell */
1335 static zend_class_entry * CairoWin32Surface_ce_ptr = NULL;
1336 static zend_object_handlers CairoWin32Surface_handlers;
1338 /* {{{ Methods */
1341 /* {{{ proto void construct(int hdc)
1343 PHP_METHOD(CairoWin32Surface, __construct)
1345 zend_class_entry * _this_ce;
1346 zval * _this_zval;
1348 long hdc = 0;
1352 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hdc) == FAILURE) {
1353 return;
1356 _this_zval = getThis();
1357 _this_ce = Z_OBJCE_P(_this_zval);
1358 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1359 curr->surface = cairo_win32_surface_create(hdc, NULL);
1361 /* }}} __construct */
1364 static zend_function_entry CairoWin32Surface_methods[] = {
1365 PHP_ME(CairoWin32Surface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1366 { NULL, NULL, NULL }
1369 /* }}} Methods */
1371 static zend_object_value CairoWin32Surface_object_new(zend_class_entry *ce TSRMLS_DC)
1373 zend_object_value retval;
1374 retval=CairoSurface_object_new(ce TSRMLS_CC);
1375 retval.handlers = &CairoWin32Surface_handlers;
1376 return retval;
1379 static void class_init_CairoWin32Surface(void)
1381 zend_class_entry ce;
1383 INIT_CLASS_ENTRY(ce, "CairoWin32Surface", CairoWin32Surface_methods);
1384 CairoWin32Surface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1385 CairoWin32Surface_ce_ptr->create_object = CairoWin32Surface_object_new;
1386 memcpy(&CairoWin32Surface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1390 /* }}} Class CairoWin32Surface */
1392 /* {{{ Class CairoXlibSurface */
1394 static zend_class_entry * CairoXlibSurface_ce_ptr = NULL;
1395 static zend_object_handlers CairoXlibSurface_handlers;
1396 /* {{{ Methods */
1399 /* {{{ proto void construct()
1401 PHP_METHOD(CairoXlibSurface, __construct)
1403 zend_class_entry * _this_ce;
1404 zval * _this_zval;
1408 if (ZEND_NUM_ARGS()>0) {
1409 WRONG_PARAM_COUNT;
1412 _this_zval = getThis();
1413 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1415 php_error(E_WARNING, "Cannot Be Initialized"); RETURN_FALSE;
1418 /* }}} __construct */
1422 /* {{{ proto int get_depth()
1424 PHP_METHOD(CairoXlibSurface, get_depth)
1426 zend_class_entry * _this_ce;
1428 zval * _this_zval = NULL;
1429 long depth;
1432 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1433 return;
1436 _this_ce = Z_OBJCE_P(_this_zval);
1437 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1439 depth = cairo_xlib_surface_get_depth(curr->surface);
1441 RETURN_LONG(depth);
1443 /* }}} get_depth */
1447 /* {{{ proto int get_height()
1449 PHP_METHOD(CairoXlibSurface, get_height)
1451 zend_class_entry * _this_ce;
1453 zval * _this_zval = NULL;
1454 long height;
1457 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1458 return;
1461 _this_ce = Z_OBJCE_P(_this_zval);
1462 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1463 height = cairo_xlib_surface_get_height(curr->surface);
1465 RETURN_LONG(height);
1467 /* }}} get_height */
1471 /* {{{ proto int get_width()
1473 PHP_METHOD(CairoXlibSurface, get_width)
1475 zend_class_entry * _this_ce;
1477 zval * _this_zval = NULL;
1478 long width;
1481 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1482 return;
1485 _this_ce = Z_OBJCE_P(_this_zval);
1486 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1487 width = cairo_xlib_surface_get_width(curr->surface);
1489 RETURN_LONG(width);
1491 /* }}} get_width */
1494 static zend_function_entry CairoXlibSurface_methods[] = {
1495 PHP_ME(CairoXlibSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1496 PHP_ME(CairoXlibSurface, get_depth, NULL, /**/ZEND_ACC_PUBLIC)
1497 PHP_ME(CairoXlibSurface, get_height, NULL, /**/ZEND_ACC_PUBLIC)
1498 PHP_ME(CairoXlibSurface, get_width, NULL, /**/ZEND_ACC_PUBLIC)
1499 { NULL, NULL, NULL }
1502 /* }}} Methods */
1504 static zend_object_value CairoXlibSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1506 zend_object_value retval;
1507 retval=CairoSurface_object_new(ce TSRMLS_CC);
1508 retval.handlers = &CairoXlibSurface_handlers;
1509 return retval;
1512 static void class_init_CairoXlibSurface(void)
1514 zend_class_entry ce;
1516 INIT_CLASS_ENTRY(ce, "CairoXlibSurface", CairoXlibSurface_methods);
1517 CairoXlibSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1518 CairoXlibSurface_ce_ptr->create_object = CairoXlibSurface_object_new;
1519 memcpy(&CairoXlibSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1523 /* }}} Class CairoXlibSurface */
1525 /* {{{ Helper Functions */
1526 zend_class_entry *
1527 get_CairoSurface_ce_ptr(cairo_surface_t *surface)
1529 zend_class_entry *type;
1530 if(surface == NULL)
1531 return;
1533 switch(cairo_surface_get_type(surface)) {
1534 case CAIRO_SURFACE_TYPE_IMAGE:
1535 type = CairoImageSurface_ce_ptr;
1536 break;
1537 case CAIRO_SURFACE_TYPE_PDF:
1538 type = CairoPDFSurface_ce_ptr;
1539 break;
1540 case CAIRO_SURFACE_TYPE_PS:
1541 type = CairoPSSurface_ce_ptr;
1542 break;
1543 case CAIRO_SURFACE_TYPE_SVG:
1544 type = CairoSVGSurface_ce_ptr;
1545 break;
1546 case CAIRO_SURFACE_TYPE_WIN32:
1547 type = CairoWin32Surface_ce_ptr;
1548 break;
1549 case CAIRO_SURFACE_TYPE_XLIB:
1550 type = CairoXlibSurface_ce_ptr;
1551 break;
1552 case CAIRO_SURFACE_TYPE_QUARTZ:
1553 type = CairoQuartzSurface_ce_ptr;
1554 break;
1555 default:
1556 php_error(E_ERROR,"Unsupported Surface Type");
1557 return NULL;
1559 return type;
1562 /* }}} Helper Function*/