Updating checkpoint ...
[phpCairo.git] / individual_files / phpCairoSurface.c
blob2ee2cf84992f11f837b35cf9480de6565eb9c725
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 createSimilar(int content, int width, int height)
72 PHP_METHOD(CairoSurface, createSimilar)
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 /* }}} createSimilar */
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 getContent()
142 PHP_METHOD(CairoSurface, getContent)
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 /* }}} getContent */
162 /* {{{ proto array getDeviceOffset()
164 PHP_METHOD(CairoSurface, getDeviceOffset)
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", x_offset);
182 add_assoc_double(return_value, "y", y_offset);
185 /* }}} getDeviceOffset */
189 /* {{{ proto object getFontOptions()
191 PHP_METHOD(CairoSurface, getFontOptions)
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 /* }}} getFontOptions */
217 /* {{{ proto void markDirtyRectangle([int x, int y, int width, int height])
219 PHP_METHOD(CairoSurface, markDirtyRectangle)
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 /* }}} markDirtyRectangle */
243 /* {{{ proto void setDeviceOffset(float x_offset, float y_offset)
245 PHP_METHOD(CairoSurface, setDeviceOffset)
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 /* }}} setDeviceOffset */
266 /* {{{ proto void setFallbackResolution(float x_ppi, float y_ppi)
268 PHP_METHOD(CairoSurface, setFallbackResolution)
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 /* }}} setFallbackResolution */
289 /* {{{ proto void writeToPng(string file)
291 PHP_METHOD(CairoSurface, writeToPng)
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 /* }}} writeToPng */
312 /* {{{ proto void writeToPngStream(stream file)
314 PHP_METHOD(CairoSurface, writeToPngStream)
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 /* }}} writeToPngStream*/
338 static zend_function_entry CairoSurface_methods[] = {
339 PHP_ME(CairoSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
340 PHP_ME(CairoSurface, createSimilar, 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, getContent, NULL, /**/ZEND_ACC_PUBLIC)
344 PHP_ME(CairoSurface, getDeviceOffset, NULL, /**/ZEND_ACC_PUBLIC)
345 PHP_ME(CairoSurface, getFontOptions, NULL, /**/ZEND_ACC_PUBLIC)
346 PHP_ME(CairoSurface, markDirtyRectangle, CairoSurface__mark_dirty_rectangle_args, /**/ZEND_ACC_PUBLIC)
347 PHP_ME(CairoSurface, setDeviceOffset, CairoSurface__set_device_offset_args, /**/ZEND_ACC_PUBLIC)
348 PHP_ME(CairoSurface, setFallbackResolution, CairoSurface__set_fallback_resolution_args, /**/ZEND_ACC_PUBLIC)
349 PHP_ME(CairoSurface, writeToPng, CairoSurface__write_to_png_args, /**/ZEND_ACC_PUBLIC)
350 PHP_ME(CairoSurface, writeToPngStream, 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;
408 /* {{{ Methods */
411 /* {{{ proto void construct(int format, int widthm, int height)
413 PHP_METHOD(CairoImageSurface, __construct)
415 zend_class_entry * _this_ce;
416 zval * _this_zval;
418 cairo_format_t format = 0;
419 long widthm = 0;
420 long height = 0;
424 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &format, &widthm, &height) == FAILURE) {
425 return;
428 _this_zval = getThis();
429 _this_ce = Z_OBJCE_P(_this_zval);
430 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
431 curr->surface = cairo_image_surface_create(format, widthm, height);
434 /* }}} __construct */
438 /* {{{ proto void createFromData(string obj, int format, int width, int height [, int stride])
440 PHP_METHOD(CairoImageSurface, createFromData)
442 zend_class_entry * _this_ce;
444 zval * _this_zval = NULL;
445 const char * buffer = NULL;
446 int buffer_len = 0;
447 long format = 0;
448 long width = 0;
449 long height = 0;
450 long stride = -1;
454 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) {
455 return;
458 _this_ce = Z_OBJCE_P(_this_zval);
459 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
460 cairo_surface_finish(curr->surface);
461 cairo_surface_destroy(curr->surface);
463 if(stride < 0 ){
464 switch(format) {
465 case CAIRO_FORMAT_ARGB32:
466 case CAIRO_FORMAT_RGB24:
467 stride = width * 4;
468 break;
469 case CAIRO_FORMAT_RGB16_565:
470 stride = width * 2;
471 break;
472 case CAIRO_FORMAT_A8:
473 stride = width;
474 break;
475 case CAIRO_FORMAT_A1:
476 stride = (width + 1) / 8;
477 break;
478 default:
479 php_error(E_ERROR, "Unknown format");
480 return;
485 if (height * stride > buffer_len) {
486 php_error(E_ERROR,"buffer is not long enough");
487 return;
490 curr->surface = cairo_image_surface_create_for_data(buffer, format, width, height, stride);
493 /* }}} createFromData */
497 /* {{{ proto void createFromPng(string file)
499 PHP_METHOD(CairoImageSurface, createFromPng)
501 zend_class_entry * _this_ce;
503 zval * _this_zval = NULL;
504 const char * file = NULL;
505 int file_len = 0;
507 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoImageSurface_ce_ptr, &file, &file_len) == FAILURE) {
508 return;
511 _this_ce = Z_OBJCE_P(_this_zval);
512 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
514 curr->surface = cairo_image_surface_create_from_png(file);
517 /* }}} createFromPng */
521 /* {{{ proto void createFromPngStream(stream zstream)
524 PHP_METHOD(CairoImageSurface, createFromPngStream)
526 zend_class_entry *_this_ce;
527 FILE *file;
528 zval *_this_zval = NULL;
529 cairo_status_t status;
530 zval *zstream;
531 php_stream *stream;
532 int err;
534 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoImageSurface_ce_ptr, &zstream)) {
535 return;
538 _this_ce = Z_OBJCE_P(_this_zval);
539 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
541 php_stream_from_zval(stream, &zstream);
542 curr->surface = cairo_image_surface_create_from_png_stream( _read_func, stream);
547 /* }}} createFromPngStream*/
551 /* {{{ proto string getData() -- not required
553 PHP_METHOD(CairoImageSurface, getData)
555 zend_class_entry * _this_ce;
557 zval * _this_zval = NULL;
558 char *str;
561 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
562 return;
565 _this_ce = Z_OBJCE_P(_this_zval);
566 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
569 str = cairo_image_surface_get_data(curr->surface);
570 RETURN_STRING(str, 0);
572 /* }}} getData */
576 /* {{{ proto int getFormat()
578 PHP_METHOD(CairoImageSurface, getFormat)
580 zend_class_entry * _this_ce;
581 long x;
582 zval * _this_zval = NULL;
584 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
585 return;
587 _this_ce = Z_OBJCE_P(_this_zval);
588 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
590 x = cairo_image_surface_get_format(curr->surface);
591 RETURN_LONG(x);
593 /* }}} getFormat */
597 /* {{{ proto int getHeight()
599 PHP_METHOD(CairoImageSurface, getHeight)
601 zend_class_entry * _this_ce;
602 zval * _this_zval = NULL;
603 long x;
605 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
606 return;
609 _this_ce = Z_OBJCE_P(_this_zval);
610 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
611 x = cairo_image_surface_get_height(curr->surface);
613 RETURN_LONG(x);
615 /* }}} getHeight */
619 /* {{{ proto int getStride()
621 PHP_METHOD(CairoImageSurface, getStride)
623 zend_class_entry * _this_ce;
624 zval * _this_zval = NULL;
625 long x;
627 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
628 return;
631 _this_ce = Z_OBJCE_P(_this_zval);
632 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
633 x = cairo_image_surface_get_stride(curr->surface);
635 RETURN_LONG(x);
637 /* }}} getStride */
641 /* {{{ proto int getWidth()
643 PHP_METHOD(CairoImageSurface, getWidth)
645 zend_class_entry * _this_ce;
646 zval * _this_zval = NULL;
647 long x;
649 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
650 return;
653 _this_ce = Z_OBJCE_P(_this_zval);
655 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
657 x = cairo_image_surface_get_width(curr->surface);
658 RETURN_LONG(x);
660 /* }}} getWidth */
663 static zend_function_entry CairoImageSurface_methods[] = {
664 PHP_ME(CairoImageSurface, __construct, CairoImageSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
665 PHP_ME(CairoImageSurface, createFromData, CairoImageSurface__create_from_data_args, /**/ZEND_ACC_PUBLIC)
666 PHP_ME(CairoImageSurface, createFromPng, CairoImageSurface__create_from_png_args, /**/ZEND_ACC_PUBLIC)
667 PHP_ME(CairoImageSurface, createFromPngStream, CairoImageSurface__create_from_png_stream_args, /**/ZEND_ACC_PUBLIC)
668 PHP_ME(CairoImageSurface, getData, NULL, /**/ZEND_ACC_PUBLIC)
669 PHP_ME(CairoImageSurface, getFormat, NULL, /**/ZEND_ACC_PUBLIC)
670 PHP_ME(CairoImageSurface, getHeight, NULL, /**/ZEND_ACC_PUBLIC)
671 PHP_ME(CairoImageSurface, getStride, NULL, /**/ZEND_ACC_PUBLIC)
672 PHP_ME(CairoImageSurface, getWidth, NULL, /**/ZEND_ACC_PUBLIC)
673 { NULL, NULL, NULL }
676 /* }}} Methods */
678 static zend_object_value CairoImageSurface_object_new(zend_class_entry *ce TSRMLS_DC)
680 zend_object_value retval;
681 retval=CairoSurface_object_new(ce TSRMLS_CC);
682 retval.handlers = &CairoImageSurface_handlers;
683 return retval;
687 static void class_init_CairoImageSurface(void)
689 zend_class_entry ce;
691 INIT_CLASS_ENTRY(ce, "CairoImageSurface", CairoImageSurface_methods);
692 CairoImageSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
693 CairoImageSurface_ce_ptr->create_object = CairoImageSurface_object_new;
694 memcpy(&CairoImageSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
697 /* }}} Class CairoImageSurface */
699 /* {{{ Class CairoPDFSurface */
701 static zend_class_entry * CairoPDFSurface_ce_ptr = NULL;
702 static zend_object_handlers CairoPDFSurface_handlers;
703 /* {{{ Methods */
706 /* {{{ proto void construct(string file, float wpts, float hpts)
708 PHP_METHOD(CairoPDFSurface, __construct)
710 zend_class_entry * _this_ce;
711 zval * _this_zval;
712 zval *zstream = NULL;
713 const char * file = NULL;
714 int file_len = 0;
715 double wpts = 0.0;
716 double hpts = 0.0;
717 php_stream *stream;
718 int argc = ZEND_NUM_ARGS();
719 zval ***args, *obj;
721 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
722 if(ZEND_NUM_ARGS()== 0 ||
723 zend_get_parameters_array_ex(argc, args)== FAILURE) {
724 printf("ERROR");
725 efree(args);
726 WRONG_PARAM_COUNT;
729 obj = *(args[1]);
730 switch(Z_TYPE_P(obj)) {
731 case IS_DOUBLE:
732 wpts = Z_DVAL_P(obj);
733 break;
734 case IS_LONG:
735 wpts = Z_LVAL_P(obj);
736 break;
737 default :
738 printf("Error!!!");
739 return;
742 obj = *(args[2]);
744 switch(Z_TYPE_P(obj)) {
745 case IS_DOUBLE:
746 hpts = Z_DVAL_P(obj);
747 break;
748 case IS_LONG:
749 hpts = Z_LVAL_P(obj);
750 break;
751 default :
752 printf("Error!!!");
753 return;
757 _this_zval = getThis();
758 _this_ce = Z_OBJCE_P(_this_zval);
759 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
761 obj = *(args[0]);
762 if(Z_TYPE_P(obj)==IS_STRING) {
763 file = Z_STRVAL_P(obj);
764 curr->surface = cairo_pdf_surface_create(file, wpts, hpts);
766 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
767 zstream = obj;
768 php_stream_from_zval(stream, &zstream);
769 curr->surface = cairo_pdf_surface_create_for_stream(_write_func, stream, wpts, hpts);
771 else {
772 printf("ERROR\n");
775 efree(args);
777 /* }}} __construct */
781 /* {{{ proto void setSize(float wptd, float hpts)
783 PHP_METHOD(CairoPDFSurface, setSize)
785 zend_class_entry * _this_ce;
787 zval * _this_zval = NULL;
788 double wpts = 0.0;
789 double hpts = 0.0;
793 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPDFSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
794 return;
797 _this_ce = Z_OBJCE_P(_this_zval);
798 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
799 cairo_pdf_surface_set_size(curr->surface, wpts, hpts);
802 /* }}} setSize */
805 static zend_function_entry CairoPDFSurface_methods[] = {
806 PHP_ME(CairoPDFSurface, __construct, CairoPDFSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
807 PHP_ME(CairoPDFSurface, setSize, CairoPDFSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
808 { NULL, NULL, NULL }
811 /* }}} Methods */
813 static zend_object_value CairoPDFSurface_object_new(zend_class_entry *ce TSRMLS_DC)
815 zend_object_value retval;
816 retval=CairoSurface_object_new(ce TSRMLS_CC);
817 retval.handlers = &CairoPDFSurface_handlers;
818 return retval;
821 static void class_init_CairoPDFSurface(void)
823 zend_class_entry ce;
825 INIT_CLASS_ENTRY(ce, "CairoPDFSurface", CairoPDFSurface_methods);
826 CairoPDFSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
827 CairoPDFSurface_ce_ptr->create_object = CairoPDFSurface_object_new;
828 memcpy(&CairoPDFSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
832 /* }}} Class CairoPDFSurface */
834 /* {{{ Class CairoPSSurface */
836 static zend_class_entry * CairoPSSurface_ce_ptr = NULL;
837 static zend_object_handlers CairoPSSurface_handlers;
838 /* {{{ Methods */
841 /* {{{ proto void construct(string file | stream stream, float wpts, float hpts)
843 PHP_METHOD(CairoPSSurface, __construct)
845 zend_class_entry * _this_ce;
846 zval * _this_zval;
847 zval *zstream = NULL;
848 const char * file = NULL;
849 int file_len = 0;
850 double wpts = 0.0;
851 double hpts = 0.0;
852 php_stream *stream;
853 int argc = ZEND_NUM_ARGS();
854 zval ***args, *obj;
856 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
857 if(ZEND_NUM_ARGS()== 0 ||
858 zend_get_parameters_array_ex(argc, args)== FAILURE) {
859 printf("ERROR");
860 efree(args);
861 WRONG_PARAM_COUNT;
864 obj = *(args[1]);
865 switch(Z_TYPE_P(obj)) {
866 case IS_DOUBLE:
867 wpts = Z_DVAL_P(obj);
868 break;
869 case IS_LONG:
870 wpts = Z_LVAL_P(obj);
871 break;
872 default :
873 printf("Error!!!");
874 return;
877 obj = *(args[2]);
879 switch(Z_TYPE_P(obj)) {
880 case IS_DOUBLE:
881 hpts = Z_DVAL_P(obj);
882 break;
883 case IS_LONG:
884 hpts = Z_LVAL_P(obj);
885 break;
886 default :
887 printf("Error!!!");
888 return;
892 _this_zval = getThis();
893 _this_ce = Z_OBJCE_P(_this_zval);
894 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
896 obj = *(args[0]);
897 if(Z_TYPE_P(obj)==IS_STRING) {
898 file = Z_STRVAL_P(obj);
899 curr->surface = cairo_ps_surface_create(file, wpts, hpts);
901 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
902 zstream = obj;
903 php_stream_from_zval(stream, &zstream);
904 curr->surface = cairo_ps_surface_create_for_stream(_write_func, stream, wpts, hpts);
906 else {
907 printf("ERROR\n");
910 efree(args);
916 /* }}} __construct */
920 /* {{{ proto void dscBeginPageSetup()
922 PHP_METHOD(CairoPSSurface, dscBeginPageSetup)
924 zend_class_entry * _this_ce;
926 zval * _this_zval = NULL;
930 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
931 return;
933 _this_ce = Z_OBJCE_P(_this_zval);
934 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
935 cairo_ps_surface_dsc_begin_page_setup(curr->surface);
936 phpCAIRO_SURFACE_ERROR(curr->surface);
941 /* }}} dscBeginPageSetup */
945 /* {{{ proto void dscBeginSetup()
947 PHP_METHOD(CairoPSSurface, dscBeginSetup)
949 zend_class_entry * _this_ce;
951 zval * _this_zval = NULL;
955 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
956 return;
959 _this_ce = Z_OBJCE_P(_this_zval);
960 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
961 cairo_ps_surface_dsc_begin_setup(curr->surface);
962 phpCAIRO_SURFACE_ERROR(curr->surface);
965 /* }}} dscBeginSetup */
969 /* {{{ proto void dscComment()
971 PHP_METHOD(CairoPSSurface, dscComment)
973 zend_class_entry * _this_ce;
975 zval * _this_zval = NULL;
979 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
980 return;
983 _this_ce = Z_OBJCE_P(_this_zval);
984 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
985 cairo_ps_surface_dsc_comment(curr->surface);
986 phpCAIRO_SURFACE_ERROR(curr->surface);
989 /* }}} dscComment */
993 /* {{{ proto array getLevels() -- cairo 1.6
995 PHP_METHOD(CairoPSSurface, getLevels)
997 zend_class_entry * _this_ce;
999 zval * _this_zval = NULL;
1003 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1004 return;
1007 _this_ce = Z_OBJCE_P(_this_zval);
1008 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1011 array_init(return_value);
1013 do {
1014 /* ONLY for CAIRO 1.6 */
1015 } while (0);
1017 /* }}} getLevels */
1021 /* {{{ proto string getLevelString() --cairo 1.6
1023 PHP_METHOD(CairoPSSurface, getLevelString)
1025 zend_class_entry * _this_ce;
1027 zval * _this_zval = NULL;
1031 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1032 return;
1035 _this_ce = Z_OBJCE_P(_this_zval);
1036 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1039 do {
1040 /* ONLY for CAIRO 1.6*/
1041 } while (0);
1043 /* }}} getLevelString */
1047 /* {{{ proto void restrictToLevel(int level) --cairo 1.6
1049 PHP_METHOD(CairoPSSurface, restrictToLevel)
1051 zend_class_entry * _this_ce;
1053 zval * _this_zval = NULL;
1054 long level = 0;
1058 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoPSSurface_ce_ptr, &level) == FAILURE) {
1059 return;
1062 _this_ce = Z_OBJCE_P(_this_zval);
1063 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1066 do {
1067 /* ONLY for CAIRO 1.6 */
1068 } while (0);
1070 /* }}} restrictToLevel */
1074 /* {{{ proto void setEps() --cairo 1.6
1076 PHP_METHOD(CairoPSSurface, setEps)
1078 zend_class_entry * _this_ce;
1080 zval * _this_zval = NULL;
1084 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1085 return;
1088 _this_ce = Z_OBJCE_P(_this_zval);
1089 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1092 do {
1093 /* ONLY for CAIRO 1.6 */
1094 } while (0);
1096 /* }}} setEps */
1100 /* {{{ proto void setSize(float wpts, float hpts)
1102 PHP_METHOD(CairoPSSurface, setSize)
1104 zend_class_entry * _this_ce;
1106 zval * _this_zval = NULL;
1107 double wpts = 0.0;
1108 double hpts = 0.0;
1112 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPSSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
1113 return;
1116 _this_ce = Z_OBJCE_P(_this_zval);
1117 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1118 cairo_ps_surface_set_size(curr->surface, wpts, hpts);
1121 /* }}} setSize */
1124 static zend_function_entry CairoPSSurface_methods[] = {
1125 PHP_ME(CairoPSSurface, __construct, CairoPSSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1126 PHP_ME(CairoPSSurface, dscBeginPageSetup, NULL, /**/ZEND_ACC_PUBLIC)
1127 PHP_ME(CairoPSSurface, dscBeginSetup, NULL, /**/ZEND_ACC_PUBLIC)
1128 PHP_ME(CairoPSSurface, dscComment, NULL, /**/ZEND_ACC_PUBLIC)
1129 PHP_ME(CairoPSSurface, getLevels, NULL, /**/ZEND_ACC_PUBLIC)
1130 PHP_ME(CairoPSSurface, getLevelString, NULL, /**/ZEND_ACC_PUBLIC)
1131 PHP_ME(CairoPSSurface, restrictToLevel, CairoPSSurface__restrict_to_level_args, /**/ZEND_ACC_PUBLIC)
1132 PHP_ME(CairoPSSurface, setEps, NULL, /**/ZEND_ACC_PUBLIC)
1133 PHP_ME(CairoPSSurface, setSize, CairoPSSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
1134 { NULL, NULL, NULL }
1137 /* }}} Methods */
1139 static zend_object_value CairoPSSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1141 zend_object_value retval;
1142 retval=CairoSurface_object_new(ce TSRMLS_CC);
1143 retval.handlers = &CairoPSSurface_handlers;
1144 return retval;
1147 static void class_init_CairoPSSurface(void)
1149 zend_class_entry ce;
1151 INIT_CLASS_ENTRY(ce, "CairoPSSurface", CairoPSSurface_methods);
1152 CairoPSSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1153 CairoPSSurface_ce_ptr->create_object = CairoPSSurface_object_new;
1154 memcpy(&CairoPSSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1157 /* }}} Class CairoPSSurface */
1159 /* {{{ Class CairoQuartzSurface */
1161 static zend_class_entry * CairoQuartzSurface_ce_ptr = NULL;
1162 static zend_object_handlers CairoQuartzSurface_handlers;
1163 /* {{{ Methods */
1166 /* {{{ proto void construct(float wpixels, float hpixels [, int format])
1168 PHP_METHOD(CairoQuartzSurface, __construct)
1170 zend_class_entry * _this_ce;
1171 zval * _this_zval;
1173 double wpixels = 0.0;
1174 double hpixels = 0.0;
1175 long format = 0;
1179 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &wpixels, &hpixels, &format) == FAILURE) {
1180 return;
1183 _this_zval = getThis();
1184 _this_ce = Z_OBJCE_P(_this_zval);
1185 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1188 php_error(E_ERROR, "CANNOT BE CALLED"); RETURN_FALSE;
1191 /* }}} __construct */
1194 static zend_function_entry CairoQuartzSurface_methods[] = {
1195 PHP_ME(CairoQuartzSurface, __construct, CairoQuartzSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1196 { NULL, NULL, NULL }
1199 /* }}} Methods */
1201 static zend_object_value CairoQuartzSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1203 zend_object_value retval;
1204 retval=CairoSurface_object_new(ce TSRMLS_CC);
1205 retval.handlers = &CairoQuartzSurface_handlers;
1206 return retval;
1209 static void class_init_CairoQuartzSurface(void)
1211 zend_class_entry ce;
1213 INIT_CLASS_ENTRY(ce, "CairoQuartzSurface", CairoQuartzSurface_methods);
1214 CairoQuartzSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1215 CairoQuartzSurface_ce_ptr->create_object = CairoQuartzSurface_object_new;
1216 memcpy(&CairoQuartzSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1220 /* }}} Class CairoQuartzSurface */
1222 /* {{{ Class CairoSVGSurface */
1224 static zend_class_entry * CairoSVGSurface_ce_ptr = NULL;
1225 static zend_object_handlers CairoSVGSurface_handlers;
1228 /* {{{ Methods */
1231 /* {{{ proto void construct(string file, float wpts, float hpts)
1233 PHP_METHOD(CairoSVGSurface, __construct)
1235 zend_class_entry * _this_ce;
1236 zval * _this_zval;
1237 zval *zstream = NULL;
1238 const char * file = NULL;
1239 int file_len = 0;
1240 double wpts = 0.0;
1241 double hpts = 0.0;
1242 php_stream *stream;
1243 int argc = ZEND_NUM_ARGS();
1244 zval ***args, *obj;
1246 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
1247 if(ZEND_NUM_ARGS()== 0 ||
1248 zend_get_parameters_array_ex(argc, args)== FAILURE) {
1249 printf("ERROR");
1250 efree(args);
1251 WRONG_PARAM_COUNT;
1254 obj = *(args[1]);
1255 switch(Z_TYPE_P(obj)) {
1256 case IS_DOUBLE:
1257 wpts = Z_DVAL_P(obj);
1258 break;
1259 case IS_LONG:
1260 wpts = Z_LVAL_P(obj);
1261 break;
1262 default :
1263 printf("error!!!");
1264 return;
1267 obj = *(args[2]);
1269 switch(Z_TYPE_P(obj)) {
1270 case IS_DOUBLE:
1271 hpts = Z_DVAL_P(obj);
1272 break;
1273 case IS_LONG:
1274 hpts = Z_LVAL_P(obj);
1275 break;
1276 default :
1277 printf("Error!!!");
1278 return;
1282 _this_zval = getThis();
1283 _this_ce = Z_OBJCE_P(_this_zval);
1284 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1286 obj = *(args[0]);
1287 if(Z_TYPE_P(obj)==IS_STRING) {
1288 file = Z_STRVAL_P(obj);
1289 curr->surface = cairo_svg_surface_create(file, wpts, hpts);
1291 else if(Z_TYPE_P(obj)==IS_RESOURCE) {
1292 zstream = obj;
1293 php_stream_from_zval(stream, &zstream);
1294 curr->surface = cairo_svg_surface_create_for_stream(_write_func, stream, wpts, hpts);
1296 else {
1297 printf("ERROR\n");
1300 efree(args);
1304 /* }}} __construct */
1307 static zend_function_entry CairoSVGSurface_methods[] = {
1308 PHP_ME(CairoSVGSurface, __construct, CairoSVGSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1309 { NULL, NULL, NULL }
1312 /* }}} Methods */
1314 static zend_object_value CairoSVGSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1316 zend_object_value retval;
1317 retval=CairoSurface_object_new(ce TSRMLS_CC);
1318 retval.handlers = &CairoSVGSurface_handlers;
1319 return retval;
1322 static void class_init_CairoSVGSurface(void)
1324 zend_class_entry ce;
1326 INIT_CLASS_ENTRY(ce, "CairoSVGSurface", CairoSVGSurface_methods);
1327 CairoSVGSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1328 CairoSVGSurface_ce_ptr->create_object = CairoSVGSurface_object_new;
1329 memcpy(&CairoSVGSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1333 /* }}} Class CairoSVGSurface */
1335 /* {{{ Class CairoWin32Surface -- Have to work on this aswell */
1337 static zend_class_entry * CairoWin32Surface_ce_ptr = NULL;
1338 static zend_object_handlers CairoWin32Surface_handlers;
1340 /* {{{ Methods */
1343 /* {{{ proto void construct(int hdc)
1345 PHP_METHOD(CairoWin32Surface, __construct)
1347 zend_class_entry * _this_ce;
1348 zval * _this_zval;
1350 long hdc = 0;
1354 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hdc) == FAILURE) {
1355 return;
1358 _this_zval = getThis();
1359 _this_ce = Z_OBJCE_P(_this_zval);
1360 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1361 curr->surface = cairo_win32_surface_create(hdc, NULL);
1363 /* }}} __construct */
1366 static zend_function_entry CairoWin32Surface_methods[] = {
1367 PHP_ME(CairoWin32Surface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1368 { NULL, NULL, NULL }
1371 /* }}} Methods */
1373 static zend_object_value CairoWin32Surface_object_new(zend_class_entry *ce TSRMLS_DC)
1375 zend_object_value retval;
1376 retval=CairoSurface_object_new(ce TSRMLS_CC);
1377 retval.handlers = &CairoWin32Surface_handlers;
1378 return retval;
1381 static void class_init_CairoWin32Surface(void)
1383 zend_class_entry ce;
1385 INIT_CLASS_ENTRY(ce, "CairoWin32Surface", CairoWin32Surface_methods);
1386 CairoWin32Surface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1387 CairoWin32Surface_ce_ptr->create_object = CairoWin32Surface_object_new;
1388 memcpy(&CairoWin32Surface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1392 /* }}} Class CairoWin32Surface */
1394 /* {{{ Class CairoXlibSurface */
1396 static zend_class_entry * CairoXlibSurface_ce_ptr = NULL;
1397 static zend_object_handlers CairoXlibSurface_handlers;
1398 /* {{{ Methods */
1401 /* {{{ proto void construct()
1403 PHP_METHOD(CairoXlibSurface, __construct)
1405 zend_class_entry * _this_ce;
1406 zval * _this_zval;
1410 if (ZEND_NUM_ARGS()>0) {
1411 WRONG_PARAM_COUNT;
1414 _this_zval = getThis();
1415 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1417 php_error(E_WARNING, "Cannot Be Initialized"); RETURN_FALSE;
1420 /* }}} __construct */
1424 /* {{{ proto int getDepth()
1426 PHP_METHOD(CairoXlibSurface, getDepth)
1428 zend_class_entry * _this_ce;
1430 zval * _this_zval = NULL;
1431 long depth;
1434 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1435 return;
1438 _this_ce = Z_OBJCE_P(_this_zval);
1439 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1441 depth = cairo_xlib_surface_get_depth(curr->surface);
1443 RETURN_LONG(depth);
1445 /* }}} getDepth */
1449 /* {{{ proto int getHeight()
1451 PHP_METHOD(CairoXlibSurface, getHeight)
1453 zend_class_entry * _this_ce;
1455 zval * _this_zval = NULL;
1456 long height;
1459 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1460 return;
1463 _this_ce = Z_OBJCE_P(_this_zval);
1464 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1465 height = cairo_xlib_surface_get_height(curr->surface);
1467 RETURN_LONG(height);
1469 /* }}} getHeight */
1473 /* {{{ proto int getWidth()
1475 PHP_METHOD(CairoXlibSurface, getWidth)
1477 zend_class_entry * _this_ce;
1479 zval * _this_zval = NULL;
1480 long width;
1483 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1484 return;
1487 _this_ce = Z_OBJCE_P(_this_zval);
1488 surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1489 width = cairo_xlib_surface_get_width(curr->surface);
1491 RETURN_LONG(width);
1493 /* }}} getWidth */
1496 static zend_function_entry CairoXlibSurface_methods[] = {
1497 PHP_ME(CairoXlibSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1498 PHP_ME(CairoXlibSurface, getDepth, NULL, /**/ZEND_ACC_PUBLIC)
1499 PHP_ME(CairoXlibSurface, getHeight, NULL, /**/ZEND_ACC_PUBLIC)
1500 PHP_ME(CairoXlibSurface, getWidth, NULL, /**/ZEND_ACC_PUBLIC)
1501 { NULL, NULL, NULL }
1504 /* }}} Methods */
1506 static zend_object_value CairoXlibSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1508 zend_object_value retval;
1509 retval=CairoSurface_object_new(ce TSRMLS_CC);
1510 retval.handlers = &CairoXlibSurface_handlers;
1511 return retval;
1514 static void class_init_CairoXlibSurface(void)
1516 zend_class_entry ce;
1518 INIT_CLASS_ENTRY(ce, "CairoXlibSurface", CairoXlibSurface_methods);
1519 CairoXlibSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1520 CairoXlibSurface_ce_ptr->create_object = CairoXlibSurface_object_new;
1521 memcpy(&CairoXlibSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1525 /* }}} Class CairoXlibSurface */
1527 /* {{{ Helper Functions */
1528 zend_class_entry *
1529 get_CairoSurface_ce_ptr(cairo_surface_t *surface)
1531 zend_class_entry *type;
1532 if(surface == NULL)
1533 return;
1535 switch(cairo_surface_get_type(surface)) {
1536 case CAIRO_SURFACE_TYPE_IMAGE:
1537 type = CairoImageSurface_ce_ptr;
1538 break;
1539 case CAIRO_SURFACE_TYPE_PDF:
1540 type = CairoPDFSurface_ce_ptr;
1541 break;
1542 case CAIRO_SURFACE_TYPE_PS:
1543 type = CairoPSSurface_ce_ptr;
1544 break;
1545 case CAIRO_SURFACE_TYPE_SVG:
1546 type = CairoSVGSurface_ce_ptr;
1547 break;
1548 case CAIRO_SURFACE_TYPE_WIN32:
1549 type = CairoWin32Surface_ce_ptr;
1550 break;
1551 case CAIRO_SURFACE_TYPE_XLIB:
1552 type = CairoXlibSurface_ce_ptr;
1553 break;
1554 case CAIRO_SURFACE_TYPE_QUARTZ:
1555 type = CairoQuartzSurface_ce_ptr;
1556 break;
1557 default:
1558 php_error(E_ERROR,"Unsupported Surface Type");
1559 return NULL;
1561 return type;
1564 /* }}} Helper Function*/