On Sat, May 28, 2005 at 03:47:49PM +0200, Werner LEMBERG wrote:
> 
> > This patch fixes some bugs in FT_Bitmap_Embolden.
> 
> Applied, thanks.  I think there is still a bug for graymap fonts.
> Have a look at the attached test glyph.  Emboldening produces a
> strange result.
This is introduced by the last patch :(

I've dirty hacked ftview for testing bitmap emboldening of various
pixel_mode.  You can find the hack in the attachments.

For testing, launch ftview with outline font and press 'c' to disable
cache first.  Then you can use 'l' to switch between normal/emboldened
mode, and 'L' to rotate between LCD modes.  I hope this would help bug
hunting the bitmap emboldening algorithm (and help me not send buggy
patches).

Anyway, here's the changelog:

ft2-bitmap-embolden-fix2.patch
* src/base/ftbitmap.c (FT_Bitmap_Embolden): Fix emboldening bitmap of
mode FT_PIXEL_MODE_GRAY.  Also add support for mode FT_PIXEL_MODE_LCD
and FT_PIXEL_MODE_LCD_V.
(ft_bitmap_assure_buffer): FT_PIXEL_MODE_LCD and FT_PIXEL_MODE_LCD_V
should have ppb (pixel per byte) 1.
Zero the padding when there's no need to allocate memory.

ft2-ftsynth-advance.patch
* src/base/ftsynth.c (FT_GlyphSlot_Embolden): Modify slot->advance
accordingly.

-- 
Regards,
olv
=== src/base/ftbitmap.c
==================================================================
--- src/base/ftbitmap.c   (/freetype2/trunk)   (revision 923)
+++ src/base/ftbitmap.c   (/freetype2/branches/embolden)   (local)
@@ -115,8 +115,6 @@
     switch ( bitmap->pixel_mode )
     {
     case FT_PIXEL_MODE_MONO:
-    case FT_PIXEL_MODE_LCD:
-    case FT_PIXEL_MODE_LCD_V:
       ppb = 8;
       break;
     case FT_PIXEL_MODE_GRAY2:
@@ -126,15 +124,44 @@
       ppb = 2;
       break;
     case FT_PIXEL_MODE_GRAY:
+    case FT_PIXEL_MODE_LCD:
+    case FT_PIXEL_MODE_LCD_V:
       ppb = 1;
       break;
     default:
       return FT_Err_Invalid_Glyph_Format;
     }
 
-    /* check whether we must allocate memory */
+    /* if no need to allocate memory */
     if ( ypixels == 0 && pitch * ppb >= bitmap->width + xpixels )
+    {
+      /* zero the padding */
+      for ( i = 0; i < bitmap->rows; i++ )
+      {
+        unsigned char*  last_byte;
+        int             bits = xpixels * ( 8 / ppb );
+        int             mask = 0;
+
+
+        last_byte = bitmap->buffer + i * pitch + ( bitmap->width - 1 ) / ppb;
+
+        if ( bits >= 8 )
+        {
+          FT_MEM_ZERO( last_byte + 1, bits / 8 );
+          bits %= 8;
+        }
+
+        if ( bits > 0 )
+        {
+          while ( bits-- > 0 )
+            mask |= 1 << bits;
+
+          *last_byte &= ~mask;
+        }
+      }
+
       return FT_Err_Ok;
+    }
 
     new_pitch = ( bitmap->width + xpixels + ppb - 1 ) / ppb;
 
@@ -187,16 +214,22 @@
     if ( !bitmap )
       return FT_Err_Invalid_Argument;
 
+    xstr = FT_PIX_ROUND( xStrength ) >> 6;
+    ystr = FT_PIX_ROUND( yStrength ) >> 6;
+
     switch ( bitmap->pixel_mode )
     {
     case FT_PIXEL_MODE_GRAY2:
     case FT_PIXEL_MODE_GRAY4:
       return FT_Err_Invalid_Glyph_Format;
+    case FT_PIXEL_MODE_LCD:
+      xstr *= 3;
+      break;
+    case FT_PIXEL_MODE_LCD_V:
+      ystr *= 3;
+      break;
     }
 
-    xstr = FT_PIX_ROUND( xStrength ) >> 6;
-    ystr = FT_PIX_ROUND( yStrength ) >> 6;
-
     if ( xstr == 0 && ystr == 0 )
       return FT_Err_Ok;
     else if ( xstr < 0 || ystr < 0 || xstr > 8 )
@@ -245,19 +278,19 @@
               break;
 #endif
           }
-          else if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
+          else
           {
             if ( x - i >= 0 )
             {
-              if ( p[x] + p[x - i] > bitmap->num_grays )
+              if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
               {
-                p[x] = bitmap->num_grays;
+                p[x] = bitmap->num_grays - 1;
                 break;
               }
               else
               {
                 p[x] += p[x - i];
-                if ( p[x] == bitmap->num_grays )
+                if ( p[x] == bitmap->num_grays - 1 )
                   break;
               }
             }
=== src/ftcommon.i
==================================================================
--- src/ftcommon.i   (/freetype2/trunk/ft2demos)   (revision 923)
+++ src/ftcommon.i   (/freetype2/branches/embolden/ft2demos)   (local)
@@ -752,6 +752,39 @@
                                      &glyf,
                                      NULL );
 
+      /* XXX dirty hack for testing bitmap emboldening */
+      if ( glyf->format == FT_GLYPH_FORMAT_OUTLINE )
+      {
+        FT_Render_Mode  render_mode;
+
+        if ( lcd_mode <= 1 )
+          render_mode = FT_RENDER_MODE_NORMAL;
+        else if ( lcd_mode <= 3 )
+          render_mode = FT_RENDER_MODE_LCD;
+        else
+          render_mode = FT_RENDER_MODE_LCD_V;
+
+        if ( !antialias )
+          render_mode = FT_RENDER_MODE_MONO;
+
+        /* render the glyph to a bitmap, don't destroy original */
+        error = FT_Glyph_To_Bitmap( &glyf, render_mode, NULL, 0 );
+        if ( error )
+          goto Exit;
+
+        /* use 'l' to toggle */
+        if ( low_prec )
+        {
+          error = FT_Bitmap_Embolden( glyf->library, 
&((FT_BitmapGlyph)glyf)->bitmap, 1 << 6, 1 << 6);
+          if ( error )
+            goto Exit;
+          ((FT_BitmapGlyph)glyf)->top += 1;
+         glyf->advance.x += 1 << 16;
+        }
+
+        *aglyf = glyf;
+      }
+
       if ( !error )
         error = glyph_to_bitmap( glyf, target, left, top, x_advance, 
y_advance, aglyf );
     }
=== src/base/ftsynth.c
==================================================================
--- src/base/ftsynth.c  (revision 922)
+++ src/base/ftsynth.c  (local)
@@ -122,6 +122,9 @@
     /* modify the metrics accordingly */
     if ( !error )
     {
+      slot->advance.x += xstr;
+      slot->advance.y += ystr;
+
       slot->metrics.width        += xstr;
       slot->metrics.height       += ystr;
       slot->metrics.horiBearingY += ystr;
_______________________________________________
Freetype-devel mailing list
Freetype-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to