Line data Source code
1 : /*
2 : +----------------------------------------------------------------------+
3 : | For PHP Version 8 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 2015 Elizabeth M Smith |
6 : +----------------------------------------------------------------------+
7 : | http://www.opensource.org/licenses/mit-license.php MIT License |
8 : | Also available in LICENSE |
9 : +----------------------------------------------------------------------+
10 : | Authors: Elizabeth M Smith <auroraeosrose@gmail.com> |
11 : | Swen Zanon <swen.zanon@geoglis.de> |
12 : +----------------------------------------------------------------------+
13 : */
14 :
15 : #ifdef HAVE_CONFIG_H
16 : #include "config.h"
17 : #endif
18 :
19 : #include <cairo.h>
20 : #include <php.h>
21 : #include <zend_exceptions.h>
22 :
23 : #include "php_cairo.h"
24 : #include "php_cairo_internal.h"
25 : #include "font_arginfo.h"
26 :
27 :
28 : zend_class_entry *ce_cairo_fontslant;
29 : zend_class_entry *ce_cairo_fontweight;
30 : zend_class_entry *ce_cairo_toyfontface;
31 :
32 : /* ----------------------------------------------------------------
33 : Cairo\FontOptions C API
34 : ------------------------------------------------------------------*/
35 :
36 2 : zend_class_entry * php_cairo_get_toyfontface_ce()
37 : {
38 2 : return ce_cairo_toyfontface;
39 : }
40 :
41 :
42 : /* ----------------------------------------------------------------
43 : \Cairo\FontFace\Toy Class API
44 : ------------------------------------------------------------------*/
45 :
46 : /* {{{ proto void __construct(string family, \Cairo\FontSlant slant, \Cairo\FontWeight weight)
47 : Creates a font face from a triplet of family, slant, and weight. These font
48 : faces are used in implementation of the the "toy" font API.*/
49 36 : PHP_METHOD(Cairo_FontFace_Toy, __construct)
50 : {
51 : char *family;
52 : size_t family_len;
53 36 : zval *slant = NULL;
54 36 : zval *weight = NULL;
55 : cairo_font_face_object *font_face_object;
56 :
57 36 : ZEND_PARSE_PARAMETERS_START(1, 3)
58 70 : Z_PARAM_STRING(family, family_len)
59 34 : Z_PARAM_OPTIONAL
60 66 : Z_PARAM_OBJECT_OF_CLASS(slant, ce_cairo_fontslant)
61 61 : Z_PARAM_OBJECT_OF_CLASS(weight, ce_cairo_fontweight)
62 36 : ZEND_PARSE_PARAMETERS_END();
63 :
64 64 : font_face_object = Z_CAIRO_FONT_FACE_P(getThis());
65 32 : if (!font_face_object) {
66 0 : RETURN_NULL();
67 : }
68 :
69 35 : font_face_object->font_face = cairo_toy_font_face_create(
70 : (const char *)family,
71 : slant
72 62 : ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(slant)))
73 : : CAIRO_FONT_SLANT_NORMAL,
74 : weight
75 61 : ? Z_LVAL_P(zend_enum_fetch_case_value(Z_OBJ_P(weight)))
76 : : CAIRO_FONT_WEIGHT_NORMAL
77 : );
78 :
79 32 : if (php_cairo_throw_exception(cairo_font_face_status(font_face_object->font_face))) {
80 0 : RETURN_THROWS();
81 : }
82 : }
83 :
84 : /* {{{ proto string \Cairo\FontFace\Toy::getFamily()
85 : Gets the family name of a toy font. */
86 1 : PHP_METHOD(Cairo_FontFace_Toy, getFamily)
87 : {
88 : cairo_font_face_object *font_face_object;
89 :
90 1 : ZEND_PARSE_PARAMETERS_NONE();
91 :
92 2 : font_face_object = cairo_font_face_object_get(getThis());
93 1 : if (!font_face_object) {
94 0 : RETURN_THROWS();
95 : }
96 :
97 2 : RETURN_STRING(cairo_toy_font_face_get_family(font_face_object->font_face));
98 : }
99 : /* }}} */
100 :
101 : /* {{{ proto \Cairo\FontSlant \Cairo\FontFace\Toy::getSlant()
102 : Gets the slant of a toy font. */
103 2 : PHP_METHOD(Cairo_FontFace_Toy, getSlant)
104 : {
105 : cairo_font_face_object *font_face_object;
106 : zval slant_case;
107 :
108 4 : ZEND_PARSE_PARAMETERS_NONE();
109 :
110 4 : font_face_object = cairo_font_face_object_get(getThis());
111 2 : if (!font_face_object) {
112 0 : RETURN_THROWS();
113 : }
114 :
115 2 : slant_case = php_enum_from_cairo_c_enum(
116 : ce_cairo_fontslant,
117 2 : cairo_toy_font_face_get_slant(font_face_object->font_face)
118 : );
119 :
120 2 : if (Z_TYPE(slant_case) == IS_OBJECT) {
121 4 : RETURN_ZVAL(&slant_case, 1, 1);
122 : }
123 : }
124 : /* }}} */
125 :
126 : /* {{{ proto long \Cairo\FontFace\Toy::getWeight()
127 : Gets the weight of a toy font. */
128 2 : PHP_METHOD(Cairo_FontFace_Toy, getWeight)
129 : {
130 : cairo_font_face_object *font_face_object;
131 : zval weight_case;
132 :
133 4 : ZEND_PARSE_PARAMETERS_NONE();
134 :
135 4 : font_face_object = cairo_font_face_object_get(getThis());
136 2 : if (!font_face_object) {
137 0 : RETURN_THROWS();
138 : }
139 :
140 2 : weight_case = php_enum_from_cairo_c_enum(
141 : ce_cairo_fontweight,
142 2 : cairo_toy_font_face_get_weight(font_face_object->font_face)
143 : );
144 :
145 2 : if (Z_TYPE(weight_case) == IS_OBJECT) {
146 4 : RETURN_ZVAL(&weight_case, 1, 1);
147 : }
148 : }
149 : /* }}} */
150 :
151 : /* ----------------------------------------------------------------
152 : \Cairo\FontFace\Toy Definition and registration
153 : ------------------------------------------------------------------*/
154 :
155 :
156 : /* {{{ PHP_MINIT_FUNCTION */
157 424 : PHP_MINIT_FUNCTION(cairo_font)
158 : {
159 424 : ce_cairo_toyfontface = register_class_Cairo_FontFace_Toy(php_cairo_get_fontface_ce());
160 424 : ce_cairo_toyfontface->create_object = cairo_font_face_create_object;
161 :
162 : /* FontSlant */
163 424 : ce_cairo_fontslant = register_class_Cairo_FontSlant();
164 :
165 : /* FontWeight */
166 424 : ce_cairo_fontweight = register_class_Cairo_FontWeight();
167 :
168 424 : return SUCCESS;
169 : }
170 : /* }}} */
|