On Thu, May 26, 2005 at 05:25:33PM +0800, Chia I Wu wrote:
> On Thu, May 26, 2005 at 07:32:49AM +0200, Werner LEMBERG wrote:
> > Anyway, there is a bug, either in your emboldening code or in ftview.
> > Load the attached font with
> > 
> >   ftview 15 Chicago.12.bdf
> > 
> > then press the space key, arrow up, arrow down, arrow up, arrow down,
> > etc., and you can see that the glyphs get fatter and fatter.
> Thanks for testing. The attached patch should fix the problem.
> (Changelog entry included. You may need to change the date.)
> 
> This happens when slot is not bitmap-owner (like this case of bdf font).
> I also make the metrics always being modified in this patch, as those
> who want more control should use FT_{Bitmap,Outline}_Embolden instead.
There is one stupid bug in the last patch. Please apply this one.

Sorry for the inconvenience.

-- 
Regards,
olv
=== ChangeLog
==================================================================
--- ChangeLog   (/freetype2/trunk)   (revision 904)
+++ ChangeLog   (/freetype2/branches/embolden)   (local)
@@ -1,3 +1,12 @@
+2005-05-26  Chia I Wu  <[EMAIL PROTECTED]>
+
+       * include/freetype/ftbitmap.h (FT_Bitmap_Embolden): Improve
+       documentation.
+
+       * src/base/ftsynth.c: Remove macro FT_BOLD_THRESHOLD.
+       (FT_GlyphSlot_Embolden): Check whether slot is bitmap-owner.
+       Always modify the metrics.
+
 2005-05-24  Werner Lemberg  <[EMAIL PROTECTED]>
 
        * docs/CHANGES: Updated.
=== include/freetype/ftbitmap.h
==================================================================
--- include/freetype/ftbitmap.h   (/freetype2/trunk)   (revision 904)
+++ include/freetype/ftbitmap.h   (/freetype2/branches/embolden)   (local)
@@ -118,6 +118,10 @@
   /*    The current implementation restricts `xStrength' to be less than   */
   /*    or equal to 8.                                                     */
   /*                                                                       */
+  /*    Don't embolden the bitmap owned by a @FT_GlyphSlot.  Call          */
+  /*    @FT_Bitmap_Copy to get a copy and work on the copy.                */
+  /*                                                                       */
+  /*                                                                       */
   FT_EXPORT_DEF( FT_Error )
   FT_Bitmap_Embolden( FT_Library  library,
                       FT_Bitmap*  bitmap,
=== src/base/ftsynth.c
==================================================================
--- src/base/ftsynth.c   (/freetype2/trunk)   (revision 904)
+++ src/base/ftsynth.c   (/freetype2/branches/embolden)   (local)
@@ -23,7 +23,6 @@
 #include FT_BITMAP_H
 
 
-#define FT_BOLD_THRESHOLD  0x0100
 
 
   /*************************************************************************/
@@ -78,8 +77,8 @@
   {
     FT_Library  library = slot->library;
     FT_Face     face    = FT_SLOT_FACE( slot );
+    FT_Error    error   = FT_Err_Ok;
     FT_Pos      xstr, ystr;
-    FT_Error    error;
 
 
     /* some reasonable strength */
@@ -90,7 +89,7 @@
     if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
     {
       error = FT_Outline_Embolden( &slot->outline, xstr );
-      xstr = ( xstr * 4 ) & ~63;
+      xstr = xstr * 4 ; /* according to the document */
       ystr = xstr;
     }
     else if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
@@ -100,25 +99,41 @@
         xstr = 1 << 6;
       ystr = FT_PIX_FLOOR( ystr );
 
-      error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
+      /* slot must be bitmap-owner */
+      if ( !(slot->internal->flags & FT_GLYPH_OWN_BITMAP) )
+      {
+        FT_Bitmap  bitmap;
 
-      /* XXX should we set these? */
+
+        FT_Bitmap_New( &bitmap );
+        error = FT_Bitmap_Copy( library, &slot->bitmap, &bitmap );
+
+        if ( !error )
+        {
+          slot->bitmap = bitmap;
+          slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
+        }
+      }
+
       if ( !error )
-        slot->bitmap_top += ystr >> 6;
+        error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
     }
     else
       error = FT_Err_Invalid_Argument;
 
-    /* XXX should we set these? */
+    /* modify the metrics accordingly */
     if ( !error )
     {
-#if 0
-      slot->advance.x            += xstr;
       slot->metrics.width        += xstr;
       slot->metrics.height       += ystr;
       slot->metrics.horiBearingY += ystr;
-#endif
       slot->metrics.horiAdvance  += xstr;
+      slot->metrics.vertBearingX -= xstr / 2;
+      slot->metrics.vertBearingY += ystr;
+      slot->metrics.vertAdvance  += ystr;
+
+      if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
+        slot->bitmap_top += ystr >> 6;
     }
   }
 

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

_______________________________________________
Freetype-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to