2 /* {{{ Class CairoFontFace */
4 static zend_class_entry
* CairoFontFace_ce_ptr
= NULL
;
9 /* {{{ proto void construct()
11 PHP_METHOD(CairoFontFace
, __construct
)
17 if (ZEND_NUM_ARGS()>0) {
22 php_error(E_WARNING
,"Please use Context.get_font_face()");
30 static zend_function_entry CairoFontFace_methods
[] = {
31 PHP_ME(CairoFontFace
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
38 static zend_object_handlers CairoFontFace_handlers
;
40 static void CairoFontFace_object_dtor(void *object
)
42 fontface_object
*fontface
= (fontface_object
*)object
;
43 zend_hash_destroy(fontface
->std
.properties
);
44 FREE_HASHTABLE(fontface
->std
.properties
);
46 if(fontface
->fontface
){
47 cairo_font_face_destroy(fontface
->fontface
);
52 static zend_object_value
CairoFontFace_object_new(zend_class_entry
*ce
)
54 zend_object_value retval
;
55 fontface_object
*fontface
;
57 fontface
= emalloc(sizeof(fontface_object
));
58 memset(fontface
,0,sizeof(fontface_object
));
59 fontface
->std
.ce
= ce
;
60 ALLOC_HASHTABLE(fontface
->std
.properties
);
61 zend_hash_init(fontface
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
62 zend_hash_copy(fontface
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
63 retval
.handle
= zend_objects_store_put(fontface
, NULL
, (zend_objects_free_object_storage_t
)CairoFontFace_object_dtor
, NULL TSRMLS_CC
);
64 retval
.handlers
= &CairoFontFace_handlers
;
69 static void class_init_CairoFontFace(void)
73 INIT_CLASS_ENTRY(ce
, "CairoFontFace", CairoFontFace_methods
);
74 CairoFontFace_ce_ptr
= zend_register_internal_class(&ce
);
75 CairoFontFace_ce_ptr
->create_object
= CairoFontFace_object_new
;
76 memcpy(&CairoFontFace_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
77 CairoFontFace_handlers
.clone_obj
= NULL
;
80 /* }}} Class CairoFontFace */
83 /* {{{ Class CairoFontOptions */
85 static zend_class_entry
* CairoFontOptions_ce_ptr
= NULL
;
90 /* {{{ proto void construct()
92 PHP_METHOD(CairoFontOptions
, __construct
)
98 if (ZEND_NUM_ARGS()>0) {
101 _this_zval
= getThis();
102 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
103 curr
->fontoptions
= cairo_font_options_create();
106 /* }}} __construct */
110 /* {{{ proto int getAntialias()
112 PHP_METHOD(CairoFontOptions
, getAntialias
)
115 zval
* _this_zval
= NULL
;
119 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
123 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
124 x
= cairo_font_options_get_antialias(curr
->fontoptions
);
128 /* }}} getAntialias */
132 /* {{{ proto int getHintMetrics()
134 PHP_METHOD(CairoFontOptions
, getHintMetrics
)
137 zval
* _this_zval
= NULL
;
141 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
146 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
148 x
= cairo_font_options_get_hint_metrics(curr
->fontoptions
);
151 /* }}} getHintMetrics */
155 /* {{{ proto int getHintStyle()
157 PHP_METHOD(CairoFontOptions
, getHintStyle
)
160 zval
* _this_zval
= NULL
;
164 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
168 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
170 x
= cairo_font_options_get_hint_style(curr
->fontoptions
);
173 /* }}} getHintStyle */
177 /* {{{ proto int getSubpixelOrder()
179 PHP_METHOD(CairoFontOptions
, getSubpixelOrder
)
182 zval
* _this_zval
= NULL
;
186 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoFontOptions_ce_ptr
) == FAILURE
) {
190 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
192 x
= cairo_font_options_get_subpixel_order(curr
->fontoptions
);
195 /* }}} getSubpixelOrder */
199 /* {{{ proto void setAntialias([int aa])
201 PHP_METHOD(CairoFontOptions
, setAntialias
)
204 zval
* _this_zval
= NULL
;
205 cairo_antialias_t aa
= CAIRO_ANTIALIAS_DEFAULT
;
209 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &aa
) == FAILURE
) {
213 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
214 cairo_font_options_set_antialias(curr
->fontoptions
, aa
);
215 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
218 /* }}} setAntialias */
222 /* {{{ proto void setHintMetrics([int hm])
224 PHP_METHOD(CairoFontOptions
, setHintMetrics
)
227 zval
* _this_zval
= NULL
;
228 cairo_hint_metrics_t hm
= CAIRO_HINT_METRICS_DEFAULT
;
232 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hm
) == FAILURE
) {
237 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
238 cairo_font_options_set_hint_metrics(curr
->fontoptions
, hm
);
239 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
242 /* }}} setHintMetrics */
246 /* {{{ proto void setHintStyle([int hs])
248 PHP_METHOD(CairoFontOptions
, setHintStyle
)
251 zval
* _this_zval
= NULL
;
252 cairo_hint_style_t hs
= CAIRO_HINT_STYLE_DEFAULT
;
256 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &hs
) == FAILURE
) {
260 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
261 cairo_font_options_set_hint_style(curr
->fontoptions
, hs
);
262 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
265 /* }}} setHintStyle */
269 /* {{{ proto void setSubpixelOrder([int so])
271 PHP_METHOD(CairoFontOptions
, setSubpixelOrder
)
274 zval
* _this_zval
= NULL
;
275 cairo_subpixel_order_t so
= CAIRO_SUBPIXEL_ORDER_DEFAULT
;
279 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O|l", &_this_zval
, CairoFontOptions_ce_ptr
, &so
) == FAILURE
) {
283 fontoptions_object
*curr
= (fontoptions_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
284 cairo_font_options_set_subpixel_order(curr
->fontoptions
, so
);
285 PHP_CAIRO_FONTOPTIONS_ERROR(curr
->fontoptions
);
288 /* }}} setSubpixelOrder */
291 static zend_function_entry CairoFontOptions_methods
[] = {
292 PHP_ME(CairoFontOptions
, __construct
, NULL
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
293 PHP_ME(CairoFontOptions
, getAntialias
, NULL
, /**/ZEND_ACC_PUBLIC
)
294 PHP_ME(CairoFontOptions
, getHintMetrics
, NULL
, /**/ZEND_ACC_PUBLIC
)
295 PHP_ME(CairoFontOptions
, getHintStyle
, NULL
, /**/ZEND_ACC_PUBLIC
)
296 PHP_ME(CairoFontOptions
, getSubpixelOrder
, NULL
, /**/ZEND_ACC_PUBLIC
)
297 PHP_ME(CairoFontOptions
, setAntialias
, CairoFontOptions__set_antialias_args
, /**/ZEND_ACC_PUBLIC
)
298 PHP_ME(CairoFontOptions
, setHintMetrics
, CairoFontOptions__set_hint_metrics_args
, /**/ZEND_ACC_PUBLIC
)
299 PHP_ME(CairoFontOptions
, setHintStyle
, CairoFontOptions__set_hint_style_args
, /**/ZEND_ACC_PUBLIC
)
300 PHP_ME(CairoFontOptions
, setSubpixelOrder
, CairoFontOptions__set_subpixel_order_args
, /**/ZEND_ACC_PUBLIC
)
307 static zend_object_handlers CairoFontOptions_handlers
;
309 static void CairoFontOptions_object_dtor(void *object
)
311 fontoptions_object
*fontoptions
= (fontoptions_object
*)object
;
312 zend_hash_destroy(fontoptions
->std
.properties
);
313 FREE_HASHTABLE(fontoptions
->std
.properties
);
315 if(fontoptions
->fontoptions
){
316 cairo_font_options_destroy(fontoptions
->fontoptions
);
321 static zend_object_value
CairoFontOptions_object_new(zend_class_entry
*ce
)
323 zend_object_value retval
;
324 fontoptions_object
*fontoptions
;
326 fontoptions
=emalloc(sizeof(fontoptions_object
));
327 memset(fontoptions
,0,sizeof(fontoptions_object
));
328 fontoptions
->std
.ce
= ce
;
329 ALLOC_HASHTABLE(fontoptions
->std
.properties
);
330 zend_hash_init(fontoptions
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
331 zend_hash_copy(fontoptions
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
332 retval
.handle
= zend_objects_store_put(fontoptions
, NULL
, (zend_objects_free_object_storage_t
)CairoFontOptions_object_dtor
, NULL TSRMLS_CC
);
333 retval
.handlers
= &CairoFontOptions_handlers
;
338 static void class_init_CairoFontOptions(void)
342 INIT_CLASS_ENTRY(ce
, "CairoFontOptions", CairoFontOptions_methods
);
343 CairoFontOptions_ce_ptr
= zend_register_internal_class(&ce
);
344 CairoFontOptions_ce_ptr
->create_object
= CairoFontOptions_object_new
;
345 memcpy(&CairoFontOptions_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
346 CairoFontOptions_handlers
.clone_obj
= NULL
;
349 /* }}} Class CairoFontOptions */
352 /* {{{ Class CairoScaledFont */
354 static zend_class_entry
* CairoScaledFont_ce_ptr
= NULL
;
359 /* {{{ proto void construct(object ff, object mx1, object mx2, object fo)
361 PHP_METHOD(CairoScaledFont
, __construct
)
372 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "oooo", &ff
, &mx1
, &mx2
, &fo
) == FAILURE
) {
376 _this_zval
= getThis();
377 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
378 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(ff TSRMLS_CC
);
379 matrix_object
*mobj1
= (matrix_object
*)zend_objects_get_address(mx1 TSRMLS_CC
);
380 matrix_object
*mobj2
= (matrix_object
*)zend_objects_get_address(mx2 TSRMLS_CC
);
381 fontoptions_object
*foobj
= (fontoptions_object
*)zend_objects_get_address(fo TSRMLS_CC
);
382 curr
->scaledfont
= cairo_scaled_font_create(ffobj
->fontface
, &mobj1
->matrix
, &mobj2
->matrix
, foobj
->fontoptions
);
385 /* }}} __construct */
389 /* {{{ proto array extents()
391 PHP_METHOD(CairoScaledFont
, extents
)
394 zval
* _this_zval
= NULL
;
396 cairo_font_extents_t e
;
398 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
402 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
403 cairo_scaled_font_extents(curr
->scaledfont
, &e
);
405 PHP_CAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
406 array_init(return_value
);
407 add_assoc_double(return_value
, "ascent", e
.ascent
);
408 add_assoc_double(return_value
, "descent", e
.descent
);
409 add_assoc_double(return_value
, "height", e
.height
);
410 add_assoc_double(return_value
, "max_x_advance", e
.max_x_advance
);
411 add_assoc_double(return_value
, "max_y_advance", e
.max_y_advance
);
418 /* {{{ proto object getFontFace()
420 PHP_METHOD(CairoScaledFont
, getFontFace
)
423 zval
* _this_zval
= NULL
;
427 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoScaledFont_ce_ptr
) == FAILURE
) {
431 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
433 object_init_ex(return_value
, CairoFontFace_ce_ptr
);
434 fontface_object
*ffobj
= (fontface_object
*)zend_objects_get_address(return_value
);
435 ffobj
->fontface
= cairo_font_face_reference(cairo_scaled_font_get_font_face(curr
->scaledfont
));
438 /* }}} getFontFace */
442 /* {{{ proto array textExtents(string str)
444 PHP_METHOD(CairoScaledFont
, textExtents
)
447 zval
* _this_zval
= NULL
;
448 const char * str
= NULL
;
450 cairo_text_extents_t extents
;
454 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Os", &_this_zval
, CairoScaledFont_ce_ptr
, &str
, &str_len
) == FAILURE
) {
458 scaledfont_object
*curr
= (scaledfont_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
460 cairo_scaled_font_text_extents(curr
->scaledfont
, str
, &extents
);
461 PHP_CAIRO_SCALEDFONT_ERROR(curr
->scaledfont
);
463 array_init(return_value
);
464 add_assoc_double(return_value
, "x_bearing", extents
.x_bearing
);
465 add_assoc_double(return_value
, "y_bearing", extents
.y_bearing
);
466 add_assoc_double(return_value
, "width", extents
.width
);
467 add_assoc_double(return_value
, "height", extents
.height
);
468 add_assoc_double(return_value
, "x_advance", extents
.x_advance
);
469 add_assoc_double(return_value
, "y_advance", extents
.y_advance
);
472 /* }}} textExtents */
475 static zend_function_entry CairoScaledFont_methods
[] = {
476 PHP_ME(CairoScaledFont
, __construct
, CairoScaledFont____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
477 PHP_ME(CairoScaledFont
, extents
, NULL
, /**/ZEND_ACC_PUBLIC
)
478 PHP_ME(CairoScaledFont
, getFontFace
, NULL
, /**/ZEND_ACC_PUBLIC
)
479 PHP_ME(CairoScaledFont
, textExtents
, CairoScaledFont__text_extents_args
, /**/ZEND_ACC_PUBLIC
)
486 static zend_object_handlers CairoScaledFont_handlers
;
488 static void CairoScaledFont_object_dtor(void *object
)
490 scaledfont_object
*scaledfont
= (scaledfont_object
*)object
;
491 zend_hash_destroy(scaledfont
->std
.properties
);
492 FREE_HASHTABLE(scaledfont
->std
.properties
);
494 if(scaledfont
->scaledfont
){
495 cairo_scaled_font_destroy(scaledfont
->scaledfont
);
500 static zend_object_value
CairoScaledFont_object_new(zend_class_entry
*ce
)
502 zend_object_value retval
;
503 scaledfont_object
*scaledfont
;
505 scaledfont
=emalloc(sizeof(scaledfont_object
));
506 memset(scaledfont
,0,sizeof(scaledfont_object
));
507 scaledfont
->std
.ce
= ce
;
508 ALLOC_HASHTABLE(scaledfont
->std
.properties
);
509 zend_hash_init(scaledfont
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
510 zend_hash_copy(scaledfont
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
511 retval
.handle
= zend_objects_store_put(scaledfont
, NULL
, (zend_objects_free_object_storage_t
)CairoScaledFont_object_dtor
, NULL TSRMLS_CC
);
512 retval
.handlers
= &CairoScaledFont_handlers
;
517 static void class_init_CairoScaledFont(void)
521 INIT_CLASS_ENTRY(ce
, "CairoScaledFont", CairoScaledFont_methods
);
522 CairoScaledFont_ce_ptr
= zend_register_internal_class(&ce
);
523 CairoScaledFont_ce_ptr
->create_object
= CairoScaledFont_object_new
;
524 memcpy(&CairoScaledFont_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
525 CairoScaledFont_handlers
.clone_obj
= NULL
;
528 /* }}} Class CairoScaledFont */