CVS update: php3/functions
| From: | jah | Date: | Fri, 28 May 1999 07:22:02 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6119@lists.php.net to get a copy of this message | ||
Date: Friday May 28, 1999 @ 3:22
Author: jah
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv13520/functions
Modified Files:
gd.c php3_gd.h
Log Message:
Some more work on PostScript Type 1 fonts and gd.c.
imagepstext with it's 12 (!) args is the winner of "the function with most
arguments in PHP3" contest...
Index: php3/functions/gd.c
diff -u php3/functions/gd.c:1.112 php3/functions/gd.c:1.113
--- php3/functions/gd.c:1.112 Mon May 24 18:24:39 1999
+++ php3/functions/gd.c Fri May 28 03:22:02 1999
@@ -29,7 +29,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.112 1999/05/24 22:24:39 jah Exp $ */
+/* $Id: gd.c,v 1.113 1999/05/28 07:22:02 jah Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -97,6 +97,7 @@
int le_gd_font;
#if HAVE_LIBT1
int le_ps_font;
+ gd_module php3_gd_module;
#endif
} gdlib_global_struct;
@@ -110,6 +111,7 @@
int le_gd_font;
#if HAVE_LIBT1
int le_ps_font;
+gd_module php3_gd_module;
#endif
#endif
@@ -211,9 +213,13 @@
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_InitLib(NO_LOGFILE|IGNORE_CONFIGFILE|IGNORE_FONTDATABASE);
T1_SetLogLevel(T1LOG_DEBUG);
GD_GLOBAL(le_ps_font) = register_list_destructors(_php3_free_ps_font, NULL);
+ if (cfg_get_string("ps.default_encoding",
&GD_GLOBAL(php3_gd_module).default_encoding) != FAILURE
+ && GD_GLOBAL(php3_gd_module).default_encoding[0] != 0) {
+ T1_SetDefaultEncoding(T1_LoadEncoding(GD_GLOBAL(php3_gd_module).default_encoding));
+ }
#endif
return SUCCESS;
}
@@ -1936,10 +1942,11 @@
}
/* }}} */
-/* {{{ proto bool imagepsencodefont(int font_index, ? encodingvector)
+/* {{{ proto bool imagepsencodefont(int font_index, string filename)
To change a fonts character encoding vector */
void php3_imagepsencodefont(INTERNAL_FUNCTION_PARAMETERS) {
pval *fnt, *enc;
+ char **enc_vector;
int type, *f_ind;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &fnt, &enc) == FAILURE) {
@@ -1947,6 +1954,7 @@
}
convert_to_long(fnt);
+ convert_to_string(enc);
f_ind = php3_list_find(fnt->value.lval, &type);
@@ -1954,8 +1962,18 @@
php3_error(E_WARNING, "%d is not a Type 1 font index", fnt->value.lval);
RETURN_FALSE;
}
+
+ if ((enc_vector = T1_LoadEncoding(enc->value.str.val)) == NULL) {
+ php3_error(E_WARNING, "Couldn't load encoding vector from %s",
enc->value.str.val);
+ RETURN_FALSE;
+ }
- /* Yet to be implemented... */
+ T1_DeleteAllSizes(*f_ind);
+ if (T1_ReencodeFont(*f_ind, enc_vector)) {
+ T1_DeleteEncoding(enc_vector);
+ php3_error(E_WARNING, "Couldn't reencode font");
+ RETURN_FALSE;
+ }
RETURN_TRUE;
}
/* }}} */
@@ -2010,17 +2028,22 @@
}
/* }}} */
-/* {{{ proto array imagepstext([in flux...])
+/* {{{ proto array imagepstext(int image, string text, int font, int size, int xcoord, int ycoord
[, int space, int tightness, double angle, int antialias])
Rasterize a string over an image */
void php3_imagepstext(INTERNAL_FUNCTION_PARAMETERS) {
- pval *img, *str, *fnt, *sz, *fg, *bg, *sp, *px, *py;
+ pval *img, *str, *fnt, *sz, *fg, *bg, *sp, *px, *py, *aas, *wd, *ang;
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];
+ int aa[16], aa_steps;
+ int dx, dy, width, amount_kern;
+ int make_path = 0;
+ double angle;
+ 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;
switch(ARG_COUNT(ht)) {
case 8:
@@ -2037,9 +2060,12 @@
x = px->value.lval;
y = py->value.lval;
space = 0;
+ aa_steps = 4;
+ width = 0;
+ angle = 0;
break;
- case 9:
- if (getParameters(ht, 9, &img, &str, &fnt, &sz, &fg, &bg, &px,
&py, &sp) == FAILURE) {
+ case 12:
+ if (getParameters(ht, 12, &img, &str, &fnt, &sz, &fg, &bg, &px,
&py, &sp, &wd, &ang, &aas) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(str);
@@ -2052,7 +2078,15 @@
convert_to_long(py);
x = px->value.lval;
y = py->value.lval;
+ convert_to_long(sp);
space = sp->value.lval;
+ convert_to_long(aas);
+ aa_steps = aas->value.lval;
+ convert_to_long(wd);
+ width = wd->value.lval;
+ convert_to_double(ang);
+ angle = ang->value.dval;
+ make_path = 1;
break;
default:
WRONG_PARAM_COUNT;
@@ -2079,26 +2113,60 @@
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);
+ 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);
aa[i] = gdImageColorResolve(bg_img, rd, gr, bl);
/*
- printf("%d %d %d %d\n", rd, gr, bl, aa[i]);
+ printf("%d %d %d %d %d\n", rd, gr, bl, aa[i], aa_steps);
*/
}
T1_AASetBitsPerPixel(8);
- T1_AASetGrayValues(0, 1, 2, 3, 4);
+
+ 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:
+ php3_error(E_WARNING, "Invalid value %d as number of steps for antialiasing",
aa_steps);
+ RETURN_FALSE;
+ }
+
+ if (make_path) {
+#ifdef HAVE_LIBT1_OUTLINE
+ dy = 0;
+ dx = width;
+ str_path = T1_GetCharOutline(*f_ind, str->value.str.val[0], sz->value.lval, NULL);
+ for (i = 1; i < str->value.str.len; i++) {
+ amount_kern = T1_GetKerning(*f_ind, str->value.str.val[i-1], str->value.str.val[i]);
+ amount_kern += str->value.str.val[i-1] == ' ' ? space : 0;
+ char_path = T1_GetMoveOutline(*f_ind, dx+amount_kern, dy, 0, sz->value.lval, NULL);
+ str_path = T1_ConcatOutlines(str_path, char_path);
+ char_path = T1_GetCharOutline(*f_ind, str->value.str.val[i], sz->value.lval, NULL);
+ str_path = T1_ConcatOutlines(str_path, char_path);
+ }
+ str_img = T1_AAFillOutline(str_path, 0);
-#ifdef T1_TMATRIX
+#else
+ php3_error(E_WARNING, "This form of function ImagePSText is supported only with t1lib version
0.8 or above");
+ RETURN_FALSE;
+#endif
+ } else {
+#ifdef HAVE_LIBT1_OUTLINE
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;
@@ -2134,12 +2202,13 @@
}
/* }}} */
-/* {{{ proto array imagepsbbox([in flux...])
+/* {{{ proto array imagepsbbox(string text, int font, int size[, int space, int tightness, int
angle])
Return the bounding box needed by a string if rasterized */
void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS) {
- pval *str, *fnt, *sz, *sp;
- int space, type, *f_ind;
- BBox str_bbox;
+ pval *str, *fnt, *sz, *sp, *wd, *ang;
+ int i, space, width, amount_kern, type, *f_ind;
+ int per_char = 0;
+ BBox char_bbox, str_bbox;
switch(ARG_COUNT(ht)) {
case 3:
@@ -2151,8 +2220,8 @@
convert_to_long(sz);
space = 0;
break;
- case 4:
- if (getParameters(ht, 4, &str, &fnt, &sz, &sp) == FAILURE) {
+ case 6:
+ if (getParameters(ht, 6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(str);
@@ -2160,6 +2229,10 @@
convert_to_long(sz);
convert_to_long(sp);
space = sp->value.lval;
+ convert_to_long(wd);
+ width = wd->value.lval;
+ convert_to_double(ang);
+ per_char = 1;
break;
default:
WRONG_PARAM_COUNT;
@@ -2171,11 +2244,38 @@
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 (per_char) {
+ if (str->value.str.val[0] != ' ') {
+ str_bbox = T1_GetCharBBox(*f_ind, str->value.str.val[0]);
+ } else {
+ str_bbox.llx = str_bbox.lly = str_bbox.ury = 0;
+ str_bbox.urx = T1_GetCharWidth(*f_ind, ' ') + space;
+ }
+ for (i = 1; i < str->value.str.len; i++) {
+ if (str->value.str.val[i] == ' ') {
+ char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
+ char_bbox.urx = T1_GetCharWidth(*f_ind, ' ') + space + width;
+ } else {
+ amount_kern = T1_GetKerning(*f_ind, str->value.str.val[i-1], str->value.str.val[i]);
+ amount_kern += str->value.str.val[i-1] == ' ' ? space : 0;
+ str_bbox.urx += amount_kern;
+ char_bbox = T1_GetCharBBox(*f_ind, str->value.str.val[i]);
+ }
+ str_bbox.urx += width;
+ str_bbox.urx += char_bbox.urx + char_bbox.llx;
+ str_bbox.lly = (char_bbox.lly < str_bbox.lly ? char_bbox.lly : str_bbox.lly);
+ str_bbox.ury = (char_bbox.ury > str_bbox.ury ? char_bbox.ury : str_bbox.ury);
+ /*
+ printf("%d %d %d %d : %d %d %d %d\n", char_bbox.llx, char_bbox.lly, char_bbox.urx,
char_bbox.ury,
+ str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
+ */
+ }
+ } else {
+ 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;
}
Index: php3/functions/php3_gd.h
diff -u php3/functions/php3_gd.h:1.29 php3/functions/php3_gd.h:1.30
--- php3/functions/php3_gd.h:1.29 Mon May 24 18:24:39 1999
+++ php3/functions/php3_gd.h Fri May 28 03:22:02 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_gd.h,v 1.29 1999/05/24 22:24:39 jah Exp $ */
+/* $Id: php3_gd.h,v 1.30 1999/05/28 07:22:02 jah Exp $ */
#ifndef _PHP3_GD_H
#define _PHP3_GD_H
@@ -103,6 +103,13 @@
extern void php3_imagepsslantfont(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagepstext(INTERNAL_FUNCTION_PARAMETERS);
+
+typedef struct {
+ char *default_encoding;
+} gd_module;
+
+extern gd_module php3_gd_module;
+
#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