Patch for freetype issue

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch for freetype issue

Erwan Loaëc
Hello,

I've found a bug in the function font_render() of _imagingft.c.
The "x" value is adapted according to the horiBearingX value of the
first glyph but the concerned glyph is loaded after.

I suggest the patch in attachment.
Is anyone can take a look and confirm this is really a bug ?

Regards,


--
Erwan Loaec

--- Imaging-1.1.7/_imagingft.c 2009-11-01 01:44:12.000000000 +0100
+++ Imaging-1.1.7_patch/_imagingft.c 2011-01-14 16:06:10.000000000 +0100
@@ -331,18 +331,18 @@
         load_flags |= FT_LOAD_TARGET_MONO;
 
     for (x = i = 0; font_getchar(string, i, &ch); i++) {
+        index = FT_Get_Char_Index(self->face, ch);
+        error = FT_Load_Glyph(self->face, index, load_flags);
+        if (error)
+            return geterror(error);
         if (i == 0 && self->face->glyph->metrics.horiBearingX < 0)
             x = -PIXEL(self->face->glyph->metrics.horiBearingX);
-        index = FT_Get_Char_Index(self->face, ch);
         if (kerning && last_index && index) {
             FT_Vector delta;
             FT_Get_Kerning(self->face, last_index, index, ft_kerning_default,
                            &delta);
             x += delta.x >> 6;
         }
-        error = FT_Load_Glyph(self->face, index, load_flags);
-        if (error)
-            return geterror(error);
         glyph = self->face->glyph;
         if (mask) {
             /* use monochrome mask (on palette images, etc) */

_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Patch for freetype issue

Norbert Cauderan
On Fri, Jan 14, 2011 at 4:21 PM, Erwan Loaëc <[hidden email]> wrote:
Is anyone can take a look and confirm this is really a bug ?

 Without  the patch, following code gives 2 truncated "j". With the patch, everything looks OK. The problem does not appear with every font but at least with "arial" on windows and DejaVuSerif on linux.

import Image
import ImageDraw
import ImageFont
font = ImageFont.truetype('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf', 150,encoding="unic")
im = Image.new("RGBA",(500,800),(0,255,0,127))
draw = ImageDraw.Draw(im)
draw.text((100,10),"jj ",font=font,fill=(255,0,0,255))
draw.text((100,180),"ji",font=font,fill=(255,0,0,255))
draw.text((100,370),"jj",font=font,fill=(255,0,0,255))
im.save("test.png")


_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig