1 #include "php_cairo_api.h"
3 #include "CairoExceptionMacro.h"
4 #include "php_cairo_ce_ptr.h"
6 /* {{{ Class CairoFontFace */
8 //static zend_class_entry * CairoFontFace_ce_ptr = NULL;
13 /* {{{ proto void construct()
15 PHP_METHOD(CairoFontFace
, __construct
)
21 if (ZEND_NUM_ARGS()>0) {
26 php_error(E_WARNING
,"Please use Context.get_font_face()");
34 static zend_function_entry CairoFontFace_methods
[] = {
35 PHP_ME(CairoFontFace
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
42 static zend_object_handlers CairoFontFace_handlers
;
44 static void CairoFontFace_object_dtor(void *object
)
46 fontface_object
*fontface
= (fontface_object
*)object
;
47 zend_hash_destroy(fontface
->std
.properties
);
48 FREE_HASHTABLE(fontface
->std
.properties
);
50 if(fontface
->fontface
){
51 cairo_font_face_destroy(fontface
->fontface
);
56 static zend_object_value
CairoFontFace_object_new(zend_class_entry
*ce
)
58 zend_object_value retval
;
59 fontface_object
*fontface
;
61 fontface
= emalloc(sizeof(fontface_object
));
62 memset(fontface
,0,sizeof(fontface_object
));
63 fontface
->std
.ce
= ce
;
64 ALLOC_HASHTABLE(fontface
->std
.properties
);
65 zend_hash_init(fontface
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
66 zend_hash_copy(fontface
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
67 retval
.handle
= zend_objects_store_put(fontface
, NULL
, (zend_objects_free_object_storage_t
)CairoFontFace_object_dtor
, NULL TSRMLS_CC
);
68 retval
.handlers
= &CairoFontFace_handlers
;
73 void class_init_CairoFontFace(void)
77 INIT_CLASS_ENTRY(ce
, "CairoFontFace", CairoFontFace_methods
);
78 CairoFontFace_ce_ptr
= zend_register_internal_class(&ce
);
79 CairoFontFace_ce_ptr
->create_object
= CairoFontFace_object_new
;
80 memcpy(&CairoFontFace_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
81 CairoFontFace_handlers
.clone_obj
= NULL
;
84 /* }}} Class CairoFontFace */
87 /* {{{ Class CairoFontOptions */
89 //istatic zend_class_entry * CairoFontOptions_ce_ptr = NULL;
94 /* {{{ proto void construct()
96 PHP_METHOD(CairoFontOptions
, __construct
)
102 if (ZEND_NUM_ARGS()>0) {
105 _this_zval
= getThis();
106 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
107 curr
->fontoptions
= cairo_font_options_create();
110 /* }}} __construct */
114 /* {{{ proto int getAntialias()
116 PHP_METHOD(CairoFontOptions
, getAntialias
)
119 zval
* _this_zval
= NULL
;
122 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
126 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
127 RETURN_LONG(cairo_font_options_get_antialias(curr
->fontoptions
));
130 /* }}} getAntialias */
134 /* {{{ proto int getHintMetrics()
136 PHP_METHOD(CairoFontOptions
, getHintMetrics
)
139 zval
* _this_zval
= NULL
;
142 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
147 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
149 RETURN_LONG(cairo_font_options_get_hint_metrics(curr
->fontoptions
));
151 /* }}} getHintMetrics */
155 /* {{{ proto int getHintStyle()
157 PHP_METHOD(CairoFontOptions
, getHintStyle
)
160 zval
* _this_zval
= NULL
;
163 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
167 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
169 RETURN_LONG(cairo_font_options_get_hint_style(curr
->fontoptions
));
171 /* }}} getHintStyle */
175 /* {{{ proto int getSubpixelOrder()
177 PHP_METHOD(CairoFontOptions
, getSubpixelOrder
)
180 zval
* _this_zval
= NULL
;
183 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
187 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
189 RETURN_LONG(cairo_font_options_get_subpixel_order(curr
->fontoptions
));
191 /* }}} getSubpixelOrder */
195 /* {{{ proto void setAntialias([int aa])
197 PHP_METHOD(CairoFontOptions
, setAntialias
)
200 zval
* _this_zval
= NULL
;
201 cairo_antialias_t aa
= CAIRO_ANTIALIAS_DEFAULT
;
205 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &aa
) == FAILURE
) {
209 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
210 cairo_font_options_set_antialias(curr
->fontoptions
, aa
);
211 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
214 /* }}} setAntialias */
218 /* {{{ proto void setHintMetrics([int hm])
220 PHP_METHOD(CairoFontOptions
, setHintMetrics
)
223 zval
* _this_zval
= NULL
;
224 cairo_hint_metrics_t hm
= CAIRO_HINT_METRICS_DEFAULT
;
228 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hm
) == FAILURE
) {
233 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
234 cairo_font_options_set_hint_metrics(curr
->fontoptions
, hm
);
235 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
238 /* }}} setHintMetrics */
242 /* {{{ proto void setHintStyle([int hs])
244 PHP_METHOD(CairoFontOptions
, setHintStyle
)
247 zval
* _this_zval
= NULL
;
248 cairo_hint_style_t hs
= CAIRO_HINT_STYLE_DEFAULT
;
252 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hs
) == FAILURE
) {
256 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
257 cairo_font_options_set_hint_style(curr
->fontoptions
, hs
);
258 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
261 /* }}} setHintStyle */
265 /* {{{ proto void setSubpixelOrder([int so])
267 PHP_METHOD(CairoFontOptions
, setSubpixelOrder
)
270 zval
* _this_zval
= NULL
;
271 cairo_subpixel_order_t so
= CAIRO_SUBPIXEL_ORDER_DEFAULT
;
275 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &so
) == FAILURE
) {
279 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
280 cairo_font_options_set_subpixel_order(curr
->fontoptions
, so
);
281 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
284 /* }}} setSubpixelOrder */
287 static zend_function_entry CairoFontOptions_methods
[] = {
288 PHP_ME(CairoFontOptions
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
289 PHP_ME(CairoFontOptions
, getAntialias
, NULL
, /**/ZEND_ACC_PUBLIC
)
290 PHP_ME(CairoFontOptions
, getHintMetrics
, NULL
, /**/ZEND_ACC_PUBLIC
)
291 PHP_ME(CairoFontOptions
, getHintStyle
, NULL
, /**/ZEND_ACC_PUBLIC
)
292 PHP_ME(CairoFontOptions
, getSubpixelOrder
, NULL
, /**/ZEND_ACC_PUBLIC
)
293 PHP_ME(CairoFontOptions
, setAntialias
, CairoFontOptions__set_antialias_args
, /**/ZEND_ACC_PUBLIC
)
294 PHP_ME(CairoFontOptions
, setHintMetrics
, CairoFontOptions__set_hint_metrics_args
, /**/ZEND_ACC_PUBLIC
)
295 PHP_ME(CairoFontOptions
, setHintStyle
, CairoFontOptions__set_hint_style_args
, /**/ZEND_ACC_PUBLIC
)
296 PHP_ME(CairoFontOptions
, setSubpixelOrder
, CairoFontOptions__set_subpixel_order_args
, /**/ZEND_ACC_PUBLIC
)
303 static zend_object_handlers CairoFontOptions_handlers
;
305 static void CairoFontOptions_object_dtor(void *object
)
307 fontoptions_object
*fontoptions
= (fontoptions_object
*)object
;
308 zend_hash_destroy(fontoptions
->std
.properties
);
309 FREE_HASHTABLE(fontoptions
->std
.properties
);
311 if(fontoptions
->fontoptions
){
312 cairo_font_options_destroy(fontoptions
->fontoptions
);
317 static zend_object_value
CairoFontOptions_object_new(zend_class_entry
*ce
)
319 zend_object_value retval
;
320 fontoptions_object
*fontoptions
;
322 fontoptions
= emalloc(sizeof(fontoptions_object
));
323 memset(fontoptions
,0,sizeof(fontoptions_object
));
324 fontoptions
->std
.ce
= ce
;
325 ALLOC_HASHTABLE(fontoptions
->std
.properties
);
326 zend_hash_init(fontoptions
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
327 zend_hash_copy(fontoptions
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
328 retval
.handle
= zend_objects_store_put(fontoptions
, NULL
, (zend_objects_free_object_storage_t
)CairoFontOptions_object_dtor
, NULL TSRMLS_CC
);
329 retval
.handlers
= &CairoFontOptions_handlers
;
334 void class_init_CairoFontOptions(void)
338 INIT_CLASS_ENTRY(ce
, "CairoFontOptions", CairoFontOptions_methods
);
339 CairoFontOptions_ce_ptr
= zend_register_internal_class(&ce
);
340 CairoFontOptions_ce_ptr
->create_object
= CairoFontOptions_object_new
;
341 memcpy(&CairoFontOptions_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
342 CairoFontOptions_handlers
.clone_obj
= NULL
;
345 /* }}} Class CairoFontOptions */
348 /* {{{ Class CairoScaledFont */
350 //static zend_class_entry * CairoScaledFont_ce_ptr = NULL;
355 /* {{{ proto void construct(object ff, object mx1, object mx2, object fo)
357 PHP_METHOD(CairoScaledFont
, __construct
)
368 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "oooo", &ff
, &mx1
, &mx2
, &fo
) == FAILURE
) {
372 _this_zval
= getThis();
373 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
374 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(ff TSRMLS_CC
);
375 matrix_object
*mobj1
= (matrix_object
*)zend_objects_get_address(mx1 TSRMLS_CC
);
376 matrix_object
*mobj2
= (matrix_object
*)zend_objects_get_address(mx2 TSRMLS_CC
);
377 fontoptions_object
*foobj
= (fontoptions_object
*)zend_objects_get_address(fo TSRMLS_CC
);
378 curr
->scaledfont
= cairo_scaled_font_create(ffobj
->fontface
, &mobj1
->matrix
, &mobj2
->matrix
, foobj
->fontoptions
);
381 /* }}} __construct */
385 /* {{{ proto array extents()
387 PHP_METHOD(CairoScaledFont
, extents
)
390 zval
* _this_zval
= NULL
;
392 cairo_font_extents_t e
;
394 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
398 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
399 cairo_scaled_font_extents(curr
->scaledfont
, &e
);
401 PHP_CAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
402 array_init(return_value
);
403 add_assoc_double(return_value
, "ascent", e
.ascent
);
404 add_assoc_double(return_value
, "descent", e
.descent
);
405 add_assoc_double(return_value
, "height", e
.height
);
406 add_assoc_double(return_value
, "max_x_advance", e
.max_x_advance
);
407 add_assoc_double(return_value
, "max_y_advance", e
.max_y_advance
);
414 /* {{{ proto object getFontFace()
416 PHP_METHOD(CairoScaledFont
, getFontFace
)
419 zval
* _this_zval
= NULL
;
423 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
427 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
429 object_init_ex(return_value
, CairoFontFace_ce_ptr
);
430 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(return_value
);
431 ffobj
->fontface
= cairo_font_face_reference(cairo_scaled_font_get_font_face(curr
->scaledfont
));
434 /* }}} getFontFace */
438 /* {{{ proto array textExtents(string str)
440 PHP_METHOD(CairoScaledFont
, textExtents
)
443 zval
* _this_zval
= NULL
;
444 const char * str
= NULL
;
446 cairo_text_extents_t extents
;
450 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Os", &_this_zval
, CairoScaledFont_ce_ptr
, &str
, &str_len
) == FAILURE
) {
454 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
456 cairo_scaled_font_text_extents(curr
->scaledfont
, str
, &extents
);
457 PHP_CAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
459 array_init(return_value
);
460 add_assoc_double(return_value
, "x_bearing", extents
.x_bearing
);
461 add_assoc_double(return_value
, "y_bearing", extents
.y_bearing
);
462 add_assoc_double(return_value
, "width", extents
.width
);
463 add_assoc_double(return_value
, "height", extents
.height
);
464 add_assoc_double(return_value
, "x_advance", extents
.x_advance
);
465 add_assoc_double(return_value
, "y_advance", extents
.y_advance
);
468 /* }}} textExtents */
471 static zend_function_entry CairoScaledFont_methods
[] = {
472 PHP_ME(CairoScaledFont
, __construct
, CairoScaledFont____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
473 PHP_ME(CairoScaledFont
, extents
, NULL
, /**/ZEND_ACC_PUBLIC
)
474 PHP_ME(CairoScaledFont
, getFontFace
, NULL
, /**/ZEND_ACC_PUBLIC
)
475 PHP_ME(CairoScaledFont
, textExtents
, CairoScaledFont__text_extents_args
, /**/ZEND_ACC_PUBLIC
)
482 static zend_object_handlers CairoScaledFont_handlers
;
484 static void CairoScaledFont_object_dtor(void *object
)
486 scaledfont_object
*scaledfont
= (scaledfont_object
*)object
;
487 zend_hash_destroy(scaledfont
->std
.properties
);
488 FREE_HASHTABLE(scaledfont
->std
.properties
);
490 if(scaledfont
->scaledfont
){
491 cairo_scaled_font_destroy(scaledfont
->scaledfont
);
496 static zend_object_value
CairoScaledFont_object_new(zend_class_entry
*ce
)
498 zend_object_value retval
;
499 scaledfont_object
*scaledfont
;
501 scaledfont
= emalloc(sizeof(scaledfont_object
));
502 memset(scaledfont
,0,sizeof(scaledfont_object
));
503 scaledfont
->std
.ce
= ce
;
504 ALLOC_HASHTABLE(scaledfont
->std
.properties
);
505 zend_hash_init(scaledfont
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
506 zend_hash_copy(scaledfont
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
507 retval
.handle
= zend_objects_store_put(scaledfont
, NULL
, (zend_objects_free_object_storage_t
)CairoScaledFont_object_dtor
, NULL TSRMLS_CC
);
508 retval
.handlers
= &CairoScaledFont_handlers
;
513 void class_init_CairoScaledFont(void)
517 INIT_CLASS_ENTRY(ce
, "CairoScaledFont", CairoScaledFont_methods
);
518 CairoScaledFont_ce_ptr
= zend_register_internal_class(&ce
);
519 CairoScaledFont_ce_ptr
->create_object
= CairoScaledFont_object_new
;
520 memcpy(&CairoScaledFont_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
521 CairoScaledFont_handlers
.clone_obj
= NULL
;
524 /* }}} Class CairoScaledFont */