-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcairo_scaled_font.c
559 lines (478 loc) · 22.2 KB
/
cairo_scaled_font.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Elizabeth Smith <auroraeosrose@php.net> |
| Michael Maclean <mgdm@php.net> |
| Mark Skilbeck <markskilbeck@php.net> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "php_cairo.h"
zend_class_entry *cairo_ce_cairoscaledfont;
ZEND_BEGIN_ARG_INFO_EX(CairoScaledFont___construct_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, font_face)
ZEND_ARG_INFO(0, matrix)
ZEND_ARG_INFO(0, ctm)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoScaledFont_textExtents_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(CairoScaledFont_glyphExtents_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, glyphs)
ZEND_END_ARG_INFO()
/* {{{ proto CairoScaledFont cairo_scaled_font_create(CairoFontFace font_face[, CairoMatrix matrix, CairoMatrix ctm, CairoFontOptions options])
Creates a CairoScaledFont object from a font face and matrices that describe the size of the font and the environment in which it will be used */
PHP_FUNCTION(cairo_scaled_font_create)
{
zval *font_face_zval, *matrix_zval, *ctm_zval, *font_options_zval;
cairo_scaled_font_object *scaled_font_object;
cairo_font_face_object *font_face_object;
cairo_matrix_object *matrix_object, *ctm_object;
cairo_font_options_object *font_options_object;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOOO", &font_face_zval, cairo_ce_cairofontface,
&matrix_zval, cairo_ce_cairomatrix,
&ctm_zval, cairo_ce_cairomatrix,
&font_options_zval, cairo_ce_cairofontoptions) == FAILURE) {
return;
}
font_face_object = (cairo_font_face_object *)cairo_font_face_object_get(font_face_zval TSRMLS_CC);
matrix_object = (cairo_matrix_object *)cairo_matrix_object_get(matrix_zval TSRMLS_CC);
ctm_object = (cairo_matrix_object *)cairo_matrix_object_get(ctm_zval TSRMLS_CC);
font_options_object = (cairo_font_options_object *)cairo_font_options_object_get(font_options_zval TSRMLS_CC);
object_init_ex(return_value, cairo_ce_cairoscaledfont);
scaled_font_object = (cairo_scaled_font_object *)zend_object_store_get_object(return_value TSRMLS_CC);
scaled_font_object->scaled_font = cairo_scaled_font_create(font_face_object->font_face, matrix_object->matrix, ctm_object->matrix, font_options_object->font_options);
php_cairo_trigger_error(cairo_scaled_font_status(scaled_font_object->scaled_font) TSRMLS_CC);
/* we need to be able to get these zvals out later, so ref and store */
scaled_font_object->font_face = font_face_zval;
Z_ADDREF_P(font_face_zval);
scaled_font_object->matrix = matrix_zval;
Z_ADDREF_P(matrix_zval);
scaled_font_object->ctm = ctm_zval;
Z_ADDREF_P(ctm_zval);
scaled_font_object->font_options = font_options_zval;
Z_ADDREF_P(font_options_zval);
}
/* }}} */
/* {{{ proto void __construct(CairoFontFace font_face[, CairoMatrix matrix, CairoMatrix ctm, CairoFontOptions options])
Creates a CairoScaledFont object from a font face and matrices that describe the size of the font and the environment in which it will be used */
PHP_METHOD(CairoScaledFont, __construct)
{
zval *font_face_zval, *matrix_zval, *ctm_zval, *font_options_zval;
cairo_scaled_font_object *scaled_font_object;
cairo_font_face_object *font_face_object;
cairo_matrix_object *matrix_object, *ctm_object;
cairo_font_options_object *font_options_object;
PHP_CAIRO_ERROR_HANDLING(TRUE)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOOO", &font_face_zval, cairo_ce_cairofontface,
&matrix_zval, cairo_ce_cairomatrix,
&ctm_zval, cairo_ce_cairomatrix,
&font_options_zval, cairo_ce_cairofontoptions) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(TRUE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(TRUE)
font_face_object = (cairo_font_face_object *)cairo_font_face_object_get(font_face_zval TSRMLS_CC);
matrix_object = (cairo_matrix_object *)cairo_matrix_object_get(matrix_zval TSRMLS_CC);
ctm_object = (cairo_matrix_object *)cairo_matrix_object_get(ctm_zval TSRMLS_CC);
font_options_object = (cairo_font_options_object *)cairo_font_options_object_get(font_options_zval TSRMLS_CC);
scaled_font_object = (cairo_scaled_font_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
scaled_font_object->scaled_font = cairo_scaled_font_create(font_face_object->font_face, matrix_object->matrix, ctm_object->matrix, font_options_object->font_options);
php_cairo_throw_exception(cairo_scaled_font_status(scaled_font_object->scaled_font) TSRMLS_CC);
/* we need to be able to get these zvals out later, so ref and store */
scaled_font_object->font_face = font_face_zval;
Z_ADDREF_P(font_face_zval);
scaled_font_object->matrix = matrix_zval;
Z_ADDREF_P(matrix_zval);
scaled_font_object->ctm = ctm_zval;
Z_ADDREF_P(ctm_zval);
scaled_font_object->font_options = font_options_zval;
Z_ADDREF_P(font_options_zval);
}
/* }}} */
/* {{{ proto long cairo_scaled_font_status(CairoScaledFont object)
proto long CairoScaledFont->status()
Returns the current integer status of the CairoScaledFont */
PHP_FUNCTION(cairo_scaled_font_status)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
RETURN_LONG(cairo_scaled_font_status(scaled_font_object->scaled_font));
}
/* }}} */
/* {{{ proto array cairo_scaled_font_extents(CairoScaledFont object)
proto array CairoScaledFont->extents()
Gets the metrics for a scaled font in an assoc array
*/
PHP_FUNCTION(cairo_scaled_font_extents)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_font_extents_t extents;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
cairo_scaled_font_extents(scaled_font_object->scaled_font, &extents);
array_init(return_value);
add_assoc_double(return_value, "ascent", extents.ascent);
add_assoc_double(return_value, "descent", extents.descent);
add_assoc_double(return_value, "height", extents.height);
add_assoc_double(return_value, "max_x_advance", extents.max_x_advance);
add_assoc_double(return_value, "max_y_advance", extents.max_y_advance);
}
/* }}} */
/* {{{ proto array cairo_scaled_font_text_extents(CairoScaledFont object, string text)
proto array CairoScaledFont->textExtents(string text)
Gets the extents for a string of UTF8 text.
*/
PHP_FUNCTION(cairo_scaled_font_text_extents)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
char *text, *cairo_text;
int text_len;
cairo_text_extents_t extents;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&scaled_font_zval, cairo_ce_cairoscaledfont,
&text, &text_len ) == FAILURE) {
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
cairo_text = estrdup(text);
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
cairo_scaled_font_text_extents(scaled_font_object->scaled_font, cairo_text, &extents);
efree(cairo_text);
array_init(return_value);
add_assoc_double(return_value, "x_bearing", extents.x_bearing);
add_assoc_double(return_value, "y_bearing", extents.y_bearing);
add_assoc_double(return_value, "width", extents.width);
add_assoc_double(return_value, "height", extents.height);
add_assoc_double(return_value, "x_advance", extents.x_advance);
add_assoc_double(return_value, "y_advance", extents.y_advance);
}
/* }}} */
/* {{{ proto array cairo_scaled_font_glyph_extents(CairoScaledFont object, array glyphs)
proto array CairoScaledFont->glyphPath(array glyphs)
Gets the extents for an array of glyphs. The extents describe a user-space rectangle that encloses the "inked" portion of the glyphs. */
PHP_FUNCTION(cairo_scaled_font_glyph_extents)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
const cairo_glyph_t *glyphs = NULL;
long num_glyphs = 0;
cairo_text_extents_t extents;
zval * php_glyphs = NULL, **ppzval;
HashTable *glyphs_hash = NULL;
int i = 0;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa", &scaled_font_zval, cairo_ce_cairoscaledfont, &php_glyphs) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
/* Grab the zend hash */
glyphs_hash = Z_ARRVAL_P(php_glyphs);
/* iterate the array, each value inside MUST be an instance of CairoGlyph */
for(zend_hash_internal_pointer_reset(glyphs_hash); zend_hash_has_more_elements(glyphs_hash) == SUCCESS; zend_hash_move_forward(glyphs_hash)) {
if (zend_hash_get_current_data(glyphs_hash, (void **)&ppzval) == FAILURE) {
continue;
}
/* TODO: check here for is object and instanceof CairoGlyph, then rip the internal glyph out and stick it in the array
then increment the glyph count
if (Z_TYPE_PP(ppzval) != IS_DOUBLE) {
convert_to_double(*ppzval);
}
dashes_array[i++] = Z_DVAL_PP(ppzval);*/
}
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
cairo_scaled_font_glyph_extents(scaled_font_object->scaled_font, glyphs, num_glyphs, &extents);
array_init(return_value);
add_assoc_double(return_value, "x_bearing", extents.x_bearing);
add_assoc_double(return_value, "y_bearing", extents.y_bearing);
add_assoc_double(return_value, "width", extents.width);
add_assoc_double(return_value, "height", extents.height);
add_assoc_double(return_value, "x_advance", extents.x_advance);
add_assoc_double(return_value, "y_advance", extents.y_advance);
}
/* }}} */
/* {{{ proto CairoFontFace object cairo_scaled_font_get_font_face(CairoScaledFont object)
proto CairoFontFace object CairoScaledFont->getFontFace()
Retrieves the font face used to create the scaled font. */
PHP_FUNCTION(cairo_scaled_font_get_font_face)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_font_face_object *font_face_object;
cairo_font_face_t *font_face;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
/* Grab the font face properly */
font_face = cairo_scaled_font_get_font_face(scaled_font_object->scaled_font);
PHP_CAIRO_ERROR(cairo_scaled_font_status(scaled_font_object->scaled_font));
/* If we have a font face object stored, grab that zval to use */
if(scaled_font_object->font_face) {
zval_dtor(return_value);
*return_value = *scaled_font_object->font_face;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
object_init_ex(return_value, cairo_ce_cairotoyfontface);
}
font_face_object = (cairo_font_face_object *)zend_object_store_get_object(return_value TSRMLS_CC);
font_face_object->font_face = font_face;
}
/* }}} */
/* {{{ proto CairoFontOptions object cairo_scaled_font_get_font_options(CairoScaledFont object)
proto CairoFontOptions object CairoScaledFont->getFontOptions()
Retrieves the font options used to create the scaled font. */
PHP_FUNCTION(cairo_scaled_font_get_font_options)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_font_options_object *font_options_object;
cairo_font_options_t *font_options = NULL;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
/* Grab the font options properly */
cairo_scaled_font_get_font_options(scaled_font_object->scaled_font, font_options);
PHP_CAIRO_ERROR(cairo_scaled_font_status(scaled_font_object->scaled_font));
/* If we have a font options object stored, grab that zval to use */
if(scaled_font_object->font_options) {
zval_dtor(return_value);
*return_value = *scaled_font_object->font_options;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
object_init_ex(return_value, cairo_ce_cairofontoptions);
}
font_options_object = (cairo_font_options_object *)zend_object_store_get_object(return_value TSRMLS_CC);
font_options_object->font_options = font_options;
}
/* }}} */
/* {{{ proto CairoMatrix object cairo_scaled_font_get_font_matrix(CairoScaledFont object)
proto CairoMatrix object CairoScaledFont->getFontMatrix()
Returns the font matrix used when creating the scaled font */
PHP_FUNCTION(cairo_scaled_font_get_font_matrix)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_matrix_object *matrix_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
/* If we have a matrix object stored, grab that zval to use */
if(scaled_font_object->matrix) {
zval_dtor(return_value);
*return_value = *scaled_font_object->matrix;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
object_init_ex(return_value, cairo_ce_cairomatrix);
}
matrix_object = (cairo_matrix_object *)zend_object_store_get_object(return_value TSRMLS_CC);
matrix_object->matrix = ecalloc(sizeof(cairo_matrix_t), 1);
cairo_scaled_font_get_font_matrix(scaled_font_object->scaled_font, matrix_object->matrix);
}
/* }}} */
/* {{{ proto CairoMatrix object cairo_scaled_font_get_ctm (CairoScaledFont object)
proto CairoMatrix object CairoScaledFont->getCtm()
Returns the ctm matrix used when creating the scaled font */
PHP_FUNCTION(cairo_scaled_font_get_ctm)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_matrix_object *matrix_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
/* If we have a matrix object stored, grab that zval to use */
if(scaled_font_object->ctm) {
zval_dtor(return_value);
*return_value = *scaled_font_object->ctm;
zval_copy_ctor(return_value);
Z_SET_REFCOUNT_P(return_value, 1);
/* Otherwise we spawn a new object */
} else {
object_init_ex(return_value, cairo_ce_cairomatrix);
}
matrix_object = (cairo_matrix_object *)zend_object_store_get_object(return_value TSRMLS_CC);
matrix_object->matrix = ecalloc(sizeof(cairo_matrix_t), 1);
cairo_scaled_font_get_ctm(scaled_font_object->scaled_font, matrix_object->matrix);
}
/* }}} */
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)
/* {{{ proto CairoMatrix object cairo_scaled_font_get_scale_matrix (CairoScaledFont object)
proto CairoMatrix object CairoScaledFont->getScaleMatrix()
The scale matrix is product of the font matrix and the ctm associated with the scaled font, and hence is the matrix mapping from font space to device space */
PHP_FUNCTION(cairo_scaled_font_get_scale_matrix)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
cairo_matrix_object *matrix_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
/* This is never stored in the object, but created every time */
object_init_ex(return_value, cairo_ce_cairomatrix);
matrix_object = (cairo_matrix_object *)zend_object_store_get_object(return_value TSRMLS_CC);
matrix_object->matrix = ecalloc(sizeof(cairo_matrix_t), 1);
cairo_scaled_font_get_scale_matrix(scaled_font_object->scaled_font, matrix_object->matrix);
}
/* }}} */
#endif
/* {{{ proto long cairo_scaled_font_get_type(CairoScaledFont object)
proto long CairoScaledFont->getType()
Returns the current integer type of the CairoScaledFont backend */
PHP_FUNCTION(cairo_scaled_font_get_type)
{
zval *scaled_font_zval = NULL;
cairo_scaled_font_object *scaled_font_object;
PHP_CAIRO_ERROR_HANDLING(FALSE)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &scaled_font_zval, cairo_ce_cairoscaledfont) == FAILURE) {
PHP_CAIRO_RESTORE_ERRORS(FALSE)
return;
}
PHP_CAIRO_RESTORE_ERRORS(FALSE)
scaled_font_object = (cairo_scaled_font_object *) cairo_scaled_font_object_get(scaled_font_zval TSRMLS_CC);
RETURN_LONG(cairo_scaled_font_get_type(scaled_font_object->scaled_font));
}
/* }}} */
/* {{{ cairo_scaled_font_methods[] */
const zend_function_entry cairo_scaled_font_methods[] = {
PHP_ME(CairoScaledFont, __construct, CairoScaledFont___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME_MAPPING(status, cairo_scaled_font_status, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(extents, cairo_scaled_font_extents, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(textExtents, cairo_scaled_font_text_extents, CairoScaledFont_textExtents_args, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(glyphExtents, cairo_scaled_font_glyph_extents, CairoScaledFont_glyphExtents_args, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getFontFace, cairo_scaled_font_get_font_face, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getFontOptions, cairo_scaled_font_get_font_options, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getFontMatrix, cairo_scaled_font_get_font_matrix , NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getCtm, cairo_scaled_font_get_ctm, NULL, ZEND_ACC_PUBLIC)
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0)
PHP_ME_MAPPING(getScaleMatrix, cairo_scaled_font_get_scale_matrix, NULL, ZEND_ACC_PUBLIC)
#endif
PHP_ME_MAPPING(getType, cairo_scaled_font_get_type , NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
/* }}} */
static void cairo_scaled_font_object_destroy(void *object TSRMLS_DC)
{
cairo_scaled_font_object *scaled_font = (cairo_scaled_font_object *)object;
zend_hash_destroy(scaled_font->std.properties);
FREE_HASHTABLE(scaled_font->std.properties);
if(scaled_font->font_face != NULL) {
Z_DELREF_P(scaled_font->font_face);
scaled_font->font_face = NULL;
}
if(scaled_font->matrix != NULL) {
Z_DELREF_P(scaled_font->matrix);
scaled_font->matrix = NULL;
}
if(scaled_font->ctm != NULL) {
Z_DELREF_P(scaled_font->ctm);
scaled_font->ctm = NULL;
}
if(scaled_font->font_options != NULL) {
Z_DELREF_P(scaled_font->font_options);
scaled_font->font_options = NULL;
}
if(scaled_font->scaled_font){
cairo_scaled_font_destroy(scaled_font->scaled_font);
}
efree(object);
}
static zend_object_value cairo_scaled_font_object_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
cairo_scaled_font_object *scaled_font;
#if PHP_VERSION_ID < 50399
zval *temp;
#endif
scaled_font = ecalloc(1, sizeof(cairo_scaled_font_object));
scaled_font->std.ce = ce;
scaled_font->font_face = NULL;
scaled_font->matrix = NULL;
scaled_font->ctm = NULL;
scaled_font->font_options = NULL;
ALLOC_HASHTABLE(scaled_font->std.properties);
zend_hash_init(scaled_font->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
#if PHP_VERSION_ID < 50399
zend_hash_copy(scaled_font->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
#else
object_properties_init(&scaled_font->std, ce);
#endif
retval.handle = zend_objects_store_put(scaled_font, NULL, (zend_objects_free_object_storage_t)cairo_scaled_font_object_destroy, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(cairo_scaled_font)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "CairoScaledFont", cairo_scaled_font_methods);
cairo_ce_cairoscaledfont = zend_register_internal_class(&ce TSRMLS_CC);
cairo_ce_cairoscaledfont->create_object = cairo_scaled_font_object_new;
return SUCCESS;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/