forked from gtkforphp/pango
/
pango_context.c
269 lines (229 loc) · 10.2 KB
/
pango_context.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
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2008 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: Michael Maclean <mgdm@php.net> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_pango.h"
zend_class_entry *pango_ce_pangocontext;
zend_class_entry *pango_ce_pangodirection;
#ifdef PANGO_VERSION
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0)
zend_class_entry *pango_ce_pangogravity;
zend_class_entry *pango_ce_pangogravityhint;
#endif
#endif
PHP_PANGO_API zend_class_entry* php_pango_get_context_ce() {
return pango_ce_pangocontext;
}
#ifdef PANGO_VERSION
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0)
/* {{{ proto void pango_context_set_base_gravity(PangoContext context, int gravity)
proto void PangoContext::setBaseGravity(int gravity)
Sets the gravity to be used to lay out the text */
PHP_FUNCTION(pango_context_set_base_gravity)
{
zval *context_zval = NULL;
pango_context_object *context_object;
long gravity;
PHP_PANGO_ERROR_HANDLING(FALSE)
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, pango_ce_pangocontext, &gravity) == FAILURE) {
PHP_PANGO_RESTORE_ERRORS(FALSE)
return;
}
PHP_PANGO_RESTORE_ERRORS(FALSE)
context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC);
pango_context_set_base_gravity(context_object->context, gravity);
}
/* }}} */
/* {{{ proto void pango_context_get_base_gravity(PangoContext context, int gravity)
proto void PangoContext::setBaseGravity(int gravity)
Gets the gravity to be used to lay out the text */
PHP_FUNCTION(pango_context_get_base_gravity)
{
zval *context_zval = NULL;
pango_context_object *context_object;
PHP_PANGO_ERROR_HANDLING(FALSE)
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) {
PHP_PANGO_RESTORE_ERRORS(FALSE)
return;
}
PHP_PANGO_RESTORE_ERRORS(FALSE)
context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC);
RETURN_LONG(pango_context_get_base_gravity(context_object->context));
}
/* }}} */
/* {{{ proto void pango_context_get_gravity(PangoContext context, int gravity)
proto void PangoContext::getGravity(int gravity)
Gets the gravity to be used to lay out the text */
PHP_FUNCTION(pango_context_get_gravity)
{
zval *context_zval = NULL;
pango_context_object *context_object;
PHP_PANGO_ERROR_HANDLING(FALSE)
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) {
PHP_PANGO_RESTORE_ERRORS(FALSE)
return;
}
PHP_PANGO_RESTORE_ERRORS(FALSE)
context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC);
RETURN_LONG(pango_context_get_gravity(context_object->context));
}
/* }}} */
/* {{{ proto void pango_context_set_gravity_hint(PangoContext context, int gravityHint)
proto void PangoContext::setGravityHint(int gravityHint)
Sets the gravity to be used to lay out the text */
PHP_FUNCTION(pango_context_set_gravity_hint)
{
zval *context_zval = NULL;
pango_context_object *context_object;
long gravity;
PHP_PANGO_ERROR_HANDLING(FALSE)
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, pango_ce_pangocontext, &gravity) == FAILURE) {
PHP_PANGO_RESTORE_ERRORS(FALSE)
return;
}
PHP_PANGO_RESTORE_ERRORS(FALSE)
context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC);
pango_context_set_gravity_hint(context_object->context, gravity);
}
/* }}} */
/* {{{ proto void pango_context_get_gravity_hint(PangoContext context)
proto void PangoContext::getGravityHint()
Gets the gravity hint to be used to lay out the text */
PHP_FUNCTION(pango_context_get_gravity_hint)
{
zval *context_zval = NULL;
pango_context_object *context_object;
PHP_PANGO_ERROR_HANDLING(FALSE)
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) {
PHP_PANGO_RESTORE_ERRORS(FALSE)
return;
}
PHP_PANGO_RESTORE_ERRORS(FALSE)
context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC);
RETURN_LONG(pango_context_get_gravity_hint(context_object->context));
}
/* }}} */
#endif
#endif
/* {{{ Object creation/destruction functions */
static void pango_context_object_destroy(void *object TSRMLS_DC)
{
pango_context_object *context = (pango_context_object *)object;
zend_hash_destroy(context->std.properties);
FREE_HASHTABLE(context->std.properties);
if(context->context){
g_object_unref(context->context);
}
efree(object);
}
static zend_object_value pango_context_object_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
pango_context_object *context;
zval *temp;
context = ecalloc(1, sizeof(pango_context_object));
context->std.ce = ce;
context->context = NULL;
ALLOC_HASHTABLE(context->std.properties);
zend_hash_init(context->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
#if PHP_VERSION_ID < 50399
zend_hash_copy(context->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
#else
object_properties_init(&(context->std),ce);
#endif
retval.handle = zend_objects_store_put(context, NULL, (zend_objects_free_object_storage_t)pango_context_object_destroy, NULL TSRMLS_CC);
retval.handlers = &pango_std_object_handlers;
return retval;
}
/* }}} */
const zend_function_entry pango_context_methods[] = {
#ifdef PANGO_VERSION
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0)
PHP_ME_MAPPING(setBaseGravity, pango_context_set_base_gravity, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getBaseGravity, pango_context_get_base_gravity, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getGravity, pango_context_get_gravity, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(setGravityHint, pango_context_set_gravity_hint, NULL, ZEND_ACC_PUBLIC)
PHP_ME_MAPPING(getGravityHint, pango_context_get_gravity_hint, NULL, ZEND_ACC_PUBLIC)
#endif
#endif
{ NULL, NULL, NULL }
};
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pango_context)
{
zend_class_entry context_ce;
zend_class_entry direction_ce;
#ifdef PANGO_VERSION
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0)
zend_class_entry gravity_ce;
zend_class_entry gravityhint_ce;
#endif
#endif
INIT_CLASS_ENTRY(context_ce, "PangoContext", pango_context_methods);
pango_ce_pangocontext = zend_register_internal_class(&context_ce TSRMLS_CC);
pango_ce_pangocontext->create_object = pango_context_object_new;
INIT_CLASS_ENTRY(direction_ce, "PangoDirection", NULL);
pango_ce_pangodirection = zend_register_internal_class(&direction_ce TSRMLS_CC);
pango_ce_pangodirection->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
#define REGISTER_PANGO_DIRECTION_LONG_CONST(const_name, value) \
zend_declare_class_constant_long(pango_ce_pangodirection, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \
REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT);
REGISTER_PANGO_DIRECTION_LONG_CONST("LTR", PANGO_DIRECTION_LTR);
REGISTER_PANGO_DIRECTION_LONG_CONST("RTL", PANGO_DIRECTION_RTL);
REGISTER_PANGO_DIRECTION_LONG_CONST("TTB_LTR", PANGO_DIRECTION_TTB_LTR);
REGISTER_PANGO_DIRECTION_LONG_CONST("TTB_RTL", PANGO_DIRECTION_TTB_RTL);
REGISTER_PANGO_DIRECTION_LONG_CONST("WEAK_LTR", PANGO_DIRECTION_WEAK_LTR);
REGISTER_PANGO_DIRECTION_LONG_CONST("WEAK_RTL", PANGO_DIRECTION_WEAK_RTL);
REGISTER_PANGO_DIRECTION_LONG_CONST("NEUTRAL", PANGO_DIRECTION_NEUTRAL);
#ifdef PANGO_VERSION
#if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0)
INIT_CLASS_ENTRY(gravity_ce, "PangoGravity", NULL);
pango_ce_pangogravity = zend_register_internal_class(&gravity_ce TSRMLS_CC);
pango_ce_pangogravity->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
#define REGISTER_PANGO_GRAVITY_LONG_CONST(const_name, value) \
zend_declare_class_constant_long(pango_ce_pangogravity, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \
REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT);
REGISTER_PANGO_GRAVITY_LONG_CONST("SOUTH", PANGO_GRAVITY_SOUTH);
REGISTER_PANGO_GRAVITY_LONG_CONST("EAST", PANGO_GRAVITY_EAST);
REGISTER_PANGO_GRAVITY_LONG_CONST("NORTH", PANGO_GRAVITY_NORTH);
REGISTER_PANGO_GRAVITY_LONG_CONST("WEST", PANGO_GRAVITY_WEST);
REGISTER_PANGO_GRAVITY_LONG_CONST("AUTO", PANGO_GRAVITY_AUTO);
INIT_CLASS_ENTRY(gravityhint_ce, "PangoGravityHint", NULL);
pango_ce_pangogravityhint = zend_register_internal_class(&gravityhint_ce TSRMLS_CC);
pango_ce_pangogravityhint->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
#define REGISTER_PANGO_GRAVITY_HINT_LONG_CONST(const_name, value) \
zend_declare_class_constant_long(pango_ce_pangogravityhint, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \
REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT);
REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("NATURAL", PANGO_GRAVITY_HINT_NATURAL);
REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("STRONG", PANGO_GRAVITY_HINT_STRONG);
REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("LINE", PANGO_GRAVITY_HINT_LINE);
#endif
#endif
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
*/