CVS update: php3/functions
| From: | jah | Date: | Sun, 30 May 1999 04:08:13 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6289@lists.php.net to get a copy of this message | ||
Date: Sunday May 30, 1999 @ 0:08
Author: jah
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv6184/functions
Modified Files:
gd.c
Log Message:
Finally working...
Index: php3/functions/gd.c
diff -u php3/functions/gd.c:1.119 php3/functions/gd.c:1.120
--- php3/functions/gd.c:1.119 Sat May 29 08:02:27 1999
+++ php3/functions/gd.c Sun May 30 00:08:13 1999
@@ -29,7 +29,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.119 1999/05/29 12:02:27 jah Exp $ */
+/* $Id: gd.c,v 1.120 1999/05/30 04:08:13 jah Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -1854,7 +1854,9 @@
f_ind->font_id = T1_AddFont(file->value.str.val);
if (f_ind->font_id < 0) {
- switch (f_ind->font_id) {
+ l_ind = f_ind->font_id;
+ efree(f_ind);
+ switch (l_ind) {
case -1:
php3_error(E_WARNING, "Couldn't find the font file");
RETURN_FALSE;
@@ -1902,9 +1904,11 @@
nf_ind->font_id = T1_CopyFont(of_ind->font_id);
if (nf_ind->font_id < 0) {
- switch (nf_ind->font_id) {
+ l_ind = nf_ind->font_id;
+ efree(nf_ind);
+ switch (l_ind) {
case -1:
- php3_error(E_WARNING, "FontID %d is not loaded in memory", of_ind->font_id);
+ php3_error(E_WARNING, "FontID %d is not loaded in memory", l_ind);
RETURN_FALSE;
break;
case -2:
@@ -2158,18 +2162,18 @@
#ifdef HAVE_LIBT1_OUTLINE
dy = 0;
dx = (int) width/f_ind->extend;
- /*
+
if (angle) {
transform = T1_RotateMatrix(NULL, angle);
}
- */
+
str_path = T1_GetCharOutline(f_ind->font_id, str->value.str.val[0], sz->value.lval,
transform);
for (i = 1; i < str->value.str.len; i++) {
- amount_kern = (int) T1_GetKerning(f_ind->font_id, str->value.str.val[i-1],
str->value.str.val[i])/f_ind->extend;
+ amount_kern = (int) T1_GetKerning(f_ind->font_id, 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->font_id, amount_kern, dy, 0, sz->value.lval,
transform);
+ char_path = T1_GetMoveOutline(f_ind->font_id, (int)amount_kern/f_ind->extend, dy, 0,
sz->value.lval, transform);
str_path = T1_ConcatOutlines(str_path, char_path);
- /* Should scale according to the extend? And how to get it? */
+
char_path = T1_GetMoveOutline(f_ind->font_id, dx, dy, 0, sz->value.lval, transform);
str_path = T1_ConcatOutlines(str_path, char_path);
char_path = T1_GetCharOutline(f_ind->font_id, str->value.str.val[i], sz->value.lval,
transform);
@@ -2207,7 +2211,10 @@
}
}
}
-
+ /*
+ free(str_img);
+ str_img = NULL;
+ */
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
@@ -2223,10 +2230,12 @@
Return the bounding box needed by a string if rasterized */
void php3_imagepsbbox(INTERNAL_FUNCTION_PARAMETERS) {
pval *str, *fnt, *sz, *sp, *wd, *ang;
- int i, space, width, amount_kern, type;
+ int i, space, add_width, char_width, amount_kern, type;
+ int cur_x, cur_y, dx, dy;
+ int x1, y1, x2, y2, x3, y3, x4, y4;
gd_ps_font *f_ind;
int per_char = 0;
- double angle;
+ double angle, sin_a, cos_a;
BBox char_bbox, str_bbox = {0, 0, 0, 0};
switch(ARG_COUNT(ht)) {
@@ -2249,10 +2258,12 @@
convert_to_long(sp);
space = sp->value.lval;
convert_to_long(wd);
- width = wd->value.lval;
+ add_width = wd->value.lval;
convert_to_double(ang);
- angle = ang->value.dval;
- per_char = width || angle ? 1 : 0;
+ angle = ang->value.dval * M_PI / 180;
+ sin_a = sin(angle);
+ cos_a = cos(angle);
+ per_char = add_width || angle ? 1 : 0;
break;
default:
WRONG_PARAM_COUNT;
@@ -2265,30 +2276,49 @@
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->font_id, ' ');
+ cur_x = cur_y = 0;
for (i = 0; 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 = space;
- str_bbox.urx += space;
+ char_bbox.urx = char_width = space;
} else {
char_bbox = T1_GetCharBBox(f_ind->font_id, str->value.str.val[i]);
- str_bbox.urx += i != str->value.str.len-1 ? T1_GetCharWidth(f_ind->font_id,
str->value.str.val[i]) : char_bbox.urx;
- }
- str_bbox.urx += i != str->value.str.len-1 ? width : 0;
- if (!i) {
- str_bbox.llx = char_bbox.llx;
- } else {
- amount_kern = T1_GetKerning(f_ind->font_id, str->value.str.val[i-1],
str->value.str.val[i]);
- str_bbox.urx += amount_kern;
+ char_width = T1_GetCharWidth(f_ind->font_id, str->value.str.val[i]);
}
- str_bbox.lly = str_bbox.lly > char_bbox.lly ? char_bbox.lly : str_bbox.lly;
- str_bbox.ury = str_bbox.ury > char_bbox.ury ? str_bbox.ury : char_bbox.ury;
- /*
- printf("%d %d %d '%c'\n", char_bbox.llx, char_bbox.urx, str_bbox.urx,
str->value.str.val[i]);
- */
+ amount_kern = i ? T1_GetKerning(f_ind->font_id, str->value.str.val[i-1],
str->value.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 {
@@ -2299,6 +2329,7 @@
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
+ 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->value.lval/1000));
add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz->value.lval/1000));
--
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