CVS update: php3/functions
| From: | jah | Date: | Mon, 24 May 1999 00:02:07 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-5913@lists.php.net to get a copy of this message | ||
Date: Sunday May 23, 1999 @ 20:02
Author: jah
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv15579/functions
Modified Files:
gd.c php3_gd.h
Log Message:
A few functions/global.h -> functions/php3_global.h in Makefile.in.
Initial support for using Postscript Type 1 fonts in gifs.
Index: php3/functions/gd.c
diff -u php3/functions/gd.c:1.108 php3/functions/gd.c:1.109
--- php3/functions/gd.c:1.108 Sun May 16 11:45:09 1999
+++ php3/functions/gd.c Sun May 23 20:02:07 1999
@@ -29,7 +29,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.108 1999/05/16 15:45:09 ssb Exp $ */
+/* $Id: gd.c,v 1.109 1999/05/24 00:02:07 jah Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -75,6 +75,9 @@
# include "functions/gdttf.h"
# endif
#endif
+#if HAVE_LIBT1
+#include <t1lib.h>
+#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
@@ -92,6 +95,9 @@
typedef struct gdlib_global_struct{
int le_gd;
int le_gd_font;
+#if HAVE_LIBT1
+ int le_ps_font;
+#endif
} gdlib_global_struct;
# define GD_GLOBAL(a) gdlib_globals->a
@@ -102,7 +108,10 @@
# define GD_TLS_VARS
int le_gd;
int le_gd_font;
+#if HAVE_LIBT1
+int le_ps_font;
#endif
+#endif
function_entry gd_functions[] = {
{"imagearc", php3_imagearc, NULL},
@@ -145,6 +154,13 @@
{"imagettfbbox", php3_imagettfbbox, NULL},
{"imagettftext", php3_imagettftext, NULL},
#endif
+#if HAVE_LIBT1
+ {"imagepsloadfont", php3_imagepsloadfont, NULL},
+ {"imagepsfreefont", php3_imagepsfreefont, NULL},
+ {"imagepsextfont", php3_imagepsextfont, NULL},
+ {"imagepsbbox", php3_imagepsbbox, NULL},
+ {"imagepstext", php3_imagepstext, NULL},
+#endif
{NULL, NULL, NULL}
};
@@ -190,6 +206,12 @@
#endif
GD_GLOBAL(le_gd) = register_list_destructors(php3i_destructor_gdImageDestroy, NULL);
GD_GLOBAL(le_gd_font) = register_list_destructors(php3_free_gd_font, NULL);
+#if HAVE_LIBT1
+ T1_SetBitmapPad(8);
+ T1_InitLib(LOGFILE|IGNORE_CONFIGFILE|IGNORE_FONTDATABASE);
+ T1_SetLogLevel(T1LOG_DEBUG);
+ GD_GLOBAL(le_ps_font) = register_list_destructors(_php3_free_ps_font, NULL);
+#endif
return SUCCESS;
}
@@ -203,6 +225,9 @@
#if HAVE_LIBTTF
php3_printf(" with FreeType support");
#endif
+#if HAVE_LIBT1
+ php3_printf(" with Type1 support");
+#endif
}
int php3_mend_gd(void){
@@ -219,6 +244,9 @@
}
PHP3_MUTEX_UNLOCK(gdlib_mutex);
#endif
+#if HAVE_LIBT1
+ T1_CloseLib();
+#endif
return SUCCESS;
}
@@ -1785,6 +1813,266 @@
}
}
#endif
+
+#if HAVE_LIBT1
+
+void _php3_free_ps_font(int *f_ind)
+{
+ T1_DeleteFont(*f_ind);
+ efree(f_ind);
+}
+
+void php3_imagepsloadfont(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *file;
+ int *f_ind, l_ind;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string(file);
+
+ f_ind = emalloc(sizeof(int));
+ *f_ind = T1_AddFont(file->value.str.val);
+
+ if (*f_ind < 0) {
+ switch (*f_ind) {
+ case -1:
+ php3_error(E_WARNING, "Couldn't find the font file");
+ RETURN_FALSE;
+ break;
+ case -2:
+ case -3:
+ php3_error(E_WARNING, "Memory allocation fault in t1lib");
+ RETURN_FALSE;
+ break;
+ default:
+ php3_error(E_WARNING, "An unknown error occurred in t1lib");
+ RETURN_FALSE;
+ break;
+ }
+ }
+
+ l_ind = php3_list_insert(f_ind, GD_GLOBAL(le_ps_font));
+ RETURN_LONG(l_ind);
+}
+
+void php3_imagepsfreefont(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *fnt;
+ int type;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &fnt) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(fnt);
+
+ php3_list_find(fnt->value.lval, &type);
+
+ if (type != GD_GLOBAL(le_ps_font)) {
+ php3_error(E_WARNING, "%d is not a Type 1 font index", fnt->value.lval);
+ RETURN_FALSE;
+ }
+
+ php3_list_delete(fnt->value.lval);
+ RETURN_TRUE;
+}
+
+void php3_imagepsextfont(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *fnt, *ext;
+ int type, *f_ind;
+
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &fnt, &ext) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(fnt);
+ convert_to_double(ext);
+
+ f_ind = php3_list_find(fnt->value.lval, &type);
+
+ if (type != GD_GLOBAL(le_ps_font)) {
+ php3_error(E_WARNING, "%d is not a Type 1 font index", fnt->value.lval);
+ RETURN_FALSE;
+ }
+
+ if (!T1_ExtendFont(*f_ind, ext->value.dval)) RETURN_FALSE;
+ RETURN_TRUE;
+}
+
+void php3_imagepstext(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *img, *str, *fnt, *sz, *fg, *bg, *sp, *px, *py;
+ int i, j, x, y;
+ int space, type, *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 aa[3];
+ gdImagePtr bg_img;
+ GLYPH *str_img;
+
+ switch(ARG_COUNT(ht)) {
+ case 8:
+ if (getParameters(ht, 8, &img, &str, &fnt, &sz, &fg, &bg, &px,
&py) == FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string(str);
+ convert_to_long(fnt);
+ convert_to_long(sz);
+ convert_to_long(fg);
+ convert_to_long(bg);
+ convert_to_long(px);
+ convert_to_long(py);
+ x = px->value.lval;
+ y = py->value.lval;
+ space = 0;
+ break;
+ case 9:
+ if (getParameters(ht, 9, &img, &str, &fnt, &sz, &fg, &bg, &px,
&py, &sp) == FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string(str);
+ convert_to_long(fnt);
+ convert_to_long(sz);
+ convert_to_long(sp);
+ convert_to_long(fg);
+ convert_to_long(bg);
+ convert_to_long(px);
+ convert_to_long(py);
+ x = px->value.lval;
+ y = py->value.lval;
+ space = sp->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ }
+
+ bg_img = php3_list_find(img->value.lval, &type);
+
+ if (!bg_img || type != GD_GLOBAL(le_gd)) {
+ php3_error(E_WARNING, "Unable to find image pointer");
+ RETURN_FALSE;
+ }
+
+ f_ind = php3_list_find(fnt->value.lval, &type);
+
+ if (!f_ind || type != GD_GLOBAL(le_ps_font)) {
+ php3_error(E_WARNING, "%d is not a Type 1 font index", fnt->value.lval);
+ RETURN_FALSE;
+ }
+
+ fg_rd = gdImageRed(bg_img, fg->value.lval);
+ fg_gr = gdImageGreen(bg_img, fg->value.lval);
+ fg_bl = gdImageBlue(bg_img, fg->value.lval);
+ bg_rd = gdImageRed(bg_img, bg->value.lval);
+ bg_gr = gdImageGreen(bg_img, bg->value.lval);
+ bg_bl = gdImageBlue(bg_img, bg->value.lval);
+
+ for (i = 0; i < 4; i++) {
+ rd = bg_rd+(double)(fg_rd-bg_rd)/4*(i+1);
+ gr = bg_gr+(double)(fg_gr-bg_gr)/4*(i+1);
+ bl = bg_bl+(double)(fg_bl-bg_bl)/4*(i+1);
+ aa[i] = gdImageColorResolve(bg_img, rd, gr, bl);
+ /*
+ printf("%d %d %d %d\n", rd, gr, bl, aa[i]);
+ */
+ }
+
+ T1_AASetBitsPerPixel(8);
+ T1_AASetGrayValues(0, 1, 2, 3, 4);
+
+#ifdef T1_TMATRIX
+ str_img = T1_AASetString(*f_ind, str->value.str.val, str->value.str.len,
+ space, T1_KERNING, sz->value.lval, NULL);
+#else
+ str_img = T1_AASetString(*f_ind, str->value.str.val, str->value.str.len,
+ space, T1_KERNING, sz->value.lval, 0);
+#endif
+
+ if (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:
+ /*
+ printf("%d %d %d %d\n", x+str_img->metrics.leftSideBearing+i,
y-str_img->metrics.ascent+j, 0, str_img->bits[j*v_lines+i]);
+ */
+ 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);
+ /*
+ printf("%d %d %d %d\n", x+str_img->metrics.leftSideBearing+i,
y-str_img->metrics.ascent+j, c_ind, str_img->bits[j*v_lines+i]);
+ */
+ }
+ }
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ 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);
+}
+
+void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *str, *fnt, *sz, *sp;
+ int space, type, *f_ind;
+ BBox str_bbox;
+
+ switch(ARG_COUNT(ht)) {
+ case 3:
+ if (getParameters(ht, 3, &str, &fnt, &sz) == FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string(str);
+ convert_to_long(fnt);
+ convert_to_long(sz);
+ space = 0;
+ break;
+ case 4:
+ if (getParameters(ht, 4, &str, &fnt, &sz, &sp) == FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string(str);
+ convert_to_long(fnt);
+ convert_to_long(sz);
+ convert_to_long(sp);
+ space = sp->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ }
+
+ f_ind = php3_list_find(fnt->value.lval, &type);
+
+ if (type != GD_GLOBAL(le_ps_font)) {
+ php3_error(E_WARNING, "%d is not a Type 1 font index", fnt->value.lval);
+ RETURN_FALSE;
+ }
+
+ str_bbox = T1_GetStringBBox(*f_ind, str->value.str.val, str->value.str.len, space,
T1_KERNING);
+
+ if (T1_errno) RETURN_FALSE;
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)/1000*sz->value.lval));
+ add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)/1000*sz->value.lval));
+ add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)/1000*sz->value.lval));
+ add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)/1000*sz->value.lval));
+}
+
+#endif /* HAVE_LIBT1 */
+
#endif
Index: php3/functions/php3_gd.h
diff -u php3/functions/php3_gd.h:1.26 php3/functions/php3_gd.h:1.27
--- php3/functions/php3_gd.h:1.26 Thu Apr 22 09:19:50 1999
+++ php3/functions/php3_gd.h Sun May 23 20:02:07 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_gd.h,v 1.26 1999/04/22 13:19:50 ssb Exp $ */
+/* $Id: php3_gd.h,v 1.27 1999/05/24 00:02:07 jah Exp $ */
#ifndef _PHP3_GD_H
#define _PHP3_GD_H
@@ -92,6 +92,14 @@
#ifdef HAVE_LIBTTF
extern void php3_imagettfbbox(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagettftext(INTERNAL_FUNCTION_PARAMETERS);
+#endif
+#if HAVE_LIBT1
+extern void php3_imagepsloadfont(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_imagepsfreefont(INTERNAL_FUNCTION_PARAMETERS);
+extern void _php3_free_ps_font(int *);
+extern void php3_imagepsextfont(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_imagepstext(INTERNAL_FUNCTION_PARAMETERS);
#endif
#else
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net