Skip to content
Newer
Older
100644 181 lines (152 sloc) 6.36 KB
60b7d9b @auroraeosrose font face class
auroraeosrose authored
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: Elizabeth Smith <auroraeosrose@php.net> |
16 | Michael Maclean <mgdm@php.net> |
17 | Akshat Gupta <g.akshat@gmail.com> |
18 +----------------------------------------------------------------------+
19 */
20
21 /* $Id$ */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "php.h"
28 #include "zend_exceptions.h"
29 #include "php_cairo.h"
30
31 zend_class_entry *cairo_ce_cairofontface;
32 zend_class_entry *cairo_ce_cairofonttype;
33
34 /* {{{ proto void CairoFontFace->__contruct()
35 CairoFontFace CANNOT be extended in userspace, this will throw an exception on use */
36 PHP_METHOD(CairoFontFace, __construct)
37 {
38 zend_throw_exception(cairo_ce_cairoexception, "CairoFontFace cannot be constructed", 0 TSRMLS_CC);
39 }
40 /* }}} */
41
42 /* {{{ proto long cairo_font_face_status(CairoFontFace object)
43 proto long CairoFontFace->status()
44 Returns the current integer status of the CairoFontFace */
45 PHP_FUNCTION(cairo_font_face_status)
46 {
47 zval *font_face_zval = NULL;
48 cairo_font_face_object *font_face_object;
49
50 PHP_CAIRO_ERROR_HANDLING(FALSE)
51 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &font_face_zval, cairo_ce_cairofontface) == FAILURE) {
52 PHP_CAIRO_RESTORE_ERRORS(FALSE)
53 return;
54 }
55 PHP_CAIRO_RESTORE_ERRORS(FALSE)
56
57 font_face_object = (cairo_font_face_object *) cairo_font_face_object_get(font_face_zval TSRMLS_CC);
58 RETURN_LONG(cairo_font_face_status(font_face_object->font_face));
59 }
60 /* }}} */
61
62 /* {{{ proto long cairo_font_face_get_type(CairoFontFace object)
63 proto long CairoFontFace->getType()
64 Returns the current integer type of the CairoFontFace backend */
65 PHP_FUNCTION(cairo_font_face_get_type)
66 {
67 zval *font_face_zval = NULL;
68 cairo_font_face_object *font_face_object;
69
70 PHP_CAIRO_ERROR_HANDLING(FALSE)
71 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &font_face_zval, cairo_ce_cairofontface) == FAILURE) {
72 PHP_CAIRO_RESTORE_ERRORS(FALSE)
73 return;
74 }
75 PHP_CAIRO_RESTORE_ERRORS(FALSE)
76
77 font_face_object = (cairo_font_face_object *) cairo_font_face_object_get(font_face_zval TSRMLS_CC);
78 RETURN_LONG(cairo_font_face_get_type(font_face_object->font_face));
79 }
80 /* }}} */
81
82 /* {{{ cairo_font_face_methods[] */
83 const zend_function_entry cairo_font_face_methods[] = {
86d484a @auroraeosrose More cairocontext tests, some fixes for cairo font face
auroraeosrose authored
84 PHP_ME(CairoFontFace, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
60b7d9b @auroraeosrose font face class
auroraeosrose authored
85 PHP_ME_MAPPING(status, cairo_font_face_status, NULL, ZEND_ACC_PUBLIC)
86 PHP_ME_MAPPING(getType, cairo_font_face_get_type, NULL, ZEND_ACC_PUBLIC)
87 {NULL, NULL, NULL}
88 };
89 /* }}} */
90
91 /* {{{ cairo_font_face_object_destroy
92 */
93 static void cairo_font_face_object_destroy(void *object TSRMLS_DC)
94 {
95 cairo_font_face_object *font_face = (cairo_font_face_object *)object;
96 zend_hash_destroy(font_face->std.properties);
97 FREE_HASHTABLE(font_face->std.properties);
98 if(font_face->font_face){
99 cairo_font_face_destroy(font_face->font_face);
100 }
101
102 /* if this was created with cairo_quartz_font_face_create_for_cgfont
103 we may have a font ref to free up
104 #ifdef CAIRO_HAS_QUARTZ_FONT
105 if (font_face->quartzref != NULL)
106 CFRelease(font_face->quartzref);
107 #endif*/
108 efree(object);
109 }
110
111 /* }}} */
112
113 /* {{{ cairo_font_face_object_new
114 */
115 zend_object_value cairo_font_face_object_new(zend_class_entry *ce TSRMLS_DC)
116 {
117 zend_object_value retval;
118 cairo_font_face_object *font_face;
119 zval *temp;
120
3dba46f @auroraeosrose Beginning of scaled font support
auroraeosrose authored
121 font_face = ecalloc(1, sizeof(cairo_font_face_object));
60b7d9b @auroraeosrose font face class
auroraeosrose authored
122
123 font_face->std.ce = ce;
124
125 ALLOC_HASHTABLE(font_face->std.properties);
126 zend_hash_init(font_face->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
127 zend_hash_copy(font_face->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *));
128 retval.handle = zend_objects_store_put(font_face, NULL, (zend_objects_free_object_storage_t)cairo_font_face_object_destroy, NULL TSRMLS_CC);
129 retval.handlers = zend_get_std_object_handlers();
130 return retval;
131 }
132
133 /* }}} */
134
135 /* Helper Functions */
136 PHP_CAIRO_API zend_class_entry * php_cairo_get_fontface_ce()
137 {
138 return cairo_ce_cairofontface;
139 }
140
141 /* {{{ PHP_MINIT_FUNCTION */
142 PHP_MINIT_FUNCTION(cairo_font_face)
143 {
144 zend_class_entry fontface_ce;
145 zend_class_entry fonttype_ce;
146
147 INIT_CLASS_ENTRY(fontface_ce, "CairoFontFace", cairo_font_face_methods);
148 cairo_ce_cairofontface = zend_register_internal_class(&fontface_ce TSRMLS_CC);
149 cairo_ce_cairofontface->create_object = cairo_font_face_object_new;
150 cairo_ce_cairofontface->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
151
152 INIT_CLASS_ENTRY(fonttype_ce, "CairoFontType", NULL);
153 cairo_ce_cairofonttype = zend_register_internal_class(&fonttype_ce TSRMLS_CC);
154 cairo_ce_cairofonttype->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_FINAL_CLASS;
155
156 #define REGISTER_CAIRO_FONTTYPE_LONG_CONST(const_name, value) \
157 zend_declare_class_constant_long(cairo_ce_cairofonttype, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); \
158 REGISTER_LONG_CONSTANT(#value, value, CONST_CS | CONST_PERSISTENT);
159
160 REGISTER_CAIRO_FONTTYPE_LONG_CONST("TOY", CAIRO_FONT_TYPE_TOY);
161 REGISTER_CAIRO_FONTTYPE_LONG_CONST("FT", CAIRO_FONT_TYPE_FT);
162 REGISTER_CAIRO_FONTTYPE_LONG_CONST("WIN32", CAIRO_FONT_TYPE_WIN32);
163 #ifdef CAIRO_FONT_TYPE_QUARTZ
164 REGISTER_CAIRO_FONTTYPE_LONG_CONST("QUARTZ", CAIRO_FONT_TYPE_QUARTZ);
165 #endif
166 #ifdef CAIRO_FONT_TYPE_USER
167 REGISTER_CAIRO_FONTTYPE_LONG_CONST("USER", CAIRO_FONT_TYPE_USER);
168 #endif
169
170 return SUCCESS;
171 }
172
173 /*
174 * Local variables:
175 * tab-width: 4
176 * c-basic-offset: 4
177 * End:
178 * vim600: noet sw=4 ts=4 fdm=marker
179 * vim<600: noet sw=4 ts=4
180 */
Something went wrong with that request. Please try again.