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 "font_face_arginfo.h"
26 :
27 : #include <string.h>
28 : #include "zend_exceptions.h"
29 :
30 : zend_class_entry *pango_ce_pango_font_face;
31 :
32 : static zend_object_handlers pango_font_face_object_handlers;
33 :
34 32 : pango_font_face_object *pango_font_face_fetch_object(zend_object *object)
35 : {
36 32 : return (pango_font_face_object *) ((char*)(object) - XtOffsetOf(pango_font_face_object, std));
37 : }
38 :
39 13 : PHP_PANGO_API zend_class_entry* php_pango_get_font_face_ce()
40 : {
41 13 : return pango_ce_pango_font_face;
42 : }
43 :
44 6 : PHP_PANGO_API PangoFontFace* pango_font_face_object_get_font_face(zval *zv)
45 : {
46 6 : pango_font_face_object *obj = Z_PANGO_FONT_FACE_P(zv);
47 6 : return obj->font_face;
48 : }
49 :
50 : /* {{{ */
51 2 : PHP_METHOD(Pango_FontFace, describe)
52 : {
53 : PangoFontDescription *font_desc;
54 : pango_font_description_object *font_description_object;
55 :
56 2 : ZEND_PARSE_PARAMETERS_NONE();
57 :
58 0 : font_desc = pango_font_face_describe(
59 2 : pango_font_face_object_get_font_face(getThis())
60 : );
61 :
62 1 : object_init_ex(return_value, php_pango_get_font_description_ce());
63 1 : font_description_object = Z_PANGO_FONT_DESC_P(return_value);
64 1 : font_description_object->font_description = font_desc;
65 : }
66 : /* }}} */
67 :
68 : /* {{{ */
69 2 : PHP_METHOD(Pango_FontFace, getName)
70 : {
71 2 : ZEND_PARSE_PARAMETERS_NONE();
72 :
73 3 : RETURN_STRING((char *)pango_font_face_get_face_name(
74 : pango_font_face_object_get_font_face(getThis())
75 : ));
76 : }
77 : /* }}} */
78 :
79 : #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 46, 0)
80 : /* {{{ */
81 2 : PHP_METHOD(Pango_FontFace, getFamily)
82 : {
83 : PangoFontFamily *font_family;
84 : pango_font_family_object *font_family_object;
85 :
86 2 : ZEND_PARSE_PARAMETERS_NONE();
87 :
88 1 : object_init_ex(return_value, php_pango_get_font_family_ce());
89 1 : font_family_object = Z_PANGO_FONT_FAMILY_P(return_value);
90 2 : font_family_object->font_family = g_object_ref(pango_font_face_get_family(
91 : pango_font_face_object_get_font_face(getThis()))
92 : );
93 : }
94 : /* }}} */
95 : #endif
96 :
97 : /* {{{ */
98 2 : PHP_METHOD(Pango_FontFace, isSynthesized)
99 : {
100 2 : ZEND_PARSE_PARAMETERS_NONE();
101 :
102 2 : RETURN_BOOL(pango_font_face_is_synthesized(
103 : pango_font_face_object_get_font_face(getThis())
104 : ));
105 : }
106 : /* }}} */
107 :
108 : /* {{{ */
109 3 : PHP_METHOD(Pango_FontFace, listSizes)
110 : {
111 : int* sizes;
112 : int num_sizes;
113 :
114 3 : ZEND_PARSE_PARAMETERS_NONE();
115 :
116 0 : pango_font_face_list_sizes(
117 4 : pango_font_face_object_get_font_face(getThis()),
118 : &sizes,
119 : &num_sizes
120 : );
121 :
122 2 : array_init(return_value);
123 3 : for (int i = 0; i < num_sizes; i++) {
124 1 : add_next_index_long(return_value, sizes[i]);
125 : }
126 :
127 2 : g_free(sizes);
128 : }
129 : /* }}} */
130 :
131 : /* ----------------------------------------------------------------
132 : \Pango\FontFace Object management
133 : ------------------------------------------------------------------*/
134 :
135 : /* {{{ */
136 13 : static void pango_font_face_free_obj(zend_object *zobj)
137 : {
138 13 : pango_font_face_object *intern = pango_font_face_fetch_object(zobj);
139 :
140 13 : if (!intern) {
141 0 : return;
142 : }
143 :
144 13 : if (intern->font_face != NULL) {
145 13 : intern->font_face = NULL;
146 : }
147 :
148 13 : zend_object_std_dtor(&intern->std);
149 : }
150 : /* }}} */
151 :
152 : /* {{{ */
153 13 : static zend_object* pango_font_face_obj_ctor(zend_class_entry *ce, pango_font_face_object **intern)
154 : {
155 13 : pango_font_face_object *object = ecalloc(1, sizeof(pango_font_face_object) + zend_object_properties_size(ce));
156 :
157 13 : zend_object_std_init(&object->std, ce);
158 :
159 13 : object->std.handlers = &pango_font_face_object_handlers;
160 13 : *intern = object;
161 :
162 13 : return &object->std;
163 : }
164 : /* }}} */
165 :
166 : /* {{{ */
167 13 : static zend_object* pango_font_face_create_object(zend_class_entry *ce)
168 : {
169 13 : pango_font_face_object *intern = NULL;
170 13 : zend_object *return_value = pango_font_face_obj_ctor(ce, &intern);
171 :
172 13 : object_properties_init(&intern->std, ce);
173 13 : return return_value;
174 : }
175 : /* }}} */
176 :
177 : /* {{{ PHP_MINIT_FUNCTION */
178 194 : PHP_MINIT_FUNCTION(pango_font_face)
179 : {
180 194 : memcpy(
181 : &pango_font_face_object_handlers,
182 : zend_get_std_object_handlers(),
183 : sizeof(zend_object_handlers)
184 : );
185 :
186 194 : pango_font_face_object_handlers.offset = XtOffsetOf(pango_font_face_object, std);
187 194 : pango_font_face_object_handlers.free_obj = pango_font_face_free_obj;
188 :
189 194 : pango_ce_pango_font_face = register_class_Pango_FontFace();
190 194 : pango_ce_pango_font_face->create_object = pango_font_face_create_object;
191 :
192 194 : return SUCCESS;
193 : }
194 : /* }}} */
|