Skip to content

Commit f9664ce

Browse files
committed
PHP7 API updates
1 parent a25054b commit f9664ce

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

ext/gd/gd.c

+28-29
Original file line numberDiff line numberDiff line change
@@ -1426,18 +1426,17 @@ PHP_GD_API int phpi_get_le_gd(void)
14261426
PHP_FUNCTION(imageloadfont)
14271427
{
14281428
zval *ind;
1429-
char *file;
1430-
size_t file_name;
1429+
zend_string *file;
14311430
int hdr_size = sizeof(gdFont) - sizeof(char *);
14321431
int body_size, n = 0, b, i, body_size_check;
14331432
gdFontPtr font;
14341433
php_stream *stream;
14351434

1436-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_name) == FAILURE) {
1435+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file) == FAILURE) {
14371436
return;
14381437
}
14391438

1440-
stream = php_stream_open_wrapper(file, "rb", IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
1439+
stream = php_stream_open_wrapper(file->val, "rb", IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
14411440
if (stream == NULL) {
14421441
RETURN_FALSE;
14431442
}
@@ -3898,24 +3897,24 @@ static void php_free_ps_enc(zend_resource *rsrc)
38983897
Load a new font from specified file */
38993898
PHP_FUNCTION(imagepsloadfont)
39003899
{
3901-
char *file;
3902-
int file_len, f_ind, *font;
3900+
zend_string *file;
3901+
int f_ind, *font;
39033902
#ifdef PHP_WIN32
39043903
zend_stat_t st;
39053904
#endif
39063905

3907-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) {
3906+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file) == FAILURE) {
39083907
return;
39093908
}
39103909

39113910
#ifdef PHP_WIN32
3912-
if (VCWD_STAT(file, &st) < 0) {
3911+
if (VCWD_STAT(file->val, &st) < 0) {
39133912
php_error_docref(NULL, E_WARNING, "Font file not found (%s)", file);
39143913
RETURN_FALSE;
39153914
}
39163915
#endif
39173916

3918-
f_ind = T1_AddFont(file);
3917+
f_ind = T1_AddFont(file->val);
39193918

39203919
if (f_ind < 0) {
39213920
php_error_docref(NULL, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
@@ -3940,7 +3939,7 @@ PHP_FUNCTION(imagepscopyfont)
39403939
{
39413940
int l_ind, type;
39423941
gd_ps_font *nf_ind, *of_ind;
3943-
long fnt;
3942+
zend_long fnt;
39443943
39453944
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &fnt) == FAILURE) {
39463945
return;
@@ -4009,7 +4008,8 @@ PHP_FUNCTION(imagepsencodefont)
40094008
{
40104009
zval *fnt;
40114010
char *enc, **enc_vector;
4012-
size_t enc_len, *f_ind;
4011+
size_t enc_len;
4012+
int *f_ind;
40134013

40144014
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &fnt, &enc, &enc_len) == FAILURE) {
40154015
return;
@@ -4105,10 +4105,9 @@ PHP_FUNCTION(imagepstext)
41054105
GLYPH *str_img;
41064106
T1_OUTLINE *char_path, *str_path;
41074107
T1_TMATRIX *transform = NULL;
4108-
char *str;
4109-
int str_len;
4108+
zend_string *str;
41104109

4111-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
4110+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSrlllll|lldl", &img, &str, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
41124111
return;
41134112
}
41144113

@@ -4171,7 +4170,7 @@ PHP_FUNCTION(imagepstext)
41714170

41724171
if (width) {
41734172
extend = T1_GetExtend(*f_ind);
4174-
str_path = T1_GetCharOutline(*f_ind, str[0], size, transform);
4173+
str_path = T1_GetCharOutline(*f_ind, str->val[0], size, transform);
41754174

41764175
if (!str_path) {
41774176
if (T1_errno) {
@@ -4180,20 +4179,20 @@ PHP_FUNCTION(imagepstext)
41804179
RETURN_FALSE;
41814180
}
41824181

4183-
for (i = 1; i < str_len; i++) {
4184-
amount_kern = (int) T1_GetKerning(*f_ind, str[i - 1], str[i]);
4185-
amount_kern += str[i - 1] == ' ' ? space : 0;
4182+
for (i = 1; i < str->len; i++) {
4183+
amount_kern = (int) T1_GetKerning(*f_ind, str->val[i - 1], str->val[i]);
4184+
amount_kern += str->val[i - 1] == ' ' ? space : 0;
41864185
add_width = (int) (amount_kern + width) / extend;
41874186

41884187
char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
41894188
str_path = T1_ConcatOutlines(str_path, char_path);
41904189

4191-
char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
4190+
char_path = T1_GetCharOutline(*f_ind, str->val[i], size, transform);
41924191
str_path = T1_ConcatOutlines(str_path, char_path);
41934192
}
41944193
str_img = T1_AAFillOutline(str_path, 0);
41954194
} else {
4196-
str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
4195+
str_img = T1_AASetString(*f_ind, str->val, str->len, space, T1_KERNING, size, transform);
41974196
}
41984197
if (T1_errno) {
41994198
php_error_docref(NULL, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
@@ -4231,12 +4230,12 @@ PHP_FUNCTION(imagepsbbox)
42314230
{
42324231
zval *fnt;
42334232
zend_long sz = 0, sp = 0, wd = 0;
4234-
char *str;
4233+
zend_string *str;
42354234
int i, space = 0, add_width = 0, char_width, amount_kern;
42364235
int cur_x, cur_y, dx, dy;
42374236
int x1, y1, x2, y2, x3, y3, x4, y4;
42384237
int *f_ind;
4239-
int str_len, per_char = 0;
4238+
int per_char = 0;
42404239
int argc = ZEND_NUM_ARGS();
42414240
double angle = 0, sin_a = 0, cos_a = 0;
42424241
BBox char_bbox, str_bbox = {0, 0, 0, 0};
@@ -4245,7 +4244,7 @@ PHP_FUNCTION(imagepsbbox)
42454244
ZEND_WRONG_PARAM_COUNT();
42464245
}
42474246

4248-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
4247+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Srl|lld", &str, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
42494248
return;
42504249
}
42514250

@@ -4269,15 +4268,15 @@ PHP_FUNCTION(imagepsbbox)
42694268
space += T1_GetCharWidth(*f_ind, ' ');
42704269
cur_x = cur_y = 0;
42714270

4272-
for (i = 0; i < str_len; i++) {
4273-
if (str[i] == ' ') {
4271+
for (i = 0; i < str->len; i++) {
4272+
if (str->val[i] == ' ') {
42744273
char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
42754274
char_bbox.urx = char_width = space;
42764275
} else {
4277-
char_bbox = T1_GetCharBBox(*f_ind, str[i]);
4278-
char_width = T1_GetCharWidth(*f_ind, str[i]);
4276+
char_bbox = T1_GetCharBBox(*f_ind, str->val[i]);
4277+
char_width = T1_GetCharWidth(*f_ind, str->val[i]);
42794278
}
4280-
amount_kern = i ? T1_GetKerning(*f_ind, str[i - 1], str[i]) : 0;
4279+
amount_kern = i ? T1_GetKerning(*f_ind, str->val[i - 1], str->val[i]) : 0;
42814280

42824281
/* Transfer character bounding box to right place */
42834282
x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
@@ -4306,7 +4305,7 @@ PHP_FUNCTION(imagepsbbox)
43064305
}
43074306

43084307
} else {
4309-
str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING);
4308+
str_bbox = T1_GetStringBBox(*f_ind, str->val, str->len, space, T1_KERNING);
43104309
}
43114310

43124311
if (T1_errno) {

ext/gd/tests/imageloadfont_error1.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ Neveo Harrison <neveoo [at] gmail [dot] com> #testfest #tek11
1111
var_dump( imageloadfont(array()) );
1212
?>
1313
--EXPECTF--
14-
Warning: imageloadfont() expects parameter 1 to be string, array given in %s on line %d
15-
NULL
14+
Warning: imageloadfont() expects parameter 1 to be a valid path, array given in %s on line %d
15+
NULL

0 commit comments

Comments
 (0)