1 diff -Nur gd-2.0.1.orig/gd.c gd-2.0.1/gd.c
2 --- gd-2.0.1.orig/gd.c Sat Aug 10 23:19:14 2002
3 +++ gd-2.0.1/gd.c Sat Aug 10 23:39:35 2002
5 op = c; /* Save open slot */
6 continue; /* Color not in use */
8 + if (c == im->transparent)
10 + /* don't ever resolve to the color that has
11 + * been designated as the transparent color */
14 rd = (long) (im->red[c] - r);
15 gd = (long) (im->green[c] - g);
16 bd = (long) (im->blue[c] - b);
20 /* Find or create the best match */
21 - mapTo = gdImageColorResolveAlpha (dst,
22 + nc = gdImageColorResolveAlpha (dst,
23 gdTrueColorGetRed (c),
24 gdTrueColorGetGreen (c),
25 gdTrueColorGetBlue (c),
28 for (x = dstX; (x < dstX + dstW); x++)
30 - int pd = gdImageGetPixel (dst, x, y);
31 + /* int pd = gdImageGetPixel (dst, x, y); -- not used */
32 float sy1, sy2, sx1, sx2;
35 diff -Nur gd-2.0.1.orig/gd_gd2.c gd-2.0.1/gd_gd2.c
36 --- gd-2.0.1.orig/gd_gd2.c Tue Apr 3 22:44:41 2001
37 +++ gd-2.0.1/gd_gd2.c Sat Aug 10 23:48:23 2002
42 - ch = chunkBuf[chunkPos++] << 24 +
43 - chunkBuf[chunkPos++] << 16 +
44 - chunkBuf[chunkPos++] << 8 +
45 - chunkBuf[chunkPos++];
46 + ch = chunkBuf[chunkPos++] << 24;
47 + ch += chunkBuf[chunkPos++] << 16;
48 + ch += chunkBuf[chunkPos++] << 8;
49 + ch += chunkBuf[chunkPos++];
53 diff -Nur gd-2.0.1.orig/gd_topal.c gd-2.0.1/gd_topal.c
54 --- gd-2.0.1.orig/gd_topal.c Tue Apr 3 22:44:42 2001
55 +++ gd-2.0.1/gd_topal.c Sat Aug 10 23:55:17 2002
58 for (ic2 = BOX_C2_ELEMS - 1; ic2 >= 0; ic2--)
62 for (ic3 = BOX_C3_ELEMS - 1; ic3 >= 0; ic3--)
65 diff -Nur gd-2.0.1.orig/gdft.c gd-2.0.1/gdft.c
66 --- gd-2.0.1.orig/gdft.c Tue Apr 3 22:44:42 2001
67 +++ gd-2.0.1/gdft.c Sun Aug 11 00:19:56 2002
69 fontsearchpath = getenv ("GDFONTPATH");
71 fontsearchpath = DEFAULT_FONTPATH;
72 - path = strdup (fontsearchpath);
73 fontlist = strdup (a->fontlist);
77 for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name;
78 name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr))
81 + /* make a fresh copy each time - strtok corrupts it. */
82 + path = strdup (fontsearchpath);
84 * Allocate an oversized buffer that is guaranteed to be
85 * big enough for all paths to be tested.
90 + sprintf (fullname, "%s/%s.pfa", dir, name);
91 + if (access (fullname, R_OK) == 0)
96 + sprintf (fullname, "%s/%s.pfb", dir, name);
97 + if (access (fullname, R_OK) == 0)
112 /* if fg is specified by a negative color idx, then don't antialias */
115 - a->tweencolor = -fg;
116 + if ((pixel + pixel) >= NUMCOLORS)
117 + a->tweencolor = -fg;
119 + a->tweencolor = bg;
125 /* draw_bitmap - transfers glyph bitmap to GD image */
127 -gdft_draw_bitmap (gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
128 +gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
130 unsigned char *pixel;
132 @@ -543,21 +558,15 @@
133 tweencolor_t *tc_elem;
134 tweencolorkey_t tc_key;
136 - /* initialize tweenColorCache on first call */
137 - static gdCache_head_t *tc_cache;
141 - tc_cache = gdCacheCreate (TWEENCOLORCACHESIZE,
142 - tweenColorTest, tweenColorFetch, tweenColorRelease);
145 /* copy to image, mapping colors */
148 for (row = 0; row < bitmap.rows; row++)
150 pc = row * bitmap.pitch;
151 + if(bitmap.pixel_mode==ft_pixel_mode_mono)
152 + pc *= 8; /* pc is measured in bits for monochrome images */
156 /* clip if out of bounds */
157 @@ -608,11 +617,11 @@
158 /* use fg color directly */
162 + *tpixel = abs( fg );
167 + *pixel = abs( fg );
172 return (char *) NULL;
176 +gdroundupdown (FT_F26Dot6 v1, int updown)
179 + ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
180 + : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
183 extern int any2eucjp (char *, char *, unsigned int);
185 +/* Persistent font cache until explicitly cleared */
186 +/* Fonts can be used across multiple images */
187 +static gdCache_head_t *fontCache;
188 +static FT_Library library;
193 + gdCacheDelete(fontCache);
194 + FT_Done_FreeType(library);
198 /********************************************************************/
199 /* gdImageStringFT - render a utf8 string onto a gd image */
201 @@ -671,15 +701,26 @@
203 int render = (im && (im->trueColor || (fg <= 255 && fg >= -255)));
205 + int render_mode = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
207 -/***** initialize font library and font cache on first call ******/
208 - static gdCache_head_t *fontCache;
209 - static FT_Library library;
211 + * make a new tweenColorCache on every call
212 + * because caching colormappings between calls
213 + * is not safe. If the im-pointer points to a
214 + * brand new image, the cache gives out bogus
215 + * colorindexes. -- 27.06.2001 <krisku@arrak.fi>
217 + gdCache_head_t *tc_cache;
219 + tc_cache = gdCacheCreate( TWEENCOLORCACHESIZE,
220 + tweenColorTest, tweenColorFetch, tweenColorRelease );
222 +/***** initialize font library and font cache on first call ******/
225 if (FT_Init_FreeType (&library))
227 + gdCacheDelete( tc_cache );
228 return "Failure to initialize font library";
230 fontCache = gdCacheCreate (FONTCACHESIZE,
232 font = (font_t *) gdCacheGet (fontCache, &fontkey);
235 + gdCacheDelete( tc_cache );
236 return fontCache->error;
238 face = font->face; /* shortcut */
240 if (FT_Set_Char_Size (face, 0, (FT_F26Dot6) (ptsize * 64),
241 GD_RESOLUTION, GD_RESOLUTION))
243 + gdCacheDelete( tc_cache );
244 return "Could not set character size";
249 use_kerning = FT_HAS_KERNING (face);
253 + render_mode |= FT_LOAD_MONOCHROME;
257 if (font->have_char_map_sjis)
262 + /* set rotation transform */
263 + FT_Set_Transform(face, &matrix, NULL);
265 /* Convert character code to glyph index */
266 glyph_index = FT_Get_Char_Index (face, ch);
268 @@ -833,50 +883,60 @@
271 /* load glyph image into the slot (erase previous one) */
272 - err = FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT);
273 + err = FT_Load_Glyph (face, glyph_index, render_mode);
275 - return "Problem loading glyph";
277 + gdCacheDelete( tc_cache );
278 + return "Problem loading glyph";
281 /* transform glyph image */
282 FT_Get_Glyph (slot, &image);
284 { /* only if need brect */
285 FT_Glyph_Get_CBox (image, ft_glyph_bbox_gridfit, &glyph_bbox);
287 - { /* if first character, init BB corner values */
288 - bbox.xMin = bbox.yMin = (1 << 30) - 1;
289 - bbox.xMax = bbox.yMax = -bbox.xMin;
291 glyph_bbox.xMin += penf.x;
292 glyph_bbox.yMin += penf.y;
293 glyph_bbox.xMax += penf.x;
294 glyph_bbox.yMax += penf.y;
295 - if (bbox.xMin > glyph_bbox.xMin)
296 - bbox.xMin = glyph_bbox.xMin;
297 - if (bbox.yMin > glyph_bbox.yMin)
298 - bbox.yMin = glyph_bbox.yMin;
299 - if (bbox.xMax < glyph_bbox.xMax)
300 - bbox.xMax = glyph_bbox.xMax;
301 - if (bbox.yMax < glyph_bbox.yMax)
302 - bbox.yMax = glyph_bbox.yMax;
303 + if (ch == ' ') /* special case for trailing space */
304 + glyph_bbox.xMax += slot->metrics.horiAdvance;
306 + { /* if first character, init BB corner values */
307 + bbox.xMin = glyph_bbox.xMin;
308 + bbox.yMin = glyph_bbox.yMin;
309 + bbox.xMax = glyph_bbox.xMax;
310 + bbox.yMax = glyph_bbox.yMax;
314 + if (bbox.xMin > glyph_bbox.xMin)
315 + bbox.xMin = glyph_bbox.xMin;
316 + if (bbox.yMin > glyph_bbox.yMin)
317 + bbox.yMin = glyph_bbox.yMin;
318 + if (bbox.xMax < glyph_bbox.xMax)
319 + bbox.xMax = glyph_bbox.xMax;
320 + if (bbox.yMax < glyph_bbox.yMax)
321 + bbox.yMax = glyph_bbox.yMax;
326 - /* transform glyph image */
327 - FT_Glyph_Transform (image, &matrix, 0);
331 if (image->format != ft_glyph_format_bitmap)
333 err = FT_Glyph_To_Bitmap (&image, ft_render_mode_normal, 0, 1);
335 - return "Problem rendering glyph";
337 + gdCacheDelete( tc_cache );
338 + return "Problem rendering glyph";
342 /* now, draw to our target surface */
343 bm = (FT_BitmapGlyph) image;
344 - gdft_draw_bitmap (im, fg, bm->bitmap,
345 + gdft_draw_bitmap (tc_cache, im, fg, bm->bitmap,
346 x + x1 + ((pen.x + 31) >> 6) + bm->left,
347 y - y1 + ((pen.y + 31) >> 6) - bm->top);
353 + gdCacheDelete (tc_cache);
354 return (char *) NULL;
358 -gdroundupdown (FT_F26Dot6 v1, int updown)
361 - ? (v1 < 0 ? ((v1 - 63) >> 6) : v1 >> 6)
362 - : (v1 > 0 ? ((v1 + 63) >> 6) : v1 >> 6);
365 #endif /* HAVE_LIBFREETYPE */