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 "glyph_info_arginfo.h"
26 :
27 : #include <string.h>
28 : #include "zend_exceptions.h"
29 :
30 : zend_class_entry *pango_ce_pango_glyph_info;
31 :
32 : static zend_object_handlers pango_glyph_info_object_handlers;
33 :
34 28 : pango_glyph_info_object *pango_glyph_info_fetch_object(zend_object *object)
35 : {
36 28 : return (pango_glyph_info_object *) ((char*)(object) - XtOffsetOf(pango_glyph_info_object, std));
37 : }
38 :
39 12 : PHP_PANGO_API zend_class_entry* php_pango_get_glyph_info_ce()
40 : {
41 12 : return pango_ce_pango_glyph_info;
42 : }
43 :
44 : /* ----------------------------------------------------------------
45 : \Pango\GlyphInfo Object management
46 : ------------------------------------------------------------------*/
47 :
48 : /* {{{ */
49 12 : static void pango_glyph_info_free_obj(zend_object *zobj)
50 : {
51 12 : pango_glyph_info_object *intern = pango_glyph_info_fetch_object(zobj);
52 :
53 12 : if (!intern) {
54 0 : return;
55 : }
56 :
57 12 : if (intern->glyph_info != NULL) {
58 12 : intern->glyph_info = NULL;
59 : }
60 :
61 12 : zval_ptr_dtor(&intern->glyph_string_zv);
62 :
63 12 : zend_object_std_dtor(&intern->std);
64 : }
65 : /* }}} */
66 :
67 : /* {{{ */
68 12 : static zend_object* pango_glyph_info_obj_ctor(zend_class_entry *ce, pango_glyph_info_object **intern)
69 : {
70 12 : pango_glyph_info_object *object = ecalloc(1, sizeof(pango_glyph_info_object) + zend_object_properties_size(ce));
71 :
72 12 : ZVAL_UNDEF(&object->glyph_string_zv);
73 :
74 12 : zend_object_std_init(&object->std, ce);
75 :
76 12 : object->std.handlers = &pango_glyph_info_object_handlers;
77 12 : *intern = object;
78 :
79 12 : return &object->std;
80 : }
81 : /* }}} */
82 :
83 : /* {{{ */
84 12 : static zend_object* pango_glyph_info_create_object(zend_class_entry *ce)
85 : {
86 12 : pango_glyph_info_object *intern = NULL;
87 12 : zend_object *return_value = pango_glyph_info_obj_ctor(ce, &intern);
88 :
89 12 : object_properties_init(&intern->std, ce);
90 12 : return return_value;
91 : }
92 : /* }}} */
93 :
94 : /* {{{ */
95 3 : static zval *pango_glyph_info_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv)
96 : {
97 3 : pango_glyph_info_object *glyph_info_object = pango_glyph_info_fetch_object(zobj);
98 :
99 3 : if (strcmp(ZSTR_VAL(member), "glyph") == 0) {
100 1 : ZVAL_LONG(rv, glyph_info_object->glyph_info->glyph);
101 1 : return rv;
102 : }
103 2 : else if (strcmp(ZSTR_VAL(member), "geometry") == 0) {
104 1 : array_init(rv);
105 1 : add_assoc_long(rv, "width", glyph_info_object->glyph_info->geometry.width);
106 1 : add_assoc_long(rv, "xOffset", glyph_info_object->glyph_info->geometry.x_offset);
107 1 : add_assoc_long(rv, "yOffset", glyph_info_object->glyph_info->geometry.y_offset);
108 1 : return rv;
109 : }
110 1 : else if (strcmp(ZSTR_VAL(member), "attributes") == 0) {
111 1 : array_init(rv);
112 1 : add_assoc_long(rv, "isClusterStart", glyph_info_object->glyph_info->attr.is_cluster_start);
113 1 : add_assoc_long(rv, "isColor", glyph_info_object->glyph_info->attr.is_color);
114 1 : return rv;
115 : }
116 :
117 0 : return zend_std_read_property(zobj, member, type, cache_slot, rv);
118 : }
119 : /* }}} */
120 :
121 : /* {{{ */
122 1 : static HashTable *pango_glyph_info_get_properties(zend_object *object)
123 : {
124 : HashTable *props;
125 1 : pango_glyph_info_object *glyph_info_object = pango_glyph_info_fetch_object(object);
126 :
127 1 : props = zend_std_get_properties(object);
128 :
129 1 : if (!glyph_info_object->glyph_info) {
130 0 : return props;
131 : }
132 :
133 : zval glyph;
134 1 : ZVAL_LONG(&glyph, glyph_info_object->glyph_info->glyph);
135 1 : zend_hash_str_update(props, "glyph", sizeof("glyph")-1, &glyph);
136 :
137 : zval geometry;
138 1 : array_init(&geometry);
139 1 : add_assoc_long(&geometry, "width", glyph_info_object->glyph_info->geometry.width);
140 1 : add_assoc_long(&geometry, "xOffset", glyph_info_object->glyph_info->geometry.x_offset);
141 1 : add_assoc_long(&geometry, "yOffset", glyph_info_object->glyph_info->geometry.y_offset);
142 1 : zend_hash_str_update(props, "geometry", sizeof("geometry")-1, &geometry);
143 :
144 : zval attributes;
145 1 : array_init(&attributes);
146 1 : add_assoc_long(&attributes, "isClusterStart", glyph_info_object->glyph_info->attr.is_cluster_start);
147 1 : add_assoc_long(&attributes, "isColor", glyph_info_object->glyph_info->attr.is_color);
148 1 : zend_hash_str_update(props, "attributes", sizeof("attributes")-1, &attributes);
149 :
150 1 : return props;
151 : }
152 : /* }}} */
153 :
154 : /* {{{ PHP_MINIT_FUNCTION */
155 194 : PHP_MINIT_FUNCTION(pango_glyph_info)
156 : {
157 194 : memcpy(
158 : &pango_glyph_info_object_handlers,
159 : zend_get_std_object_handlers(),
160 : sizeof(zend_object_handlers)
161 : );
162 :
163 194 : pango_glyph_info_object_handlers.offset = XtOffsetOf(pango_glyph_info_object, std);
164 194 : pango_glyph_info_object_handlers.free_obj = pango_glyph_info_free_obj;
165 194 : pango_glyph_info_object_handlers.read_property = pango_glyph_info_read_property;
166 194 : pango_glyph_info_object_handlers.get_property_ptr_ptr = NULL;
167 194 : pango_glyph_info_object_handlers.get_properties = pango_glyph_info_get_properties;
168 :
169 194 : pango_ce_pango_glyph_info = register_class_Pango_GlyphInfo();
170 194 : pango_ce_pango_glyph_info->create_object = pango_glyph_info_create_object;
171 :
172 194 : return SUCCESS;
173 : }
174 : /* }}} */
|