static int le_gd, le_gd_font;
-#if HAVE_LIBT1
-#include <t1lib.h>
-static int le_ps_font, le_ps_enc;
-static void php_free_ps_font(zend_resource *rsrc);
-static void php_free_ps_enc(zend_resource *rsrc);
-#endif
#include <gd.h>
#include <gdfontt.h> /* 1 Tiny font */
ZEND_END_ARG_INFO()
#endif
-#ifdef HAVE_LIBT1
-ZEND_BEGIN_ARG_INFO(arginfo_imagepsloadfont, 0)
- ZEND_ARG_INFO(0, pathname)
-ZEND_END_ARG_INFO()
-
-/*
-ZEND_BEGIN_ARG_INFO(arginfo_imagepscopyfont, 0)
- ZEND_ARG_INFO(0, font_index)
-ZEND_END_ARG_INFO()
-*/
-
-ZEND_BEGIN_ARG_INFO(arginfo_imagepsfreefont, 0)
- ZEND_ARG_INFO(0, font_index)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_imagepsencodefont, 0)
- ZEND_ARG_INFO(0, font_index)
- ZEND_ARG_INFO(0, filename)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_imagepsextendfont, 0)
- ZEND_ARG_INFO(0, font_index)
- ZEND_ARG_INFO(0, extend)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_imagepsslantfont, 0)
- ZEND_ARG_INFO(0, font_index)
- ZEND_ARG_INFO(0, slant)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8)
- ZEND_ARG_INFO(0, im)
- ZEND_ARG_INFO(0, text)
- ZEND_ARG_INFO(0, font)
- ZEND_ARG_INFO(0, size)
- ZEND_ARG_INFO(0, foreground)
- ZEND_ARG_INFO(0, background)
- ZEND_ARG_INFO(0, xcoord)
- ZEND_ARG_INFO(0, ycoord)
- ZEND_ARG_INFO(0, space)
- ZEND_ARG_INFO(0, tightness)
- ZEND_ARG_INFO(0, angle)
- ZEND_ARG_INFO(0, antialias)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepsbbox, 0, 0, 3)
- ZEND_ARG_INFO(0, text)
- ZEND_ARG_INFO(0, font)
- ZEND_ARG_INFO(0, size)
- ZEND_ARG_INFO(0, space)
- ZEND_ARG_INFO(0, tightness)
- ZEND_ARG_INFO(0, angle)
-ZEND_END_ARG_INFO()
-#endif
-
ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, filename)
#endif
#endif
-#ifdef HAVE_LIBT1
- PHP_FE(imagepsloadfont, arginfo_imagepsloadfont)
- /*
- PHP_FE(imagepscopyfont, arginfo_imagepscopyfont)
- */
- PHP_FE(imagepsfreefont, arginfo_imagepsfreefont)
- PHP_FE(imagepsencodefont, arginfo_imagepsencodefont)
- PHP_FE(imagepsextendfont, arginfo_imagepsextendfont)
- PHP_FE(imagepsslantfont, arginfo_imagepsslantfont)
- PHP_FE(imagepstext, arginfo_imagepstext)
- PHP_FE(imagepsbbox, arginfo_imagepsbbox)
-#endif
PHP_FE(imagetypes, arginfo_imagetypes)
#if defined(HAVE_GD_JPG)
"gd",
gd_functions,
PHP_MINIT(gd),
-#if HAVE_LIBT1
- PHP_MSHUTDOWN(gd),
-#else
NULL,
-#endif
NULL,
#if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
PHP_RSHUTDOWN(gd),
/* }}} */
#endif
-/* {{{ PHP_MSHUTDOWN_FUNCTION
- */
-#if HAVE_LIBT1
-PHP_MSHUTDOWN_FUNCTION(gd)
-{
- T1_CloseLib();
-#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
- gdFontCacheMutexShutdown();
-#endif
- UNREGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-#endif
-/* }}} */
-
-
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(gd)
#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
gdFontCacheMutexSetup();
#endif
-#if HAVE_LIBT1
- T1_SetBitmapPad(8);
- T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
- T1_SetLogLevel(T1LOG_DEBUG);
- le_ps_font = zend_register_list_destructors_ex(php_free_ps_font, NULL, "gd PS font", module_number);
- le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
-#endif
#ifndef HAVE_GD_BUNDLED
gdSetErrorMethod(php_gd_error_method);
#endif
#endif
#endif
-#ifdef HAVE_LIBT1
- php_info_print_table_row(2, "T1Lib Support", "enabled");
-#endif
-
php_info_print_table_row(2, "GIF Read Support", "enabled");
php_info_print_table_row(2, "GIF Create Support", "enabled");
#else
add_assoc_bool(return_value, "FreeType Support", 0);
#endif
-
-#ifdef HAVE_LIBT1
- add_assoc_bool(return_value, "T1Lib Support", 1);
-#else
- add_assoc_bool(return_value, "T1Lib Support", 0);
-#endif
add_assoc_bool(return_value, "GIF Read Support", 1);
add_assoc_bool(return_value, "GIF Create Support", 1);
#ifdef HAVE_GD_JPG
/* }}} */
#endif /* ENABLE_GD_TTF */
-#if HAVE_LIBT1
-
-/* {{{ php_free_ps_font
- */
-static void php_free_ps_font(zend_resource *rsrc)
-{
- int *font = (int *)rsrc->ptr;
-
- T1_DeleteFont(*font);
- efree(font);
-}
-/* }}} */
-
-/* {{{ php_free_ps_enc
- */
-static void php_free_ps_enc(zend_resource *rsrc)
-{
- char **enc = (char **)rsrc->ptr;
-
- T1_DeleteEncoding(enc);
-}
-/* }}} */
-
-/* {{{ proto resource imagepsloadfont(string pathname)
- Load a new font from specified file */
-PHP_FUNCTION(imagepsloadfont)
-{
- zend_string *file;
- int f_ind, *font;
-#ifdef PHP_WIN32
- zend_stat_t st;
-#endif
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file) == FAILURE) {
- return;
- }
-
-#ifdef PHP_WIN32
- if (VCWD_STAT(file->val, &st) < 0) {
- php_error_docref(NULL, E_WARNING, "Font file not found (%s)", file);
- RETURN_FALSE;
- }
-#endif
-
- f_ind = T1_AddFont(file->val);
-
- if (f_ind < 0) {
- php_error_docref(NULL, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
- RETURN_FALSE;
- }
-
- if (T1_LoadFont(f_ind)) {
- php_error_docref(NULL, E_WARNING, "Couldn't load the font");
- RETURN_FALSE;
- }
-
- font = (int *) emalloc(sizeof(int));
- *font = f_ind;
- RETURN_RES(zend_register_resource(font, le_gd));
-}
-/* }}} */
-
-/* {{{ proto int imagepscopyfont(int font_index)
- Make a copy of a font for purposes like extending or reenconding */
-/* The function in t1lib which this function uses seem to be buggy...
-PHP_FUNCTION(imagepscopyfont)
-{
- int l_ind, type;
- gd_ps_font *nf_ind, *of_ind;
- zend_long fnt;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &fnt) == FAILURE) {
- return;
- }
-
- of_ind = zend_list_find(fnt, &type);
-
- if (type != le_ps_font) {
- php_error_docref(NULL, E_WARNING, "%ld is not a Type 1 font index", fnt);
- RETURN_FALSE;
- }
-
- nf_ind = emalloc(sizeof(gd_ps_font));
- nf_ind->font_id = T1_CopyFont(of_ind->font_id);
-
- if (nf_ind->font_id < 0) {
- l_ind = nf_ind->font_id;
- efree(nf_ind);
- switch (l_ind) {
- case -1:
- php_error_docref(NULL, E_WARNING, "FontID %d is not loaded in memory", l_ind);
- RETURN_FALSE;
- break;
- case -2:
- php_error_docref(NULL, E_WARNING, "Tried to copy a logical font");
- RETURN_FALSE;
- break;
- case -3:
- php_error_docref(NULL, E_WARNING, "Memory allocation fault in t1lib");
- RETURN_FALSE;
- break;
- default:
- php_error_docref(NULL, E_WARNING, "An unknown error occurred in t1lib");
- RETURN_FALSE;
- break;
- }
- }
-
- nf_ind->extend = 1;
- l_ind = zend_list_insert(nf_ind, le_ps_font);
- RETURN_LONG(l_ind);
-}
-*/
-/* }}} */
-
-/* {{{ proto bool imagepsfreefont(resource font_index)
- Free memory used by a font */
-PHP_FUNCTION(imagepsfreefont)
-{
- zval *fnt;
- int *f_ind;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &fnt) == FAILURE) {
- return;
- }
-
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
- zend_list_close(Z_RES_P(fnt));
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool imagepsencodefont(resource font_index, string filename)
- To change a fonts character encoding vector */
-PHP_FUNCTION(imagepsencodefont)
-{
- zval *fnt;
- char *enc, **enc_vector;
- size_t enc_len;
- int *f_ind;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &fnt, &enc, &enc_len) == FAILURE) {
- return;
- }
-
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
- if ((enc_vector = T1_LoadEncoding(enc)) == NULL) {
- php_error_docref(NULL, E_WARNING, "Couldn't load encoding vector from %s", enc);
- RETURN_FALSE;
- }
-
- T1_DeleteAllSizes(*f_ind);
- if (T1_ReencodeFont(*f_ind, enc_vector)) {
- T1_DeleteEncoding(enc_vector);
- php_error_docref(NULL, E_WARNING, "Couldn't re-encode font");
- RETURN_FALSE;
- }
-
- zend_list_insert(enc_vector, le_ps_enc);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool imagepsextendfont(resource font_index, float extend)
- Extend or or condense (if extend < 1) a font */
-PHP_FUNCTION(imagepsextendfont)
-{
- zval *fnt;
- double ext;
- int *f_ind;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rd", &fnt, &ext) == FAILURE) {
- return;
- }
-
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
- T1_DeleteAllSizes(*f_ind);
-
- if (ext <= 0) {
- php_error_docref(NULL, E_WARNING, "Second parameter %F out of range (must be > 0)", ext);
- RETURN_FALSE;
- }
-
- if (T1_ExtendFont(*f_ind, ext) != 0) {
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool imagepsslantfont(resource font_index, float slant)
- Slant a font */
-PHP_FUNCTION(imagepsslantfont)
-{
- zval *fnt;
- double slt;
- int *f_ind;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rd", &fnt, &slt) == FAILURE) {
- return;
- }
-
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
- if (T1_SlantFont(*f_ind, slt) != 0) {
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto array imagepstext(resource image, string text, resource font, int size, int foreground, int background, int xcoord, int ycoord [, int space [, int tightness [, float angle [, int antialias])
- Rasterize a string over an image */
-PHP_FUNCTION(imagepstext)
-{
- zval *img, *fnt;
- int i, j;
- zend_long _fg, _bg, x, y, size, space = 0, aa_steps = 4, width = 0;
- int *f_ind;
- int h_lines, v_lines, c_ind;
- int rd, gr, bl, fg_rd, fg_gr, fg_bl, bg_rd, bg_gr, bg_bl;
- int fg_al, bg_al, al;
- int aa[16];
- int amount_kern, add_width;
- double angle = 0.0, extend;
- unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- gdImagePtr bg_img;
- GLYPH *str_img;
- T1_OUTLINE *char_path, *str_path;
- T1_TMATRIX *transform = NULL;
- zend_string *str;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSrlllll|lldl", &img, &str, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
- return;
- }
-
- if (aa_steps != 4 && aa_steps != 16) {
- php_error_docref(NULL, E_WARNING, "Antialias steps must be 4 or 16");
- RETURN_FALSE;
- }
-
- if ((bg_img = (gdImagePtr)zend_fetch_resource(Z_RES_P(img), "Image", le_gd)) == NULL) {
- RETURN_FALSE;
- }
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
- /* Ensure that the provided colors are valid */
- if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
- php_error_docref(NULL, E_WARNING, "Foreground color index %pd out of range", _fg);
- RETURN_FALSE;
- }
-
- if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
- php_error_docref(NULL, E_WARNING, "Background color index %pd out of range", _bg);
- RETURN_FALSE;
- }
-
- fg_rd = gdImageRed (bg_img, _fg);
- fg_gr = gdImageGreen(bg_img, _fg);
- fg_bl = gdImageBlue (bg_img, _fg);
- fg_al = gdImageAlpha(bg_img, _fg);
-
- bg_rd = gdImageRed (bg_img, _bg);
- bg_gr = gdImageGreen(bg_img, _bg);
- bg_bl = gdImageBlue (bg_img, _bg);
- bg_al = gdImageAlpha(bg_img, _bg);
-
- for (i = 0; i < aa_steps; i++) {
- rd = bg_rd + (double) (fg_rd - bg_rd) / aa_steps * (i + 1);
- gr = bg_gr + (double) (fg_gr - bg_gr) / aa_steps * (i + 1);
- bl = bg_bl + (double) (fg_bl - bg_bl) / aa_steps * (i + 1);
- al = bg_al + (double) (fg_al - bg_al) / aa_steps * (i + 1);
- aa[i] = gdImageColorResolveAlpha(bg_img, rd, gr, bl, al);
- }
-
- T1_AASetBitsPerPixel(8);
-
- switch (aa_steps) {
- case 4:
- T1_AASetGrayValues(0, 1, 2, 3, 4);
- T1_AASetLevel(T1_AA_LOW);
- break;
- case 16:
- T1_AAHSetGrayValues(aa_greys);
- T1_AASetLevel(T1_AA_HIGH);
- break;
- default:
- php_error_docref(NULL, E_WARNING, "Invalid value %pd as number of steps for antialiasing", aa_steps);
- RETURN_FALSE;
- }
-
- if (angle) {
- transform = T1_RotateMatrix(NULL, angle);
- }
-
- if (width) {
- extend = T1_GetExtend(*f_ind);
- str_path = T1_GetCharOutline(*f_ind, str->val[0], size, transform);
-
- if (!str_path) {
- if (T1_errno) {
- php_error_docref(NULL, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
- }
- RETURN_FALSE;
- }
-
- for (i = 1; i < str->len; i++) {
- amount_kern = (int) T1_GetKerning(*f_ind, str->val[i - 1], str->val[i]);
- amount_kern += str->val[i - 1] == ' ' ? space : 0;
- add_width = (int) (amount_kern + width) / extend;
-
- char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
- str_path = T1_ConcatOutlines(str_path, char_path);
-
- char_path = T1_GetCharOutline(*f_ind, str->val[i], size, transform);
- str_path = T1_ConcatOutlines(str_path, char_path);
- }
- str_img = T1_AAFillOutline(str_path, 0);
- } else {
- str_img = T1_AASetString(*f_ind, str->val, str->len, space, T1_KERNING, size, transform);
- }
- if (T1_errno) {
- php_error_docref(NULL, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
- RETURN_FALSE;
- }
-
- h_lines = str_img->metrics.ascent - str_img->metrics.descent;
- v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing;
-
- for (i = 0; i < v_lines; i++) {
- for (j = 0; j < h_lines; j++) {
- switch (str_img->bits[j * v_lines + i]) {
- case 0:
- break;
- default:
- c_ind = aa[str_img->bits[j * v_lines + i] - 1];
- gdImageSetPixel(bg_img, x + str_img->metrics.leftSideBearing + i, y - str_img->metrics.ascent + j, c_ind);
- break;
- }
- }
- }
-
- array_init(return_value);
-
- add_next_index_long(return_value, str_img->metrics.leftSideBearing);
- add_next_index_long(return_value, str_img->metrics.descent);
- add_next_index_long(return_value, str_img->metrics.rightSideBearing);
- add_next_index_long(return_value, str_img->metrics.ascent);
-}
-/* }}} */
-
-/* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, float angle])
- Return the bounding box needed by a string if rasterized */
-PHP_FUNCTION(imagepsbbox)
-{
- zval *fnt;
- zend_long sz = 0, sp = 0, wd = 0;
- zend_string *str;
- int i, space = 0, add_width = 0, char_width, amount_kern;
- int cur_x, cur_y, dx, dy;
- int x1, y1, x2, y2, x3, y3, x4, y4;
- int *f_ind;
- int per_char = 0;
- int argc = ZEND_NUM_ARGS();
- double angle = 0, sin_a = 0, cos_a = 0;
- BBox char_bbox, str_bbox = {0, 0, 0, 0};
-
- if (argc != 3 && argc != 6) {
- ZEND_WRONG_PARAM_COUNT();
- }
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "Srl|lld", &str, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
- return;
- }
-
- if (argc == 6) {
- space = sp;
- add_width = wd;
- angle = angle * M_PI / 180;
- sin_a = sin(angle);
- cos_a = cos(angle);
- per_char = add_width || angle ? 1 : 0;
- }
-
- if ((f_ind = (int *)zend_fetch_resource(Z_RES_P(fnt), "Type 1 font", le_ps_font)) == NULL) {
- RETURN_FALSE;
- }
-
-#define max(a, b) (a > b ? a : b)
-#define min(a, b) (a < b ? a : b)
-#define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
-#define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
-
- if (per_char) {
- space += T1_GetCharWidth(*f_ind, ' ');
- cur_x = cur_y = 0;
-
- for (i = 0; i < str->len; i++) {
- if (str->val[i] == ' ') {
- char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
- char_bbox.urx = char_width = space;
- } else {
- char_bbox = T1_GetCharBBox(*f_ind, str->val[i]);
- char_width = T1_GetCharWidth(*f_ind, str->val[i]);
- }
- amount_kern = i ? T1_GetKerning(*f_ind, str->val[i - 1], str->val[i]) : 0;
-
- /* Transfer character bounding box to right place */
- x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
- y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y;
- x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x;
- y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y;
- x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x;
- y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y;
- x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x;
- y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y;
-
- /* Find min & max values and compare them with current bounding box */
- str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4))));
- str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4))));
- str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4))));
- str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4))));
-
- /* Move to the next base point */
- dx = new_x(char_width + add_width + amount_kern, 0);
- dy = new_y(char_width + add_width + amount_kern, 0);
- cur_x += dx;
- cur_y += dy;
- /*
- printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", x1, y1, x2, y2, x3, y3, x4, y4, char_bbox.llx, char_bbox.lly, char_bbox.urx, char_bbox.ury, char_width, amount_kern, cur_x, cur_y, dx, dy);
- */
- }
-
- } else {
- str_bbox = T1_GetStringBBox(*f_ind, str->val, str->len, space, T1_KERNING);
- }
-
- if (T1_errno) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
- /*
- printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
- */
- add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*sz/1000));
- add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz/1000));
- add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*sz/1000));
- add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*sz/1000));
-}
-/* }}} */
-#endif
-
/* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
Output WBMP image to browser or file */
PHP_FUNCTION(image2wbmp)