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 : | Authors: Michael Maclean <mgdm@php.net> |
16 : | Marcel Bolten <github@marcelbolten.de> |
17 : +----------------------------------------------------------------------+
18 : */
19 :
20 : #ifdef HAVE_CONFIG_H
21 : #include "config.h"
22 : #endif
23 :
24 : #include "php.h"
25 : #include "php_ini.h"
26 : #include "ext/standard/info.h"
27 :
28 : #include "php_pango.h"
29 : #include "pango_arginfo.h"
30 :
31 : zend_class_entry *pango_ce_pango;
32 : zend_object_handlers pango_std_object_handlers;
33 :
34 : /* {{{ returns the Pango version */
35 1 : ZEND_METHOD(Pango_Pango, version)
36 : {
37 1 : ZEND_PARSE_PARAMETERS_NONE();
38 :
39 1 : RETURN_LONG(pango_version());
40 : }
41 : /* }}} */
42 :
43 : /* {{{ returns the Pango version as a string */
44 2 : ZEND_METHOD(Pango_Pango, versionString)
45 : {
46 2 : ZEND_PARSE_PARAMETERS_NONE();
47 :
48 4 : RETURN_STRING((char *)pango_version_string());
49 : }
50 : /* }}} */
51 :
52 : static const zend_module_dep pango_module_deps[] = {
53 : ZEND_MOD_REQUIRED("cairo")
54 : ZEND_MOD_END
55 : };
56 :
57 : /* {{{ pango_module_entry */
58 : zend_module_entry pango_module_entry = {
59 : STANDARD_MODULE_HEADER_EX,
60 : NULL,
61 : pango_module_deps,
62 : "pango",
63 : NULL,
64 : PHP_MINIT(pango),
65 : PHP_MSHUTDOWN(pango),
66 : PHP_RINIT(pango),
67 : PHP_RSHUTDOWN(pango),
68 : PHP_MINFO(pango),
69 : PHP_PANGO_VERSION,
70 : STANDARD_MODULE_PROPERTIES
71 : };
72 : /* }}} */
73 :
74 : #ifdef COMPILE_DL_PANGO
75 194 : ZEND_GET_MODULE(pango)
76 : #endif
77 :
78 : /* {{{ PHP_MINIT_FUNCTION */
79 194 : PHP_MINIT_FUNCTION(pango)
80 : {
81 194 : memcpy(
82 : &pango_std_object_handlers,
83 : zend_get_std_object_handlers(),
84 : sizeof(zend_object_handlers)
85 : );
86 194 : pango_std_object_handlers.clone_obj = NULL;
87 :
88 194 : pango_ce_pango = register_class_Pango_Pango();
89 : // Make abstract so no-one can instantiate it
90 194 : pango_ce_pango->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
91 :
92 194 : PHP_MINIT(pango_exception)(INIT_FUNC_ARGS_PASSTHRU);
93 194 : PHP_MINIT(pango_context)(INIT_FUNC_ARGS_PASSTHRU);
94 194 : PHP_MINIT(pango_layout)(INIT_FUNC_ARGS_PASSTHRU);
95 194 : PHP_MINIT(pango_font_description)(INIT_FUNC_ARGS_PASSTHRU);
96 194 : PHP_MINIT(pango_layout_line)(INIT_FUNC_ARGS_PASSTHRU);
97 194 : PHP_MINIT(pango_glyph_item)(INIT_FUNC_ARGS_PASSTHRU);
98 194 : PHP_MINIT(pango_item)(INIT_FUNC_ARGS_PASSTHRU);
99 194 : PHP_MINIT(pango_glyph_string)(INIT_FUNC_ARGS_PASSTHRU);
100 194 : PHP_MINIT(pango_glyph_info)(INIT_FUNC_ARGS_PASSTHRU);
101 194 : PHP_MINIT(pango_matrix)(INIT_FUNC_ARGS_PASSTHRU);
102 194 : PHP_MINIT(pango_rectangle)(INIT_FUNC_ARGS_PASSTHRU);
103 : // PHP_MINIT(pango_ft2_font_map)(INIT_FUNC_ARGS_PASSTHRU);
104 194 : PHP_MINIT(pango_font_map)(INIT_FUNC_ARGS_PASSTHRU);
105 194 : PHP_MINIT(pango_cairo_font_map)(INIT_FUNC_ARGS_PASSTHRU);
106 194 : PHP_MINIT(pango_font_family)(INIT_FUNC_ARGS_PASSTHRU);
107 194 : PHP_MINIT(pango_font_face)(INIT_FUNC_ARGS_PASSTHRU);
108 194 : PHP_MINIT(pango_cairo_layout)(INIT_FUNC_ARGS_PASSTHRU);
109 194 : PHP_MINIT(pango_cairo_context)(INIT_FUNC_ARGS_PASSTHRU);
110 :
111 194 : return SUCCESS;
112 : }
113 : /* }}} */
114 :
115 : /* {{{ PHP_MSHUTDOWN_FUNCTION */
116 194 : PHP_MSHUTDOWN_FUNCTION(pango)
117 : {
118 : /* uncomment this line if you have INI entries
119 : UNREGISTER_INI_ENTRIES();
120 : */
121 194 : return SUCCESS;
122 : }
123 : /* }}} */
124 :
125 194 : PHP_RINIT_FUNCTION(pango)
126 : {
127 : /**
128 : * Initialize fontconfig via pango_cairo_font_map_get_default on request
129 : * start and load the default font map to ensure fontconfig is ready to use.
130 : *
131 : * If there would be a way to wait for the shutdown of the worker thread
132 : * started by the fontconfig backend, we could avoid the race conditions
133 : * and the default font map could be lazy-loaded when needed.
134 : * TODO: only load if fontconfig backend is used
135 : */
136 194 : PangoFontMap *font_map = pango_cairo_font_map_get_default();
137 : // This will block internally until fontconfig is initialized
138 194 : pango_fc_font_map_get_config((PangoFcFontMap *)font_map);
139 :
140 194 : return SUCCESS;
141 : }
142 :
143 194 : PHP_RSHUTDOWN_FUNCTION(pango)
144 : {
145 : /**
146 : * This is a hack, but if we don't wait a bit here, tests sometimes
147 : * fail with segfaults. There is a race condition between the php shutdown
148 : * and an asynchronous worker thread started by pango if a fontconfig
149 : * backend is used that only gets cleaned up properly if we wait a bit here.
150 : * There is no alternative way I'm aware of to ensure the worker thread is closed.
151 : * TODO: investigate further, fix it, and remove this.
152 : * TODO: make it an ini setting to configure the wait time
153 : */
154 194 : usleep(50000);
155 :
156 194 : return SUCCESS;
157 : }
158 :
159 : /* {{{ PHP_MINFO_FUNCTION */
160 1 : PHP_MINFO_FUNCTION(pango)
161 : {
162 1 : php_info_print_table_start();
163 1 : php_info_print_table_header(2, "Pango text rendering support", "enabled");
164 1 : php_info_print_table_row(2, "Compiled as",
165 : #ifdef COMPILE_DL_PANGO
166 : "dynamic module"
167 : #else
168 : "static module"
169 : #endif
170 : );
171 1 : php_info_print_table_row(2, "Pango version",
172 : #ifdef PANGO_VERSION_STRING
173 : PANGO_VERSION_STRING
174 : #else
175 : "Unknown"
176 : #endif
177 : );
178 1 : php_info_print_table_row(2, "Extension version", PHP_PANGO_VERSION);
179 1 : php_info_print_table_end();
180 1 : }
181 : /* }}} */
|