Pattern Class is complete -- Testing to be done ;)
[phpCairo.git] / individual_files / phpCairoSurface.c
blob4a53e272da1bbc0e468e29edf8bae3dc5d816c4d
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 printf("%d %d",written, length);
14 if(written == length)
15 return CAIRO_STATUS_SUCCESS;
16 else {
17 printf("is it an error ?");
18 // CAIRO_STATUS_WRITE_ERROR;
22 static cairo_status_t
23 _read_func(void *closure, const unsigned char *data, unsigned int length)
25 int read;
26 php_stream *zs = (php_stream *)closure;
27 //data = emalloc(length);
28 read = php_stream_read(zs, data, length);
29 printf("%d %d", read, length);
30 if(read == length)
31 return CAIRO_STATUS_SUCCESS;
32 else {
33 printf("is it an error");
40 typedef struct _surface_object {
41 zend_object std;
42 cairo_surface_t *surface;
43 } surface_object;
46 /* {{{ Methods */
49 /* {{{ proto void construct()
51 PHP_METHOD(CairoSurface, __construct)
53 zend_class_entry * _this_ce;
54 zval * _this_zval;
58 if (ZEND_NUM_ARGS()>0) {
59 WRONG_PARAM_COUNT;
60 php_print("wtf");
61 return;
64 php_print("No direct call for this constructor");
68 /* }}} __construct */
72 /* {{{ proto object create_similar(int content, int width, int height)
74 PHP_METHOD(CairoSurface, create_similar)
76 zend_class_entry * _this_ce;
78 zval * _this_zval = NULL;
79 cairo_surface_t *sur;
80 int content;
81 long width = 0;
82 long height = 0;
84 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oill", &_this_zval, CairoSurface_ce_ptr, &content, &width, &height) == FAILURE) {
85 return;
88 _this_ce = Z_OBJCE_P(_this_zval);
89 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
90 sur = cairo_surface_create_similar(curr->surface, content, width, height);
91 object_init(return_value);
92 surface_object *sobj = (surface_object *)zend_objects_get_address(return_value TSRMLS_CC);
93 sobj->surface=sur;
96 /* }}} create_similar */
99 /* {{{ proto void finish()
101 PHP_METHOD(CairoSurface, finish)
103 zend_class_entry * _this_ce;
105 zval * _this_zval = NULL;
107 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
108 return;
111 _this_ce = Z_OBJCE_P(_this_zval);
112 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
113 cairo_surface_finish(curr->surface);
115 /* }}} finish */
119 /* {{{ proto void flush()
121 PHP_METHOD(CairoSurface, flush)
123 zend_class_entry * _this_ce;
125 zval * _this_zval = NULL;
127 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
128 return;
131 _this_ce = Z_OBJCE_P(_this_zval);
132 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
134 cairo_surface_flush(curr->surface);
137 /* }}} flush */
141 /* {{{ proto int get_content()
143 PHP_METHOD(CairoSurface, get_content)
145 zend_class_entry * _this_ce;
147 zval * _this_zval = NULL;
148 long x;
149 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
150 return;
153 _this_ce = Z_OBJCE_P(_this_zval);
154 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
156 x=cairo_surface_get_content(curr->surface);
157 RETURN_LONG(x);
159 /* }}} get_content */
163 /* {{{ proto array get_device_offset()
165 PHP_METHOD(CairoSurface, get_device_offset)
167 zend_class_entry * _this_ce;
169 zval * _this_zval = NULL;
170 double x_offset, y_offset;
172 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
173 return;
176 _this_ce = Z_OBJCE_P(_this_zval);
177 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
179 cairo_surface_get_device_offset(curr->surface, &x_offset, &y_offset);
181 array_init(return_value);
182 add_assoc_double(return_value, "x_offset", x_offset);
183 add_assoc_double(return_value, "y_offset", y_offset);
186 /* }}} get_device_offset */
190 /* {{{ proto object get_font_options()
192 PHP_METHOD(CairoSurface, get_font_options)
194 zend_class_entry * _this_ce;
196 zval * _this_zval = NULL;
198 cairo_font_options_t *options = cairo_font_options_create();
201 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
202 return;
205 _this_ce = Z_OBJCE_P(_this_zval);
206 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
208 cairo_surface_get_font_options(curr->surface, options);
209 object_init(return_value);
210 fontoptions_object *fobj = (fontoptions_object *)zend_objects_get_address(return_value TSRMLS_CC);
211 fobj->fontoptions=options;
214 /* }}} get_font_options */
218 /* {{{ proto void mark_dirty_rectangle([int x, int y, int width, int height])
220 PHP_METHOD(CairoSurface, mark_dirty_rectangle)
222 zend_class_entry * _this_ce;
224 zval * _this_zval = NULL;
225 long x = 0;
226 long y = 0;
227 long width = -1;
228 long height = -1;
232 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|llll", &_this_zval, CairoSurface_ce_ptr, &x, &y, &width, &height) == FAILURE) {
233 return;
235 _this_ce = Z_OBJCE_P(_this_zval);
236 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
237 cairo_surface_mark_dirty_rectangle(curr->surface, x, y, width, height);
240 /* }}} mark_dirty_rectangle */
244 /* {{{ proto void set_device_offset(float x_offset, float y_offset)
246 PHP_METHOD(CairoSurface, set_device_offset)
248 zend_class_entry * _this_ce;
250 zval * _this_zval = NULL;
251 double x_offset = 0.0;
252 double y_offset = 0.0;
254 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_offset, &y_offset) == FAILURE) {
255 return;
258 _this_ce = Z_OBJCE_P(_this_zval);
259 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
260 cairo_surface_set_device_offset(curr->surface, x_offset, y_offset);
263 /* }}} set_device_offset */
267 /* {{{ proto void set_fallback_resolution(float x_ppi, float y_ppi)
269 PHP_METHOD(CairoSurface, set_fallback_resolution)
271 zend_class_entry * _this_ce;
273 zval * _this_zval = NULL;
274 double x_ppi = 0.0;
275 double y_ppi = 0.0;
277 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_ppi, &y_ppi) == FAILURE) {
278 return;
281 _this_ce = Z_OBJCE_P(_this_zval);
282 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
283 cairo_surface_set_fallback_resolution(curr->surface, x_ppi, y_ppi);
286 /* }}} set_fallback_resolution */
290 /* {{{ proto void write_to_png(string file)
292 PHP_METHOD(CairoSurface, write_to_png)
294 zend_class_entry * _this_ce;
296 zval * _this_zval = NULL;
297 const char * file = NULL;
298 int file_len = 0;
299 cairo_status_t status;
301 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoSurface_ce_ptr, &file, &file_len) == FAILURE) {
302 return;
305 _this_ce = Z_OBJCE_P(_this_zval);
306 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
307 status = cairo_surface_write_to_png(curr->surface, file);
310 /* }}} write_to_png */
313 /* {{{ proto void write_to_png_stream(stream file)
315 PHP_METHOD(CairoSurface, write_to_png_stream)
317 zend_class_entry *_this_ce;
318 FILE *file;
319 zval *_this_zval = NULL;
320 cairo_status_t status;
321 zval *zstream;
322 php_stream *stream;
323 int err;
325 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoSurface_ce_ptr, &zstream)) {
326 return;
329 _this_ce = Z_OBJCE_P(_this_zval);
330 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
331 php_stream_from_zval(stream, &zstream);
332 status = cairo_surface_write_to_png_stream(curr->surface, _write_func, stream);
336 /* }}} */
339 static zend_function_entry CairoSurface_methods[] = {
340 PHP_ME(CairoSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
341 PHP_ME(CairoSurface, create_similar, CairoSurface__create_similar_args, /**/ZEND_ACC_PUBLIC)
342 PHP_ME(CairoSurface, finish, NULL, /**/ZEND_ACC_PUBLIC)
343 PHP_ME(CairoSurface, flush, NULL, /**/ZEND_ACC_PUBLIC)
344 PHP_ME(CairoSurface, get_content, NULL, /**/ZEND_ACC_PUBLIC)
345 PHP_ME(CairoSurface, get_device_offset, NULL, /**/ZEND_ACC_PUBLIC)
346 PHP_ME(CairoSurface, get_font_options, NULL, /**/ZEND_ACC_PUBLIC)
347 PHP_ME(CairoSurface, mark_dirty_rectangle, CairoSurface__mark_dirty_rectangle_args, /**/ZEND_ACC_PUBLIC)
348 PHP_ME(CairoSurface, set_device_offset, CairoSurface__set_device_offset_args, /**/ZEND_ACC_PUBLIC)
349 PHP_ME(CairoSurface, set_fallback_resolution, CairoSurface__set_fallback_resolution_args, /**/ZEND_ACC_PUBLIC)
350 PHP_ME(CairoSurface, write_to_png, CairoSurface__write_to_png_args, /**/ZEND_ACC_PUBLIC)
351 PHP_ME(CairoSurface, write_to_png_stream, CairoSurface__write_to_png_stream_args, /**/ZEND_ACC_PUBLIC)
352 { NULL, NULL, NULL }
355 /* }}} Methods */
358 static void CairoSurface_object_dtor(void *object)
360 surface_object *surface = (surface_object *)object;
361 zend_hash_destroy(surface->std.properties);
362 FREE_HASHTABLE(surface->std.properties);
363 if(surface->surface){
364 cairo_surface_finish(surface->surface);
365 cairo_surface_destroy(surface->surface);
368 efree(object);
371 static zend_object_value CairoSurface_object_new(zend_class_entry *ce)
373 zend_object_value retval;
374 surface_object *surface;
375 zval *temp;
377 surface = emalloc(sizeof(surface_object));
378 memset(surface,0,sizeof(surface_object));
380 surface->std.ce=ce;
382 ALLOC_HASHTABLE(surface->std.properties);
383 zend_hash_init(surface->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
384 zend_hash_copy(surface->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
385 retval.handle=zend_objects_store_put(surface, NULL, (zend_objects_free_object_storage_t)CairoSurface_object_dtor, NULL TSRMLS_CC);
386 retval.handlers = &CairoSurface_handlers;
387 return retval;
390 static void class_init_CairoSurface(void)
392 zend_class_entry ce;
394 INIT_CLASS_ENTRY(ce, "CairoSurface", CairoSurface_methods);
395 CairoSurface_ce_ptr = zend_register_internal_class(&ce);
396 CairoSurface_ce_ptr->create_object = CairoSurface_object_new;
397 memcpy(&CairoSurface_handlers, zend_get_std_object_handlers(),sizeof(zend_object_handlers));
398 CairoSurface_handlers.clone_obj = NULL;
401 /* }}} Class CairoSurface */
403 /* {{{ Class CairoImageSurface -- done :)*/
405 static zend_class_entry * CairoImageSurface_ce_ptr = NULL;
406 static zend_object_handlers CairoImageSurface_handlers;
407 /* {{{ Methods */
410 /* {{{ proto void construct(int format, int widthm, int height)
412 PHP_METHOD(CairoImageSurface, __construct)
414 zend_class_entry * _this_ce;
415 zval * _this_zval;
417 cairo_format_t format = 0;
418 long widthm = 0;
419 long height = 0;
423 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &format, &widthm, &height) == FAILURE) {
424 return;
427 _this_zval = getThis();
428 _this_ce = Z_OBJCE_P(_this_zval);
429 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
430 curr->surface = cairo_image_surface_create(format, widthm, height);
433 /* }}} __construct */
437 /* {{{ proto void create_from_data(object obj, int format, int width, int height [, int stride])
439 PHP_METHOD(CairoImageSurface, create_from_data)
441 zend_class_entry * _this_ce;
443 zval * _this_zval = NULL;
444 const char * buffer = NULL;
445 int buffer_len = 0;
446 long format = 0;
447 long width = 0;
448 long height = 0;
449 long stride = -1;
453 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) {
454 return;
457 _this_ce = Z_OBJCE_P(_this_zval);
458 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
460 if(stride < 0 ){
461 switch(format) {
462 case CAIRO_FORMAT_ARGB32:
463 case CAIRO_FORMAT_RGB24:
464 stride = width * 4;
465 break;
466 case CAIRO_FORMAT_RGB16_565:
467 stride = width * 2;
468 break;
469 case CAIRO_FORMAT_A8:
470 stride = width;
471 break;
472 case CAIRO_FORMAT_A1:
473 stride = (width + 1) / 8;
474 break;
475 default:
476 //php_error(CairoError, "Unknown format");
477 return;
481 if (height * stride > buffer_len) {
482 php_error(E_ERROR,"buffer is not long enough");
483 return;
485 curr->surface = cairo_image_surface_create_for_data(buffer, format, width, height, stride);
487 /* }}} create_from_data */
491 /* {{{ proto void create_from_png(string file)
493 PHP_METHOD(CairoImageSurface, create_from_png)
495 zend_class_entry * _this_ce;
497 zval * _this_zval = NULL;
498 const char * file = NULL;
499 int file_len = 0;
501 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoImageSurface_ce_ptr, &file, &file_len) == FAILURE) {
502 return;
505 _this_ce = Z_OBJCE_P(_this_zval);
506 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
508 curr->surface = cairo_image_surface_create_from_png(file);
511 /* }}} create_from_png */
515 /* {{{ proto void create_from_png_stream(stream zstream)
518 PHP_METHOD(CairoImageSurface, create_from_png_stream)
520 zend_class_entry *_this_ce;
521 FILE *file;
522 zval *_this_zval = NULL;
523 cairo_status_t status;
524 zval *zstream;
525 php_stream *stream;
526 int err;
528 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoImageSurface_ce_ptr, &zstream)) {
529 return;
532 _this_ce = Z_OBJCE_P(_this_zval);
533 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
535 php_stream_from_zval(stream, &zstream);
536 curr->surface = cairo_image_surface_create_from_png_stream( _read_func, stream);
541 /* }}} */
545 /* {{{ proto string get_data() -- not required
547 PHP_METHOD(CairoImageSurface, get_data)
549 zend_class_entry * _this_ce;
551 zval * _this_zval = NULL;
555 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
556 return;
559 _this_ce = Z_OBJCE_P(_this_zval);
560 php_error(E_WARNING,"Not Implemented .. not required");
562 RETURN_STRINGL("", 0, 1);
564 /* }}} get_data */
568 /* {{{ proto int get_format()
570 PHP_METHOD(CairoImageSurface, get_format)
572 zend_class_entry * _this_ce;
573 long x;
574 zval * _this_zval = NULL;
576 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
577 return;
579 _this_ce = Z_OBJCE_P(_this_zval);
580 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
582 x = cairo_image_surface_get_format(curr->surface);
583 RETURN_LONG(x);
585 /* }}} get_format */
589 /* {{{ proto int get_height()
591 PHP_METHOD(CairoImageSurface, get_height)
593 zend_class_entry * _this_ce;
594 zval * _this_zval = NULL;
595 long x;
597 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
598 return;
601 _this_ce = Z_OBJCE_P(_this_zval);
602 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
603 x = cairo_image_surface_get_height(curr->surface);
605 RETURN_LONG(x);
607 /* }}} get_height */
611 /* {{{ proto int get_stride()
613 PHP_METHOD(CairoImageSurface, get_stride)
615 zend_class_entry * _this_ce;
616 zval * _this_zval = NULL;
617 long x;
619 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
620 return;
623 _this_ce = Z_OBJCE_P(_this_zval);
624 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
625 x = cairo_image_surface_get_stride(curr->surface);
627 RETURN_LONG(x);
629 /* }}} get_stride */
633 /* {{{ proto int get_width()
635 PHP_METHOD(CairoImageSurface, get_width)
637 zend_class_entry * _this_ce;
638 zval * _this_zval = NULL;
639 long x;
641 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
642 return;
645 _this_ce = Z_OBJCE_P(_this_zval);
647 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
649 x = cairo_image_surface_get_width(curr->surface);
650 RETURN_LONG(x);
652 /* }}} get_width */
655 static zend_function_entry CairoImageSurface_methods[] = {
656 PHP_ME(CairoImageSurface, __construct, CairoImageSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
657 PHP_ME(CairoImageSurface, create_from_data, CairoImageSurface__create_from_data_args, /**/ZEND_ACC_PUBLIC)
658 PHP_ME(CairoImageSurface, create_from_png, CairoImageSurface__create_from_png_args, /**/ZEND_ACC_PUBLIC)
659 PHP_ME(CairoImageSurface, create_from_png_stream, CairoImageSurface__create_from_png_stream_args, /**/ZEND_ACC_PUBLIC)
660 PHP_ME(CairoImageSurface, get_data, NULL, /**/ZEND_ACC_PUBLIC)
661 PHP_ME(CairoImageSurface, get_format, NULL, /**/ZEND_ACC_PUBLIC)
662 PHP_ME(CairoImageSurface, get_height, NULL, /**/ZEND_ACC_PUBLIC)
663 PHP_ME(CairoImageSurface, get_stride, NULL, /**/ZEND_ACC_PUBLIC)
664 PHP_ME(CairoImageSurface, get_width, NULL, /**/ZEND_ACC_PUBLIC)
665 { NULL, NULL, NULL }
668 /* }}} Methods */
670 static zend_object_value CairoImageSurface_object_new(zend_class_entry *ce TSRMLS_DC)
672 zend_object_value retval;
673 retval=CairoSurface_object_new(ce TSRMLS_CC);
674 retval.handlers = &CairoImageSurface_handlers;
675 return retval;
679 static void class_init_CairoImageSurface(void)
681 zend_class_entry ce;
683 INIT_CLASS_ENTRY(ce, "CairoImageSurface", CairoImageSurface_methods);
684 CairoImageSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
685 CairoImageSurface_ce_ptr->create_object = CairoImageSurface_object_new;
686 memcpy(&CairoImageSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
689 /* }}} Class CairoImageSurface */
691 /* {{{ Class CairoPDFSurface */
693 static zend_class_entry * CairoPDFSurface_ce_ptr = NULL;
694 static zend_object_handlers CairoPDFSurface_handlers;
695 /* {{{ Methods */
698 /* {{{ proto void construct(string file, float wpts, float hpts)
700 PHP_METHOD(CairoPDFSurface, __construct)
702 zend_class_entry * _this_ce;
703 zval * _this_zval;
704 zval *zstream = NULL;
705 const char * file = NULL;
706 int file_len = 0;
707 double wpts = 0.0;
708 double hpts = 0.0;
709 php_stream *stream;
710 int argc = ZEND_NUM_ARGS();
711 zval ***args, *obj;
713 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
714 if(ZEND_NUM_ARGS()== 0 ||
715 zend_get_parameters_array_ex(argc, args)== FAILURE) {
716 printf("ERROR");
717 efree(args);
718 WRONG_PARAM_COUNT;
721 obj = *(args[1]);
722 switch(Z_TYPE_P(obj)) {
723 case IS_DOUBLE:
724 wpts = Z_DVAL_P(obj);
725 break;
726 case IS_LONG:
727 wpts = Z_LVAL_P(obj);
728 break;
729 default :
730 printf("Error!!!");
731 return;
734 obj = *(args[2]);
736 switch(Z_TYPE_P(obj)) {
737 case IS_DOUBLE:
738 hpts = Z_DVAL_P(obj);
739 break;
740 case IS_LONG:
741 hpts = Z_LVAL_P(obj);
742 break;
743 default :
744 printf("Error!!!");
745 return;
749 _this_zval = getThis();
750 _this_ce = Z_OBJCE_P(_this_zval);
751 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
753 obj = *(args[0]);
754 if(Z_TYPE_P(obj)==IS_STRING) {
755 file = Z_STRVAL_P(obj);
756 curr->surface = cairo_pdf_surface_create(file, wpts, hpts);
758 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
759 zstream = obj;
760 php_stream_from_zval(stream, &zstream);
761 curr->surface = cairo_pdf_surface_create_for_stream(_write_func, stream, wpts, hpts);
763 else {
764 printf("ERROR\n");
767 efree(args);
769 /* }}} __construct */
773 /* {{{ proto void set_size(float wptd, float hpts)
775 PHP_METHOD(CairoPDFSurface, set_size)
777 zend_class_entry * _this_ce;
779 zval * _this_zval = NULL;
780 double wpts = 0.0;
781 double hpts = 0.0;
785 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPDFSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
786 return;
789 _this_ce = Z_OBJCE_P(_this_zval);
790 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
791 cairo_pdf_surface_set_size(curr->surface, wpts, hpts);
794 /* }}} set_size */
797 static zend_function_entry CairoPDFSurface_methods[] = {
798 PHP_ME(CairoPDFSurface, __construct, CairoPDFSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
799 PHP_ME(CairoPDFSurface, set_size, CairoPDFSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
800 { NULL, NULL, NULL }
803 /* }}} Methods */
805 static zend_object_value CairoPDFSurface_object_new(zend_class_entry *ce TSRMLS_DC)
807 zend_object_value retval;
808 retval=CairoSurface_object_new(ce TSRMLS_CC);
809 retval.handlers = &CairoPDFSurface_handlers;
810 return retval;
813 static void class_init_CairoPDFSurface(void)
815 zend_class_entry ce;
817 INIT_CLASS_ENTRY(ce, "CairoPDFSurface", CairoPDFSurface_methods);
818 CairoPDFSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
819 CairoPDFSurface_ce_ptr->create_object = CairoPDFSurface_object_new;
820 memcpy(&CairoPDFSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
824 /* }}} Class CairoPDFSurface */
826 /* {{{ Class CairoPSSurface */
828 static zend_class_entry * CairoPSSurface_ce_ptr = NULL;
829 static zend_object_handlers CairoPSSurface_handlers;
830 /* {{{ Methods */
833 /* {{{ proto void construct(string file | stream stream, float wpts, float hpts)
835 PHP_METHOD(CairoPSSurface, __construct)
837 zend_class_entry * _this_ce;
838 zval * _this_zval;
839 zval *zstream = NULL;
840 const char * file = NULL;
841 int file_len = 0;
842 double wpts = 0.0;
843 double hpts = 0.0;
844 php_stream *stream;
845 int argc = ZEND_NUM_ARGS();
846 zval ***args, *obj;
848 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
849 if(ZEND_NUM_ARGS()== 0 ||
850 zend_get_parameters_array_ex(argc, args)== FAILURE) {
851 printf("ERROR");
852 efree(args);
853 WRONG_PARAM_COUNT;
856 obj = *(args[1]);
857 switch(Z_TYPE_P(obj)) {
858 case IS_DOUBLE:
859 wpts = Z_DVAL_P(obj);
860 break;
861 case IS_LONG:
862 wpts = Z_LVAL_P(obj);
863 break;
864 default :
865 printf("Error!!!");
866 return;
869 obj = *(args[2]);
871 switch(Z_TYPE_P(obj)) {
872 case IS_DOUBLE:
873 hpts = Z_DVAL_P(obj);
874 break;
875 case IS_LONG:
876 hpts = Z_LVAL_P(obj);
877 break;
878 default :
879 printf("Error!!!");
880 return;
884 _this_zval = getThis();
885 _this_ce = Z_OBJCE_P(_this_zval);
886 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
888 obj = *(args[0]);
889 if(Z_TYPE_P(obj)==IS_STRING) {
890 file = Z_STRVAL_P(obj);
891 curr->surface = cairo_ps_surface_create(file, wpts, hpts);
893 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
894 zstream = obj;
895 php_stream_from_zval(stream, &zstream);
896 curr->surface = cairo_ps_surface_create_for_stream(_write_func, stream, wpts, hpts);
898 else {
899 printf("ERROR\n");
902 efree(args);
908 /* }}} __construct */
912 /* {{{ proto void dsc_begin_page_setup()
914 PHP_METHOD(CairoPSSurface, dsc_begin_page_setup)
916 zend_class_entry * _this_ce;
918 zval * _this_zval = NULL;
922 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
923 return;
925 _this_ce = Z_OBJCE_P(_this_zval);
926 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
927 cairo_ps_surface_dsc_begin_page_setup(curr->surface);
928 phpCAIRO_SURFACE_ERROR(curr->surface);
933 /* }}} dsc_begin_page_setup */
937 /* {{{ proto void dsc_begin_setup()
939 PHP_METHOD(CairoPSSurface, dsc_begin_setup)
941 zend_class_entry * _this_ce;
943 zval * _this_zval = NULL;
947 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
948 return;
951 _this_ce = Z_OBJCE_P(_this_zval);
952 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
953 cairo_ps_surface_dsc_begin_setup(curr->surface);
954 phpCAIRO_SURFACE_ERROR(curr->surface);
957 /* }}} dsc_begin_setup */
961 /* {{{ proto void dsc_comment()
963 PHP_METHOD(CairoPSSurface, dsc_comment)
965 zend_class_entry * _this_ce;
967 zval * _this_zval = NULL;
971 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
972 return;
975 _this_ce = Z_OBJCE_P(_this_zval);
976 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
977 cairo_ps_surface_dsc_comment(curr->surface);
978 phpCAIRO_SURFACE_ERROR(curr->surface);
981 /* }}} dsc_comment */
985 /* {{{ proto array get_levels() -- cairo 1.6
987 PHP_METHOD(CairoPSSurface, get_levels)
989 zend_class_entry * _this_ce;
991 zval * _this_zval = NULL;
995 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
996 return;
999 _this_ce = Z_OBJCE_P(_this_zval);
1000 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1003 array_init(return_value);
1005 do {
1006 /* ONLY for CAIRO 1.6 */
1007 } while (0);
1009 /* }}} get_levels */
1013 /* {{{ proto string get_level_string() --cairo 1.6
1015 PHP_METHOD(CairoPSSurface, get_level_string)
1017 zend_class_entry * _this_ce;
1019 zval * _this_zval = NULL;
1023 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1024 return;
1027 _this_ce = Z_OBJCE_P(_this_zval);
1028 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1031 do {
1032 /* ONLY for CAIRO 1.6*/
1033 } while (0);
1035 /* }}} get_level_string */
1039 /* {{{ proto void restrict_to_level(int level) --cairo 1.6
1041 PHP_METHOD(CairoPSSurface, restrict_to_level)
1043 zend_class_entry * _this_ce;
1045 zval * _this_zval = NULL;
1046 long level = 0;
1050 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoPSSurface_ce_ptr, &level) == FAILURE) {
1051 return;
1054 _this_ce = Z_OBJCE_P(_this_zval);
1055 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1058 do {
1059 /* ONLY for CAIRO 1.6 */
1060 } while (0);
1062 /* }}} restrict_to_level */
1066 /* {{{ proto void set_eps() --cairo 1.6
1068 PHP_METHOD(CairoPSSurface, set_eps)
1070 zend_class_entry * _this_ce;
1072 zval * _this_zval = NULL;
1076 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1077 return;
1080 _this_ce = Z_OBJCE_P(_this_zval);
1081 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1084 do {
1085 /* ONLY for CAIRO 1.6 */
1086 } while (0);
1088 /* }}} set_eps */
1092 /* {{{ proto void set_size(float wpts, float hpts)
1094 PHP_METHOD(CairoPSSurface, set_size)
1096 zend_class_entry * _this_ce;
1098 zval * _this_zval = NULL;
1099 double wpts = 0.0;
1100 double hpts = 0.0;
1104 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPSSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
1105 return;
1108 _this_ce = Z_OBJCE_P(_this_zval);
1109 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1110 cairo_ps_surface_set_size(curr->surface, wpts, hpts);
1113 /* }}} set_size */
1116 static zend_function_entry CairoPSSurface_methods[] = {
1117 PHP_ME(CairoPSSurface, __construct, CairoPSSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1118 PHP_ME(CairoPSSurface, dsc_begin_page_setup, NULL, /**/ZEND_ACC_PUBLIC)
1119 PHP_ME(CairoPSSurface, dsc_begin_setup, NULL, /**/ZEND_ACC_PUBLIC)
1120 PHP_ME(CairoPSSurface, dsc_comment, NULL, /**/ZEND_ACC_PUBLIC)
1121 PHP_ME(CairoPSSurface, get_levels, NULL, /**/ZEND_ACC_PUBLIC)
1122 PHP_ME(CairoPSSurface, get_level_string, NULL, /**/ZEND_ACC_PUBLIC)
1123 PHP_ME(CairoPSSurface, restrict_to_level, CairoPSSurface__restrict_to_level_args, /**/ZEND_ACC_PUBLIC)
1124 PHP_ME(CairoPSSurface, set_eps, NULL, /**/ZEND_ACC_PUBLIC)
1125 PHP_ME(CairoPSSurface, set_size, CairoPSSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
1126 { NULL, NULL, NULL }
1129 /* }}} Methods */
1131 static zend_object_value CairoPSSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1133 zend_object_value retval;
1134 retval=CairoSurface_object_new(ce TSRMLS_CC);
1135 retval.handlers = &CairoPSSurface_handlers;
1136 return retval;
1139 static void class_init_CairoPSSurface(void)
1141 zend_class_entry ce;
1143 INIT_CLASS_ENTRY(ce, "CairoPSSurface", CairoPSSurface_methods);
1144 CairoPSSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1145 CairoPSSurface_ce_ptr->create_object = CairoPSSurface_object_new;
1146 memcpy(&CairoPSSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1149 /* }}} Class CairoPSSurface */
1151 /* {{{ Class CairoQuartzSurface */
1153 static zend_class_entry * CairoQuartzSurface_ce_ptr = NULL;
1154 static zend_object_handlers CairoQuartzSurface_handlers;
1155 /* {{{ Methods */
1158 /* {{{ proto void construct(float wpixels, float hpixels [, int format])
1160 PHP_METHOD(CairoQuartzSurface, __construct)
1162 zend_class_entry * _this_ce;
1163 zval * _this_zval;
1165 double wpixels = 0.0;
1166 double hpixels = 0.0;
1167 long format = 0;
1171 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &wpixels, &hpixels, &format) == FAILURE) {
1172 return;
1175 _this_zval = getThis();
1176 _this_ce = Z_OBJCE_P(_this_zval);
1177 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1180 php_error(E_ERROR, "CANNOT BE CALLED"); RETURN_FALSE;
1183 /* }}} __construct */
1186 static zend_function_entry CairoQuartzSurface_methods[] = {
1187 PHP_ME(CairoQuartzSurface, __construct, CairoQuartzSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1188 { NULL, NULL, NULL }
1191 /* }}} Methods */
1193 static zend_object_value CairoQuartzSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1195 zend_object_value retval;
1196 retval=CairoSurface_object_new(ce TSRMLS_CC);
1197 retval.handlers = &CairoQuartzSurface_handlers;
1198 return retval;
1201 static void class_init_CairoQuartzSurface(void)
1203 zend_class_entry ce;
1205 INIT_CLASS_ENTRY(ce, "CairoQuartzSurface", CairoQuartzSurface_methods);
1206 CairoQuartzSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1207 CairoQuartzSurface_ce_ptr->create_object = CairoQuartzSurface_object_new;
1208 memcpy(&CairoQuartzSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1212 /* }}} Class CairoQuartzSurface */
1214 /* {{{ Class CairoSVGSurface */
1216 static zend_class_entry * CairoSVGSurface_ce_ptr = NULL;
1217 static zend_object_handlers CairoSVGSurface_handlers;
1220 /* {{{ Methods */
1223 /* {{{ proto void construct(string file, float wpts, float hpts)
1225 PHP_METHOD(CairoSVGSurface, __construct)
1227 zend_class_entry * _this_ce;
1228 zval * _this_zval;
1229 zval *zstream = NULL;
1230 const char * file = NULL;
1231 int file_len = 0;
1232 double wpts = 0.0;
1233 double hpts = 0.0;
1234 php_stream *stream;
1235 int argc = ZEND_NUM_ARGS();
1236 zval ***args, *obj;
1238 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
1239 if(ZEND_NUM_ARGS()== 0 ||
1240 zend_get_parameters_array_ex(argc, args)== FAILURE) {
1241 printf("ERROR");
1242 efree(args);
1243 WRONG_PARAM_COUNT;
1246 obj = *(args[1]);
1247 switch(Z_TYPE_P(obj)) {
1248 case IS_DOUBLE:
1249 wpts = Z_DVAL_P(obj);
1250 break;
1251 case IS_LONG:
1252 wpts = Z_LVAL_P(obj);
1253 break;
1254 default :
1255 printf("error!!!");
1256 return;
1259 obj = *(args[2]);
1261 switch(Z_TYPE_P(obj)) {
1262 case IS_DOUBLE:
1263 hpts = Z_DVAL_P(obj);
1264 break;
1265 case IS_LONG:
1266 hpts = Z_LVAL_P(obj);
1267 break;
1268 default :
1269 printf("Error!!!");
1270 return;
1274 _this_zval = getThis();
1275 _this_ce = Z_OBJCE_P(_this_zval);
1276 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1278 obj = *(args[0]);
1279 if(Z_TYPE_P(obj)==IS_STRING) {
1280 file = Z_STRVAL_P(obj);
1281 curr->surface = cairo_svg_surface_create(file, wpts, hpts);
1283 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
1284 zstream = obj;
1285 php_stream_from_zval(stream, &zstream);
1286 curr->surface = cairo_svg_surface_create_for_stream(_write_func, stream, wpts, hpts);
1288 else {
1289 printf("ERROR\n");
1292 efree(args);
1296 /* }}} __construct */
1299 static zend_function_entry CairoSVGSurface_methods[] = {
1300 PHP_ME(CairoSVGSurface, __construct, CairoSVGSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1301 { NULL, NULL, NULL }
1304 /* }}} Methods */
1306 static zend_object_value CairoSVGSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1308 zend_object_value retval;
1309 retval=CairoSurface_object_new(ce TSRMLS_CC);
1310 retval.handlers = &CairoSVGSurface_handlers;
1311 return retval;
1314 static void class_init_CairoSVGSurface(void)
1316 zend_class_entry ce;
1318 INIT_CLASS_ENTRY(ce, "CairoSVGSurface", CairoSVGSurface_methods);
1319 CairoSVGSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1320 CairoSVGSurface_ce_ptr->create_object = CairoSVGSurface_object_new;
1321 memcpy(&CairoSVGSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1325 /* }}} Class CairoSVGSurface */
1327 /* {{{ Class CairoWin32Surface -- Have to work on this aswell */
1329 static zend_class_entry * CairoWin32Surface_ce_ptr = NULL;
1330 static zend_object_handlers CairoWin32Surface_handlers;
1332 /* {{{ Methods */
1335 /* {{{ proto void construct(int hdc)
1337 PHP_METHOD(CairoWin32Surface, __construct)
1339 zend_class_entry * _this_ce;
1340 zval * _this_zval;
1342 long hdc = 0;
1346 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hdc) == FAILURE) {
1347 return;
1350 _this_zval = getThis();
1351 _this_ce = Z_OBJCE_P(_this_zval);
1352 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1353 curr->surface = cairo_win32_surface_create(hdc, NULL);
1355 /* }}} __construct */
1358 static zend_function_entry CairoWin32Surface_methods[] = {
1359 PHP_ME(CairoWin32Surface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1360 { NULL, NULL, NULL }
1363 /* }}} Methods */
1365 static zend_object_value CairoWin32Surface_object_new(zend_class_entry *ce TSRMLS_DC)
1367 zend_object_value retval;
1368 retval=CairoSurface_object_new(ce TSRMLS_CC);
1369 retval.handlers = &CairoWin32Surface_handlers;
1370 return retval;
1373 static void class_init_CairoWin32Surface(void)
1375 zend_class_entry ce;
1377 INIT_CLASS_ENTRY(ce, "CairoWin32Surface", CairoWin32Surface_methods);
1378 CairoWin32Surface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1379 CairoWin32Surface_ce_ptr->create_object = CairoWin32Surface_object_new;
1380 memcpy(&CairoWin32Surface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1384 /* }}} Class CairoWin32Surface */
1386 /* {{{ Class CairoXlibSurface */
1388 static zend_class_entry * CairoXlibSurface_ce_ptr = NULL;
1389 static zend_object_handlers CairoXlibSurface_handlers;
1390 /* {{{ Methods */
1393 /* {{{ proto void construct()
1395 PHP_METHOD(CairoXlibSurface, __construct)
1397 zend_class_entry * _this_ce;
1398 zval * _this_zval;
1402 if (ZEND_NUM_ARGS()>0) {
1403 WRONG_PARAM_COUNT;
1406 _this_zval = getThis();
1407 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1409 php_error(E_WARNING, "Cannot Be Initialized"); RETURN_FALSE;
1412 /* }}} __construct */
1416 /* {{{ proto int get_depth()
1418 PHP_METHOD(CairoXlibSurface, get_depth)
1420 zend_class_entry * _this_ce;
1422 zval * _this_zval = NULL;
1423 long depth;
1426 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1427 return;
1430 _this_ce = Z_OBJCE_P(_this_zval);
1431 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1433 depth = cairo_xlib_surface_get_depth(curr->surface);
1435 RETURN_LONG(depth);
1437 /* }}} get_depth */
1441 /* {{{ proto int get_height()
1443 PHP_METHOD(CairoXlibSurface, get_height)
1445 zend_class_entry * _this_ce;
1447 zval * _this_zval = NULL;
1448 long height;
1451 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1452 return;
1455 _this_ce = Z_OBJCE_P(_this_zval);
1456 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1457 height = cairo_xlib_surface_get_height(curr->surface);
1459 RETURN_LONG(height);
1461 /* }}} get_height */
1465 /* {{{ proto int get_width()
1467 PHP_METHOD(CairoXlibSurface, get_width)
1469 zend_class_entry * _this_ce;
1471 zval * _this_zval = NULL;
1472 long width;
1475 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1476 return;
1479 _this_ce = Z_OBJCE_P(_this_zval);
1480 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1481 width = cairo_xlib_surface_get_width(curr->surface);
1483 RETURN_LONG(width);
1485 /* }}} get_width */
1488 static zend_function_entry CairoXlibSurface_methods[] = {
1489 PHP_ME(CairoXlibSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1490 PHP_ME(CairoXlibSurface, get_depth, NULL, /**/ZEND_ACC_PUBLIC)
1491 PHP_ME(CairoXlibSurface, get_height, NULL, /**/ZEND_ACC_PUBLIC)
1492 PHP_ME(CairoXlibSurface, get_width, NULL, /**/ZEND_ACC_PUBLIC)
1493 { NULL, NULL, NULL }
1496 /* }}} Methods */
1498 static zend_object_value CairoXlibSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1500 zend_object_value retval;
1501 retval=CairoSurface_object_new(ce TSRMLS_CC);
1502 retval.handlers = &CairoXlibSurface_handlers;
1503 return retval;
1506 static void class_init_CairoXlibSurface(void)
1508 zend_class_entry ce;
1510 INIT_CLASS_ENTRY(ce, "CairoXlibSurface", CairoXlibSurface_methods);
1511 CairoXlibSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1512 CairoXlibSurface_ce_ptr->create_object = CairoXlibSurface_object_new;
1513 memcpy(&CairoXlibSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1517 /* }}} Class CairoXlibSurface */
1519 /* {{{ Helper Functions */
1520 zend_class_entry *
1521 get_CairoSurface_ce_ptr(cairo_surface_t *surface)
1523 zend_class_entry *type;
1524 if(surface == NULL)
1525 return;
1527 switch(cairo_surface_get_type(surface)) {
1528 case CAIRO_SURFACE_TYPE_IMAGE:
1529 type = CairoImageSurface_ce_ptr;
1530 break;
1531 case CAIRO_SURFACE_TYPE_PDF:
1532 type = CairoPDFSurface_ce_ptr;
1533 break;
1534 case CAIRO_SURFACE_TYPE_PS:
1535 type = CairoPSSurface_ce_ptr;
1536 break;
1537 case CAIRO_SURFACE_TYPE_SVG:
1538 type = CairoSVGSurface_ce_ptr;
1539 break;
1540 case CAIRO_SURFACE_TYPE_WIN32:
1541 type = CairoWin32Surface_ce_ptr;
1542 break;
1543 case CAIRO_SURFACE_TYPE_XLIB:
1544 type = CairoXlibSurface_ce_ptr;
1545 break;
1546 case CAIRO_SURFACE_TYPE_QUARTZ:
1547 type = CairoQuartzSurface_ce_ptr;
1548 break;
1549 default:
1550 php_error(E_ERROR,"Unsupported Surface Type");
1551 return NULL;
1553 return type;
1556 /* }}} Helper Function*/