Commit 71d7628175c1130e2d698ef558641279de70d553

Werner Lemberg 2005-05-30T07:54:20

* 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. * src/base/ftsynth.c (FT_GlyphSlot_Embolden): Handle slot->advance too. More suited emboldening strength.

diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 0306188..6380391 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -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;
               }
             }
diff --git a/src/base/ftsynth.c b/src/base/ftsynth.c
index 4548a02..020bfdf 100644
--- a/src/base/ftsynth.c
+++ b/src/base/ftsynth.c
@@ -81,7 +81,7 @@
 
     /* some reasonable strength */
     xstr = FT_MulFix( face->units_per_EM,
-                      face->size->metrics.y_scale ) / 32;
+                      face->size->metrics.y_scale ) / 42;
     ystr = xstr;
 
     if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
@@ -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;