Changed the entire file structure to remove the .c includes from cairo.c
[phpCairo.git] / src / cairo / CairoSurface.c
blobb419b91c9c526e20e6bccbd2318c21003f988856
1 #include "php_cairo_api.h"
2 #include "CairoSurface.h"
3 #include "CairoExceptionMacro.h"
4 #include "php_cairo_ce_ptr.h"
6 /* {{{ Class CairoSurface */
8 static zend_class_entry * CairoSurface_ce_ptr = NULL;
9 static zend_object_handlers CairoSurface_handlers;
11 static cairo_status_t
12 _write_func(void *closure, const unsigned char *data, unsigned int length)
14 int written;
15 php_stream *zs = (php_stream *)closure ;
16 written = php_stream_write(zs, data, length);
17 if(written == length)
18 return CAIRO_STATUS_SUCCESS;
19 else {
20 printf("is it an error ?");
24 static cairo_status_t
25 _read_func(void *closure, const unsigned char *data, unsigned int length)
27 int read;
28 php_stream *zs = (php_stream *)closure;
29 read = php_stream_read(zs, data, 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 zval * _this_zval;
57 if (ZEND_NUM_ARGS()>0) {
58 WRONG_PARAM_COUNT;
59 php_print("wtf");
60 return;
63 php_print("No direct call for this constructor");
67 /* }}} __construct */
71 /* {{{ proto object createSimilar(int content, int width, int height)
73 PHP_METHOD(CairoSurface, createSimilar)
75 zend_class_entry *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 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
87 sur = cairo_surface_create_similar(curr->surface, content, width, height);
88 ce = get_CairoSurface_ce_ptr(sur);
89 object_init_ex(return_value, ce);
90 surface_object *sobj = (surface_object *)zend_objects_get_address(return_value TSRMLS_CC);
91 sobj->surface = sur;
94 /* }}} createSimilar */
97 /* {{{ proto void finish()
99 PHP_METHOD(CairoSurface, finish)
102 zval * _this_zval = NULL;
104 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
105 return;
108 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
109 cairo_surface_finish(curr->surface);
111 /* }}} finish */
115 /* {{{ proto void flush()
117 PHP_METHOD(CairoSurface, flush)
120 zval * _this_zval = NULL;
122 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
123 return;
126 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
128 cairo_surface_flush(curr->surface);
131 /* }}} flush */
135 /* {{{ proto int getContent()
137 PHP_METHOD(CairoSurface, getContent)
140 zval * _this_zval = NULL;
141 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
142 return;
145 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
147 RETURN_LONG(cairo_surface_get_content(curr->surface));
149 /* }}} getContent */
153 /* {{{ proto array getDeviceOffset()
155 PHP_METHOD(CairoSurface, getDeviceOffset)
158 zval * _this_zval = NULL;
159 double x_offset, y_offset;
161 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
162 return;
165 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
167 cairo_surface_get_device_offset(curr->surface, &x_offset, &y_offset);
169 array_init(return_value);
170 add_assoc_double(return_value, "x", x_offset);
171 add_assoc_double(return_value, "y", y_offset);
174 /* }}} getDeviceOffset */
178 /* {{{ proto object getFontOptions()
180 PHP_METHOD(CairoSurface, getFontOptions)
183 zval * _this_zval = NULL;
185 cairo_font_options_t *options = cairo_font_options_create();
188 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurface_ce_ptr) == FAILURE) {
189 return;
192 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
194 cairo_surface_get_font_options(curr->surface, options);
195 object_init_ex(return_value, CairoFontOptions_ce_ptr);
196 fontoptions_object *fobj = (fontoptions_object *)zend_objects_get_address(return_value TSRMLS_CC);
197 fobj->fontoptions = options;
200 /* }}} getFontOptions */
204 /* {{{ proto void markDirtyRectangle([int x, int y, int width, int height])
206 PHP_METHOD(CairoSurface, markDirtyRectangle)
209 zval * _this_zval = NULL;
210 long x = 0;
211 long y = 0;
212 long width = -1;
213 long height = -1;
217 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|llll", &_this_zval, CairoSurface_ce_ptr, &x, &y, &width, &height) == FAILURE) {
218 return;
220 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
221 cairo_surface_mark_dirty_rectangle(curr->surface, x, y, width, height);
224 /* }}} markDirtyRectangle */
228 /* {{{ proto void setDeviceOffset(float x_offset, float y_offset)
230 PHP_METHOD(CairoSurface, setDeviceOffset)
233 zval * _this_zval = NULL;
234 double x_offset = 0.0;
235 double y_offset = 0.0;
237 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_offset, &y_offset) == FAILURE) {
238 return;
241 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
242 cairo_surface_set_device_offset(curr->surface, x_offset, y_offset);
245 /* }}} setDeviceOffset */
249 /* {{{ proto void setFallbackResolution(float x_ppi, float y_ppi)
251 PHP_METHOD(CairoSurface, setFallbackResolution)
254 zval * _this_zval = NULL;
255 double x_ppi = 0.0;
256 double y_ppi = 0.0;
258 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoSurface_ce_ptr, &x_ppi, &y_ppi) == FAILURE) {
259 return;
262 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
263 cairo_surface_set_fallback_resolution(curr->surface, x_ppi, y_ppi);
266 /* }}} setFallbackResolution */
270 /* {{{ proto void writeToPng(string file)
272 PHP_METHOD(CairoSurface, writeToPng)
275 zval * _this_zval = NULL;
276 const char * file = NULL;
277 int file_len = 0;
278 cairo_status_t status;
280 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoSurface_ce_ptr, &file, &file_len) == FAILURE) {
281 return;
284 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
285 status = cairo_surface_write_to_png(curr->surface, file);
288 /* }}} writeToPng */
291 /* {{{ proto void writeToPngStream(stream file)
293 PHP_METHOD(CairoSurface, writeToPngStream)
295 FILE *file;
296 zval *_this_zval = NULL;
297 cairo_status_t status;
298 zval *zstream;
299 php_stream *stream;
300 int err;
302 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoSurface_ce_ptr, &zstream)) {
303 return;
306 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
307 php_stream_from_zval(stream, &zstream);
308 status = cairo_surface_write_to_png_stream(curr->surface, _write_func, stream);
312 /* }}} writeToPngStream*/
315 static zend_function_entry CairoSurface_methods[] = {
316 PHP_ME(CairoSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
317 PHP_ME(CairoSurface, createSimilar, CairoSurface__create_similar_args, /**/ZEND_ACC_PUBLIC)
318 PHP_ME(CairoSurface, finish, NULL, /**/ZEND_ACC_PUBLIC)
319 PHP_ME(CairoSurface, flush, NULL, /**/ZEND_ACC_PUBLIC)
320 PHP_ME(CairoSurface, getContent, NULL, /**/ZEND_ACC_PUBLIC)
321 PHP_ME(CairoSurface, getDeviceOffset, NULL, /**/ZEND_ACC_PUBLIC)
322 PHP_ME(CairoSurface, getFontOptions, NULL, /**/ZEND_ACC_PUBLIC)
323 PHP_ME(CairoSurface, markDirtyRectangle, CairoSurface__mark_dirty_rectangle_args, /**/ZEND_ACC_PUBLIC)
324 PHP_ME(CairoSurface, setDeviceOffset, CairoSurface__set_device_offset_args, /**/ZEND_ACC_PUBLIC)
325 PHP_ME(CairoSurface, setFallbackResolution, CairoSurface__set_fallback_resolution_args, /**/ZEND_ACC_PUBLIC)
326 PHP_ME(CairoSurface, writeToPng, CairoSurface__write_to_png_args, /**/ZEND_ACC_PUBLIC)
327 PHP_ME(CairoSurface, writeToPngStream, CairoSurface__write_to_png_stream_args, /**/ZEND_ACC_PUBLIC)
328 { NULL, NULL, NULL }
331 /* }}} Methods */
334 static void CairoSurface_object_dtor(void *object)
336 surface_object *surface = (surface_object *)object;
337 zend_hash_destroy(surface->std.properties);
338 FREE_HASHTABLE(surface->std.properties);
339 if(surface->surface){
340 cairo_surface_finish(surface->surface);
341 cairo_surface_destroy(surface->surface);
344 efree(object);
347 static zend_object_value CairoSurface_object_new(zend_class_entry *ce)
349 zend_object_value retval;
350 surface_object *surface;
351 zval *temp;
353 surface = emalloc(sizeof(surface_object));
354 memset(surface,0,sizeof(surface_object));
356 surface->std.ce = ce;
358 ALLOC_HASHTABLE(surface->std.properties);
359 zend_hash_init(surface->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
360 zend_hash_copy(surface->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
361 retval.handle = zend_objects_store_put(surface, NULL, (zend_objects_free_object_storage_t)CairoSurface_object_dtor, NULL TSRMLS_CC);
362 retval.handlers = &CairoSurface_handlers;
363 return retval;
366 void class_init_CairoSurface(void)
368 zend_class_entry ce;
370 INIT_CLASS_ENTRY(ce, "CairoSurface", CairoSurface_methods);
371 CairoSurface_ce_ptr = zend_register_internal_class(&ce);
372 CairoSurface_ce_ptr->create_object = CairoSurface_object_new;
373 memcpy(&CairoSurface_handlers, zend_get_std_object_handlers(),sizeof(zend_object_handlers));
374 CairoSurface_handlers.clone_obj = NULL;
377 /* }}} Class CairoSurface */
379 /* {{{ Class CairoImageSurface -- done :)*/
381 static zend_class_entry * CairoImageSurface_ce_ptr = NULL;
382 static zend_object_handlers CairoImageSurface_handlers;
385 /* {{{ Methods */
388 /* {{{ proto void construct(int format, int widthm, int height)
390 PHP_METHOD(CairoImageSurface, __construct)
392 zval * _this_zval;
394 cairo_format_t format = 0;
395 long widthm = 0;
396 long height = 0;
400 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &format, &widthm, &height) == FAILURE) {
401 return;
404 _this_zval = getThis();
405 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
406 curr->surface = cairo_image_surface_create(format, widthm, height);
409 /* }}} __construct */
413 /* {{{ proto void createFromData(string obj, int format, int width, int height [, int stride])
415 PHP_METHOD(CairoImageSurface, createFromData)
418 zval * _this_zval = NULL;
419 const char * buffer = NULL;
420 int buffer_len = 0;
421 long format = 0;
422 long width = 0;
423 long height = 0;
424 long stride = -1;
428 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oslll|l", &_this_zval, CairoImageSurface_ce_ptr, &buffer, &buffer_len, &format, &width, &height, &stride) == FAILURE) {
429 return;
432 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
433 cairo_surface_finish(curr->surface);
434 cairo_surface_destroy(curr->surface);
436 if(stride < 0 ){
437 switch(format) {
438 case CAIRO_FORMAT_ARGB32:
439 case CAIRO_FORMAT_RGB24:
440 stride = width * 4;
441 break;
442 case CAIRO_FORMAT_RGB16_565:
443 stride = width * 2;
444 break;
445 case CAIRO_FORMAT_A8:
446 stride = width;
447 break;
448 case CAIRO_FORMAT_A1:
449 stride = (width + 1) / 8;
450 break;
451 default:
452 php_error(E_WARNING, "Unknown format");
453 return;
458 if (height * stride > buffer_len) {
459 php_error(E_WARNING,"buffer is not long enough");
460 return;
463 curr->surface = cairo_image_surface_create_for_data(buffer, format, width, height, stride);
466 /* }}} createFromData */
470 /* {{{ proto void createFromPng(string file)
472 PHP_METHOD(CairoImageSurface, createFromPng)
475 zval * _this_zval = NULL;
476 const char * file = NULL;
477 int file_len = 0;
479 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &_this_zval, CairoImageSurface_ce_ptr, &file, &file_len) == FAILURE) {
480 return;
483 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
485 curr->surface = cairo_image_surface_create_from_png(file);
488 /* }}} createFromPng */
492 /* {{{ proto void createFromPngStream(stream zstream)
495 PHP_METHOD(CairoImageSurface, createFromPngStream)
497 FILE *file;
498 zval *_this_zval = NULL;
499 cairo_status_t status;
500 zval *zstream;
501 php_stream *stream;
502 int err;
504 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Or", &_this_zval, CairoImageSurface_ce_ptr, &zstream)) {
505 return;
508 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
510 php_stream_from_zval(stream, &zstream);
511 curr->surface = cairo_image_surface_create_from_png_stream( _read_func, stream);
516 /* }}} createFromPngStream*/
520 /* {{{ proto string getData() -- not required
522 PHP_METHOD(CairoImageSurface, getData)
525 zval * _this_zval = NULL;
526 char *str;
529 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
530 return;
533 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
536 str = cairo_image_surface_get_data(curr->surface);
537 RETURN_STRING(str, 0);
539 /* }}} getData */
543 /* {{{ proto int getFormat()
545 PHP_METHOD(CairoImageSurface, getFormat)
547 zval * _this_zval = NULL;
549 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
550 return;
552 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
554 RETURN_LONG(cairo_image_surface_get_format(curr->surface));
556 /* }}} getFormat */
560 /* {{{ proto int getHeight()
562 PHP_METHOD(CairoImageSurface, getHeight)
564 zval * _this_zval = NULL;
566 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
567 return;
570 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
571 RETURN_LONG(cairo_image_surface_get_height(curr->surface));
574 /* }}} getHeight */
578 /* {{{ proto int getStride()
580 PHP_METHOD(CairoImageSurface, getStride)
582 zval * _this_zval = NULL;
584 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
585 return;
588 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
589 RETURN_LONG(cairo_image_surface_get_stride(curr->surface));
592 /* }}} getStride */
596 /* {{{ proto int getWidth()
598 PHP_METHOD(CairoImageSurface, getWidth)
600 zval * _this_zval = NULL;
602 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoImageSurface_ce_ptr) == FAILURE) {
603 return;
607 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
609 RETURN_LONG(cairo_image_surface_get_width(curr->surface));
611 /* }}} getWidth */
614 static zend_function_entry CairoImageSurface_methods[] = {
615 PHP_ME(CairoImageSurface, __construct, CairoImageSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
616 PHP_ME(CairoImageSurface, createFromData, CairoImageSurface__create_from_data_args, /**/ZEND_ACC_PUBLIC)
617 PHP_ME(CairoImageSurface, createFromPng, CairoImageSurface__create_from_png_args, /**/ZEND_ACC_PUBLIC)
618 PHP_ME(CairoImageSurface, createFromPngStream, CairoImageSurface__create_from_png_stream_args, /**/ZEND_ACC_PUBLIC)
619 PHP_ME(CairoImageSurface, getData, NULL, /**/ZEND_ACC_PUBLIC)
620 PHP_ME(CairoImageSurface, getFormat, NULL, /**/ZEND_ACC_PUBLIC)
621 PHP_ME(CairoImageSurface, getHeight, NULL, /**/ZEND_ACC_PUBLIC)
622 PHP_ME(CairoImageSurface, getStride, NULL, /**/ZEND_ACC_PUBLIC)
623 PHP_ME(CairoImageSurface, getWidth, NULL, /**/ZEND_ACC_PUBLIC)
624 { NULL, NULL, NULL }
627 /* }}} Methods */
629 static zend_object_value CairoImageSurface_object_new(zend_class_entry *ce TSRMLS_DC)
631 zend_object_value retval;
632 retval = CairoSurface_object_new(ce TSRMLS_CC);
633 retval.handlers = &CairoImageSurface_handlers;
634 return retval;
638 void class_init_CairoImageSurface(void)
640 zend_class_entry ce;
642 INIT_CLASS_ENTRY(ce, "CairoImageSurface", CairoImageSurface_methods);
643 CairoImageSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
644 CairoImageSurface_ce_ptr->create_object = CairoImageSurface_object_new;
645 memcpy(&CairoImageSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
648 /* }}} Class CairoImageSurface */
650 /* {{{ Class CairoPDFSurface */
652 static zend_class_entry * CairoPDFSurface_ce_ptr = NULL;
653 static zend_object_handlers CairoPDFSurface_handlers;
654 /* {{{ Methods */
657 /* {{{ proto void construct(string file, float wpts, float hpts)
659 PHP_METHOD(CairoPDFSurface, __construct)
661 zval * _this_zval;
662 zval *zstream = NULL;
663 const char * file = NULL;
664 int file_len = 0;
665 double wpts = 0.0;
666 double hpts = 0.0;
667 php_stream *stream;
668 int argc = ZEND_NUM_ARGS();
669 zval ***args, *obj;
671 args = (zval ***)safe_emalloc(argc, sizeof(zval *),0);
672 if(ZEND_NUM_ARGS() == 0 ||
673 zend_get_parameters_array_ex(argc, args) == FAILURE) {
674 printf("ERROR");
675 efree(args);
676 WRONG_PARAM_COUNT;
679 obj = *(args[1]);
680 switch(Z_TYPE_P(obj)) {
681 case IS_DOUBLE:
682 wpts = Z_DVAL_P(obj);
683 break;
684 case IS_LONG:
685 wpts = Z_LVAL_P(obj);
686 break;
687 default :
688 printf("Error!!!");
689 return;
692 obj = *(args[2]);
694 switch(Z_TYPE_P(obj)) {
695 case IS_DOUBLE:
696 hpts = Z_DVAL_P(obj);
697 break;
698 case IS_LONG:
699 hpts = Z_LVAL_P(obj);
700 break;
701 default :
702 printf("Error!!!");
703 return;
707 _this_zval = getThis();
709 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
711 obj = *(args[0]);
712 if(Z_TYPE_P(obj) == IS_STRING) {
713 file = Z_STRVAL_P(obj);
714 curr->surface = cairo_pdf_surface_create(file, wpts, hpts);
716 else if(Z_TYPE_P(obj) == IS_RESOURCE) {
717 zstream = obj;
718 php_stream_from_zval(stream, &zstream);
719 curr->surface = cairo_pdf_surface_create_for_stream(_write_func, stream, wpts, hpts);
721 else {
722 printf("ERROR\n");
725 efree(args);
727 /* }}} __construct */
731 /* {{{ proto void setSize(float wptd, float hpts)
733 PHP_METHOD(CairoPDFSurface, setSize)
736 zval * _this_zval = NULL;
737 double wpts = 0.0;
738 double hpts = 0.0;
742 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPDFSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
743 return;
746 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
747 cairo_pdf_surface_set_size(curr->surface, wpts, hpts);
750 /* }}} setSize */
753 static zend_function_entry CairoPDFSurface_methods[] = {
754 PHP_ME(CairoPDFSurface, __construct, CairoPDFSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
755 PHP_ME(CairoPDFSurface, setSize, CairoPDFSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
756 { NULL, NULL, NULL }
759 /* }}} Methods */
761 static zend_object_value CairoPDFSurface_object_new(zend_class_entry *ce TSRMLS_DC)
763 zend_object_value retval;
764 retval = CairoSurface_object_new(ce TSRMLS_CC);
765 retval.handlers = &CairoPDFSurface_handlers;
766 return retval;
769 void class_init_CairoPDFSurface(void)
771 zend_class_entry ce;
773 INIT_CLASS_ENTRY(ce, "CairoPDFSurface", CairoPDFSurface_methods);
774 CairoPDFSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
775 CairoPDFSurface_ce_ptr->create_object = CairoPDFSurface_object_new;
776 memcpy(&CairoPDFSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
780 /* }}} Class CairoPDFSurface */
782 /* {{{ Class CairoPSSurface */
784 static zend_class_entry * CairoPSSurface_ce_ptr = NULL;
785 static zend_object_handlers CairoPSSurface_handlers;
786 /* {{{ Methods */
789 /* {{{ proto void construct(string file | stream stream, float wpts, float hpts)
791 PHP_METHOD(CairoPSSurface, __construct)
793 zval * _this_zval;
794 zval *zstream = NULL;
795 const char * file = NULL;
796 int file_len = 0;
797 double wpts = 0.0;
798 double hpts = 0.0;
799 php_stream *stream;
800 int argc = ZEND_NUM_ARGS();
801 zval ***args, *obj;
803 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
804 if(ZEND_NUM_ARGS() == 0 ||
805 zend_get_parameters_array_ex(argc, args) == FAILURE) {
806 printf("ERROR");
807 efree(args);
808 WRONG_PARAM_COUNT;
811 obj = *(args[1]);
812 switch(Z_TYPE_P(obj)) {
813 case IS_DOUBLE:
814 wpts = Z_DVAL_P(obj);
815 break;
816 case IS_LONG:
817 wpts = Z_LVAL_P(obj);
818 break;
819 default :
820 printf("Error!!!");
821 return;
824 obj = *(args[2]);
826 switch(Z_TYPE_P(obj)) {
827 case IS_DOUBLE:
828 hpts = Z_DVAL_P(obj);
829 break;
830 case IS_LONG:
831 hpts = Z_LVAL_P(obj);
832 break;
833 default :
834 printf("Error!!!");
835 return;
839 _this_zval = getThis();
840 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
842 obj = *(args[0]);
843 if(Z_TYPE_P(obj) == IS_STRING) {
844 file = Z_STRVAL_P(obj);
845 curr->surface = cairo_ps_surface_create(file, wpts, hpts);
847 else if(Z_TYPE_P(obj) == IS_RESOURCE) {
848 zstream = obj;
849 php_stream_from_zval(stream, &zstream);
850 curr->surface = cairo_ps_surface_create_for_stream(_write_func, stream, wpts, hpts);
852 else {
853 printf("ERROR\n");
856 efree(args);
862 /* }}} __construct */
866 /* {{{ proto void dscBeginPageSetup()
868 PHP_METHOD(CairoPSSurface, dscBeginPageSetup)
871 zval * _this_zval = NULL;
875 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
876 return;
878 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
879 cairo_ps_surface_dsc_begin_page_setup(curr->surface);
880 PHP_CAIRO_SURFACE_ERROR(curr->surface);
885 /* }}} dscBeginPageSetup */
889 /* {{{ proto void dscBeginSetup()
891 PHP_METHOD(CairoPSSurface, dscBeginSetup)
894 zval * _this_zval = NULL;
898 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
899 return;
902 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
903 cairo_ps_surface_dsc_begin_setup(curr->surface);
904 PHP_CAIRO_SURFACE_ERROR(curr->surface);
907 /* }}} dscBeginSetup */
911 /* {{{ proto void dscComment()
913 PHP_METHOD(CairoPSSurface, dscComment)
916 zval * _this_zval = NULL;
920 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
921 return;
924 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
925 cairo_ps_surface_dsc_comment(curr->surface);
926 PHP_CAIRO_SURFACE_ERROR(curr->surface);
929 /* }}} dscComment */
933 /* {{{ proto array getLevels() -- cairo 1.6
935 PHP_METHOD(CairoPSSurface, getLevels)
938 zval * _this_zval = NULL;
942 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
943 return;
946 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
949 array_init(return_value);
951 do {
952 /* ONLY for CAIRO 1.6 */
953 } while (0);
955 /* }}} getLevels */
959 /* {{{ proto string getLevelString() --cairo 1.6
961 PHP_METHOD(CairoPSSurface, getLevelString)
964 zval * _this_zval = NULL;
968 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
969 return;
972 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
975 do {
976 /* ONLY for CAIRO 1.6*/
977 } while (0);
979 /* }}} getLevelString */
983 /* {{{ proto void restrictToLevel(int level) --cairo 1.6
985 PHP_METHOD(CairoPSSurface, restrictToLevel)
988 zval * _this_zval = NULL;
989 long level = 0;
993 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoPSSurface_ce_ptr, &level) == FAILURE) {
994 return;
997 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1000 do {
1001 /* ONLY for CAIRO 1.6 */
1002 } while (0);
1004 /* }}} restrictToLevel */
1008 /* {{{ proto void setEps() --cairo 1.6
1010 PHP_METHOD(CairoPSSurface, setEps)
1013 zval * _this_zval = NULL;
1017 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPSSurface_ce_ptr) == FAILURE) {
1018 return;
1021 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1024 do {
1025 /* ONLY for CAIRO 1.6 */
1026 } while (0);
1028 /* }}} setEps */
1032 /* {{{ proto void setSize(float wpts, float hpts)
1034 PHP_METHOD(CairoPSSurface, setSize)
1037 zval * _this_zval = NULL;
1038 double wpts = 0.0;
1039 double hpts = 0.0;
1043 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoPSSurface_ce_ptr, &wpts, &hpts) == FAILURE) {
1044 return;
1047 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1048 cairo_ps_surface_set_size(curr->surface, wpts, hpts);
1051 /* }}} setSize */
1054 static zend_function_entry CairoPSSurface_methods[] = {
1055 PHP_ME(CairoPSSurface, __construct, CairoPSSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1056 PHP_ME(CairoPSSurface, dscBeginPageSetup, NULL, /**/ZEND_ACC_PUBLIC)
1057 PHP_ME(CairoPSSurface, dscBeginSetup, NULL, /**/ZEND_ACC_PUBLIC)
1058 PHP_ME(CairoPSSurface, dscComment, NULL, /**/ZEND_ACC_PUBLIC)
1059 PHP_ME(CairoPSSurface, getLevels, NULL, /**/ZEND_ACC_PUBLIC)
1060 PHP_ME(CairoPSSurface, getLevelString, NULL, /**/ZEND_ACC_PUBLIC)
1061 PHP_ME(CairoPSSurface, restrictToLevel, CairoPSSurface__restrict_to_level_args, /**/ZEND_ACC_PUBLIC)
1062 PHP_ME(CairoPSSurface, setEps, NULL, /**/ZEND_ACC_PUBLIC)
1063 PHP_ME(CairoPSSurface, setSize, CairoPSSurface__set_size_args, /**/ZEND_ACC_PUBLIC)
1064 { NULL, NULL, NULL }
1067 /* }}} Methods */
1069 static zend_object_value CairoPSSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1071 zend_object_value retval;
1072 retval = CairoSurface_object_new(ce TSRMLS_CC);
1073 retval.handlers = &CairoPSSurface_handlers;
1074 return retval;
1077 void class_init_CairoPSSurface(void)
1079 zend_class_entry ce;
1081 INIT_CLASS_ENTRY(ce, "CairoPSSurface", CairoPSSurface_methods);
1082 CairoPSSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1083 CairoPSSurface_ce_ptr->create_object = CairoPSSurface_object_new;
1084 memcpy(&CairoPSSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1087 /* }}} Class CairoPSSurface */
1089 /* {{{ Class CairoQuartzSurface */
1091 static zend_class_entry * CairoQuartzSurface_ce_ptr = NULL;
1092 static zend_object_handlers CairoQuartzSurface_handlers;
1093 /* {{{ Methods */
1096 /* {{{ proto void construct(float wpixels, float hpixels [, int format])
1098 PHP_METHOD(CairoQuartzSurface, __construct)
1100 zval * _this_zval;
1102 double wpixels = 0.0;
1103 double hpixels = 0.0;
1104 long format = 0;
1108 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &wpixels, &hpixels, &format) == FAILURE) {
1109 return;
1112 _this_zval = getThis();
1113 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1116 php_error(E_WARNING, "CANNOT BE CALLED"); RETURN_FALSE;
1119 /* }}} __construct */
1122 static zend_function_entry CairoQuartzSurface_methods[] = {
1123 PHP_ME(CairoQuartzSurface, __construct, CairoQuartzSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1124 { NULL, NULL, NULL }
1127 /* }}} Methods */
1129 static zend_object_value CairoQuartzSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1131 zend_object_value retval;
1132 retval = CairoSurface_object_new(ce TSRMLS_CC);
1133 retval.handlers = &CairoQuartzSurface_handlers;
1134 return retval;
1137 void class_init_CairoQuartzSurface(void)
1139 zend_class_entry ce;
1141 INIT_CLASS_ENTRY(ce, "CairoQuartzSurface", CairoQuartzSurface_methods);
1142 CairoQuartzSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1143 CairoQuartzSurface_ce_ptr->create_object = CairoQuartzSurface_object_new;
1144 memcpy(&CairoQuartzSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1148 /* }}} Class CairoQuartzSurface */
1150 /* {{{ Class CairoSVGSurface */
1152 static zend_class_entry * CairoSVGSurface_ce_ptr = NULL;
1153 static zend_object_handlers CairoSVGSurface_handlers;
1156 /* {{{ Methods */
1159 /* {{{ proto void construct(string file, float wpts, float hpts)
1161 PHP_METHOD(CairoSVGSurface, __construct)
1163 zval * _this_zval;
1164 zval *zstream = NULL;
1165 const char * file = NULL;
1166 int file_len = 0;
1167 double wpts = 0.0;
1168 double hpts = 0.0;
1169 php_stream *stream;
1170 int argc = ZEND_NUM_ARGS();
1171 zval ***args, *obj;
1173 args = (zval **)safe_emalloc(argc, sizeof(zval *),0);
1174 if(ZEND_NUM_ARGS() == 0 ||
1175 zend_get_parameters_array_ex(argc, args) == FAILURE) {
1176 printf("ERROR");
1177 efree(args);
1178 WRONG_PARAM_COUNT;
1181 obj = *(args[1]);
1182 switch(Z_TYPE_P(obj)) {
1183 case IS_DOUBLE:
1184 wpts = Z_DVAL_P(obj);
1185 break;
1186 case IS_LONG:
1187 wpts = Z_LVAL_P(obj);
1188 break;
1189 default :
1190 printf("error!!!");
1191 return;
1194 obj = *(args[2]);
1196 switch(Z_TYPE_P(obj)) {
1197 case IS_DOUBLE:
1198 hpts = Z_DVAL_P(obj);
1199 break;
1200 case IS_LONG:
1201 hpts = Z_LVAL_P(obj);
1202 break;
1203 default :
1204 printf("Error!!!");
1205 return;
1209 _this_zval = getThis();
1210 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1212 obj = *(args[0]);
1213 if(Z_TYPE_P(obj) == IS_STRING) {
1214 file = Z_STRVAL_P(obj);
1215 curr->surface = cairo_svg_surface_create(file, wpts, hpts);
1217 else if(Z_TYPE_P(obj) == IS_RESOURCE) {
1218 zstream = obj;
1219 php_stream_from_zval(stream, &zstream);
1220 curr->surface = cairo_svg_surface_create_for_stream(_write_func, stream, wpts, hpts);
1222 else {
1223 printf("ERROR\n");
1226 efree(args);
1230 /* }}} __construct */
1233 static zend_function_entry CairoSVGSurface_methods[] = {
1234 PHP_ME(CairoSVGSurface, __construct, CairoSVGSurface____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1235 { NULL, NULL, NULL }
1238 /* }}} Methods */
1240 static zend_object_value CairoSVGSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1242 zend_object_value retval;
1243 retval = CairoSurface_object_new(ce TSRMLS_CC);
1244 retval.handlers = &CairoSVGSurface_handlers;
1245 return retval;
1248 void class_init_CairoSVGSurface(void)
1250 zend_class_entry ce;
1252 INIT_CLASS_ENTRY(ce, "CairoSVGSurface", CairoSVGSurface_methods);
1253 CairoSVGSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1254 CairoSVGSurface_ce_ptr->create_object = CairoSVGSurface_object_new;
1255 memcpy(&CairoSVGSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1259 /* }}} Class CairoSVGSurface */
1261 /* {{{ Class CairoWin32Surface*/
1263 static zend_class_entry * CairoWin32Surface_ce_ptr = NULL;
1264 static zend_object_handlers CairoWin32Surface_handlers;
1266 /* {{{ Methods */
1269 /* {{{ proto void construct(int hdc)
1271 PHP_METHOD(CairoWin32Surface, __construct)
1273 zval * _this_zval;
1275 long hdc = 0;
1279 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hdc) == FAILURE) {
1280 return;
1283 _this_zval = getThis();
1284 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1285 curr->surface = cairo_win32_surface_create(hdc, NULL);
1287 /* }}} __construct */
1290 static zend_function_entry CairoWin32Surface_methods[] = {
1291 PHP_ME(CairoWin32Surface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1292 { NULL, NULL, NULL }
1295 /* }}} Methods */
1297 static zend_object_value CairoWin32Surface_object_new(zend_class_entry *ce TSRMLS_DC)
1299 zend_object_value retval;
1300 retval = CairoSurface_object_new(ce TSRMLS_CC);
1301 retval.handlers = &CairoWin32Surface_handlers;
1302 return retval;
1305 void class_init_CairoWin32Surface(void)
1307 zend_class_entry ce;
1309 INIT_CLASS_ENTRY(ce, "CairoWin32Surface", CairoWin32Surface_methods);
1310 CairoWin32Surface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1311 CairoWin32Surface_ce_ptr->create_object = CairoWin32Surface_object_new;
1312 memcpy(&CairoWin32Surface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1316 /* }}} Class CairoWin32Surface */
1318 /* {{{ Class CairoXlibSurface */
1320 static zend_class_entry * CairoXlibSurface_ce_ptr = NULL;
1321 static zend_object_handlers CairoXlibSurface_handlers;
1322 /* {{{ Methods */
1325 /* {{{ proto void construct()
1327 PHP_METHOD(CairoXlibSurface, __construct)
1329 zval * _this_zval;
1333 if (ZEND_NUM_ARGS()>0) {
1334 WRONG_PARAM_COUNT;
1337 _this_zval = getThis();
1338 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1340 php_error(E_WARNING, "Cannot Be Initialized"); RETURN_FALSE;
1343 /* }}} __construct */
1347 /* {{{ proto int getDepth()
1349 PHP_METHOD(CairoXlibSurface, getDepth)
1352 zval * _this_zval = NULL;
1355 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1356 return;
1359 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1361 RETURN_LONG(cairo_xlib_surface_get_depth(curr->surface));
1364 /* }}} getDepth */
1368 /* {{{ proto int getHeight()
1370 PHP_METHOD(CairoXlibSurface, getHeight)
1373 zval * _this_zval = NULL;
1376 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1377 return;
1380 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1381 RETURN_LONG(cairo_xlib_surface_get_height(curr->surface));
1384 /* }}} getHeight */
1388 /* {{{ proto int getWidth()
1390 PHP_METHOD(CairoXlibSurface, getWidth)
1393 zval * _this_zval = NULL;
1396 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoXlibSurface_ce_ptr) == FAILURE) {
1397 return;
1400 surface_object *curr = (surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
1401 RETURN_LONG(cairo_xlib_surface_get_width(curr->surface));
1404 /* }}} getWidth */
1407 static zend_function_entry CairoXlibSurface_methods[] = {
1408 PHP_ME(CairoXlibSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1409 PHP_ME(CairoXlibSurface, getDepth, NULL, /**/ZEND_ACC_PUBLIC)
1410 PHP_ME(CairoXlibSurface, getHeight, NULL, /**/ZEND_ACC_PUBLIC)
1411 PHP_ME(CairoXlibSurface, getWidth, NULL, /**/ZEND_ACC_PUBLIC)
1412 { NULL, NULL, NULL }
1415 /* }}} Methods */
1417 static zend_object_value CairoXlibSurface_object_new(zend_class_entry *ce TSRMLS_DC)
1419 zend_object_value retval;
1420 retval = CairoSurface_object_new(ce TSRMLS_CC);
1421 retval.handlers = &CairoXlibSurface_handlers;
1422 return retval;
1425 void class_init_CairoXlibSurface(void)
1427 zend_class_entry ce;
1429 INIT_CLASS_ENTRY(ce, "CairoXlibSurface", CairoXlibSurface_methods);
1430 CairoXlibSurface_ce_ptr = zend_register_internal_class_ex(&ce, CairoSurface_ce_ptr, "CairoSurface" TSRMLS_CC);
1431 CairoXlibSurface_ce_ptr->create_object = CairoXlibSurface_object_new;
1432 memcpy(&CairoXlibSurface_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
1436 /* }}} Class CairoXlibSurface */
1438 /* {{{ Helper Functions */
1439 zend_class_entry *
1440 get_CairoSurface_ce_ptr(cairo_surface_t *surface)
1442 zend_class_entry *type;
1443 if(surface == NULL)
1444 return;
1446 switch(cairo_surface_get_type(surface)) {
1447 case CAIRO_SURFACE_TYPE_IMAGE:
1448 type = CairoImageSurface_ce_ptr;
1449 break;
1450 case CAIRO_SURFACE_TYPE_PDF:
1451 type = CairoPDFSurface_ce_ptr;
1452 break;
1453 case CAIRO_SURFACE_TYPE_PS:
1454 type = CairoPSSurface_ce_ptr;
1455 break;
1456 case CAIRO_SURFACE_TYPE_SVG:
1457 type = CairoSVGSurface_ce_ptr;
1458 break;
1459 case CAIRO_SURFACE_TYPE_WIN32:
1460 type = CairoWin32Surface_ce_ptr;
1461 break;
1462 case CAIRO_SURFACE_TYPE_XLIB:
1463 type = CairoXlibSurface_ce_ptr;
1464 break;
1465 case CAIRO_SURFACE_TYPE_QUARTZ:
1466 type = CairoQuartzSurface_ce_ptr;
1467 break;
1468 default:
1469 php_error(E_WARNING,"Unsupported Surface Type");
1470 return NULL;
1472 return type;
1475 /* }}} Helper Function*/