├── .cvsignore ├── CREDITS ├── TODO ├── .gitignore ├── examples └── pango-cairo.php ├── config.w32 ├── README ├── pango_error.c ├── package.xml ├── config.m4 ├── pango.c ├── php_pango.h ├── pango_context.c ├── pango_line.c ├── pango_font.c └── pango_layout.c /.cvsignore: -------------------------------------------------------------------------------- 1 | .deps 2 | *.lo 3 | *.la 4 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | PHP Pango text rendering library bindings 2 | Michael Maclean 3 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Lots. 2 | 3 | Complete adding PangoLayout methods 4 | Handle tab stops - map to associative arrays? 5 | add classes for PangoFont, PangoFontFace and allow access to those methods 6 | Add PangoContext methods 7 | 8 | * arginfo needs to be added basically everywhere 9 | * Tests 10 | * Docs 11 | 12 | * Investigate what font handling is actually required and come up with a plan 13 | for implementing 14 | 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.deps 2 | /Makefile 3 | /*.lo 4 | /*.loT 5 | /*.slo 6 | /*.mk 7 | /*.la 8 | /.libs 9 | /libs.mk 10 | /ac*.m4 11 | /build 12 | /config.h 13 | /config.h.in 14 | /config.nice 15 | /config.sub 16 | /configure 17 | /configure.in 18 | /config.status 19 | /config.cache 20 | /conftest 21 | /conftest.c 22 | /core 23 | /dynlib.m4 24 | /install-sh 25 | /ltmain.sh 26 | /include 27 | /Makefile.fragments 28 | /Makefile.global 29 | /Makefile.objects 30 | /missing 31 | /mkinstalldirs 32 | /modules 33 | /scan_makefile_in.awk 34 | /config.guess 35 | /*swp 36 | /config.log 37 | /libtool 38 | /Debug 39 | /Release 40 | /Debug_TS 41 | /Release_TS 42 | /*.plg 43 | /*.patch 44 | /*.tgz 45 | /*.ncb 46 | /*.opt 47 | /*.dsw 48 | /autom4te.cache 49 | /run-tests-config.php 50 | /run-tests.php 51 | /tmp-php.ini 52 | .svn 53 | -------------------------------------------------------------------------------- /examples/pango-cairo.php: -------------------------------------------------------------------------------- 1 | translate(RADIUS, RADIUS); 9 | $l = new PangoLayout($c); 10 | $l->setText("Text"); 11 | $desc = new PangoFontDescription(FONT); 12 | $l->setFontDescription($desc); 13 | 14 | for($i = 0; $i < N_WORDS; $i++) { 15 | $angle = 360.0 * $i / N_WORDS; 16 | $red = (1 + cos (($angle - 60) * M_PI / 180)) / 2; 17 | 18 | $c->save(); 19 | $c->setSourceRGB($red, 0, 1.0 - $red); 20 | $c->rotate($angle * M_PI / 180.0); 21 | $l->updateLayout($c); 22 | $size = $l->getSize(); 23 | $c->moveTo( - ((double)$size['width'] / 2048), - RADIUS); 24 | $l->showLayout(); 25 | $c->restore(); 26 | } 27 | } 28 | 29 | $s = new CairoImageSurface(CairoFormat::ARGB32, RADIUS *2, RADIUS *2); 30 | $c = new CairoContext($s); 31 | $c->setSourceRGB(1, 1, 1); 32 | $c->paint(); 33 | draw_text($c); 34 | $s->writeToPng('circle.png'); 35 | ?> 36 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | 2 | ARG_ENABLE("pango", "enable pango support", "no"); 3 | 4 | if (PHP_PANGO != "no") { 5 | if (CHECK_HEADER_ADD_INCLUDE("pango.h", "CFLAGS_PANGO", PHP_PANGO+ ";" + PHP_PHP_BUILD + "\\include\\pango") && 6 | CHECK_HEADER_ADD_INCLUDE("glib.h", "CFLAGS_PANGO", PHP_PANGO+ ";" + PHP_PHP_BUILD + "\\include\\glib-pango") && 7 | CHECK_HEADER_ADD_INCLUDE("glib-object.h", "CFLAGS_PANGO", PHP_PANGO+ ";" + PHP_PHP_BUILD + "\\include\\glib-pango") && 8 | 9 | CHECK_HEADER_ADD_INCLUDE("cairo.h", "CFLAGS_PANGO", PHP_PANGO+ ";" + PHP_PHP_BUILD + "\\include\\cairo") && 10 | CHECK_HEADER_ADD_INCLUDE("php_cairo_api.h", "CFLAGS_PANGO", PHP_PANGO+ ";" + PHP_PHP_BUILD + "\\..\\pecl\\cairo") && 11 | 12 | CHECK_LIB("pango-1.0.lib", "pango", PHP_PANGO) && 13 | CHECK_LIB("pangocairo-1.0.lib", "pango", PHP_PANGO) && 14 | CHECK_LIB("cairo.lib", "pango", PHP_PANGO) && 15 | CHECK_LIB("gobject-2.0.lib", "pango", PHP_PANGO) && 16 | 17 | ADD_EXTENSION_DEP('pango', 'cairo')) { 18 | 19 | EXTENSION("pango", "pango.c pango_error.c pango_context.c pango_layout.c pango_font.c pango_line.c"); 20 | AC_DEFINE("HAVE_PANGO", 1); 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | This is the start of a Pango binding for PHP. Current requirements are: 3 | 4 | * PHP 5.2+ 5 | * Pango 1.14+ : 6 | * pecl/cairo. Currently the only functionality I'm wrapping are those required 7 | to make Cairo rendering work which will suit my own purposes - however, once 8 | that works I intend to remove the hard dependency here if I can. 9 | 10 | Once this gets up to something usable it will be proposed for PECL. 11 | 12 | Compiling on windows 13 | ==================== 14 | 15 | 1. Setup build environment 16 | 17 | Setup your build environment as described here: 18 | https://wiki.php.net/internals/windows/stepbystepbuild 19 | 20 | 2. Pecl packages 21 | 22 | Create a directory called 'pecl' in the 'x86' directory. 23 | 24 | * Download and extract the pecl/cairo extension in the pecl directory 25 | * Download and extract the pecl/pango extension in the pecl directory 26 | 27 | 3. Dependencies 28 | 29 | Download the following dependencies from www.gtk.org/download/win32.php and 30 | extract them to the 'deps' directory. Make sure you download the 'Dev' 31 | packages. 32 | 33 | * Cairo 34 | * Freetype 35 | * Fontconfig 36 | 37 | You'll also need the GLib Dev package, you can copy the files in the lib 38 | directory to the deps/lib directory. The files in the include directory need 39 | special attention. You should extract the include/glib-2.0 directory to 40 | deps/include/glib-pango. Finally you should extract the 41 | lib/glib-2.0/include/glibconfig.h header file to deps/include/glib-pango. 42 | 43 | 4. Compiling pango 44 | 45 | * Run: buildconf. 46 | * Run: configure.js --enable-pango=shared --with-cairo=shared 47 | * Run: nmake 48 | 49 | 5. Done 50 | 51 | You're pango extension is now ready in: Release_TS/php_pango.dll 52 | 53 | -------------------------------------------------------------------------------- /pango_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2009 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: Michael Maclean | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include "config.h" 21 | #endif 22 | 23 | #include "php.h" 24 | #include "zend_exceptions.h" 25 | #include "php_pango.h" 26 | 27 | zend_class_entry *pango_ce_pangoexception; 28 | 29 | /* {{{ PHP_MINIT_FUNCTION */ 30 | PHP_MINIT_FUNCTION(pango_error) 31 | { 32 | zend_class_entry ce; 33 | 34 | INIT_CLASS_ENTRY(ce, "PangoException", NULL); 35 | pango_ce_pangoexception = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), "Exception" TSRMLS_CC); 36 | 37 | return SUCCESS; 38 | } 39 | /* }}} */ 40 | 41 | /* 42 | * Local variables: 43 | * tab-width: 4 44 | * c-basic-offset: 4 45 | * End: 46 | * vim600: noet sw=4 ts=4 fdm=marker 47 | * vim<600: noet sw=4 ts=4 48 | */ 49 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Pango 4 | pecl.mgdm.net 5 | Pango extension 6 | Pango is a library for laying out and rendering of text, with an emphasis on internationalization. 7 | 8 | Michael Maclean 9 | mgdm 10 | mgdm@php.net 11 | yes 12 | 13 | 14 | 2012-07-23 15 | 0.2.20.2.2 16 | betabeta 17 | PHP License 18 | 19 | * Adds a patch from Aleš Krajník to fix compilation on 5.4 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 | 5.2.0 45 | 46 | 47 | 1.4.0 48 | 49 | 50 | 51 | 52 | 53 | pango 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 65 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl $ Id: pango 1.0.1$ 3 | dnl 4 | 5 | PHP_ARG_WITH(pango, for Pango text layout library support, 6 | [ --with-pango Enable Pango support], yes) 7 | 8 | if test "$PHP_PANGO" != "no"; then 9 | export OLD_CPPFLAGS="$CPPFLAGS" 10 | export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_PANGO" 11 | 12 | AC_MSG_CHECKING(PHP version) 13 | AC_TRY_COMPILE([#include ], [ 14 | #if PHP_VERSION_ID < 50200 15 | #error this extension requires at least PHP version 5.2.0 16 | #endif 17 | ], 18 | [AC_MSG_RESULT(ok)], 19 | [AC_MSG_ERROR([need at least PHP 5.2.0])]) 20 | 21 | export CPPFLAGS="$OLD_CPPFLAGS" 22 | 23 | PHP_SUBST(PANGO_SHARED_LIBADD) 24 | AC_DEFINE(HAVE_PANGO, 1, [ ]) 25 | 26 | PHP_NEW_EXTENSION(pango, pango.c pango_error.c pango_context.c pango_layout.c pango_font.c pango_line.c, $ext_shared) 27 | 28 | EXT_PANGO_HEADERS="php_pango_api.h" 29 | 30 | ifdef([PHP_INSTALL_HEADERS], [ 31 | PHP_INSTALL_HEADERS(ext/pango, $EXT_PANGO_HEADERS) 32 | ]) 33 | 34 | if test "$PHP_PANGO" != "no"; then 35 | PANGO_CHECK_DIR=$PHP_PANGO 36 | PANGO_TEST_FILE=/include/pango.h 37 | PANGO_LIBNAME=pango 38 | fi 39 | condition="$PANGO_CHECK_DIR$PANGO_TEST_FILE" 40 | 41 | if test -r $condition; then 42 | PANGO_DIR=$PANGO_CHECK_DIR 43 | CFLAGS="$CFLAGS -I$PANGO_DIR/include" 44 | LDFLAGS=`$PANGO_DIR/bin/pango-config --libs` 45 | else 46 | AC_MSG_CHECKING(for pkg-config) 47 | 48 | if test ! -f "$PKG_CONFIG"; then 49 | PKG_CONFIG=`which pkg-config` 50 | fi 51 | 52 | if test -f "$PKG_CONFIG"; then 53 | AC_MSG_RESULT(found) 54 | AC_MSG_CHECKING(for pango) 55 | 56 | if $PKG_CONFIG --exists pango; then 57 | if $PKG_CONFIG --atleast-version=1.14 pango; then 58 | pango_version_full=`$PKG_CONFIG --modversion pango` 59 | AC_MSG_RESULT([found $pango_version_full]) 60 | PANGO_LIBS="$LDFLAGS `$PKG_CONFIG --libs pango`" 61 | CAIRO_LIBS="$LDFLAGS `$PKG_CONFIG --libs cairo`" 62 | PANGOCAIRO_LIBS="$LDFLAGS `$PKG_CONFIG --libs pangocairo`" 63 | PANGO_INCS="$CFLAGS `$PKG_CONFIG --cflags-only-I pango`" 64 | CAIRO_INCS="$CFLAGS `$PKG_CONFIG --cflags-only-I cairo`" 65 | PANGOCAIRO_INCS="$CFLAGS `$PKG_CONFIG --cflags-only-I pangocairo`" 66 | PHP_EVAL_INCLINE($PANGO_INCS) 67 | PHP_EVAL_INCLINE($CAIRO_INCS) 68 | PHP_EVAL_INCLINE($PANGOCAIRO_INCS) 69 | PHP_EVAL_LIBLINE($PANGO_LIBS, PANGO_SHARED_LIBADD) 70 | PHP_EVAL_LIBLINE($CAIRO_LIBS, PANGO_SHARED_LIBADD) 71 | PHP_EVAL_LIBLINE($PANGOCAIRO_LIBS, PANGO_SHARED_LIBADD) 72 | AC_DEFINE(HAVE_PANGO, 1, [whether pango exists in the system]) 73 | else 74 | AC_MSG_RESULT(too old) 75 | AC_MSG_ERROR(Ooops ! You need at least pango 1.20) 76 | fi 77 | else 78 | AC_MSG_RESULT(not found) 79 | AC_MSG_ERROR(Ooops ! no pango detected in the system) 80 | fi 81 | else 82 | AC_MSG_RESULT(not found) 83 | AC_MSG_ERROR(Ooops ! no pkg-config found .... ) 84 | fi 85 | fi 86 | 87 | AC_MSG_CHECKING(for cairo php extension) 88 | if test -f "$phpincludedir/ext/cairo/php_cairo_api.h"; then 89 | PHP_ADD_INCLUDE($phpincludedir/ext/cairo) 90 | PHP_DEF_HAVE(CAIRO) 91 | AC_MSG_RESULT(yes) 92 | else 93 | AC_MSG_RESULT(no) 94 | AC_MSG_ERROR(cairo php extension not found.) 95 | fi 96 | fi 97 | -------------------------------------------------------------------------------- /pango.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 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: Michael Maclean | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id: $ */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "php_pango.h" 29 | 30 | /* If you declare any globals in php_pango.h uncomment this: 31 | ZEND_DECLARE_MODULE_GLOBALS(pango) 32 | */ 33 | 34 | zend_class_entry *pango_ce_pango; 35 | zend_object_handlers pango_std_object_handlers; 36 | 37 | #ifdef PANGO_VERSION 38 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 39 | /* proto int pango_version(void) {{{ 40 | returns the Pango version */ 41 | PHP_FUNCTION(pango_version) 42 | { 43 | if(zend_parse_parameters_none() == FAILURE) { 44 | return; 45 | } 46 | 47 | RETURN_LONG(pango_version()); 48 | } 49 | /* }}} */ 50 | 51 | /* proto int pango_version_string(void) {{{ 52 | returns the Pango version as a string */ 53 | PHP_FUNCTION(pango_version_string) 54 | { 55 | if(zend_parse_parameters_none() == FAILURE) { 56 | return; 57 | } 58 | 59 | RETURN_STRING((char *)pango_version_string(), 1); 60 | } 61 | /* }}} */ 62 | #endif 63 | #endif 64 | 65 | /* {{{ pango_functions[] 66 | * 67 | * Every user visible function must have an entry in pango_functions[]. 68 | */ 69 | const zend_function_entry pango_functions[] = { 70 | #ifdef PANGO_VERSION 71 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 72 | PHP_FE(pango_version, NULL) 73 | PHP_FE(pango_version_string, NULL) 74 | #endif 75 | #endif 76 | PHP_FE(pango_layout_new, NULL) 77 | PHP_FE(pango_cairo_update_layout, NULL) 78 | PHP_FE(pango_cairo_show_layout, NULL) 79 | #ifdef PANGO_VERSION 80 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 81 | PHP_FE(pango_context_set_base_gravity, NULL) 82 | PHP_FE(pango_context_get_base_gravity, NULL) 83 | PHP_FE(pango_context_get_gravity, NULL) 84 | PHP_FE(pango_context_set_gravity_hint, NULL) 85 | PHP_FE(pango_context_get_gravity_hint, NULL) 86 | #endif 87 | #endif 88 | PHP_FE(pango_layout_get_context, NULL) 89 | PHP_FE(pango_layout_set_text, NULL) 90 | PHP_FE(pango_layout_get_text, NULL) 91 | PHP_FE(pango_layout_set_markup, NULL) 92 | PHP_FE(pango_layout_get_width, NULL) 93 | PHP_FE(pango_layout_get_size, NULL) 94 | PHP_FE(pango_layout_get_pixel_size, NULL) 95 | PHP_FE(pango_layout_get_extents, NULL) 96 | PHP_FE(pango_layout_get_pixel_extents, NULL) 97 | PHP_FE(pango_layout_set_width, NULL) 98 | #ifdef PANGO_VERSION 99 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 100 | PHP_FE(pango_layout_set_height, NULL) 101 | PHP_FE(pango_layout_get_height, NULL) 102 | #endif 103 | #endif 104 | PHP_FE(pango_layout_set_font_description, NULL) 105 | PHP_FE(pango_layout_set_alignment, NULL) 106 | PHP_FE(pango_layout_get_alignment, NULL) 107 | PHP_FE(pango_layout_set_justify, NULL) 108 | PHP_FE(pango_layout_get_justify, NULL) 109 | PHP_FE(pango_layout_set_wrap, NULL) 110 | PHP_FE(pango_layout_get_wrap, NULL) 111 | #ifdef PANGO_VERSION 112 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 113 | PHP_FE(pango_layout_is_wrapped, NULL) 114 | #endif 115 | #endif 116 | PHP_FE(pango_layout_set_indent, NULL) 117 | PHP_FE(pango_layout_get_indent, NULL) 118 | PHP_FE(pango_layout_set_spacing, NULL) 119 | PHP_FE(pango_layout_get_spacing, NULL) 120 | PHP_FE(pango_layout_set_ellipsize, NULL) 121 | PHP_FE(pango_layout_get_ellipsize, NULL) 122 | #ifdef PANGO_VERSION 123 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 124 | PHP_FE(pango_layout_is_ellipsized, NULL) 125 | #endif 126 | #endif 127 | PHP_FE(pango_layout_get_lines, NULL) 128 | PHP_FE(pango_layout_get_line, NULL) 129 | PHP_FE(pango_layout_get_line_count, NULL) 130 | PHP_FE(pango_layout_context_changed, NULL) 131 | 132 | /* PangoLayoutLine functions */ 133 | PHP_FE(pango_layout_line_get_extents, NULL) 134 | PHP_FE(pango_layout_line_get_pixel_extents, NULL) 135 | PHP_FE(pango_cairo_show_layout_line, NULL) 136 | 137 | /* PangoFontDescription functions */ 138 | PHP_FE(pango_font_description_new, NULL) 139 | PHP_FE(pango_font_description_get_variant, NULL) 140 | PHP_FE(pango_font_description_set_variant, NULL) 141 | 142 | /* PHP_FE(pango_font_description_new, NULL) */ 143 | {NULL, NULL, NULL} 144 | }; 145 | /* }}} */ 146 | 147 | const zend_function_entry pango_methods[] = { 148 | #ifdef PANGO_VERSION 149 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 150 | PHP_ME_MAPPING(version, pango_version, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 151 | PHP_ME_MAPPING(versionString, pango_version_string, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 152 | #endif 153 | #endif 154 | {NULL, NULL, NULL} 155 | }; 156 | 157 | /* {{{ pango_module_entry 158 | */ 159 | zend_module_entry pango_module_entry = { 160 | #if ZEND_MODULE_API_NO >= 20010901 161 | STANDARD_MODULE_HEADER, 162 | #endif 163 | "pango", 164 | pango_functions, 165 | PHP_MINIT(pango), 166 | PHP_MSHUTDOWN(pango), 167 | NULL, 168 | NULL, 169 | PHP_MINFO(pango), 170 | #if ZEND_MODULE_API_NO >= 20010901 171 | PHP_PANGO_VERSION, 172 | #endif 173 | STANDARD_MODULE_PROPERTIES 174 | }; 175 | /* }}} */ 176 | 177 | #ifdef COMPILE_DL_PANGO 178 | ZEND_GET_MODULE(pango) 179 | #endif 180 | 181 | /* {{{ PHP_MINIT_FUNCTION 182 | */ 183 | PHP_MINIT_FUNCTION(pango) 184 | { 185 | zend_class_entry pango_ce; 186 | 187 | memcpy(&pango_std_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 188 | pango_std_object_handlers.clone_obj = NULL; 189 | 190 | INIT_CLASS_ENTRY(pango_ce, "Pango", pango_methods); 191 | pango_ce_pango = zend_register_internal_class(&pango_ce TSRMLS_CC); 192 | pango_ce_pango->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 193 | 194 | #define REGISTER_PANGO_LONG_CONST(const_name, value) \ 195 | zend_declare_class_constant_long(pango_ce_pango, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 196 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 197 | 198 | REGISTER_PANGO_LONG_CONST("SCALE", PANGO_SCALE); 199 | 200 | PHP_MINIT(pango_error)(INIT_FUNC_ARGS_PASSTHRU); 201 | PHP_MINIT(pango_context)(INIT_FUNC_ARGS_PASSTHRU); 202 | PHP_MINIT(pango_layout)(INIT_FUNC_ARGS_PASSTHRU); 203 | PHP_MINIT(pango_font)(INIT_FUNC_ARGS_PASSTHRU); 204 | PHP_MINIT(pango_line)(INIT_FUNC_ARGS_PASSTHRU); 205 | 206 | return SUCCESS; 207 | } 208 | /* }}} */ 209 | 210 | /* {{{ PHP_MSHUTDOWN_FUNCTION 211 | */ 212 | PHP_MSHUTDOWN_FUNCTION(pango) 213 | { 214 | /* uncomment this line if you have INI entries 215 | UNREGISTER_INI_ENTRIES(); 216 | */ 217 | return SUCCESS; 218 | } 219 | /* }}} */ 220 | 221 | 222 | /* {{{ PHP_MINFO_FUNCTION 223 | */ 224 | PHP_MINFO_FUNCTION(pango) 225 | { 226 | php_info_print_table_start(); 227 | php_info_print_table_header(2, "Pango text rendering support", "enabled"); 228 | php_info_print_table_colspan_header(2, 229 | #ifdef COMPILE_DL_PANGO 230 | "compiled as dynamic module" 231 | #else 232 | "compiled as static module" 233 | #endif 234 | ); 235 | #ifdef PANGO_VERSION_STRING 236 | php_info_print_table_row(2, "Pango version", PANGO_VERSION_STRING); 237 | #else 238 | php_info_print_table_row(2, "Pango version", "Unknown"); 239 | #endif 240 | php_info_print_table_row(2, "Extension version", PHP_PANGO_VERSION); 241 | php_info_print_table_end(); 242 | 243 | /* Remove comments if you have entries in php.ini 244 | DISPLAY_INI_ENTRIES(); 245 | */ 246 | } 247 | /* }}} */ 248 | 249 | 250 | 251 | /* 252 | * Local variables: 253 | * tab-width: 4 254 | * c-basic-offset: 4 255 | * End: 256 | * vim600: noet sw=4 ts=4 fdm=marker 257 | * vim<600: noet sw=4 ts=4 258 | */ 259 | -------------------------------------------------------------------------------- /php_pango.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2011 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 | 16 | | David Marín | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | /* $Id: header 252479 2008-02-07 19:39:50Z iliaa $ */ 21 | 22 | #ifndef PHP_PANGO_H 23 | #define PHP_PANGO_H 24 | 25 | #define PHP_PANGO_VERSION "0.1.0-dev" 26 | 27 | extern zend_module_entry pango_module_entry; 28 | #define phpext_pango_ptr &pango_module_entry 29 | 30 | extern zend_class_entry *pango_ce_pangoexception; 31 | 32 | /* TODO: Move this elsewhere */ 33 | extern zend_class_entry *pango_ce_pangofontdescription; 34 | 35 | extern zend_object_handlers pango_std_object_handlers; 36 | 37 | #ifdef PHP_WIN32 38 | # define PHP_PANGO_API __declspec(dllexport) 39 | #elif defined(__GNUC__) && __GNUC__ >= 4 40 | # define PHP_PANGO_API __attribute__ ((visibility("default"))) 41 | #else 42 | # define PHP_PANGO_API 43 | #endif 44 | 45 | #ifdef ZTS 46 | #include "TSRM.h" 47 | #endif 48 | 49 | /* for PHP 5.2 */ 50 | #ifndef zend_parse_parameters_none 51 | #define zend_parse_parameters_none() \ 52 | zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") 53 | #endif 54 | 55 | #include 56 | #include 57 | #include "php_cairo_api.h" 58 | 59 | PHP_PANGO_API extern zend_class_entry *php_pango_get_context_ce(); 60 | PHP_PANGO_API extern zend_class_entry *php_pango_get_layoutline_ce(); 61 | PHP_PANGO_API extern zval* php_pango_make_layoutline_zval(PangoLayoutLine *line, zval *layout TSRMLS_DC); 62 | 63 | /* Objects */ 64 | typedef struct _pango_context_object { 65 | zend_object std; 66 | PangoContext *context; 67 | } pango_context_object; 68 | 69 | typedef struct _pango_layout_object { 70 | zend_object std; 71 | PangoLayout *layout; 72 | zval *cairo_context; 73 | zval *pango_context; 74 | } pango_layout_object; 75 | 76 | typedef struct _pango_fontdesc_object { 77 | zend_object std; 78 | PangoFontDescription *fontdesc; 79 | } pango_fontdesc_object; 80 | 81 | typedef struct _pango_item_object { 82 | zend_object std; 83 | PangoItem *item; 84 | } pango_item_object; 85 | 86 | typedef struct _pango_layoutline_object { 87 | zend_object std; 88 | PangoLayoutLine *line; 89 | zval *layout_zval; 90 | } pango_layoutline_object; 91 | 92 | PHP_MINIT_FUNCTION(pango); 93 | PHP_MSHUTDOWN_FUNCTION(pango); 94 | PHP_MINFO_FUNCTION(pango); 95 | 96 | PHP_MINIT_FUNCTION(pango_error); 97 | PHP_MINIT_FUNCTION(pango_context); 98 | PHP_MINIT_FUNCTION(pango_layout); 99 | PHP_MINIT_FUNCTION(pango_font); 100 | PHP_MINIT_FUNCTION(pango_line); 101 | 102 | PHP_FUNCTION(pango_version); 103 | PHP_FUNCTION(pango_version_string); 104 | 105 | /* PangoLayout functions */ 106 | PHP_FUNCTION(pango_layout_new); 107 | PHP_FUNCTION(pango_cairo_update_layout); 108 | PHP_FUNCTION(pango_cairo_show_layout); 109 | PHP_FUNCTION(pango_cairo_show_path); 110 | #ifdef PANGO_VERSION 111 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 112 | PHP_FUNCTION(pango_context_set_base_gravity); 113 | PHP_FUNCTION(pango_context_get_base_gravity); 114 | PHP_FUNCTION(pango_context_get_gravity); 115 | PHP_FUNCTION(pango_context_set_gravity_hint); 116 | PHP_FUNCTION(pango_context_get_gravity_hint); 117 | #endif 118 | #endif 119 | PHP_FUNCTION(pango_layout_get_context); 120 | PHP_FUNCTION(pango_layout_set_text); 121 | PHP_FUNCTION(pango_layout_get_text); 122 | PHP_FUNCTION(pango_layout_set_markup); 123 | PHP_FUNCTION(pango_layout_get_width); 124 | PHP_FUNCTION(pango_layout_get_height); 125 | PHP_FUNCTION(pango_layout_get_size); 126 | PHP_FUNCTION(pango_layout_get_pixel_size); 127 | PHP_FUNCTION(pango_layout_get_extents); 128 | PHP_FUNCTION(pango_layout_get_pixel_extents); 129 | PHP_FUNCTION(pango_layout_set_width); 130 | PHP_FUNCTION(pango_layout_set_height); 131 | PHP_FUNCTION(pango_layout_set_font_description); 132 | PHP_FUNCTION(pango_layout_get_font_description); 133 | PHP_FUNCTION(pango_layout_get_alignment); 134 | PHP_FUNCTION(pango_layout_set_alignment); 135 | PHP_FUNCTION(pango_layout_get_justify); 136 | PHP_FUNCTION(pango_layout_set_justify); 137 | PHP_FUNCTION(pango_layout_get_wrap); 138 | PHP_FUNCTION(pango_layout_set_wrap); 139 | PHP_FUNCTION(pango_layout_is_wrapped); 140 | PHP_FUNCTION(pango_layout_get_indent); 141 | PHP_FUNCTION(pango_layout_set_indent); 142 | PHP_FUNCTION(pango_layout_get_spacing); 143 | PHP_FUNCTION(pango_layout_set_spacing); 144 | PHP_FUNCTION(pango_layout_set_ellipsize); 145 | PHP_FUNCTION(pango_layout_get_ellipsize); 146 | PHP_FUNCTION(pango_layout_is_ellipsized); 147 | PHP_FUNCTION(pango_layout_get_lines); 148 | PHP_FUNCTION(pango_layout_get_line); 149 | PHP_FUNCTION(pango_layout_get_line_count); 150 | PHP_FUNCTION(pango_layout_context_changed); 151 | 152 | /* PangoLayoutLine functions */ 153 | PHP_FUNCTION(pango_layout_line_get_extents); 154 | PHP_FUNCTION(pango_layout_line_get_pixel_extents); 155 | PHP_FUNCTION(pango_cairo_show_layout_line); 156 | 157 | /* PangoFontDescription functions */ 158 | PHP_FUNCTION(pango_font_description_new); 159 | PHP_FUNCTION(pango_font_description_get_variant); 160 | PHP_FUNCTION(pango_font_description_set_variant); 161 | PHP_FUNCTION(pango_font_description_equal); 162 | PHP_FUNCTION(pango_font_description_set_family); 163 | PHP_FUNCTION(pango_font_description_get_family); 164 | PHP_FUNCTION(pango_font_description_set_size); 165 | PHP_FUNCTION(pango_font_description_get_size); 166 | PHP_FUNCTION(pango_font_description_get_style); 167 | PHP_FUNCTION(pango_font_description_set_style); 168 | PHP_FUNCTION(pango_font_description_get_weight); 169 | PHP_FUNCTION(pango_font_description_set_weight); 170 | PHP_FUNCTION(pango_font_description_get_stretch); 171 | PHP_FUNCTION(pango_font_description_set_stretch); 172 | PHP_FUNCTION(pango_font_description_to_string); 173 | 174 | /* 175 | Declare any global variables you may need between the BEGIN 176 | and END macros here: 177 | 178 | ZEND_BEGIN_MODULE_GLOBALS(pango) 179 | long global_value; 180 | char *global_string; 181 | ZEND_END_MODULE_GLOBALS(pango) 182 | */ 183 | 184 | /* In every utility function you add that needs to use variables 185 | in php_pango_globals, call TSRMLS_FETCH(); after declaring other 186 | variables used by that function, or better yet, pass in TSRMLS_CC 187 | after the last function argument and declare your utility function 188 | with TSRMLS_DC after the last declared argument. Always refer to 189 | the globals in your function as PANGO_G(variable). You are 190 | encouraged to rename these macros something shorter, see 191 | examples in any other php module directory. 192 | */ 193 | 194 | #ifdef ZTS 195 | #define PANGO_G(v) TSRMG(pango_globals_id, zend_pango_globals *, v) 196 | #else 197 | #define PANGO_G(v) (pango_globals.v) 198 | #endif 199 | 200 | 201 | /* turn error handling to exception mode and restore */ 202 | /* Borrowed from pecl/cairo, ta auroraeosrose */ 203 | #if PHP_VERSION_ID >= 50300 204 | /* 5.3 version of the macros */ 205 | #define PHP_PANGO_ERROR_HANDLING(force_exceptions) \ 206 | zend_error_handling error_handling; \ 207 | if(force_exceptions || getThis()) { \ 208 | zend_replace_error_handling(EH_THROW, pango_ce_pangoexception, &error_handling TSRMLS_CC); \ 209 | } 210 | 211 | #define PHP_PANGO_RESTORE_ERRORS(force_exceptions) \ 212 | if(force_exceptions || getThis()) { \ 213 | zend_restore_error_handling(&error_handling TSRMLS_CC); \ 214 | } 215 | 216 | #else 217 | /* 5.2 versions of the macros */ 218 | #define PHP_PANGO_ERROR_HANDLING(force_exceptions) \ 219 | if(force_exceptions || getThis()) { \ 220 | php_set_error_handling(EH_THROW, pango_ce_pangoexception TSRMLS_CC); \ 221 | } 222 | 223 | #define PHP_PANGO_RESTORE_ERRORS(force_exceptions) \ 224 | if(force_exceptions || getThis()) { \ 225 | php_std_error_handling(); \ 226 | } 227 | 228 | #endif 229 | 230 | /* do error or exception based on "are we in method or in function" */ 231 | #define PHP_PANGO_ERROR(status) \ 232 | if(!getThis()) { \ 233 | php_pango_trigger_error(status TSRMLS_CC); \ 234 | } else { \ 235 | php_pango_throw_exception(status TSRMLS_CC); \ 236 | } 237 | 238 | 239 | /* refcount macros */ 240 | #ifndef Z_ADDREF_P 241 | #define Z_ADDREF_P(pz) (pz)->refcount++ 242 | #endif 243 | 244 | #ifndef Z_DELREF_P 245 | #define Z_DELREF_P(pz) (pz)->refcount-- 246 | #endif 247 | 248 | #ifndef Z_SET_REFCOUNT_P 249 | #define Z_SET_REFCOUNT_P(pz, rc) (pz)->refcount = rc 250 | #endif 251 | 252 | #endif /* PHP_PANGO_H */ 253 | 254 | 255 | /* 256 | * Local variables: 257 | * tab-width: 4 258 | * c-basic-offset: 4 259 | * End: 260 | * vim600: noet sw=4 ts=4 fdm=marker 261 | * vim<600: noet sw=4 ts=4 262 | */ 263 | -------------------------------------------------------------------------------- /pango_context.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 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: Michael Maclean | 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 | 26 | zend_class_entry *pango_ce_pangocontext; 27 | zend_class_entry *pango_ce_pangodirection; 28 | 29 | #ifdef PANGO_VERSION 30 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 31 | zend_class_entry *pango_ce_pangogravity; 32 | zend_class_entry *pango_ce_pangogravityhint; 33 | #endif 34 | #endif 35 | 36 | PHP_PANGO_API zend_class_entry* php_pango_get_context_ce() { 37 | return pango_ce_pangocontext; 38 | } 39 | 40 | #ifdef PANGO_VERSION 41 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 42 | /* {{{ proto void pango_context_set_base_gravity(PangoContext context, int gravity) 43 | proto void PangoContext::setBaseGravity(int gravity) 44 | Sets the gravity to be used to lay out the text */ 45 | PHP_FUNCTION(pango_context_set_base_gravity) 46 | { 47 | zval *context_zval = NULL; 48 | pango_context_object *context_object; 49 | long gravity; 50 | 51 | PHP_PANGO_ERROR_HANDLING(FALSE) 52 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, pango_ce_pangocontext, &gravity) == FAILURE) { 53 | PHP_PANGO_RESTORE_ERRORS(FALSE) 54 | return; 55 | } 56 | PHP_PANGO_RESTORE_ERRORS(FALSE) 57 | 58 | context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 59 | pango_context_set_base_gravity(context_object->context, gravity); 60 | } 61 | /* }}} */ 62 | 63 | /* {{{ proto void pango_context_get_base_gravity(PangoContext context, int gravity) 64 | proto void PangoContext::setBaseGravity(int gravity) 65 | Gets the gravity to be used to lay out the text */ 66 | PHP_FUNCTION(pango_context_get_base_gravity) 67 | { 68 | zval *context_zval = NULL; 69 | pango_context_object *context_object; 70 | 71 | PHP_PANGO_ERROR_HANDLING(FALSE) 72 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) { 73 | PHP_PANGO_RESTORE_ERRORS(FALSE) 74 | return; 75 | } 76 | PHP_PANGO_RESTORE_ERRORS(FALSE) 77 | 78 | context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 79 | RETURN_LONG(pango_context_get_base_gravity(context_object->context)); 80 | } 81 | /* }}} */ 82 | 83 | /* {{{ proto void pango_context_get_gravity(PangoContext context, int gravity) 84 | proto void PangoContext::getGravity(int gravity) 85 | Gets the gravity to be used to lay out the text */ 86 | PHP_FUNCTION(pango_context_get_gravity) 87 | { 88 | zval *context_zval = NULL; 89 | pango_context_object *context_object; 90 | 91 | PHP_PANGO_ERROR_HANDLING(FALSE) 92 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) { 93 | PHP_PANGO_RESTORE_ERRORS(FALSE) 94 | return; 95 | } 96 | PHP_PANGO_RESTORE_ERRORS(FALSE) 97 | 98 | context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 99 | RETURN_LONG(pango_context_get_gravity(context_object->context)); 100 | } 101 | /* }}} */ 102 | 103 | /* {{{ proto void pango_context_set_gravity_hint(PangoContext context, int gravityHint) 104 | proto void PangoContext::setGravityHint(int gravityHint) 105 | Sets the gravity to be used to lay out the text */ 106 | PHP_FUNCTION(pango_context_set_gravity_hint) 107 | { 108 | zval *context_zval = NULL; 109 | pango_context_object *context_object; 110 | long gravity; 111 | 112 | PHP_PANGO_ERROR_HANDLING(FALSE) 113 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &context_zval, pango_ce_pangocontext, &gravity) == FAILURE) { 114 | PHP_PANGO_RESTORE_ERRORS(FALSE) 115 | return; 116 | } 117 | PHP_PANGO_RESTORE_ERRORS(FALSE) 118 | 119 | context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 120 | pango_context_set_gravity_hint(context_object->context, gravity); 121 | } 122 | /* }}} */ 123 | 124 | /* {{{ proto void pango_context_get_gravity_hint(PangoContext context) 125 | proto void PangoContext::getGravityHint() 126 | Gets the gravity hint to be used to lay out the text */ 127 | PHP_FUNCTION(pango_context_get_gravity_hint) 128 | { 129 | zval *context_zval = NULL; 130 | pango_context_object *context_object; 131 | 132 | PHP_PANGO_ERROR_HANDLING(FALSE) 133 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &context_zval, pango_ce_pangocontext) == FAILURE) { 134 | PHP_PANGO_RESTORE_ERRORS(FALSE) 135 | return; 136 | } 137 | PHP_PANGO_RESTORE_ERRORS(FALSE) 138 | 139 | context_object = (pango_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 140 | RETURN_LONG(pango_context_get_gravity_hint(context_object->context)); 141 | } 142 | /* }}} */ 143 | #endif 144 | #endif 145 | 146 | /* {{{ Object creation/destruction functions */ 147 | static void pango_context_object_destroy(void *object TSRMLS_DC) 148 | { 149 | pango_context_object *context = (pango_context_object *)object; 150 | zend_hash_destroy(context->std.properties); 151 | FREE_HASHTABLE(context->std.properties); 152 | 153 | if(context->context){ 154 | g_object_unref(context->context); 155 | } 156 | efree(object); 157 | } 158 | 159 | static zend_object_value pango_context_object_new(zend_class_entry *ce TSRMLS_DC) 160 | { 161 | zend_object_value retval; 162 | pango_context_object *context; 163 | zval *temp; 164 | 165 | context = ecalloc(1, sizeof(pango_context_object)); 166 | 167 | context->std.ce = ce; 168 | context->context = NULL; 169 | 170 | ALLOC_HASHTABLE(context->std.properties); 171 | zend_hash_init(context->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); 172 | #if PHP_VERSION_ID < 50399 173 | zend_hash_copy(context->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *)); 174 | #else 175 | object_properties_init(&(context->std),ce); 176 | #endif 177 | retval.handle = zend_objects_store_put(context, NULL, (zend_objects_free_object_storage_t)pango_context_object_destroy, NULL TSRMLS_CC); 178 | retval.handlers = &pango_std_object_handlers; 179 | return retval; 180 | } 181 | /* }}} */ 182 | 183 | const zend_function_entry pango_context_methods[] = { 184 | #ifdef PANGO_VERSION 185 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 186 | PHP_ME_MAPPING(setBaseGravity, pango_context_set_base_gravity, NULL, ZEND_ACC_PUBLIC) 187 | PHP_ME_MAPPING(getBaseGravity, pango_context_get_base_gravity, NULL, ZEND_ACC_PUBLIC) 188 | PHP_ME_MAPPING(getGravity, pango_context_get_gravity, NULL, ZEND_ACC_PUBLIC) 189 | PHP_ME_MAPPING(setGravityHint, pango_context_set_gravity_hint, NULL, ZEND_ACC_PUBLIC) 190 | PHP_ME_MAPPING(getGravityHint, pango_context_get_gravity_hint, NULL, ZEND_ACC_PUBLIC) 191 | #endif 192 | #endif 193 | { NULL, NULL, NULL } 194 | }; 195 | 196 | /* {{{ PHP_MINIT_FUNCTION */ 197 | PHP_MINIT_FUNCTION(pango_context) 198 | { 199 | zend_class_entry context_ce; 200 | zend_class_entry direction_ce; 201 | #ifdef PANGO_VERSION 202 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 203 | zend_class_entry gravity_ce; 204 | zend_class_entry gravityhint_ce; 205 | #endif 206 | #endif 207 | 208 | INIT_CLASS_ENTRY(context_ce, "PangoContext", pango_context_methods); 209 | pango_ce_pangocontext = zend_register_internal_class(&context_ce TSRMLS_CC); 210 | pango_ce_pangocontext->create_object = pango_context_object_new; 211 | 212 | INIT_CLASS_ENTRY(direction_ce, "PangoDirection", NULL); 213 | pango_ce_pangodirection = zend_register_internal_class(&direction_ce TSRMLS_CC); 214 | pango_ce_pangodirection->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 215 | 216 | #define REGISTER_PANGO_DIRECTION_LONG_CONST(const_name, value) \ 217 | zend_declare_class_constant_long(pango_ce_pangodirection, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 218 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 219 | 220 | REGISTER_PANGO_DIRECTION_LONG_CONST("LTR", PANGO_DIRECTION_LTR); 221 | REGISTER_PANGO_DIRECTION_LONG_CONST("RTL", PANGO_DIRECTION_RTL); 222 | REGISTER_PANGO_DIRECTION_LONG_CONST("TTB_LTR", PANGO_DIRECTION_TTB_LTR); 223 | REGISTER_PANGO_DIRECTION_LONG_CONST("TTB_RTL", PANGO_DIRECTION_TTB_RTL); 224 | REGISTER_PANGO_DIRECTION_LONG_CONST("WEAK_LTR", PANGO_DIRECTION_WEAK_LTR); 225 | REGISTER_PANGO_DIRECTION_LONG_CONST("WEAK_RTL", PANGO_DIRECTION_WEAK_RTL); 226 | REGISTER_PANGO_DIRECTION_LONG_CONST("NEUTRAL", PANGO_DIRECTION_NEUTRAL); 227 | 228 | #ifdef PANGO_VERSION 229 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 6, 0) 230 | INIT_CLASS_ENTRY(gravity_ce, "PangoGravity", NULL); 231 | pango_ce_pangogravity = zend_register_internal_class(&gravity_ce TSRMLS_CC); 232 | pango_ce_pangogravity->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 233 | 234 | #define REGISTER_PANGO_GRAVITY_LONG_CONST(const_name, value) \ 235 | zend_declare_class_constant_long(pango_ce_pangogravity, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 236 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 237 | 238 | REGISTER_PANGO_GRAVITY_LONG_CONST("SOUTH", PANGO_GRAVITY_SOUTH); 239 | REGISTER_PANGO_GRAVITY_LONG_CONST("EAST", PANGO_GRAVITY_EAST); 240 | REGISTER_PANGO_GRAVITY_LONG_CONST("NORTH", PANGO_GRAVITY_NORTH); 241 | REGISTER_PANGO_GRAVITY_LONG_CONST("WEST", PANGO_GRAVITY_WEST); 242 | REGISTER_PANGO_GRAVITY_LONG_CONST("AUTO", PANGO_GRAVITY_AUTO); 243 | 244 | INIT_CLASS_ENTRY(gravityhint_ce, "PangoGravityHint", NULL); 245 | pango_ce_pangogravityhint = zend_register_internal_class(&gravityhint_ce TSRMLS_CC); 246 | pango_ce_pangogravityhint->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 247 | 248 | #define REGISTER_PANGO_GRAVITY_HINT_LONG_CONST(const_name, value) \ 249 | zend_declare_class_constant_long(pango_ce_pangogravityhint, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 250 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 251 | 252 | REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("NATURAL", PANGO_GRAVITY_HINT_NATURAL); 253 | REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("STRONG", PANGO_GRAVITY_HINT_STRONG); 254 | REGISTER_PANGO_GRAVITY_HINT_LONG_CONST("LINE", PANGO_GRAVITY_HINT_LINE); 255 | #endif 256 | #endif 257 | 258 | return SUCCESS; 259 | } 260 | /* }}} */ 261 | 262 | /* 263 | * Local variables: 264 | * tab-width: 4 265 | * c-basic-offset: 4 266 | * End: 267 | * vim600: noet sw=4 ts=4 fdm=marker 268 | * vim<600: noet sw=4 ts=4 269 | */ 270 | -------------------------------------------------------------------------------- /pango_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 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: Michael Maclean | 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 | 26 | #include 27 | #include "zend_exceptions.h" 28 | 29 | zend_class_entry *pango_ce_pangolayoutline; 30 | 31 | static zend_object_handlers pango_layoutline_object_handlers; 32 | 33 | PHP_PANGO_API zend_class_entry* php_pango_get_layoutline_ce() 34 | { 35 | return pango_ce_pangolayoutline; 36 | } 37 | 38 | /* {{{ php_pango_make_layoutline_zval 39 | Convenience function to handle setting all the properties etc */ 40 | PHP_PANGO_API zval* php_pango_make_layoutline_zval(PangoLayoutLine *line, zval *layout TSRMLS_DC) 41 | { 42 | zval *return_value, *length, *is_paragraph_start, *resolved_dir; 43 | pango_layoutline_object *layoutline_object; 44 | 45 | MAKE_STD_ZVAL(return_value); 46 | object_init_ex(return_value, pango_ce_pangolayoutline); 47 | layoutline_object = (pango_layoutline_object *)zend_object_store_get_object(return_value TSRMLS_CC); 48 | layoutline_object->line = line; 49 | 50 | /* Optionally cache the PangoLayout zval for later */ 51 | if(layout != NULL) { 52 | Z_ADDREF_P(layout); 53 | layoutline_object->layout_zval = layout; 54 | } 55 | 56 | MAKE_STD_ZVAL(length); 57 | ZVAL_LONG(length, line->length); 58 | zend_hash_update(Z_OBJPROP_P(return_value), "length", sizeof("length"), (void **) &length, sizeof(zval *), NULL); 59 | 60 | MAKE_STD_ZVAL(is_paragraph_start); 61 | ZVAL_BOOL(is_paragraph_start, line->is_paragraph_start); 62 | zend_hash_update(Z_OBJPROP_P(return_value), "is_paragraph_start", sizeof("is_paragraph_start"), (void **) &is_paragraph_start, sizeof(zval *), NULL); 63 | 64 | MAKE_STD_ZVAL(resolved_dir); 65 | ZVAL_LONG(resolved_dir, line->resolved_dir); 66 | zend_hash_update(Z_OBJPROP_P(return_value), "resolved_dir", sizeof("resolved_dir"), (void **) &resolved_dir, sizeof(zval *), NULL); 67 | 68 | return return_value; 69 | } 70 | /* }}} */ 71 | 72 | /* {{{ proto array pango_layout_line_get_extents(PangoLayoutLine line) 73 | proto array PangoLayoutLine::getExtents() 74 | Get the logical and ink extents for the line */ 75 | PHP_FUNCTION(pango_layout_line_get_extents) 76 | { 77 | zval *layoutline_zval = NULL, *array = NULL; 78 | pango_layoutline_object *layoutline_object = NULL; 79 | PangoRectangle ink, logical; 80 | 81 | PHP_PANGO_ERROR_HANDLING(FALSE) 82 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", 83 | &layoutline_zval, pango_ce_pangolayoutline) == FAILURE) { 84 | PHP_PANGO_RESTORE_ERRORS(FALSE) 85 | return; 86 | } 87 | PHP_PANGO_RESTORE_ERRORS(FALSE) 88 | 89 | layoutline_object = (pango_layoutline_object *)zend_object_store_get_object(layoutline_zval TSRMLS_CC); 90 | pango_layout_line_get_extents(layoutline_object->line, &ink, &logical); 91 | 92 | array_init(return_value); 93 | MAKE_STD_ZVAL(array); 94 | array_init(array); 95 | add_assoc_long(array, "x", ink.x); 96 | add_assoc_long(array, "y", ink.y); 97 | add_assoc_long(array, "width", ink.width); 98 | add_assoc_long(array, "height", ink.height); 99 | add_assoc_long(array, "ascent", PANGO_ASCENT(ink)); 100 | add_assoc_long(array, "descent", PANGO_DESCENT(ink)); 101 | add_assoc_long(array, "lbearing", PANGO_LBEARING(ink)); 102 | add_assoc_long(array, "rbearing", PANGO_RBEARING(ink)); 103 | add_assoc_zval(return_value, "ink", array); 104 | ALLOC_INIT_ZVAL(array); 105 | array_init(array); 106 | add_assoc_long(array, "x", logical.x); 107 | add_assoc_long(array, "y", logical.y); 108 | add_assoc_long(array, "width", logical.width); 109 | add_assoc_long(array, "height", logical.height); 110 | add_assoc_long(array, "ascent", PANGO_ASCENT(logical)); 111 | add_assoc_long(array, "descent", PANGO_DESCENT(logical)); 112 | add_assoc_long(array, "lbearing", PANGO_LBEARING(logical)); 113 | add_assoc_long(array, "rbearing", PANGO_RBEARING(logical)); 114 | add_assoc_zval(return_value, "logical", array); 115 | } 116 | /* }}} */ 117 | 118 | /* {{{ proto array pango_layout_line_get_pixel_extents(PangoLayoutLine line) 119 | proto array PangoLayoutLine::getPixelExtents() 120 | Get the logical and ink extents for the line, in device units */ 121 | PHP_FUNCTION(pango_layout_line_get_pixel_extents) 122 | { 123 | zval *layoutline_zval = NULL, *array = NULL; 124 | pango_layoutline_object *layoutline_object = NULL; 125 | PangoRectangle ink, logical; 126 | 127 | PHP_PANGO_ERROR_HANDLING(FALSE) 128 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", 129 | &layoutline_zval, pango_ce_pangolayoutline) == FAILURE) { 130 | PHP_PANGO_RESTORE_ERRORS(FALSE) 131 | return; 132 | } 133 | PHP_PANGO_RESTORE_ERRORS(FALSE) 134 | 135 | layoutline_object = (pango_layoutline_object *)zend_object_store_get_object(layoutline_zval TSRMLS_CC); 136 | pango_layout_line_get_pixel_extents(layoutline_object->line, &ink, &logical); 137 | 138 | array_init(return_value); 139 | MAKE_STD_ZVAL(array); 140 | array_init(array); 141 | add_assoc_long(array, "x", ink.x); 142 | add_assoc_long(array, "y", ink.y); 143 | add_assoc_long(array, "width", ink.width); 144 | add_assoc_long(array, "height", ink.height); 145 | add_assoc_long(array, "ascent", PANGO_ASCENT(ink)); 146 | add_assoc_long(array, "descent", PANGO_DESCENT(ink)); 147 | add_assoc_long(array, "lbearing", PANGO_LBEARING(ink)); 148 | add_assoc_long(array, "rbearing", PANGO_RBEARING(ink)); 149 | add_assoc_zval(return_value, "ink", array); 150 | ALLOC_INIT_ZVAL(array); 151 | array_init(array); 152 | add_assoc_long(array, "x", logical.x); 153 | add_assoc_long(array, "y", logical.y); 154 | add_assoc_long(array, "width", logical.width); 155 | add_assoc_long(array, "height", logical.height); 156 | add_assoc_long(array, "ascent", PANGO_ASCENT(logical)); 157 | add_assoc_long(array, "descent", PANGO_DESCENT(logical)); 158 | add_assoc_long(array, "lbearing", PANGO_LBEARING(logical)); 159 | add_assoc_long(array, "rbearing", PANGO_RBEARING(logical)); 160 | add_assoc_zval(return_value, "logical", array); 161 | } 162 | /* }}} */ 163 | 164 | /* {{{ proto void pango_cairo_show_layout_line(PangoLayoutLine line, CairoContext context) 165 | proto void PangoLayoutLine::show([CairoContext context]) 166 | Draws a PangoLayoutLine in the specified cairo context. If no context 167 | is specified, use the cached one from when the PangoLayoutLine was created */ 168 | PHP_FUNCTION(pango_cairo_show_layout_line) 169 | { 170 | zval *layoutline_zval = NULL, *layout_zval = NULL, *cairocontext_zval = NULL; 171 | pango_layoutline_object *layoutline_object = NULL; 172 | pango_layout_object *layout_object = NULL; 173 | cairo_context_object *cairocontext_object = NULL; 174 | 175 | PHP_PANGO_ERROR_HANDLING(FALSE) 176 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", 177 | &layoutline_zval, pango_ce_pangolayoutline, 178 | &cairocontext_zval, php_cairo_get_context_ce()) == FAILURE) { 179 | PHP_PANGO_RESTORE_ERRORS(FALSE) 180 | return; 181 | } 182 | PHP_PANGO_RESTORE_ERRORS(FALSE) 183 | 184 | layoutline_object = (pango_layoutline_object *)zend_object_store_get_object(layoutline_zval TSRMLS_CC); 185 | 186 | if(cairocontext_zval == NULL) { 187 | layout_zval = layoutline_object->layout_zval; 188 | layout_object = zend_object_store_get_object(layout_zval TSRMLS_CC); 189 | cairocontext_zval = layout_object->cairo_context; 190 | } 191 | cairocontext_object = zend_object_store_get_object(cairocontext_zval TSRMLS_CC); 192 | 193 | pango_cairo_show_layout_line(cairocontext_object->context, layoutline_object->line); 194 | } 195 | /* }}} */ 196 | 197 | /* {{{ Object creation/destruction functions */ 198 | static void pango_layoutline_object_destroy(void *object TSRMLS_DC) 199 | { 200 | pango_layoutline_object *layoutline = (pango_layoutline_object *)object; 201 | zend_hash_destroy(layoutline->std.properties); 202 | FREE_HASHTABLE(layoutline->std.properties); 203 | 204 | if(layoutline->layout_zval != NULL) { 205 | Z_DELREF_P(layoutline->layout_zval); 206 | } 207 | 208 | efree(object); 209 | } 210 | 211 | #if PHP_VERSION_ID < 50399 212 | static void php_pango_layoutline_write_property(zval *object, zval *member, zval *value TSRMLS_DC) 213 | #else 214 | static void php_pango_layoutline_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) 215 | #endif 216 | { 217 | zval tmp_member; 218 | 219 | if (member->type != IS_STRING) { 220 | tmp_member = *member; 221 | zval_copy_ctor(&tmp_member); 222 | convert_to_string(&tmp_member); 223 | member = &tmp_member; 224 | } 225 | 226 | if(((Z_STRLEN_P(member) == sizeof("length") - 1 && !memcmp(Z_STRVAL_P(member), "length", sizeof("length"))) 227 | || (Z_STRLEN_P(member) == sizeof("is_paragraph_start") - 1 && !memcmp(Z_STRVAL_P(member), "is_paragraph_start", sizeof("is_paragraph_start"))) 228 | || (Z_STRLEN_P(member) == sizeof("resolved_dir") - 1 && !memcmp(Z_STRVAL_P(member), "resolved_dir", sizeof("resolved_dir"))))) 229 | { 230 | zend_throw_exception_ex(pango_ce_pangoexception, 0 TSRMLS_CC, 231 | "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name, Z_STRVAL_P(member)); 232 | } else { 233 | #if PHP_VERSION_ID < 50399 234 | pango_std_object_handlers.write_property(object, member, value TSRMLS_CC); 235 | #else 236 | pango_std_object_handlers.write_property(object, member, value, key TSRMLS_CC); 237 | #endif 238 | } 239 | 240 | if (member == &tmp_member) { 241 | zval_dtor(member); 242 | } 243 | } 244 | 245 | 246 | static zend_object_value pango_layoutline_object_new(zend_class_entry *ce TSRMLS_DC) 247 | { 248 | zend_object_value retval; 249 | pango_layoutline_object *layoutline; 250 | zval *temp; 251 | 252 | layoutline = ecalloc(1, sizeof(pango_layoutline_object)); 253 | 254 | layoutline->std.ce = ce; 255 | layoutline->line = NULL; 256 | 257 | ALLOC_HASHTABLE(layoutline->std.properties); 258 | zend_hash_init(layoutline->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); 259 | #if PHP_VERSION_ID < 50399 260 | zend_hash_copy(layoutline->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *)); 261 | #else 262 | object_properties_init(&(layoutline->std), ce); 263 | #endif 264 | retval.handle = zend_objects_store_put(layoutline, NULL, (zend_objects_free_object_storage_t)pango_layoutline_object_destroy, NULL TSRMLS_CC); 265 | retval.handlers = &pango_layoutline_object_handlers; 266 | return retval; 267 | } 268 | /* }}} */ 269 | 270 | /* {{{ pango_layout_class_functions */ 271 | const zend_function_entry pango_layoutline_methods[] = { 272 | PHP_ME_MAPPING(getExtents, pango_layout_line_get_extents, NULL, ZEND_ACC_PUBLIC) 273 | PHP_ME_MAPPING(getPixelExtents, pango_layout_line_get_pixel_extents, NULL, ZEND_ACC_PUBLIC) 274 | PHP_ME_MAPPING(show, pango_cairo_show_layout_line, NULL, ZEND_ACC_PUBLIC) 275 | {NULL, NULL, NULL} 276 | }; 277 | /* }}} */ 278 | 279 | /* {{{ PHP_MINIT_FUNCTION */ 280 | PHP_MINIT_FUNCTION(pango_line) 281 | { 282 | zend_class_entry line_ce; 283 | 284 | INIT_CLASS_ENTRY(line_ce, "PangoLayoutLine", pango_layoutline_methods); 285 | pango_ce_pangolayoutline = zend_register_internal_class(&line_ce TSRMLS_CC); 286 | pango_ce_pangolayoutline->create_object = pango_layoutline_object_new; 287 | memcpy(&pango_layoutline_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 288 | pango_layoutline_object_handlers.write_property = php_pango_layoutline_write_property; 289 | 290 | return SUCCESS; 291 | } 292 | 293 | /* 294 | * Local variables: 295 | * tab-width: 4 296 | * c-basic-offset: 4 297 | * End: 298 | * vim600: noet sw=4 ts=4 fdm=marker 299 | * vim<600: noet sw=4 ts=4 300 | */ 301 | 302 | -------------------------------------------------------------------------------- /pango_font.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2008 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: Michael Maclean | 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 | 26 | #include "zend_exceptions.h" 27 | 28 | zend_class_entry *pango_ce_pangofontdescription; 29 | zend_class_entry *pango_ce_pangostyle; 30 | zend_class_entry *pango_ce_pangoweight; 31 | zend_class_entry *pango_ce_pangovariant; 32 | zend_class_entry *pango_ce_pangostretch; 33 | zend_class_entry *pango_ce_pangofontmask; 34 | 35 | /* {{{ proto PangoFontDescription::__construct(string description) 36 | Creates a new font description object. This merges pango_font_description_new 37 | and pango_font_description_from_string. */ 38 | PHP_METHOD(PangoFontDescription, __construct) 39 | { 40 | pango_fontdesc_object *fontdesc_object = NULL; 41 | const char *text; 42 | long text_len = -1; 43 | 44 | PHP_PANGO_ERROR_HANDLING(TRUE) 45 | if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &text, &text_len) == FAILURE) 46 | { 47 | PHP_PANGO_RESTORE_ERRORS(TRUE) 48 | return; 49 | } 50 | PHP_PANGO_RESTORE_ERRORS(TRUE) 51 | 52 | if(text_len) { 53 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(getThis() TSRMLS_CC); 54 | fontdesc_object->fontdesc = pango_font_description_from_string(text); 55 | } else { 56 | fontdesc_object->fontdesc = pango_font_description_new(); 57 | } 58 | 59 | if(!fontdesc_object->fontdesc) { 60 | zend_throw_exception(pango_ce_pangoexception, "Could not create the Pango font description", 0 TSRMLS_CC); 61 | return; 62 | } 63 | } 64 | /* }}} */ 65 | 66 | /* {{{ proto PangoFontDescription pango_font_description_new(string description) 67 | Creates a new font description object. This merges pango_font_description_new 68 | and pango_font_description_from_string. */ 69 | PHP_FUNCTION(pango_font_description_new) 70 | { 71 | pango_fontdesc_object *fontdesc_object = NULL; 72 | const char *text; 73 | long text_len = -1; 74 | 75 | PHP_PANGO_ERROR_HANDLING(TRUE) 76 | if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &text, &text_len) == FAILURE) 77 | { 78 | PHP_PANGO_RESTORE_ERRORS(TRUE) 79 | return; 80 | } 81 | PHP_PANGO_RESTORE_ERRORS(TRUE) 82 | 83 | object_init_ex(return_value, pango_ce_pangofontdescription); 84 | if(text_len) { 85 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(return_value TSRMLS_CC); 86 | fontdesc_object->fontdesc = pango_font_description_from_string(text); 87 | } else { 88 | fontdesc_object->fontdesc = pango_font_description_new(); 89 | } 90 | 91 | if(fontdesc_object->fontdesc == NULL) { 92 | } 93 | } 94 | /* }}} */ 95 | 96 | /* {{{ proto long pango_font_description_get_variant(PangoFontDescription fontdesc) 97 | proto long PangoFontDescription::getVariant() 98 | Sets the variant of the font description. */ 99 | PHP_FUNCTION(pango_font_description_get_variant) 100 | { 101 | zval *fontdesc_zval = NULL; 102 | pango_fontdesc_object *fontdesc_object; 103 | 104 | PHP_PANGO_ERROR_HANDLING(FALSE) 105 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) 106 | { 107 | PHP_PANGO_RESTORE_ERRORS(FALSE) 108 | return; 109 | } 110 | PHP_PANGO_RESTORE_ERRORS(FALSE) 111 | 112 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 113 | RETURN_LONG(pango_font_description_get_variant(fontdesc_object->fontdesc)); 114 | } 115 | 116 | /* }}} */ 117 | 118 | /* {{{ proto void pango_font_description_set_variant (PangoFontDescription fontdesc, long variant) 119 | proto void PangoFontDescription::setVariant(long variant) 120 | Sets the variant of the layout. */ 121 | PHP_FUNCTION(pango_font_description_set_variant) 122 | { 123 | zval *fontdesc_zval = NULL; 124 | pango_fontdesc_object *fontdesc_object; 125 | long variant; 126 | 127 | PHP_PANGO_ERROR_HANDLING(FALSE) 128 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &fontdesc_zval, pango_ce_pangofontdescription, &variant) == FAILURE) { 129 | PHP_PANGO_RESTORE_ERRORS(FALSE) 130 | return; 131 | } 132 | PHP_PANGO_RESTORE_ERRORS(FALSE) 133 | 134 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 135 | pango_font_description_set_variant(fontdesc_object->fontdesc, variant); 136 | } 137 | 138 | /* }}} */ 139 | 140 | /* {{{ proto boolean pango_font_description_equal(PangoFontDescription fontdesc1, PangoFontDescription fontdesc2) 141 | proto boolean PangoFontDescription::equal(PangoFontDescription fontdesc2) 142 | Compares two font description objects for equality. 143 | */ 144 | PHP_FUNCTION(pango_font_description_equal) 145 | { 146 | zval *fontdesc_zval = NULL, *fontdesc2_zval = NULL; 147 | pango_fontdesc_object *fontdesc_object, *fontdesc2_object; 148 | 149 | PHP_PANGO_ERROR_HANDLING(FALSE) 150 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", 151 | &fontdesc_zval, pango_ce_pangofontdescription, &fontdesc2_zval, pango_ce_pangofontdescription) == FAILURE) { 152 | PHP_PANGO_RESTORE_ERRORS(FALSE) 153 | return; 154 | } 155 | PHP_PANGO_RESTORE_ERRORS(FALSE) 156 | 157 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 158 | fontdesc2_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc2_zval TSRMLS_CC); 159 | RETURN_BOOL(pango_font_description_equal(fontdesc_object->fontdesc, fontdesc2_object->fontdesc)); 160 | } 161 | 162 | /* }}} */ 163 | 164 | /* {{{ proto void pango_font_description_set_family (PangoFontDescription fontdesc, string family) 165 | proto void PangoFontDescription::setFamily(string family) 166 | Sets the family name field of a font description. */ 167 | PHP_FUNCTION(pango_font_description_set_family) 168 | { 169 | zval *fontdesc_zval = NULL; 170 | pango_fontdesc_object *fontdesc_object; 171 | const char *family; 172 | long family_len; 173 | 174 | PHP_PANGO_ERROR_HANDLING(FALSE) 175 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &fontdesc_zval, pango_ce_pangofontdescription, &family, &family_len) == FAILURE) { 176 | PHP_PANGO_RESTORE_ERRORS(FALSE) 177 | return; 178 | } 179 | PHP_PANGO_RESTORE_ERRORS(FALSE) 180 | 181 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 182 | pango_font_description_set_family(fontdesc_object->fontdesc, family); 183 | } 184 | 185 | /* }}} */ 186 | 187 | /* {{{ proto string pango_font_description_get_family (PangoFontDescription fontdesc) 188 | proto string PangoFontDescription::getFamily() 189 | Sets the family name field of a font description. */ 190 | PHP_FUNCTION(pango_font_description_get_family) 191 | { 192 | zval *fontdesc_zval = NULL; 193 | pango_fontdesc_object *fontdesc_object; 194 | const char *family; 195 | 196 | PHP_PANGO_ERROR_HANDLING(FALSE) 197 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) { 198 | PHP_PANGO_RESTORE_ERRORS(FALSE) 199 | return; 200 | } 201 | PHP_PANGO_RESTORE_ERRORS(FALSE) 202 | 203 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 204 | if ((family = pango_font_description_get_family(fontdesc_object->fontdesc))) { 205 | RETURN_STRING((char *)family, 1); 206 | } 207 | RETURN_FALSE; 208 | } 209 | 210 | /* }}} */ 211 | 212 | /* {{{ proto void pango_font_description_set_size (PangoFontDescription fontdesc, long size) 213 | proto void PangoFontDescription::setSize(long size) 214 | Sets the size field of a font description. */ 215 | PHP_FUNCTION(pango_font_description_set_size) 216 | { 217 | zval *fontdesc_zval = NULL; 218 | pango_fontdesc_object *fontdesc_object; 219 | long size; 220 | 221 | PHP_PANGO_ERROR_HANDLING(FALSE) 222 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &fontdesc_zval, pango_ce_pangofontdescription, &size) == FAILURE) { 223 | PHP_PANGO_RESTORE_ERRORS(FALSE) 224 | return; 225 | } 226 | PHP_PANGO_RESTORE_ERRORS(FALSE) 227 | 228 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 229 | pango_font_description_set_size(fontdesc_object->fontdesc, size); 230 | } 231 | 232 | /* }}} */ 233 | 234 | /* {{{ proto long pango_font_description_get_size (PangoFontDescription fontdesc) 235 | proto long PangoFontDescription::getSize() 236 | Gets the size field of a font description. */ 237 | PHP_FUNCTION(pango_font_description_get_size) 238 | { 239 | zval *fontdesc_zval = NULL; 240 | pango_fontdesc_object *fontdesc_object; 241 | long size; 242 | 243 | PHP_PANGO_ERROR_HANDLING(FALSE) 244 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) { 245 | PHP_PANGO_RESTORE_ERRORS(FALSE) 246 | return; 247 | } 248 | PHP_PANGO_RESTORE_ERRORS(FALSE) 249 | 250 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 251 | RETURN_LONG (pango_font_description_get_size(fontdesc_object->fontdesc)); 252 | } 253 | 254 | /* }}} */ 255 | 256 | /* {{{ proto long pango_font_description_get_style(PangoFontDescription fontdesc) 257 | proto long PangoFontDescription::getStyle() 258 | Gets the style of the font description. */ 259 | PHP_FUNCTION(pango_font_description_get_style) 260 | { 261 | zval *fontdesc_zval = NULL; 262 | pango_fontdesc_object *fontdesc_object; 263 | 264 | PHP_PANGO_ERROR_HANDLING(FALSE) 265 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) 266 | { 267 | PHP_PANGO_RESTORE_ERRORS(FALSE) 268 | return; 269 | } 270 | PHP_PANGO_RESTORE_ERRORS(FALSE) 271 | 272 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 273 | RETURN_LONG(pango_font_description_get_style(fontdesc_object->fontdesc)); 274 | } 275 | 276 | /* }}} */ 277 | 278 | /* {{{ proto void pango_font_description_set_style (PangoFontDescription fontdesc, long style) 279 | proto void PangoFontDescription::setVariant(long style) 280 | Sets the style of the layout. */ 281 | PHP_FUNCTION(pango_font_description_set_style) 282 | { 283 | zval *fontdesc_zval = NULL; 284 | pango_fontdesc_object *fontdesc_object; 285 | long style; 286 | 287 | PHP_PANGO_ERROR_HANDLING(FALSE) 288 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &fontdesc_zval, pango_ce_pangofontdescription, &style) == FAILURE) { 289 | PHP_PANGO_RESTORE_ERRORS(FALSE) 290 | return; 291 | } 292 | PHP_PANGO_RESTORE_ERRORS(FALSE) 293 | 294 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 295 | pango_font_description_set_style(fontdesc_object->fontdesc, style); 296 | } 297 | 298 | /* }}} */ 299 | 300 | 301 | /* {{{ proto long pango_font_description_get_weight(PangoFontDescription fontdesc) 302 | proto long PangoFontDescription::getWeight() 303 | Sets the weight of the font description. */ 304 | PHP_FUNCTION(pango_font_description_get_weight) 305 | { 306 | zval *fontdesc_zval = NULL; 307 | pango_fontdesc_object *fontdesc_object; 308 | 309 | PHP_PANGO_ERROR_HANDLING(FALSE) 310 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) 311 | { 312 | PHP_PANGO_RESTORE_ERRORS(FALSE) 313 | return; 314 | } 315 | PHP_PANGO_RESTORE_ERRORS(FALSE) 316 | 317 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 318 | RETURN_LONG(pango_font_description_get_weight(fontdesc_object->fontdesc)); 319 | } 320 | 321 | /* }}} */ 322 | 323 | /* {{{ proto void pango_font_description_set_weight (PangoFontDescription fontdesc, long weight) 324 | proto void PangoFontDescription::setWeight(long weight) 325 | Sets the weight of the layout. */ 326 | PHP_FUNCTION(pango_font_description_set_weight) 327 | { 328 | zval *fontdesc_zval = NULL; 329 | pango_fontdesc_object *fontdesc_object; 330 | long weight; 331 | 332 | PHP_PANGO_ERROR_HANDLING(FALSE) 333 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &fontdesc_zval, pango_ce_pangofontdescription, &weight) == FAILURE) { 334 | PHP_PANGO_RESTORE_ERRORS(FALSE) 335 | return; 336 | } 337 | PHP_PANGO_RESTORE_ERRORS(FALSE) 338 | 339 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 340 | pango_font_description_set_weight(fontdesc_object->fontdesc, weight); 341 | } 342 | 343 | /* }}} */ 344 | 345 | 346 | /* {{{ proto long pango_font_description_get_stretch(PangoFontDescription fontdesc) 347 | proto long PangoFontDescription::getStretch() 348 | Sets the stretch of the font description. */ 349 | PHP_FUNCTION(pango_font_description_get_stretch) 350 | { 351 | zval *fontdesc_zval = NULL; 352 | pango_fontdesc_object *fontdesc_object; 353 | 354 | PHP_PANGO_ERROR_HANDLING(FALSE) 355 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) 356 | { 357 | PHP_PANGO_RESTORE_ERRORS(FALSE) 358 | return; 359 | } 360 | PHP_PANGO_RESTORE_ERRORS(FALSE) 361 | 362 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 363 | RETURN_LONG(pango_font_description_get_stretch(fontdesc_object->fontdesc)); 364 | } 365 | 366 | /* }}} */ 367 | 368 | /* {{{ proto void pango_font_description_set_stretch (PangoFontDescription fontdesc, long stretch) 369 | proto void PangoFontDescription::setStretch(long stretch) 370 | Sets the stretch of the layout. */ 371 | PHP_FUNCTION(pango_font_description_set_stretch) 372 | { 373 | zval *fontdesc_zval = NULL; 374 | pango_fontdesc_object *fontdesc_object; 375 | long stretch; 376 | 377 | PHP_PANGO_ERROR_HANDLING(FALSE) 378 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &fontdesc_zval, pango_ce_pangofontdescription, &stretch) == FAILURE) { 379 | PHP_PANGO_RESTORE_ERRORS(FALSE) 380 | return; 381 | } 382 | PHP_PANGO_RESTORE_ERRORS(FALSE) 383 | 384 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 385 | pango_font_description_set_stretch(fontdesc_object->fontdesc, stretch); 386 | } 387 | 388 | /* }}} */ 389 | 390 | /* {{{ proto string pango_font_description_to_string (PangoFontDescription fontdesc) 391 | proto string PangoFontDescription::toString() 392 | Creates a string representation of a font description. */ 393 | PHP_FUNCTION(pango_font_description_to_string) 394 | { 395 | zval *fontdesc_zval = NULL; 396 | pango_fontdesc_object *fontdesc_object; 397 | const char *result; 398 | 399 | PHP_PANGO_ERROR_HANDLING(FALSE) 400 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) { 401 | PHP_PANGO_RESTORE_ERRORS(FALSE) 402 | return; 403 | } 404 | PHP_PANGO_RESTORE_ERRORS(FALSE) 405 | 406 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 407 | if ((result = pango_font_description_to_string(fontdesc_object->fontdesc))) { 408 | RETURN_STRING((char *)result, 1); 409 | } 410 | RETURN_FALSE; 411 | } 412 | 413 | /* }}} */ 414 | 415 | 416 | 417 | 418 | /* {{{ Object creation/destruction functions */ 419 | static void pango_fontdesc_object_destroy(void *object TSRMLS_DC) 420 | { 421 | pango_fontdesc_object *fontdesc = (pango_fontdesc_object *)object; 422 | zend_hash_destroy(fontdesc->std.properties); 423 | FREE_HASHTABLE(fontdesc->std.properties); 424 | 425 | if(fontdesc->fontdesc) { 426 | pango_font_description_free(fontdesc->fontdesc); 427 | } 428 | efree(object); 429 | } 430 | 431 | static zend_object_value pango_fontdesc_object_new(zend_class_entry *ce TSRMLS_DC) 432 | { 433 | zend_object_value retval; 434 | pango_fontdesc_object *fontdesc; 435 | zval *temp; 436 | 437 | fontdesc = ecalloc(1, sizeof(pango_fontdesc_object)); 438 | 439 | fontdesc->std.ce = ce; 440 | fontdesc->fontdesc = NULL; 441 | 442 | ALLOC_HASHTABLE(fontdesc->std.properties); 443 | zend_hash_init(fontdesc->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); 444 | #if PHP_VERSION_ID < 50399 445 | zend_hash_copy(fontdesc->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *)); 446 | #else 447 | object_properties_init(&(fontdesc->std), ce); 448 | #endif 449 | retval.handle = zend_objects_store_put(fontdesc, NULL, (zend_objects_free_object_storage_t)pango_fontdesc_object_destroy, NULL TSRMLS_CC); 450 | retval.handlers = &pango_std_object_handlers; 451 | return retval; 452 | } 453 | /* }}} */ 454 | 455 | /* {{{ pango fontdescription class functions */ 456 | const zend_function_entry pango_fontdesc_methods[] = { 457 | PHP_ME(PangoFontDescription, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 458 | PHP_ME_MAPPING(getVariant, pango_font_description_get_variant, NULL, ZEND_ACC_PUBLIC) 459 | PHP_ME_MAPPING(setVariant, pango_font_description_set_variant, NULL, ZEND_ACC_PUBLIC) 460 | PHP_ME_MAPPING(equal, pango_font_description_equal, NULL, ZEND_ACC_PUBLIC) 461 | PHP_ME_MAPPING(setFamily, pango_font_description_set_family, NULL, ZEND_ACC_PUBLIC) 462 | PHP_ME_MAPPING(getFamily, pango_font_description_get_family, NULL, ZEND_ACC_PUBLIC) 463 | PHP_ME_MAPPING(setSize, pango_font_description_set_size, NULL, ZEND_ACC_PUBLIC) 464 | PHP_ME_MAPPING(getSize, pango_font_description_get_size, NULL, ZEND_ACC_PUBLIC) 465 | PHP_ME_MAPPING(getStyle, pango_font_description_get_style, NULL, ZEND_ACC_PUBLIC) 466 | PHP_ME_MAPPING(setStyle, pango_font_description_set_style, NULL, ZEND_ACC_PUBLIC) 467 | PHP_ME_MAPPING(getWeight, pango_font_description_get_weight, NULL, ZEND_ACC_PUBLIC) 468 | PHP_ME_MAPPING(setWeight, pango_font_description_set_weight, NULL, ZEND_ACC_PUBLIC) 469 | PHP_ME_MAPPING(getStretch, pango_font_description_get_stretch, NULL, ZEND_ACC_PUBLIC) 470 | PHP_ME_MAPPING(setStretch, pango_font_description_set_stretch, NULL, ZEND_ACC_PUBLIC) 471 | PHP_ME_MAPPING(toString, pango_font_description_to_string, NULL, ZEND_ACC_PUBLIC) 472 | { NULL, NULL, NULL } 473 | }; 474 | 475 | /* {{{ PHP_MINIT_FUNCTION */ 476 | PHP_MINIT_FUNCTION(pango_font) 477 | { 478 | zend_class_entry fontdescription_ce; 479 | zend_class_entry style_ce; 480 | zend_class_entry weight_ce; 481 | zend_class_entry variant_ce; 482 | zend_class_entry stretch_ce; 483 | zend_class_entry fontmask_ce; 484 | 485 | INIT_CLASS_ENTRY(fontdescription_ce, "PangoFontDescription", pango_fontdesc_methods); 486 | pango_ce_pangofontdescription = zend_register_internal_class(&fontdescription_ce TSRMLS_CC); 487 | pango_ce_pangofontdescription->create_object = pango_fontdesc_object_new; 488 | 489 | INIT_CLASS_ENTRY(style_ce, "PangoStyle", NULL); 490 | pango_ce_pangostyle = zend_register_internal_class(&style_ce TSRMLS_CC); 491 | pango_ce_pangostyle->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 492 | 493 | #define REGISTER_PANGO_STYLE_LONG_CONST(const_name, value) \ 494 | zend_declare_class_constant_long(pango_ce_pangostyle, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 495 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 496 | 497 | REGISTER_PANGO_STYLE_LONG_CONST("NORMAL", PANGO_STYLE_NORMAL); 498 | REGISTER_PANGO_STYLE_LONG_CONST("OBLIQUE", PANGO_STYLE_OBLIQUE); 499 | REGISTER_PANGO_STYLE_LONG_CONST("ITALIC", PANGO_STYLE_ITALIC); 500 | 501 | INIT_CLASS_ENTRY(weight_ce, "PangoWeight", NULL); 502 | pango_ce_pangoweight = zend_register_internal_class(&weight_ce TSRMLS_CC); 503 | pango_ce_pangoweight->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 504 | 505 | #define REGISTER_PANGO_WEIGHT_LONG_CONST(const_name, value) \ 506 | zend_declare_class_constant_long(pango_ce_pangoweight, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 507 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 508 | 509 | REGISTER_PANGO_WEIGHT_LONG_CONST("ULTRALIGHT", PANGO_WEIGHT_ULTRALIGHT); 510 | REGISTER_PANGO_WEIGHT_LONG_CONST("LIGHT", PANGO_WEIGHT_LIGHT); 511 | REGISTER_PANGO_WEIGHT_LONG_CONST("NORMAL", PANGO_WEIGHT_NORMAL); 512 | REGISTER_PANGO_WEIGHT_LONG_CONST("SEMIBOLD", PANGO_WEIGHT_SEMIBOLD); 513 | REGISTER_PANGO_WEIGHT_LONG_CONST("BOLD", PANGO_WEIGHT_BOLD); 514 | REGISTER_PANGO_WEIGHT_LONG_CONST("ULTRABOLD", PANGO_WEIGHT_ULTRABOLD); 515 | REGISTER_PANGO_WEIGHT_LONG_CONST("HEAVY", PANGO_WEIGHT_HEAVY); 516 | 517 | #ifdef PANGO_VERSION 518 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 24, 0) 519 | REGISTER_PANGO_WEIGHT_LONG_CONST("THIN", PANGO_WEIGHT_THIN); 520 | REGISTER_PANGO_WEIGHT_LONG_CONST("BOOK", PANGO_WEIGHT_BOOK); 521 | REGISTER_PANGO_WEIGHT_LONG_CONST("MEDIUM", PANGO_WEIGHT_MEDIUM); 522 | REGISTER_PANGO_WEIGHT_LONG_CONST("ULTRAHEAVY", PANGO_WEIGHT_ULTRAHEAVY); 523 | #endif 524 | #endif 525 | 526 | INIT_CLASS_ENTRY(variant_ce, "PangoVariant", NULL); 527 | pango_ce_pangovariant = zend_register_internal_class(&variant_ce TSRMLS_CC); 528 | pango_ce_pangovariant->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 529 | 530 | #define REGISTER_PANGO_VARIANT_LONG_CONST(const_name, value) \ 531 | zend_declare_class_constant_long(pango_ce_pangovariant, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 532 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 533 | 534 | REGISTER_PANGO_VARIANT_LONG_CONST("NORMAL", PANGO_VARIANT_NORMAL); 535 | REGISTER_PANGO_VARIANT_LONG_CONST("SMALL_CAPS", PANGO_VARIANT_SMALL_CAPS); 536 | 537 | INIT_CLASS_ENTRY(stretch_ce, "PangoStretch", NULL); 538 | pango_ce_pangostretch = zend_register_internal_class(&stretch_ce TSRMLS_CC); 539 | pango_ce_pangostretch->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 540 | 541 | #define REGISTER_PANGO_STRETCH_LONG_CONST(const_name, value) \ 542 | zend_declare_class_constant_long(pango_ce_pangostretch, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 543 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 544 | 545 | REGISTER_PANGO_STRETCH_LONG_CONST("ULTRA_CONDENSED", PANGO_STRETCH_ULTRA_CONDENSED); 546 | REGISTER_PANGO_STRETCH_LONG_CONST("EXTRA_CONDENSED", PANGO_STRETCH_EXTRA_CONDENSED); 547 | REGISTER_PANGO_STRETCH_LONG_CONST("CONDENSED", PANGO_STRETCH_CONDENSED); 548 | REGISTER_PANGO_STRETCH_LONG_CONST("SEMI_CONDENSED", PANGO_STRETCH_SEMI_CONDENSED); 549 | REGISTER_PANGO_STRETCH_LONG_CONST("NORMAL", PANGO_STRETCH_NORMAL); 550 | REGISTER_PANGO_STRETCH_LONG_CONST("SEMI_EXPANDED", PANGO_STRETCH_SEMI_EXPANDED); 551 | REGISTER_PANGO_STRETCH_LONG_CONST("EXPANDED", PANGO_STRETCH_EXPANDED); 552 | REGISTER_PANGO_STRETCH_LONG_CONST("EXTRA_EXPANDED", PANGO_STRETCH_EXTRA_EXPANDED); 553 | REGISTER_PANGO_STRETCH_LONG_CONST("ULTRA_EXPANDED", PANGO_STRETCH_ULTRA_EXPANDED); 554 | 555 | INIT_CLASS_ENTRY(fontmask_ce, "PangoFontMask", NULL); 556 | pango_ce_pangofontmask = zend_register_internal_class(&fontmask_ce TSRMLS_CC); 557 | pango_ce_pangofontmask->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 558 | 559 | #define REGISTER_PANGO_FONT_MASK_LONG_CONST(const_name, value) \ 560 | zend_declare_class_constant_long(pango_ce_pangofontmask, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 561 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 562 | 563 | REGISTER_PANGO_FONT_MASK_LONG_CONST("FAMILY", PANGO_FONT_MASK_FAMILY); 564 | REGISTER_PANGO_FONT_MASK_LONG_CONST("STYLE", PANGO_FONT_MASK_STYLE); 565 | REGISTER_PANGO_FONT_MASK_LONG_CONST("VARIANT", PANGO_FONT_MASK_VARIANT); 566 | REGISTER_PANGO_FONT_MASK_LONG_CONST("WEIGHT", PANGO_FONT_MASK_WEIGHT); 567 | REGISTER_PANGO_FONT_MASK_LONG_CONST("STRETCH", PANGO_FONT_MASK_STRETCH); 568 | REGISTER_PANGO_FONT_MASK_LONG_CONST("SIZE", PANGO_FONT_MASK_SIZE); 569 | #ifdef PANGO_FONT_MASK_GRAVITY 570 | REGISTER_PANGO_FONT_MASK_LONG_CONST("GRAVITY", PANGO_FONT_MASK_GRAVITY); 571 | #endif 572 | 573 | return SUCCESS; 574 | } 575 | 576 | /* 577 | * Local variables: 578 | * tab-width: 4 579 | * c-basic-offset: 4 580 | * End: 581 | * vim600: noet sw=4 ts=4 fdm=marker 582 | * vim<600: noet sw=4 ts=4 583 | */ 584 | -------------------------------------------------------------------------------- /pango_layout.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2011 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 | 16 | | David Marín | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "php.h" 25 | #include "php_pango.h" 26 | 27 | #include "zend_exceptions.h" 28 | 29 | zend_class_entry *pango_ce_pangolayout; 30 | zend_class_entry *pango_ce_pangoalignment; 31 | zend_class_entry *pango_ce_pangowrapmode; 32 | zend_class_entry *pango_ce_pangoellipsizemode; 33 | zend_class_entry *pango_ce_pangofontdescription; 34 | 35 | /* {{{ proto PangoLayout::__construct(CairoContext cr) 36 | Creates a PangoLayout based on the CairoContext object */ 37 | 38 | PHP_METHOD(PangoLayout, __construct) 39 | { 40 | zval *context_zval = NULL; 41 | zend_class_entry *cairo_ce_cairocontext = php_cairo_get_context_ce(); 42 | cairo_context_object *context_object; 43 | pango_layout_object *layout_object; 44 | 45 | PHP_PANGO_ERROR_HANDLING(TRUE) 46 | if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &context_zval, cairo_ce_cairocontext) == FAILURE) 47 | { 48 | PHP_PANGO_RESTORE_ERRORS(TRUE) 49 | return; 50 | } 51 | PHP_PANGO_RESTORE_ERRORS(TRUE) 52 | 53 | context_object = (cairo_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 54 | 55 | layout_object = (pango_layout_object *)zend_object_store_get_object(getThis() TSRMLS_CC); 56 | layout_object->layout = pango_cairo_create_layout(context_object->context); 57 | 58 | if(layout_object->layout == NULL) { 59 | zend_throw_exception(pango_ce_pangoexception, "Could not create the Pango layout", 0 TSRMLS_CC); 60 | return; 61 | } 62 | 63 | /* We may want this later, so reference it and store */ 64 | layout_object->cairo_context = context_zval; 65 | Z_ADDREF_P(context_zval); 66 | } 67 | 68 | /* }}} */ 69 | 70 | /* {{{ proto pango_layout_new(CairoContext cr) 71 | Creates a PangoLayout based on the CairoContext object */ 72 | 73 | PHP_FUNCTION(pango_layout_new) 74 | { 75 | zval *context_zval = NULL; 76 | zend_class_entry *cairo_ce_cairocontext = php_cairo_get_context_ce(); 77 | cairo_context_object *context_object; 78 | pango_layout_object *layout_object; 79 | 80 | PHP_PANGO_ERROR_HANDLING(TRUE) 81 | if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &context_zval, cairo_ce_cairocontext) == FAILURE) 82 | { 83 | PHP_PANGO_RESTORE_ERRORS(TRUE) 84 | return; 85 | } 86 | PHP_PANGO_RESTORE_ERRORS(TRUE) 87 | 88 | context_object = (cairo_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 89 | 90 | object_init_ex(return_value, pango_ce_pangolayout); 91 | layout_object = (pango_layout_object *)zend_object_store_get_object(return_value TSRMLS_CC); 92 | layout_object->layout = pango_cairo_create_layout(context_object->context); 93 | 94 | if(layout_object->layout == NULL) { 95 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create the Pango layout"); 96 | return; 97 | } 98 | 99 | /* We may want this later, so reference it and store */ 100 | layout_object->cairo_context = context_zval; 101 | Z_ADDREF_P(context_zval); 102 | } 103 | 104 | 105 | /* }}} */ 106 | 107 | /* {{{ proto PangoContext PangoLayout::getContext() 108 | proto PangoContext pango_layout_get_context(PangoLayout layout) 109 | Return the PangoContext for the current layout */ 110 | PHP_FUNCTION(pango_layout_get_context) 111 | { 112 | zval *layout_zval = NULL; 113 | pango_layout_object *layout_object; 114 | pango_context_object *context_object; 115 | PangoContext *context; 116 | zend_class_entry *ce; 117 | 118 | PHP_PANGO_ERROR_HANDLING(FALSE) 119 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 120 | PHP_PANGO_RESTORE_ERRORS(FALSE) 121 | return; 122 | } 123 | PHP_PANGO_RESTORE_ERRORS(FALSE) 124 | 125 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 126 | context = pango_layout_get_context(layout_object->layout); 127 | 128 | /* Have we already got the context object and cached it? */ 129 | if(layout_object->pango_context) { 130 | zval_dtor(return_value); 131 | *return_value = *layout_object->pango_context; 132 | zval_copy_ctor(return_value); 133 | Z_SET_REFCOUNT_P(return_value, 1); 134 | } else { 135 | /* We haven't already got one, let's make one */ 136 | ce = php_pango_get_context_ce(); 137 | object_init_ex(return_value, ce); 138 | } 139 | 140 | /* Get the context_object and replace the internal context pointer 141 | * with what we fetched (should be the same) */ 142 | context_object = (pango_context_object *)zend_object_store_get_object(return_value TSRMLS_CC); 143 | /* if there IS a value in context, destroy it cause we're getting a new one */ 144 | if (context_object->context != NULL) { 145 | g_object_unref(context_object->context); 146 | } 147 | /* Grab the context properly */ 148 | context_object->context = context; 149 | g_object_ref(context_object->context); 150 | } 151 | /* }}} */ 152 | 153 | /* {{{ proto void pango_layout_set_text(PangoLayout layout, string text) 154 | proto void PangoLayout::setText(string text) 155 | Sets the text of the layout. */ 156 | PHP_FUNCTION(pango_layout_set_text) 157 | { 158 | zval *layout_zval = NULL; 159 | pango_layout_object *layout_object; 160 | const char *text; 161 | long text_len; 162 | 163 | PHP_PANGO_ERROR_HANDLING(FALSE) 164 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &layout_zval, pango_ce_pangolayout, &text, &text_len) == FAILURE) { 165 | PHP_PANGO_RESTORE_ERRORS(FALSE) 166 | return; 167 | } 168 | PHP_PANGO_RESTORE_ERRORS(FALSE) 169 | 170 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 171 | pango_layout_set_text(layout_object->layout, text, text_len); 172 | } 173 | 174 | /* }}} */ 175 | 176 | /* {{{ proto string pango_layout_get_text(PangoLayout layout) 177 | proto string PangoLayout::getText() 178 | Gets the text currently in the layout */ 179 | PHP_FUNCTION(pango_layout_get_text) 180 | { 181 | zval *layout_zval = NULL; 182 | pango_layout_object *layout_object; 183 | const char *text; 184 | 185 | PHP_PANGO_ERROR_HANDLING(FALSE) 186 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 187 | PHP_PANGO_RESTORE_ERRORS(FALSE) 188 | return; 189 | } 190 | PHP_PANGO_RESTORE_ERRORS(FALSE) 191 | 192 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 193 | if((text = pango_layout_get_text(layout_object->layout))) { 194 | RETURN_STRING((char *)text, 1); 195 | } 196 | RETURN_FALSE; 197 | } 198 | /* }}} */ 199 | 200 | /* {{{ proto void pango_layout_set_markup(PangoLayout layout, string markup) 201 | proto void PangoLayout::setMarkup(string markup) 202 | Sets the markup of the layout. */ 203 | PHP_FUNCTION(pango_layout_set_markup) 204 | { 205 | zval *layout_zval = NULL; 206 | pango_layout_object *layout_object; 207 | const char *markup; 208 | long markup_len; 209 | 210 | PHP_PANGO_ERROR_HANDLING(FALSE) 211 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &layout_zval, pango_ce_pangolayout, &markup, &markup_len) == FAILURE) { 212 | PHP_PANGO_RESTORE_ERRORS(FALSE) 213 | return; 214 | } 215 | PHP_PANGO_RESTORE_ERRORS(FALSE) 216 | 217 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 218 | pango_layout_set_markup(layout_object->layout, markup, markup_len); 219 | } 220 | 221 | /* {{{ proto void pango_layout_context_changed(PangoLayout layout) 222 | proto void PangoLayout::contextChanged() 223 | Updates the private PangoContext of a PangoLayout to match the current transformation 224 | and target surface of a Cairo context. 225 | NB: PARAMS ARE REVERSED FROM NATIVE PANGO 226 | */ 227 | 228 | PHP_FUNCTION(pango_layout_context_changed) 229 | { 230 | zval *layout_zval = NULL; 231 | pango_layout_object *layout_object; 232 | 233 | PHP_PANGO_ERROR_HANDLING(FALSE) 234 | if(zend_parse_parameters_none() == FAILURE) { 235 | PHP_PANGO_RESTORE_ERRORS(FALSE) 236 | return; 237 | } 238 | PHP_PANGO_RESTORE_ERRORS(FALSE) 239 | 240 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 241 | pango_layout_context_changed(layout_object->layout); 242 | } 243 | /* }}} */ 244 | 245 | 246 | /* }}} */ 247 | 248 | 249 | #if 0 250 | /* Need to work out how to handle multibyte characters here */ 251 | /* {{{ proto void pango_layout_set_markup(PangoLayout layout, string markup) 252 | proto void PangoLayout::setText(string markup) 253 | Sets the markup of the layout with accelerator markers. */ 254 | PHP_FUNCTION(pango_layout_set_markup_with_accel) 255 | { 256 | zval *layout_zval = NULL; 257 | pango_layout_object *layout_object; 258 | const char *markup; 259 | const char *accel_marker; 260 | long markup_len = 0, accel_marker_len = 0, first_accel = 0; 261 | 262 | PHP_PANGO_ERROR_HANDLING(FALSE) 263 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &layout_zval, pango_ce_pangolayout, &markup, &markup_len, &accel_marker, &accel_marker_len) == FAILURE) { 264 | PHP_PANGO_RESTORE_ERRORS(FALSE) 265 | return; 266 | } 267 | PHP_PANGO_RESTORE_ERRORS(FALSE) 268 | 269 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 270 | if(accel_marker_len > 0) { 271 | pango_layout_set_markup_with_accel( 272 | layout_object->layout, markup, markup_len, accel_marker[0], &first_accel); 273 | } else { 274 | pango_layout_set_markup_with_accel(layout_object->layout, markup, markup_len, 0, &first_accel); 275 | } 276 | RETURN_LONG(first_accel); 277 | } 278 | #endif 279 | 280 | /* }}} */ 281 | 282 | /* {{{ proto void pango_cairo_update_layout(CairoContext cr, PangoLayout layout) 283 | proto void PangoLayout::updateLayout(CairoContext cr) 284 | Updates the private PangoContext of a PangoLayout to match the current transformation 285 | and target surface of a Cairo context. 286 | NB: PARAMS ARE REVERSED FROM NATIVE PANGO 287 | */ 288 | 289 | PHP_FUNCTION(pango_cairo_update_layout) 290 | { 291 | zval *layout_zval = NULL, *context_zval = NULL; 292 | pango_layout_object *layout_object; 293 | cairo_context_object *context_object; 294 | zend_class_entry *cairo_ce_cairocontext = php_cairo_get_context_ce(); 295 | 296 | PHP_PANGO_ERROR_HANDLING(FALSE) 297 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", &layout_zval, pango_ce_pangolayout, &context_zval, cairo_ce_cairocontext) == FAILURE) { 298 | PHP_PANGO_RESTORE_ERRORS(FALSE) 299 | return; 300 | } 301 | PHP_PANGO_RESTORE_ERRORS(FALSE) 302 | 303 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 304 | 305 | /* If the user supplies a context, use that, otherwise get the one from the layout */ 306 | if(context_zval) { 307 | context_object = (cairo_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 308 | } else { 309 | context_object = (cairo_context_object *)zend_object_store_get_object(layout_object->cairo_context TSRMLS_CC); 310 | } 311 | 312 | pango_cairo_update_layout(context_object->context, layout_object->layout); 313 | } 314 | /* }}} */ 315 | 316 | /* {{{ proto void pango_cairo_show_layout(CairoContext cr, PangoLayout layout) 317 | proto void PangoLayout::showLayout(CairoContext cr) 318 | Draws a PangoLayoutLine in the specified cairo context. 319 | NB: PARAMS ARE REVERSED FROM NATIVE PANGO 320 | */ 321 | 322 | PHP_FUNCTION(pango_cairo_show_layout) 323 | { 324 | zval *layout_zval = NULL, *context_zval = NULL; 325 | pango_layout_object *layout_object; 326 | cairo_context_object *context_object; 327 | zend_class_entry *cairo_ce_cairocontext = php_cairo_get_context_ce(); 328 | 329 | PHP_PANGO_ERROR_HANDLING(FALSE) 330 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", &layout_zval, pango_ce_pangolayout, &context_zval, cairo_ce_cairocontext) == FAILURE) { 331 | PHP_PANGO_RESTORE_ERRORS(FALSE) 332 | return; 333 | } 334 | PHP_PANGO_RESTORE_ERRORS(FALSE) 335 | 336 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 337 | 338 | /* If the user supplies a context, use that, otherwise get the one from the layout */ 339 | if(context_zval) { 340 | context_object = (cairo_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 341 | } else { 342 | context_object = (cairo_context_object *)zend_object_store_get_object(layout_object->cairo_context TSRMLS_CC); 343 | } 344 | 345 | pango_cairo_show_layout(context_object->context, layout_object->layout); 346 | } 347 | /* }}} */ 348 | 349 | /* {{{ proto void pango_cairo_layout_path(CairoContext cr, PangoLayout layout) 350 | proto void PangoLayout::layoutPath(CairoContext cr) 351 | Adds the specified text to the current path in the specified cairo context. 352 | NB: PARAMS ARE REVERSED FROM NATIVE PANGO 353 | */ 354 | 355 | PHP_FUNCTION(pango_cairo_layout_path) 356 | { 357 | zval *layout_zval = NULL, *context_zval = NULL; 358 | pango_layout_object *layout_object; 359 | cairo_context_object *context_object; 360 | zend_class_entry *cairo_ce_cairocontext = php_cairo_get_context_ce(); 361 | 362 | PHP_PANGO_ERROR_HANDLING(FALSE) 363 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O", &layout_zval, pango_ce_pangolayout, &context_zval, cairo_ce_cairocontext) == FAILURE) { 364 | PHP_PANGO_RESTORE_ERRORS(FALSE) 365 | return; 366 | } 367 | PHP_PANGO_RESTORE_ERRORS(FALSE) 368 | 369 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 370 | 371 | /* If the user supplies a context, use that, otherwise get the one from the layout */ 372 | if(context_zval) { 373 | context_object = (cairo_context_object *)zend_object_store_get_object(context_zval TSRMLS_CC); 374 | } else { 375 | context_object = (cairo_context_object *)zend_object_store_get_object(layout_object->cairo_context TSRMLS_CC); 376 | } 377 | 378 | pango_cairo_layout_path(context_object->context, layout_object->layout); 379 | } 380 | /* }}} */ 381 | 382 | /* {{{ proto long pango_layout_get_width(PangoLayout layout) 383 | proto long PangoLayout::getWidth() 384 | Gets the width of the layout. */ 385 | PHP_FUNCTION(pango_layout_get_width) 386 | { 387 | zval *layout_zval = NULL; 388 | pango_layout_object *layout_object; 389 | long width; 390 | 391 | PHP_PANGO_ERROR_HANDLING(FALSE) 392 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 393 | { 394 | PHP_PANGO_RESTORE_ERRORS(FALSE) 395 | return; 396 | } 397 | PHP_PANGO_RESTORE_ERRORS(FALSE) 398 | 399 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 400 | if((width = pango_layout_get_width(layout_object->layout))) { 401 | RETURN_LONG(width); 402 | } 403 | RETURN_FALSE; 404 | } 405 | 406 | /* }}} */ 407 | 408 | #ifdef PANGO_VERSION 409 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 410 | /* {{{ proto long pango_layout_get_height(PangoLayout layout) 411 | proto long PangoLayout::getHeight() 412 | Gets the height of the layout. */ 413 | PHP_FUNCTION(pango_layout_get_height) 414 | { 415 | zval *layout_zval = NULL; 416 | pango_layout_object *layout_object; 417 | long height; 418 | 419 | PHP_PANGO_ERROR_HANDLING(FALSE) 420 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 421 | { 422 | PHP_PANGO_RESTORE_ERRORS(FALSE) 423 | return; 424 | } 425 | PHP_PANGO_RESTORE_ERRORS(FALSE) 426 | 427 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 428 | if((height = pango_layout_get_height(layout_object->layout))) { 429 | RETURN_LONG(height); 430 | } 431 | RETURN_FALSE; 432 | } 433 | /* }}} */ 434 | #endif 435 | #endif 436 | 437 | 438 | /* {{{ proto array pango_layout_get_size(PangoLayout layout) 439 | proto array PangoLayout::getSize() 440 | Gets the size of the layout. */ 441 | PHP_FUNCTION(pango_layout_get_size) 442 | { 443 | zval *layout_zval = NULL; 444 | pango_layout_object *layout_object; 445 | int height = 0, width = 0; 446 | 447 | PHP_PANGO_ERROR_HANDLING(FALSE) 448 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 449 | { 450 | PHP_PANGO_RESTORE_ERRORS(FALSE) 451 | return; 452 | } 453 | PHP_PANGO_RESTORE_ERRORS(FALSE) 454 | 455 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 456 | pango_layout_get_size(layout_object->layout, &width, &height); 457 | 458 | array_init(return_value); 459 | add_assoc_long(return_value, "width", width); 460 | add_assoc_long(return_value, "height", height); 461 | } 462 | 463 | /* }}} */ 464 | 465 | /* {{{ proto array pango_layout_get_pixel_size(PangoLayout layout) 466 | proto array PangoLayout::getPixelSize() 467 | Gets the size of layout in pixels */ 468 | PHP_FUNCTION(pango_layout_get_pixel_size) 469 | { 470 | zval *layout_zval = NULL; 471 | pango_layout_object *layout_object; 472 | int height = 0, width = 0; 473 | 474 | PHP_PANGO_ERROR_HANDLING(FALSE) 475 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 476 | { 477 | PHP_PANGO_RESTORE_ERRORS(FALSE) 478 | return; 479 | } 480 | PHP_PANGO_RESTORE_ERRORS(FALSE) 481 | 482 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 483 | pango_layout_get_pixel_size(layout_object->layout, &width, &height); 484 | 485 | array_init(return_value); 486 | add_assoc_long(return_value, "width", width); 487 | add_assoc_long(return_value, "height", height); 488 | } 489 | 490 | /* }}} */ 491 | 492 | /* {{{ proto array pango_layout_get_extents(PangoLayout layout) 493 | proto array PangoLayout::getExtents() 494 | Gets the extents of layout in */ 495 | PHP_FUNCTION(pango_layout_get_extents) 496 | { 497 | zval *layout_zval = NULL; 498 | pango_layout_object *layout_object; 499 | PangoRectangle ink; 500 | PangoRectangle logical; 501 | zval *array; 502 | 503 | PHP_PANGO_ERROR_HANDLING(FALSE) 504 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 505 | { 506 | PHP_PANGO_RESTORE_ERRORS(FALSE) 507 | return; 508 | } 509 | PHP_PANGO_RESTORE_ERRORS(FALSE) 510 | 511 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 512 | pango_layout_get_extents(layout_object->layout, &ink, &logical); 513 | 514 | array_init(return_value); 515 | ALLOC_INIT_ZVAL(array); 516 | array_init(array); 517 | add_assoc_long(array, "x", ink.x); 518 | add_assoc_long(array, "y", ink.y); 519 | add_assoc_long(array, "width", ink.width); 520 | add_assoc_long(array, "height", ink.height); 521 | add_assoc_zval(return_value, "ink", array); 522 | ALLOC_INIT_ZVAL(array); 523 | array_init(array); 524 | add_assoc_long(array, "x", logical.x); 525 | add_assoc_long(array, "y", logical.y); 526 | add_assoc_long(array, "width", logical.width); 527 | add_assoc_long(array, "height", logical.height); 528 | add_assoc_zval(return_value, "logical", array); 529 | } 530 | 531 | /* }}} */ 532 | 533 | /* {{{ proto array pango_layout_get_pixel_extents(PangoLayout layout) 534 | proto array PangoLayout::getPixelExtents() 535 | Gets the extents of layout in pixels */ 536 | PHP_FUNCTION(pango_layout_get_pixel_extents) 537 | { 538 | zval *layout_zval = NULL; 539 | pango_layout_object *layout_object; 540 | PangoRectangle ink; 541 | PangoRectangle logical; 542 | zval *array; 543 | 544 | PHP_PANGO_ERROR_HANDLING(FALSE) 545 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) 546 | { 547 | PHP_PANGO_RESTORE_ERRORS(FALSE) 548 | return; 549 | } 550 | PHP_PANGO_RESTORE_ERRORS(FALSE) 551 | 552 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 553 | pango_layout_get_pixel_extents(layout_object->layout, &ink, &logical); 554 | 555 | array_init(return_value); 556 | ALLOC_INIT_ZVAL(array); 557 | array_init(array); 558 | add_assoc_long(array, "x", ink.x); 559 | add_assoc_long(array, "y", ink.y); 560 | add_assoc_long(array, "width", ink.width); 561 | add_assoc_long(array, "height", ink.height); 562 | add_assoc_zval(return_value, "ink", array); 563 | ALLOC_INIT_ZVAL(array); 564 | array_init(array); 565 | add_assoc_long(array, "x", logical.x); 566 | add_assoc_long(array, "y", logical.y); 567 | add_assoc_long(array, "width", logical.width); 568 | add_assoc_long(array, "height", logical.height); 569 | add_assoc_zval(return_value, "logical", array); 570 | } 571 | 572 | /* }}} */ 573 | 574 | /* {{{ proto void pango_layout_set_width(PangoLayout layout, long width) 575 | proto void PangoLayout::setWidth(long width) 576 | Sets the width of the layout. */ 577 | PHP_FUNCTION(pango_layout_set_width) 578 | { 579 | zval *layout_zval = NULL; 580 | pango_layout_object *layout_object; 581 | long width; 582 | 583 | PHP_PANGO_ERROR_HANDLING(FALSE) 584 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &width) == FAILURE) { 585 | PHP_PANGO_RESTORE_ERRORS(FALSE) 586 | return; 587 | } 588 | PHP_PANGO_RESTORE_ERRORS(FALSE) 589 | 590 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 591 | pango_layout_set_width(layout_object->layout, width); 592 | } 593 | 594 | /* }}} */ 595 | 596 | #ifdef PANGO_VERSION 597 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 598 | /* {{{ proto void pango_layout_set_height(PangoLayout layout, long height) 599 | proto void PangoLayout::setHeight(long height) 600 | Sets the height of the layout. */ 601 | PHP_FUNCTION(pango_layout_set_height) 602 | { 603 | zval *layout_zval = NULL; 604 | pango_layout_object *layout_object; 605 | long height; 606 | 607 | PHP_PANGO_ERROR_HANDLING(FALSE) 608 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &height) == FAILURE) { 609 | PHP_PANGO_RESTORE_ERRORS(FALSE) 610 | return; 611 | } 612 | PHP_PANGO_RESTORE_ERRORS(FALSE) 613 | 614 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 615 | pango_layout_set_height(layout_object->layout, height); 616 | } 617 | /* }}} */ 618 | #endif 619 | #endif 620 | 621 | /* {{{ proto void pango_layout_set_font_description(PangoLayout layout, PangoFontDescription font_description) 622 | proto void PangoLayout::setFontDescription(PangoFontDescription font_description) 623 | Sets the font_description of the layout. */ 624 | PHP_FUNCTION(pango_layout_set_font_description) 625 | { 626 | zval *layout_zval = NULL, *fontdesc_zval = NULL; 627 | pango_layout_object *layout_object; 628 | pango_fontdesc_object *fontdesc_object; 629 | 630 | PHP_PANGO_ERROR_HANDLING(FALSE) 631 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &layout_zval, pango_ce_pangolayout, &fontdesc_zval, pango_ce_pangofontdescription) == FAILURE) { 632 | PHP_PANGO_RESTORE_ERRORS(FALSE) 633 | return; 634 | } 635 | PHP_PANGO_RESTORE_ERRORS(FALSE) 636 | 637 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 638 | fontdesc_object = (pango_fontdesc_object *)zend_object_store_get_object(fontdesc_zval TSRMLS_CC); 639 | pango_layout_set_font_description(layout_object->layout, fontdesc_object->fontdesc); 640 | } 641 | 642 | /* }}} */ 643 | 644 | 645 | /* {{{ proto PangoFontDescription object pango_layout_get_font_description(PangoLayout layout) 646 | proto PangoFontDescription object PangoLayout::getFontDescription() 647 | Gets the font_description of the layout. */ 648 | PHP_FUNCTION(pango_layout_get_font_description) 649 | { 650 | zval *layout_zval = NULL; 651 | pango_layout_object *layout_object; 652 | pango_fontdesc_object *fontdesc_object = NULL; 653 | const PangoFontDescription *aux = NULL; 654 | 655 | PHP_PANGO_ERROR_HANDLING(FALSE) 656 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 657 | PHP_PANGO_RESTORE_ERRORS(FALSE) 658 | return; 659 | } 660 | PHP_PANGO_RESTORE_ERRORS(FALSE) 661 | 662 | object_init_ex(return_value, pango_ce_pangofontdescription); 663 | fontdesc_object = (pango_fontdesc_object *) zend_object_store_get_object(return_value TSRMLS_CC); 664 | 665 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 666 | aux = pango_layout_get_font_description(layout_object->layout); 667 | fontdesc_object->fontdesc = pango_font_description_copy (aux); 668 | 669 | } 670 | 671 | /* }}} */ 672 | 673 | /* {{{ proto void pango_layout_set_justify(PangoLayout layout, bool justify) 674 | proto void PangoLayout::setJustify(bool justify) 675 | Sets whether each line should be justified. */ 676 | PHP_FUNCTION(pango_layout_set_justify) 677 | { 678 | zval *layout_zval = NULL; 679 | pango_layout_object *layout_object; 680 | zend_bool justify; 681 | 682 | PHP_PANGO_ERROR_HANDLING(FALSE) 683 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", &layout_zval, pango_ce_pangolayout, &justify) == FAILURE) { 684 | PHP_PANGO_RESTORE_ERRORS(FALSE) 685 | return; 686 | } 687 | PHP_PANGO_RESTORE_ERRORS(FALSE) 688 | 689 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 690 | pango_layout_set_justify(layout_object->layout, justify); 691 | } 692 | 693 | /* }}} */ 694 | 695 | /* {{{ proto bool pango_layout_get_justify(PangoLayout layout) 696 | proto bool PangoLayout::getJustify() 697 | Returns whether text will be justified or not in the current layout */ 698 | PHP_FUNCTION(pango_layout_get_justify) 699 | { 700 | zval *layout_zval = NULL; 701 | pango_layout_object *layout_object; 702 | 703 | PHP_PANGO_ERROR_HANDLING(FALSE) 704 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 705 | PHP_PANGO_RESTORE_ERRORS(FALSE) 706 | return; 707 | } 708 | PHP_PANGO_RESTORE_ERRORS(FALSE) 709 | 710 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 711 | RETURN_BOOL(pango_layout_get_justify(layout_object->layout)); 712 | } 713 | /* }}} */ 714 | 715 | /* {{{ proto void pango_layout_set_alignment(PangoLayout layout, long alignment) 716 | proto void PangoLayout::setAlignment(long alignment) 717 | Sets whether each line should be justified. */ 718 | PHP_FUNCTION(pango_layout_set_alignment) 719 | { 720 | zval *layout_zval = NULL; 721 | pango_layout_object *layout_object; 722 | long alignment; 723 | 724 | PHP_PANGO_ERROR_HANDLING(FALSE) 725 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &alignment) == FAILURE) { 726 | PHP_PANGO_RESTORE_ERRORS(FALSE) 727 | return; 728 | } 729 | PHP_PANGO_RESTORE_ERRORS(FALSE) 730 | 731 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 732 | pango_layout_set_alignment(layout_object->layout, alignment); 733 | } 734 | 735 | /* }}} */ 736 | 737 | /* {{{ proto long pango_layout_get_alignment(PangoLayout layout) 738 | proto long PangoLayout::getAlignment() 739 | Returns whether text will be justified or not in the current layout */ 740 | PHP_FUNCTION(pango_layout_get_alignment) 741 | { 742 | zval *layout_zval = NULL; 743 | pango_layout_object *layout_object; 744 | 745 | PHP_PANGO_ERROR_HANDLING(FALSE) 746 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 747 | PHP_PANGO_RESTORE_ERRORS(FALSE) 748 | return; 749 | } 750 | PHP_PANGO_RESTORE_ERRORS(FALSE) 751 | 752 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 753 | RETURN_LONG(pango_layout_get_alignment(layout_object->layout)); 754 | } 755 | /* }}} */ 756 | 757 | /* {{{ proto void pango_layout_set_wrap(PangoLayout layout, long wrap) 758 | proto void PangoLayout::setWrap(long wrap) 759 | Sets how each line should be wrapped. */ 760 | PHP_FUNCTION(pango_layout_set_wrap) 761 | { 762 | zval *layout_zval = NULL; 763 | pango_layout_object *layout_object; 764 | long wrap; 765 | 766 | PHP_PANGO_ERROR_HANDLING(FALSE) 767 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &wrap) == FAILURE) { 768 | PHP_PANGO_RESTORE_ERRORS(FALSE) 769 | return; 770 | } 771 | PHP_PANGO_RESTORE_ERRORS(FALSE) 772 | 773 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 774 | pango_layout_set_wrap(layout_object->layout, wrap); 775 | } 776 | 777 | /* }}} */ 778 | 779 | /* {{{ proto long pango_layout_get_wrap(PangoLayout layout) 780 | proto long PangoLayout::getWrap() 781 | Returns how text will be wrapped or not in the current layout */ 782 | PHP_FUNCTION(pango_layout_get_wrap) 783 | { 784 | zval *layout_zval = NULL; 785 | pango_layout_object *layout_object; 786 | 787 | PHP_PANGO_ERROR_HANDLING(FALSE) 788 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 789 | PHP_PANGO_RESTORE_ERRORS(FALSE) 790 | return; 791 | } 792 | PHP_PANGO_RESTORE_ERRORS(FALSE) 793 | 794 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 795 | RETURN_LONG(pango_layout_get_wrap(layout_object->layout)); 796 | } 797 | /* }}} */ 798 | 799 | #ifdef PANGO_VERSION 800 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 801 | /* {{{ proto bool pango_layout_is_wrapped(PangoLayout layout) 802 | proto bool PangoLayout::isWrapped() 803 | Returns how text will be wrapped or not in the current layout */ 804 | PHP_FUNCTION(pango_layout_is_wrapped) 805 | { 806 | zval *layout_zval = NULL; 807 | pango_layout_object *layout_object; 808 | 809 | PHP_PANGO_ERROR_HANDLING(FALSE) 810 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 811 | PHP_PANGO_RESTORE_ERRORS(FALSE) 812 | return; 813 | } 814 | PHP_PANGO_RESTORE_ERRORS(FALSE) 815 | 816 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 817 | RETURN_BOOL(pango_layout_is_wrapped(layout_object->layout)); 818 | } 819 | /* }}} */ 820 | #endif 821 | #endif 822 | 823 | /* {{{ proto void pango_layout_set_indent(PangoLayout layout, long indent) 824 | proto void PangoLayout::setWrap(long indent) 825 | Sets how far each paragraph should be indented. */ 826 | PHP_FUNCTION(pango_layout_set_indent) 827 | { 828 | zval *layout_zval = NULL; 829 | pango_layout_object *layout_object; 830 | long indent; 831 | 832 | PHP_PANGO_ERROR_HANDLING(FALSE) 833 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &indent) == FAILURE) { 834 | PHP_PANGO_RESTORE_ERRORS(FALSE) 835 | return; 836 | } 837 | PHP_PANGO_RESTORE_ERRORS(FALSE) 838 | 839 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 840 | pango_layout_set_indent(layout_object->layout, indent); 841 | } 842 | 843 | /* }}} */ 844 | 845 | /* {{{ proto long pango_layout_get_indent(PangoLayout layout) 846 | proto long PangoLayout::getIndent() 847 | Returns how text will be indentped or not in the current layout */ 848 | PHP_FUNCTION(pango_layout_get_indent) 849 | { 850 | zval *layout_zval = NULL; 851 | pango_layout_object *layout_object; 852 | 853 | PHP_PANGO_ERROR_HANDLING(FALSE) 854 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 855 | PHP_PANGO_RESTORE_ERRORS(FALSE) 856 | return; 857 | } 858 | PHP_PANGO_RESTORE_ERRORS(FALSE) 859 | 860 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 861 | RETURN_LONG(pango_layout_get_indent(layout_object->layout)); 862 | } 863 | /* }}} */ 864 | 865 | /* {{{ proto void pango_layout_set_spacing(PangoLayout layout, long spacing) 866 | proto void PangoLayout::setWrap(long spacing) 867 | Sets the line spacing for the paragraph */ 868 | PHP_FUNCTION(pango_layout_set_spacing) 869 | { 870 | zval *layout_zval = NULL; 871 | pango_layout_object *layout_object; 872 | long spacing; 873 | 874 | PHP_PANGO_ERROR_HANDLING(FALSE) 875 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &spacing) == FAILURE) { 876 | PHP_PANGO_RESTORE_ERRORS(FALSE) 877 | return; 878 | } 879 | PHP_PANGO_RESTORE_ERRORS(FALSE) 880 | 881 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 882 | pango_layout_set_spacing(layout_object->layout, spacing); 883 | } 884 | 885 | /* }}} */ 886 | 887 | /* {{{ proto long pango_layout_get_spacing(PangoLayout layout) 888 | proto long PangoLayout::getWrap() 889 | Returns the spacing for the current layout */ 890 | PHP_FUNCTION(pango_layout_get_spacing) 891 | { 892 | zval *layout_zval = NULL; 893 | pango_layout_object *layout_object; 894 | 895 | PHP_PANGO_ERROR_HANDLING(FALSE) 896 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 897 | PHP_PANGO_RESTORE_ERRORS(FALSE) 898 | return; 899 | } 900 | PHP_PANGO_RESTORE_ERRORS(FALSE) 901 | 902 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 903 | RETURN_LONG(pango_layout_get_spacing(layout_object->layout)); 904 | } 905 | /* }}} */ 906 | 907 | /* {{{ proto void pango_layout_set_ellipsize(PangoLayout layout, long ellipsize) 908 | proto void PangoLayout::setEllipsize(long ellipsize) 909 | Sets the ellipsize mode for the layout */ 910 | PHP_FUNCTION(pango_layout_set_ellipsize) 911 | { 912 | zval *layout_zval = NULL; 913 | pango_layout_object *layout_object; 914 | long ellipsize; 915 | 916 | PHP_PANGO_ERROR_HANDLING(FALSE) 917 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &ellipsize) == FAILURE) { 918 | PHP_PANGO_RESTORE_ERRORS(FALSE) 919 | return; 920 | } 921 | PHP_PANGO_RESTORE_ERRORS(FALSE) 922 | 923 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 924 | pango_layout_set_ellipsize(layout_object->layout, ellipsize); 925 | } 926 | 927 | /* }}} */ 928 | 929 | /* {{{ proto long pango_layout_get_ellipsize(PangoLayout layout) 930 | proto long PangoLayout::getEllipsize() 931 | Returns the ellipsize for the current layout */ 932 | PHP_FUNCTION(pango_layout_get_ellipsize) 933 | { 934 | zval *layout_zval = NULL; 935 | pango_layout_object *layout_object; 936 | 937 | PHP_PANGO_ERROR_HANDLING(FALSE) 938 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 939 | PHP_PANGO_RESTORE_ERRORS(FALSE) 940 | return; 941 | } 942 | PHP_PANGO_RESTORE_ERRORS(FALSE) 943 | 944 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 945 | RETURN_LONG(pango_layout_get_ellipsize(layout_object->layout)); 946 | } 947 | /* }}} */ 948 | 949 | #ifdef PANGO_VERSION 950 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 951 | /* {{{ proto bool pango_layout_is_ellipsized(PangoLayout layout) 952 | proto bool PangoLayout::isEllipsized() 953 | Returns the ellipsize for the current layout */ 954 | PHP_FUNCTION(pango_layout_is_ellipsized) 955 | { 956 | zval *layout_zval = NULL; 957 | pango_layout_object *layout_object; 958 | 959 | PHP_PANGO_ERROR_HANDLING(FALSE) 960 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 961 | PHP_PANGO_RESTORE_ERRORS(FALSE) 962 | return; 963 | } 964 | PHP_PANGO_RESTORE_ERRORS(FALSE) 965 | 966 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 967 | RETURN_BOOL(pango_layout_is_ellipsized(layout_object->layout)); 968 | } 969 | /* }}} */ 970 | #endif 971 | #endif 972 | 973 | /* {{{ proto array pango_layout_get_lines(PangoLayout layout) 974 | proto array PangoLayout::getLines() 975 | Returns an array of PangoLayoutLines representing each line of the layout */ 976 | PHP_FUNCTION(pango_layout_get_lines) 977 | { 978 | zval *layout_zval = NULL, *elem = NULL; 979 | pango_layout_object *layout_object; 980 | GSList *lines, *iter; 981 | zend_class_entry *layoutline_ce; 982 | 983 | 984 | PHP_PANGO_ERROR_HANDLING(FALSE) 985 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 986 | PHP_PANGO_RESTORE_ERRORS(FALSE) 987 | return; 988 | } 989 | PHP_PANGO_RESTORE_ERRORS(FALSE) 990 | 991 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 992 | lines = pango_layout_get_lines(layout_object->layout); 993 | 994 | layoutline_ce = php_pango_get_layoutline_ce(); 995 | array_init(return_value); 996 | for(iter = lines; iter != NULL; iter = iter->next) { 997 | elem = php_pango_make_layoutline_zval((PangoLayoutLine *)iter->data, layout_zval TSRMLS_CC); 998 | add_next_index_zval(return_value, elem); 999 | } 1000 | } 1001 | /* }}} */ 1002 | 1003 | /* {{{ proto array pango_layout_get_line(PangoLayout layout, long line) 1004 | proto array PangoLayout::getLine(long line) 1005 | Returns a particular PangoLayoutLine from the layout */ 1006 | PHP_FUNCTION(pango_layout_get_line) 1007 | { 1008 | zval *layout_zval = NULL; 1009 | pango_layout_object *layout_object; 1010 | pango_layoutline_object *layoutline_object; 1011 | PangoLayoutLine *layoutline; 1012 | long line_number = 0; 1013 | 1014 | PHP_PANGO_ERROR_HANDLING(FALSE) 1015 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &layout_zval, pango_ce_pangolayout, &line_number) == FAILURE) { 1016 | PHP_PANGO_RESTORE_ERRORS(FALSE) 1017 | return; 1018 | } 1019 | PHP_PANGO_RESTORE_ERRORS(FALSE) 1020 | 1021 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 1022 | layoutline = pango_layout_get_line(layout_object->layout, line_number); 1023 | 1024 | if(!layoutline) { 1025 | RETURN_FALSE; 1026 | } 1027 | 1028 | zval_dtor(return_value); 1029 | *return_value = *php_pango_make_layoutline_zval(layoutline, layout_zval TSRMLS_CC); 1030 | } 1031 | 1032 | /* {{{ proto long pango_layout_get_line_count(PangoLayout layout) 1033 | proto long PangoLayout::getLineCount() 1034 | Returns the number of PangoLayoutLines in the layout */ 1035 | PHP_FUNCTION(pango_layout_get_line_count) 1036 | { 1037 | zval *layout_zval = NULL, *elem = NULL; 1038 | pango_layout_object *layout_object; 1039 | pango_layoutline_object *layoutline_object; 1040 | PangoLayoutLine *layoutline; 1041 | 1042 | PHP_PANGO_ERROR_HANDLING(FALSE) 1043 | if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &layout_zval, pango_ce_pangolayout) == FAILURE) { 1044 | PHP_PANGO_RESTORE_ERRORS(FALSE) 1045 | return; 1046 | } 1047 | PHP_PANGO_RESTORE_ERRORS(FALSE) 1048 | 1049 | layout_object = (pango_layout_object *)zend_object_store_get_object(layout_zval TSRMLS_CC); 1050 | RETURN_LONG(pango_layout_get_line_count(layout_object->layout)); 1051 | } 1052 | 1053 | /* {{{ Object creation/destruction functions */ 1054 | static void pango_layout_object_destroy(void *object TSRMLS_DC) 1055 | { 1056 | pango_layout_object *layout = (pango_layout_object *)object; 1057 | zend_hash_destroy(layout->std.properties); 1058 | FREE_HASHTABLE(layout->std.properties); 1059 | 1060 | if(layout->cairo_context) { 1061 | Z_DELREF_P(layout->cairo_context); 1062 | layout->cairo_context = NULL; 1063 | } 1064 | 1065 | if(layout->layout){ 1066 | g_object_unref(layout->layout); 1067 | } 1068 | efree(object); 1069 | } 1070 | 1071 | static zend_object_value pango_layout_object_new(zend_class_entry *ce TSRMLS_DC) 1072 | { 1073 | zend_object_value retval; 1074 | pango_layout_object *layout; 1075 | zval *temp; 1076 | 1077 | layout = ecalloc(1, sizeof(pango_layout_object)); 1078 | 1079 | layout->std.ce = ce; 1080 | layout->layout = NULL; 1081 | layout->cairo_context = NULL; 1082 | 1083 | ALLOC_HASHTABLE(layout->std.properties); 1084 | zend_hash_init(layout->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); 1085 | #if PHP_VERSION_ID < 50399 1086 | zend_hash_copy(layout->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *)); 1087 | #else 1088 | object_properties_init(&(layout->std), ce); 1089 | #endif 1090 | retval.handle = zend_objects_store_put(layout, NULL, (zend_objects_free_object_storage_t)pango_layout_object_destroy, NULL TSRMLS_CC); 1091 | retval.handlers = &pango_std_object_handlers; 1092 | return retval; 1093 | } 1094 | /* }}} */ 1095 | 1096 | /* {{{ pango_layout_class_functions */ 1097 | const zend_function_entry pango_layout_methods[] = { 1098 | PHP_ME(PangoLayout, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) 1099 | PHP_ME_MAPPING(getContext, pango_layout_get_context, NULL, ZEND_ACC_PUBLIC) 1100 | PHP_ME_MAPPING(setText, pango_layout_set_text, NULL, ZEND_ACC_PUBLIC) 1101 | PHP_ME_MAPPING(getText, pango_layout_get_text, NULL, ZEND_ACC_PUBLIC) 1102 | PHP_ME_MAPPING(getWidth, pango_layout_get_width, NULL, ZEND_ACC_PUBLIC) 1103 | PHP_ME_MAPPING(getSize, pango_layout_get_size, NULL, ZEND_ACC_PUBLIC) 1104 | PHP_ME_MAPPING(getPixelSize, pango_layout_get_pixel_size, NULL, ZEND_ACC_PUBLIC) 1105 | PHP_ME_MAPPING(getExtents, pango_layout_get_extents, NULL, ZEND_ACC_PUBLIC) 1106 | PHP_ME_MAPPING(getPixelExtents, pango_layout_get_pixel_extents, NULL, ZEND_ACC_PUBLIC) 1107 | PHP_ME_MAPPING(setWidth, pango_layout_set_width, NULL, ZEND_ACC_PUBLIC) 1108 | #ifdef PANGO_VERSION 1109 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 1110 | PHP_ME_MAPPING(getHeight, pango_layout_get_height, NULL, ZEND_ACC_PUBLIC) 1111 | PHP_ME_MAPPING(setHeight, pango_layout_set_height, NULL, ZEND_ACC_PUBLIC) 1112 | #endif 1113 | #endif 1114 | PHP_ME_MAPPING(setMarkup, pango_layout_set_markup, NULL, ZEND_ACC_PUBLIC) 1115 | PHP_ME_MAPPING(updateLayout, pango_cairo_update_layout, NULL, ZEND_ACC_PUBLIC) 1116 | PHP_ME_MAPPING(showLayout, pango_cairo_show_layout, NULL, ZEND_ACC_PUBLIC) 1117 | PHP_ME_MAPPING(layoutPath, pango_cairo_layout_path, NULL, ZEND_ACC_PUBLIC) 1118 | PHP_ME_MAPPING(setFontDescription, pango_layout_set_font_description, NULL, ZEND_ACC_PUBLIC) 1119 | PHP_ME_MAPPING(getFontDescription, pango_layout_get_font_description, NULL, ZEND_ACC_PUBLIC) 1120 | PHP_ME_MAPPING(setAlignment, pango_layout_set_alignment, NULL, ZEND_ACC_PUBLIC) 1121 | PHP_ME_MAPPING(getAlignment, pango_layout_get_alignment, NULL, ZEND_ACC_PUBLIC) 1122 | PHP_ME_MAPPING(setJustify, pango_layout_set_justify, NULL, ZEND_ACC_PUBLIC) 1123 | PHP_ME_MAPPING(getJustify, pango_layout_get_justify, NULL, ZEND_ACC_PUBLIC) 1124 | PHP_ME_MAPPING(setWrap, pango_layout_set_wrap, NULL, ZEND_ACC_PUBLIC) 1125 | PHP_ME_MAPPING(getWrap, pango_layout_get_wrap, NULL, ZEND_ACC_PUBLIC) 1126 | #ifdef PANGO_VERSION 1127 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 16, 0) 1128 | PHP_ME_MAPPING(isWrapped, pango_layout_is_wrapped, NULL, ZEND_ACC_PUBLIC) 1129 | #endif 1130 | #endif 1131 | PHP_ME_MAPPING(setIndent, pango_layout_set_indent, NULL, ZEND_ACC_PUBLIC) 1132 | PHP_ME_MAPPING(getIndent, pango_layout_get_indent, NULL, ZEND_ACC_PUBLIC) 1133 | PHP_ME_MAPPING(setSpacing, pango_layout_set_spacing, NULL, ZEND_ACC_PUBLIC) 1134 | PHP_ME_MAPPING(getSpacing, pango_layout_get_spacing, NULL, ZEND_ACC_PUBLIC) 1135 | PHP_ME_MAPPING(setEllipsize, pango_layout_set_ellipsize, NULL, ZEND_ACC_PUBLIC) 1136 | PHP_ME_MAPPING(getEllipsize, pango_layout_get_ellipsize, NULL, ZEND_ACC_PUBLIC) 1137 | #ifdef PANGO_VERSION 1138 | #if PANGO_VERSION >= PANGO_VERSION_ENCODE(1, 20, 0) 1139 | PHP_ME_MAPPING(isEllipsized, pango_layout_is_ellipsized, NULL, ZEND_ACC_PUBLIC) 1140 | #endif 1141 | #endif 1142 | PHP_ME_MAPPING(contextChanged, pango_layout_context_changed, NULL, ZEND_ACC_PUBLIC) 1143 | PHP_ME_MAPPING(getLines, pango_layout_get_lines, NULL, ZEND_ACC_PUBLIC) 1144 | PHP_ME_MAPPING(getLine, pango_layout_get_line, NULL, ZEND_ACC_PUBLIC) 1145 | PHP_ME_MAPPING(getLineCount, pango_layout_get_line_count, NULL, ZEND_ACC_PUBLIC) 1146 | {NULL, NULL, NULL} 1147 | }; 1148 | /* }}} */ 1149 | 1150 | /* {{{ PHP_MINIT_FUNCTION */ 1151 | PHP_MINIT_FUNCTION(pango_layout) 1152 | { 1153 | zend_class_entry layout_ce; 1154 | zend_class_entry alignment_ce; 1155 | zend_class_entry wrapmode_ce; 1156 | zend_class_entry ellipsizemode_ce; 1157 | zend_class_entry fontdescription_ce; 1158 | 1159 | INIT_CLASS_ENTRY(layout_ce, "PangoLayout", pango_layout_methods); 1160 | pango_ce_pangolayout = zend_register_internal_class(&layout_ce TSRMLS_CC); 1161 | pango_ce_pangolayout->create_object = pango_layout_object_new; 1162 | 1163 | INIT_CLASS_ENTRY(alignment_ce, "PangoAlignment", NULL); 1164 | pango_ce_pangoalignment = zend_register_internal_class(&alignment_ce TSRMLS_CC); 1165 | pango_ce_pangoalignment->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 1166 | 1167 | #define REGISTER_PANGO_ALIGNMENT_LONG_CONST(const_name, value) \ 1168 | zend_declare_class_constant_long(pango_ce_pangoalignment, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 1169 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 1170 | 1171 | REGISTER_PANGO_ALIGNMENT_LONG_CONST("LEFT", PANGO_ALIGN_LEFT); 1172 | REGISTER_PANGO_ALIGNMENT_LONG_CONST("CENTER", PANGO_ALIGN_CENTER); 1173 | REGISTER_PANGO_ALIGNMENT_LONG_CONST("RIGHT", PANGO_ALIGN_RIGHT); 1174 | 1175 | INIT_CLASS_ENTRY(wrapmode_ce, "PangoWrapMode", NULL); 1176 | pango_ce_pangowrapmode = zend_register_internal_class(&wrapmode_ce TSRMLS_CC); 1177 | pango_ce_pangowrapmode->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 1178 | 1179 | #define REGISTER_PANGO_WRAPMODE_LONG_CONST(const_name, value) \ 1180 | zend_declare_class_constant_long(pango_ce_pangowrapmode, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 1181 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 1182 | 1183 | REGISTER_PANGO_WRAPMODE_LONG_CONST("WORD", PANGO_WRAP_WORD); 1184 | REGISTER_PANGO_WRAPMODE_LONG_CONST("CHAR", PANGO_WRAP_CHAR); 1185 | REGISTER_PANGO_WRAPMODE_LONG_CONST("WORD_CHAR", PANGO_WRAP_WORD_CHAR); 1186 | 1187 | INIT_CLASS_ENTRY(ellipsizemode_ce, "PangoEllipsizeMode", NULL); 1188 | pango_ce_pangoellipsizemode = zend_register_internal_class(&ellipsizemode_ce TSRMLS_CC); 1189 | pango_ce_pangoellipsizemode->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 1190 | 1191 | #define REGISTER_PANGO_ELLIPSIZEMODE_LONG_CONST(const_name, value) \ 1192 | zend_declare_class_constant_long(pango_ce_pangoellipsizemode, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \ 1193 | REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT); 1194 | 1195 | REGISTER_PANGO_ELLIPSIZEMODE_LONG_CONST("NONE", PANGO_ELLIPSIZE_NONE); 1196 | REGISTER_PANGO_ELLIPSIZEMODE_LONG_CONST("START", PANGO_ELLIPSIZE_START); 1197 | REGISTER_PANGO_ELLIPSIZEMODE_LONG_CONST("MIDDLE", PANGO_ELLIPSIZE_MIDDLE); 1198 | REGISTER_PANGO_ELLIPSIZEMODE_LONG_CONST("END", PANGO_ELLIPSIZE_END); 1199 | 1200 | INIT_CLASS_ENTRY(fontdescription_ce, "PangoFontDescription", NULL); 1201 | pango_ce_pangofontdescription = zend_register_internal_class(&fontdescription_ce TSRMLS_CC); 1202 | pango_ce_pangofontdescription->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS; 1203 | 1204 | return SUCCESS; 1205 | } 1206 | 1207 | /* }}} */ 1208 | 1209 | /* 1210 | * Local variables: 1211 | * tab-width: 4 1212 | * c-basic-offset: 4 1213 | * End: 1214 | * vim600: noet sw=4 ts=4 fdm=marker 1215 | * vim<600: noet sw=4 ts=4 1216 | */ 1217 | --------------------------------------------------------------------------------