2 /* {{{ Class CairoFontFace */
4 static zend_class_entry
* CairoFontFace_ce_ptr
= NULL
;
9 /* {{{ proto void construct()
11 PHP_METHOD(CairoFontFace
, __construct
)
13 zend_class_entry
* _this_ce
;
18 if (ZEND_NUM_ARGS()>0) {
23 php_error(E_ERROR
,"Please use Context.get_font_face()");
31 static zend_function_entry CairoFontFace_methods
[] = {
32 PHP_ME(CairoFontFace
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
39 static zend_object_handlers CairoFontFace_handlers
;
41 static void CairoFontFace_object_dtor(void *object
)
43 fontface_object
*fontface
= (fontface_object
*)object
;
44 zend_hash_destroy(fontface
->std
.properties
);
45 FREE_HASHTABLE(fontface
->std
.properties
);
47 if(fontface
->fontface
){
48 cairo_font_face_destroy(fontface
->fontface
);
53 static zend_object_value
CairoFontFace_object_new(zend_class_entry
*ce
)
55 zend_object_value retval
;
56 fontface_object
*fontface
;
58 fontface
= emalloc(sizeof(fontface_object
));
59 memset(fontface
,0,sizeof(fontface_object
));
60 fontface
->std
.ce
= ce
;
61 ALLOC_HASHTABLE(fontface
->std
.properties
);
62 zend_hash_init(fontface
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
63 zend_hash_copy(fontface
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
64 retval
.handle
= zend_objects_store_put(fontface
, NULL
, (zend_objects_free_object_storage_t
)CairoFontFace_object_dtor
, NULL TSRMLS_CC
);
65 retval
.handlers
= &CairoFontFace_handlers
;
70 static void class_init_CairoFontFace(void)
74 INIT_CLASS_ENTRY(ce
, "CairoFontFace", CairoFontFace_methods
);
75 CairoFontFace_ce_ptr
= zend_register_internal_class(&ce
);
76 CairoFontFace_ce_ptr
->create_object
= CairoFontFace_object_new
;
77 memcpy(&CairoFontFace_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
78 CairoFontFace_handlers
.clone_obj
= NULL
;
81 /* }}} Class CairoFontFace */
84 /* {{{ Class CairoFontOptions */
86 static zend_class_entry
* CairoFontOptions_ce_ptr
= NULL
;
91 /* {{{ proto void construct()
93 PHP_METHOD(CairoFontOptions
, __construct
)
95 zend_class_entry
* _this_ce
;
100 if (ZEND_NUM_ARGS()>0) {
103 _this_zval
= getThis();
104 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
105 curr
->fontoptions
= cairo_font_options_create();
108 /* }}} __construct */
112 /* {{{ proto int getAntialias()
114 PHP_METHOD(CairoFontOptions
, getAntialias
)
116 zend_class_entry
* _this_ce
;
118 zval
* _this_zval
= NULL
;
122 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
126 _this_ce
= Z_OBJCE_P(_this_zval
);
127 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
128 x
= cairo_font_options_get_antialias(curr
->fontoptions
);
132 /* }}} getAntialias */
136 /* {{{ proto int getHintMetrics()
138 PHP_METHOD(CairoFontOptions
, getHintMetrics
)
140 zend_class_entry
* _this_ce
;
142 zval
* _this_zval
= NULL
;
146 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
150 _this_ce
= Z_OBJCE_P(_this_zval
);
152 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
154 x
= cairo_font_options_get_hint_metrics(curr
->fontoptions
);
157 /* }}} getHintMetrics */
161 /* {{{ proto int getHintStyle()
163 PHP_METHOD(CairoFontOptions
, getHintStyle
)
165 zend_class_entry
* _this_ce
;
167 zval
* _this_zval
= NULL
;
171 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
175 _this_ce
= Z_OBJCE_P(_this_zval
);
176 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
178 x
= cairo_font_options_get_hint_style(curr
->fontoptions
);
181 /* }}} getHintStyle */
185 /* {{{ proto int getSubpixelOrder()
187 PHP_METHOD(CairoFontOptions
, getSubpixelOrder
)
189 zend_class_entry
* _this_ce
;
191 zval
* _this_zval
= NULL
;
195 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
199 _this_ce
= Z_OBJCE_P(_this_zval
);
200 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
202 x
= cairo_font_options_get_subpixel_order(curr
->fontoptions
);
205 /* }}} getSubpixelOrder */
209 /* {{{ proto void setAntialias([int aa])
211 PHP_METHOD(CairoFontOptions
, setAntialias
)
213 zend_class_entry
* _this_ce
;
215 zval
* _this_zval
= NULL
;
216 cairo_antialias_t aa
= CAIRO_ANTIALIAS_DEFAULT
;
220 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &aa
) == FAILURE
) {
224 _this_ce
= Z_OBJCE_P(_this_zval
);
225 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
226 cairo_font_options_set_antialias(curr
->fontoptions
, aa
);
227 phpCAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
230 /* }}} setAntialias */
234 /* {{{ proto void setHintMetrics([int hm])
236 PHP_METHOD(CairoFontOptions
, setHintMetrics
)
238 zend_class_entry
* _this_ce
;
240 zval
* _this_zval
= NULL
;
241 cairo_hint_metrics_t hm
= CAIRO_HINT_METRICS_DEFAULT
;
245 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hm
) == FAILURE
) {
249 _this_ce
= Z_OBJCE_P(_this_zval
);
251 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
252 cairo_font_options_set_hint_metrics(curr
->fontoptions
, hm
);
253 phpCAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
256 /* }}} setHintMetrics */
260 /* {{{ proto void setHintStyle([int hs])
262 PHP_METHOD(CairoFontOptions
, setHintStyle
)
264 zend_class_entry
* _this_ce
;
266 zval
* _this_zval
= NULL
;
267 cairo_hint_style_t hs
= CAIRO_HINT_STYLE_DEFAULT
;
271 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hs
) == FAILURE
) {
275 _this_ce
= Z_OBJCE_P(_this_zval
);
276 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
277 cairo_font_options_set_hint_style(curr
->fontoptions
, hs
);
278 phpCAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
281 /* }}} setHintStyle */
285 /* {{{ proto void setSubpixelOrder([int so])
287 PHP_METHOD(CairoFontOptions
, setSubpixelOrder
)
289 zend_class_entry
* _this_ce
;
291 zval
* _this_zval
= NULL
;
292 cairo_subpixel_order_t so
= CAIRO_SUBPIXEL_ORDER_DEFAULT
;
296 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &so
) == FAILURE
) {
300 _this_ce
= Z_OBJCE_P(_this_zval
);
301 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
302 cairo_font_options_set_subpixel_order(curr
->fontoptions
, so
);
303 phpCAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
306 /* }}} setSubpixelOrder */
309 static zend_function_entry CairoFontOptions_methods
[] = {
310 PHP_ME(CairoFontOptions
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
311 PHP_ME(CairoFontOptions
, getAntialias
, NULL
, /**/ZEND_ACC_PUBLIC
)
312 PHP_ME(CairoFontOptions
, getHintMetrics
, NULL
, /**/ZEND_ACC_PUBLIC
)
313 PHP_ME(CairoFontOptions
, getHintStyle
, NULL
, /**/ZEND_ACC_PUBLIC
)
314 PHP_ME(CairoFontOptions
, getSubpixelOrder
, NULL
, /**/ZEND_ACC_PUBLIC
)
315 PHP_ME(CairoFontOptions
, setAntialias
, CairoFontOptions__set_antialias_args
, /**/ZEND_ACC_PUBLIC
)
316 PHP_ME(CairoFontOptions
, setHintMetrics
, CairoFontOptions__set_hint_metrics_args
, /**/ZEND_ACC_PUBLIC
)
317 PHP_ME(CairoFontOptions
, setHintStyle
, CairoFontOptions__set_hint_style_args
, /**/ZEND_ACC_PUBLIC
)
318 PHP_ME(CairoFontOptions
, setSubpixelOrder
, CairoFontOptions__set_subpixel_order_args
, /**/ZEND_ACC_PUBLIC
)
325 static zend_object_handlers CairoFontOptions_handlers
;
327 static void CairoFontOptions_object_dtor(void *object
)
329 fontoptions_object
*fontoptions
= (fontoptions_object
*)object
;
330 zend_hash_destroy(fontoptions
->std
.properties
);
331 FREE_HASHTABLE(fontoptions
->std
.properties
);
333 if(fontoptions
->fontoptions
){
334 cairo_font_options_destroy(fontoptions
->fontoptions
);
339 static zend_object_value
CairoFontOptions_object_new(zend_class_entry
*ce
)
341 zend_object_value retval
;
342 fontoptions_object
*fontoptions
;
344 fontoptions
=emalloc(sizeof(fontoptions_object
));
345 memset(fontoptions
,0,sizeof(fontoptions_object
));
346 fontoptions
->std
.ce
= ce
;
347 ALLOC_HASHTABLE(fontoptions
->std
.properties
);
348 zend_hash_init(fontoptions
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
349 zend_hash_copy(fontoptions
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
350 retval
.handle
= zend_objects_store_put(fontoptions
, NULL
, (zend_objects_free_object_storage_t
)CairoFontOptions_object_dtor
, NULL TSRMLS_CC
);
351 retval
.handlers
= &CairoFontOptions_handlers
;
356 static void class_init_CairoFontOptions(void)
360 INIT_CLASS_ENTRY(ce
, "CairoFontOptions", CairoFontOptions_methods
);
361 CairoFontOptions_ce_ptr
= zend_register_internal_class(&ce
);
362 CairoFontOptions_ce_ptr
->create_object
= CairoFontOptions_object_new
;
363 memcpy(&CairoFontOptions_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
364 CairoFontOptions_handlers
.clone_obj
= NULL
;
367 /* }}} Class CairoFontOptions */
370 /* {{{ Class CairoScaledFont */
372 static zend_class_entry
* CairoScaledFont_ce_ptr
= NULL
;
377 /* {{{ proto void construct(object ff, object mx1, object mx2, object fo)
379 PHP_METHOD(CairoScaledFont
, __construct
)
381 zend_class_entry
* _this_ce
;
391 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "oooo", &ff
, &mx1
, &mx2
, &fo
) == FAILURE
) {
395 _this_zval
= getThis();
396 _this_ce
= Z_OBJCE_P(_this_zval
);
397 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
398 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(ff TSRMLS_CC
);
399 matrix_object
*mobj1
= (matrix_object
*)zend_objects_get_address(mx1 TSRMLS_CC
);
400 matrix_object
*mobj2
= (matrix_object
*)zend_objects_get_address(mx2 TSRMLS_CC
);
401 fontoptions_object
*foobj
= (fontoptions_object
*)zend_objects_get_address(fo TSRMLS_CC
);
402 curr
->scaledfont
= cairo_scaled_font_create(ffobj
->fontface
, &mobj1
->matrix
, &mobj2
->matrix
, foobj
->fontoptions
);
405 /* }}} __construct */
409 /* {{{ proto array extents()
411 PHP_METHOD(CairoScaledFont
, extents
)
413 zend_class_entry
* _this_ce
;
415 zval
* _this_zval
= NULL
;
417 cairo_font_extents_t e
;
419 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
423 _this_ce
= Z_OBJCE_P(_this_zval
);
424 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
425 cairo_scaled_font_extents(curr
->scaledfont
, &e
);
427 phpCAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
428 array_init(return_value
);
429 add_assoc_double(return_value
, "ascent", e
.ascent
);
430 add_assoc_double(return_value
, "descent", e
.descent
);
431 add_assoc_double(return_value
, "height", e
.height
);
432 add_assoc_double(return_value
, "max_x_advance", e
.max_x_advance
);
433 add_assoc_double(return_value
, "max_y_advance", e
.max_y_advance
);
440 /* {{{ proto object getFontFace()
442 PHP_METHOD(CairoScaledFont
, getFontFace
)
444 zend_class_entry
* _this_ce
;
446 zval
* _this_zval
= NULL
;
450 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
454 _this_ce
= Z_OBJCE_P(_this_zval
);
455 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
457 object_init_ex(return_value
, CairoFontFace_ce_ptr
);
458 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(return_value
);
459 ffobj
->fontface
= cairo_font_face_reference(cairo_scaled_font_get_font_face(curr
->scaledfont
));
462 /* }}} getFontFace */
466 /* {{{ proto array textExtents(string str)
468 PHP_METHOD(CairoScaledFont
, textExtents
)
470 zend_class_entry
* _this_ce
;
472 zval
* _this_zval
= NULL
;
473 const char * str
= NULL
;
475 cairo_text_extents_t extents
;
479 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Os", &_this_zval
, CairoScaledFont_ce_ptr
, &str
, &str_len
) == FAILURE
) {
483 _this_ce
= Z_OBJCE_P(_this_zval
);
484 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
486 cairo_scaled_font_text_extents(curr
->scaledfont
, str
, &extents
);
487 phpCAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
489 array_init(return_value
);
490 add_assoc_double(return_value
, "x_bearing", extents
.x_bearing
);
491 add_assoc_double(return_value
, "y_bearing", extents
.y_bearing
);
492 add_assoc_double(return_value
, "width", extents
.width
);
493 add_assoc_double(return_value
, "height", extents
.height
);
494 add_assoc_double(return_value
, "x_advance", extents
.x_advance
);
495 add_assoc_double(return_value
, "y_advance", extents
.y_advance
);
498 /* }}} textExtents */
501 static zend_function_entry CairoScaledFont_methods
[] = {
502 PHP_ME(CairoScaledFont
, __construct
, CairoScaledFont____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
503 PHP_ME(CairoScaledFont
, extents
, NULL
, /**/ZEND_ACC_PUBLIC
)
504 PHP_ME(CairoScaledFont
, getFontFace
, NULL
, /**/ZEND_ACC_PUBLIC
)
505 PHP_ME(CairoScaledFont
, textExtents
, CairoScaledFont__text_extents_args
, /**/ZEND_ACC_PUBLIC
)
512 static zend_object_handlers CairoScaledFont_handlers
;
514 static void CairoScaledFont_object_dtor(void *object
)
516 scaledfont_object
*scaledfont
= (scaledfont_object
*)object
;
517 zend_hash_destroy(scaledfont
->std
.properties
);
518 FREE_HASHTABLE(scaledfont
->std
.properties
);
520 if(scaledfont
->scaledfont
){
521 cairo_scaled_font_destroy(scaledfont
->scaledfont
);
526 static zend_object_value
CairoScaledFont_object_new(zend_class_entry
*ce
)
528 zend_object_value retval
;
529 scaledfont_object
*scaledfont
;
531 scaledfont
=emalloc(sizeof(scaledfont_object
));
532 memset(scaledfont
,0,sizeof(scaledfont_object
));
533 scaledfont
->std
.ce
= ce
;
534 ALLOC_HASHTABLE(scaledfont
->std
.properties
);
535 zend_hash_init(scaledfont
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
536 zend_hash_copy(scaledfont
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
537 retval
.handle
= zend_objects_store_put(scaledfont
, NULL
, (zend_objects_free_object_storage_t
)CairoScaledFont_object_dtor
, NULL TSRMLS_CC
);
538 retval
.handlers
= &CairoScaledFont_handlers
;
543 static void class_init_CairoScaledFont(void)
547 INIT_CLASS_ENTRY(ce
, "CairoScaledFont", CairoScaledFont_methods
);
548 CairoScaledFont_ce_ptr
= zend_register_internal_class(&ce
);
549 CairoScaledFont_ce_ptr
->create_object
= CairoScaledFont_object_new
;
550 memcpy(&CairoScaledFont_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
551 CairoScaledFont_handlers
.clone_obj
= NULL
;
554 /* }}} Class CairoScaledFont */