Line data Source code
1 : /*
2 : +----------------------------------------------------------------------+
3 : | For PHP Version 8.2+ |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Author: Marcel Bolten <github@marcelbolten.de> |
16 : +----------------------------------------------------------------------+
17 : */
18 :
19 : #ifdef HAVE_CONFIG_H
20 : #include "config.h"
21 : #endif
22 :
23 : #include "php.h"
24 : #include "php_pango.h"
25 : #include "pango_cairo_font_map_arginfo.h"
26 :
27 : #include <string.h>
28 : #include "zend_exceptions.h"
29 :
30 : zend_class_entry *pango_ce_pango_cairo_font_map;
31 :
32 : static zend_object_handlers pango_cairo_font_map_object_handlers;
33 :
34 180 : pango_font_map_object *pango_cairo_font_map_fetch_object(zend_object *object)
35 : {
36 180 : return (pango_font_map_object *) ((char*)(object) - XtOffsetOf(pango_font_map_object, std));
37 : }
38 :
39 8 : PHP_PANGO_API zend_class_entry* php_pango_cairo_get_font_map_ce()
40 : {
41 8 : return pango_ce_pango_cairo_font_map;
42 : }
43 :
44 4 : PHP_PANGO_API PangoFontMap* pango_cairo_font_map_object_get_font_map(zval *zv)
45 : {
46 4 : pango_font_map_object *obj = Z_PANGO_CAIRO_FONT_MAP_P(zv);
47 4 : return obj->font_map;
48 : }
49 :
50 : /* {{{ */
51 3 : PHP_METHOD(PangoCairo_FontMap, __construct)
52 : {
53 : pango_font_map_object *font_map_object;
54 :
55 3 : ZEND_PARSE_PARAMETERS_NONE();
56 :
57 4 : font_map_object = Z_PANGO_CAIRO_FONT_MAP_P(getThis());
58 2 : font_map_object->font_map = pango_cairo_font_map_new();
59 2 : font_map_object->is_default = false;
60 : }
61 : /* }}} */
62 :
63 : /* {{{ */
64 80 : PHP_METHOD(PangoCairo_FontMap, getDefault)
65 : {
66 : pango_font_map_object *font_map_object;
67 :
68 80 : ZEND_PARSE_PARAMETERS_NONE();
69 :
70 79 : object_init_ex(return_value, pango_ce_pango_cairo_font_map);
71 79 : font_map_object = Z_PANGO_CAIRO_FONT_MAP_P(return_value);
72 79 : font_map_object->font_map = pango_cairo_font_map_get_default();
73 79 : font_map_object->is_default = true;
74 : }
75 : /* }}} */
76 :
77 : /* {{{ */
78 5 : PHP_METHOD(PangoCairo_FontMap, newForFontType)
79 : {
80 : zend_object *font_type_object;
81 : pango_font_map_object *font_map_object;
82 : cairo_font_type_t font_type;
83 :
84 5 : ZEND_PARSE_PARAMETERS_START(1, 1);
85 6 : Z_PARAM_OBJ_OF_CLASS(font_type_object, ce_cairo_fonttype)
86 6 : ZEND_PARSE_PARAMETERS_END();
87 :
88 :
89 2 : object_init_ex(return_value, pango_ce_pango_cairo_font_map);
90 2 : font_map_object = Z_PANGO_CAIRO_FONT_MAP_P(return_value);
91 2 : font_type = Z_LVAL_P(zend_enum_fetch_case_value(font_type_object));
92 2 : font_map_object->font_map = pango_cairo_font_map_new_for_font_type(font_type);
93 2 : font_map_object->is_default = false;
94 :
95 2 : if (!font_map_object->font_map) {
96 1 : zend_throw_exception_ex(
97 : pango_ce_pango_exception,
98 : 0,
99 : "Could not create new PangoCairo\\FontMap for Cairo\\FontType::%s",
100 2 : Z_STRVAL_P(zend_enum_fetch_case_name(font_type_object))
101 : );
102 1 : RETURN_THROWS();
103 : }
104 : }
105 : /* }}} */
106 :
107 : /* {{{ */
108 2 : PHP_METHOD(PangoCairo_FontMap, getFontType)
109 : {
110 : PangoFontMap* font_map;
111 : cairo_font_type_t font_type;
112 : zend_object *font_type_case;
113 :
114 2 : ZEND_PARSE_PARAMETERS_NONE();
115 :
116 2 : font_map = pango_cairo_font_map_object_get_font_map(getThis());
117 :
118 1 : zend_enum_get_case_by_value(
119 : &font_type_case, ce_cairo_fonttype,
120 1 : pango_cairo_font_map_get_font_type((PangoCairoFontMap *) font_map),
121 : NULL, false
122 : );
123 :
124 2 : RETURN_OBJ_COPY(font_type_case);
125 : }
126 : /* }}} */
127 :
128 : /* {{{ */
129 3 : PHP_METHOD(PangoCairo_FontMap, getResolution)
130 : {
131 : PangoFontMap* font_map;
132 :
133 3 : ZEND_PARSE_PARAMETERS_NONE();
134 :
135 4 : font_map = pango_cairo_font_map_object_get_font_map(getThis());
136 :
137 2 : RETURN_DOUBLE(pango_cairo_font_map_get_resolution((PangoCairoFontMap *) font_map));
138 : }
139 : /* }}} */
140 :
141 : /* {{{ */
142 4 : PHP_METHOD(PangoCairo_FontMap, setDefault)
143 : {
144 : zval *font_map_zv;
145 : pango_font_map_object *font_map_object;
146 :
147 4 : ZEND_PARSE_PARAMETERS_START(1, 1);
148 4 : Z_PARAM_OBJECT_OF_CLASS(font_map_zv, pango_ce_pango_cairo_font_map)
149 4 : ZEND_PARSE_PARAMETERS_END();
150 :
151 1 : font_map_object = Z_PANGO_CAIRO_FONT_MAP_P(font_map_zv);
152 :
153 1 : pango_cairo_font_map_set_default((PangoCairoFontMap *) font_map_object->font_map);
154 : }
155 : /* }}} */
156 :
157 : /* {{{ */
158 4 : PHP_METHOD(PangoCairo_FontMap, setResolution)
159 : {
160 : double factor;
161 : PangoFontMap* font_map;
162 :
163 4 : ZEND_PARSE_PARAMETERS_START(1, 1);
164 4 : Z_PARAM_DOUBLE(factor)
165 4 : ZEND_PARSE_PARAMETERS_END();
166 :
167 2 : font_map = pango_cairo_font_map_object_get_font_map(getThis());
168 :
169 1 : pango_cairo_font_map_set_resolution((PangoCairoFontMap *) font_map, factor);
170 : }
171 : /* }}} */
172 :
173 :
174 : /* ----------------------------------------------------------------
175 : \PangoCairo\FontMap Object management
176 : ------------------------------------------------------------------*/
177 :
178 : /* {{{ */
179 92 : static void pango_cairo_font_map_free_obj(zend_object *zobj)
180 : {
181 92 : pango_font_map_object *intern = pango_cairo_font_map_fetch_object(zobj);
182 :
183 92 : if (!intern) {
184 0 : return;
185 : }
186 :
187 92 : if (intern->font_map && !intern->is_default) {
188 3 : g_object_unref(intern->font_map);
189 : }
190 :
191 92 : zend_object_std_dtor(&intern->std);
192 : }
193 : /* }}} */
194 :
195 : /* {{{ */
196 92 : static zend_object* pango_cairo_font_map_obj_ctor(zend_class_entry *ce, pango_font_map_object **intern)
197 : {
198 92 : pango_font_map_object *object = ecalloc(1, sizeof(pango_font_map_object) + zend_object_properties_size(ce));
199 :
200 92 : zend_object_std_init(&object->std, ce);
201 :
202 92 : object->std.handlers = &pango_cairo_font_map_object_handlers;
203 92 : *intern = object;
204 :
205 92 : return &object->std;
206 : }
207 : /* }}} */
208 :
209 : /* {{{ */
210 92 : static zend_object* pango_cairo_font_map_create_object(zend_class_entry *ce)
211 : {
212 92 : pango_font_map_object *intern = NULL;
213 92 : zend_object *return_value = pango_cairo_font_map_obj_ctor(ce, &intern);
214 :
215 92 : object_properties_init(&intern->std, ce);
216 92 : return return_value;
217 : }
218 : /* }}} */
219 :
220 : /* {{{ PHP_MINIT_FUNCTION */
221 194 : PHP_MINIT_FUNCTION(pango_cairo_font_map)
222 : {
223 194 : memcpy(
224 : &pango_cairo_font_map_object_handlers,
225 : zend_get_std_object_handlers(),
226 : sizeof(zend_object_handlers)
227 : );
228 :
229 194 : pango_cairo_font_map_object_handlers.offset = XtOffsetOf(pango_font_map_object, std);
230 194 : pango_cairo_font_map_object_handlers.free_obj = pango_cairo_font_map_free_obj;
231 :
232 194 : pango_ce_pango_cairo_font_map = register_class_PangoCairo_FontMap(php_pango_get_font_map_ce());
233 194 : pango_ce_pango_cairo_font_map->create_object = pango_cairo_font_map_create_object;
234 :
235 194 : return SUCCESS;
236 : }
237 : /* }}} */
|