On Mon, May 30, 2005 at 03:24:30PM +0800, Chia I Wu wrote:
> gray2 and gray4 are not supported now.  I'll see if I can add support to them.
> If I can't, I'll submit a patch to update the documentation :)
Ok, this patch should fix the problem.  Instead of supporting gray[24]
directly, convertion from gray[24] to gray8 is done before emboldening.


Changelog:

* include/freetype/ftbitmap.h (FT_Bitmap_Embolden): Fix typos.
Update documentaion a little.

* include/freetype/ftoutline.h (FT_Outline_Embolden): Fix typos.

* src/base/ftbitmap.c (FT_Bitmap_Embolden): Add support for bitmap of
pixel_mode FT_PIXEL_MODE_GRAY2 or FT_PIXEL_MODE_GRAY4.
When xstr is larger than 8 and bitmap is of pixel_mode
FT_PIXEL_MODE_MONO, set xstr to 8 instead of returning error.

-- 
Regards,
olv
=== include/freetype/ftbitmap.h
==================================================================
--- include/freetype/ftbitmap.h   (/freetype2/trunk)   (revision 931)
+++ include/freetype/ftbitmap.h   (/freetype2/branches/embolden)   (local)
@@ -97,7 +97,7 @@
   /*    FT_Bitmap_Embolden                                                 */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Emboldens a bitmap.  The new bitmap will be about `xStrength'      */
+  /*    Embolden a bitmap.  The new bitmap will be about `xStrength'       */
   /*    pixels wider and `yStrength' pixels higher.  The left and bottom   */
   /*    borders are kept unchanged.                                        */
   /*                                                                       */
@@ -105,10 +105,10 @@
   /*    library   :: A handle to a library object.                         */
   /*                                                                       */
   /*    xStrength :: How strong the glyph is emboldened horizontally.      */
-  /*                 Expressed in 16.16 pixel format.                      */
+  /*                 Expressed in 26.6 pixel format.                       */
   /*                                                                       */
   /*    yStrength :: How strong the glyph is emboldened vertically.        */
-  /*                 Expressed in 16.16 pixel format.                      */
+  /*                 Expressed in 26.6 pixel format.                       */
   /*                                                                       */
   /* <InOut>                                                               */
   /*    bitmap    :: A handle to the target bitmap.                        */
@@ -118,7 +118,7 @@
   /*                                                                       */
   /* <Note>                                                                */
   /*    The current implementation restricts `xStrength' to be less than   */
-  /*    or equal to 8.                                                     */
+  /*    or equal to 8 when bitmap is of pixel_mode @FT_PIXEL_MODE_MONO.    */
   /*                                                                       */
   /*    Don't embolden the bitmap owned by a @FT_GlyphSlot directly!  Call */
   /*    @FT_Bitmap_Copy to get a copy and work on the copy instead.        */
=== include/freetype/ftoutln.h
==================================================================
--- include/freetype/ftoutln.h   (/freetype2/trunk)   (revision 931)
+++ include/freetype/ftoutln.h   (/freetype2/branches/embolden)   (local)
@@ -319,7 +319,7 @@
   /*                                                                       */
   /* <Input>                                                               */
   /*    strength :: How strong the glyph is emboldened.  Expressed in      */
-  /*                16.16 pixel format.                                    */
+  /*                26.6 pixel format.                                     */
   /*                                                                       */
   /* <Return>                                                              */
   /*    FreeType error code.  0 means success.                             */
=== src/base/ftbitmap.c
==================================================================
--- src/base/ftbitmap.c   (/freetype2/trunk)   (revision 931)
+++ src/base/ftbitmap.c   (/freetype2/branches/embolden)   (local)
@@ -211,17 +211,45 @@
     if ( !library )
       return FT_Err_Invalid_Library_Handle;
 
-    if ( !bitmap )
+    if ( !bitmap || !bitmap->buffer )
       return FT_Err_Invalid_Argument;
 
     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 )
+      return FT_Err_Invalid_Argument;
+
     switch ( bitmap->pixel_mode )
     {
     case FT_PIXEL_MODE_GRAY2:
     case FT_PIXEL_MODE_GRAY4:
-      return FT_Err_Invalid_Glyph_Format;
+      {
+        FT_Bitmap  tmp;
+        FT_Int     align;
+
+
+        if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY2 )
+          align = ( bitmap->width + xstr + 3 ) / 4;
+        else
+          align = ( bitmap->width + xstr + 1 ) / 2;
+
+        FT_Bitmap_New( &tmp );
+        error = FT_Bitmap_Convert( library, bitmap, &tmp, align );
+
+        if ( error )
+          return error;
+
+        FT_Bitmap_Done( library, bitmap );
+        *bitmap = tmp;
+      }
+      break;
+    case FT_PIXEL_MODE_MONO:
+      if ( xstr > 8 )
+        xstr = 8;
+      break;
     case FT_PIXEL_MODE_LCD:
       xstr *= 3;
       break;
@@ -230,11 +258,6 @@
       break;
     }
 
-    if ( xstr == 0 && ystr == 0 )
-      return FT_Err_Ok;
-    else if ( xstr < 0 || ystr < 0 || xstr > 8 )
-      return FT_Err_Invalid_Argument;
-
     error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr );
     if ( error )
       return error;

Property changes on: 
___________________________________________________________________
Name: svk:merge
 +5f392c16-9bf0-0310-b16c-a65848a4e34f:/freetype2/trunk:926

_______________________________________________
Freetype-devel mailing list
Freetype-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to