shithub: freetype+ttf2subf

Download patch

ref: c8ad30a7a020966e2b4ea22465b00817330b607e
parent: 14183ea0f8b9c021400d748d7311ec2a907e9f8d
author: David Turner <[email protected]>
date: Wed Dec 5 12:24:34 EST 2001

* src/base/ftglyph.c (FT_Glyph_To_Bitmap): re-ordered code for debugging
    purposes..


    * src/smooth/ftsmooth.c (ft_smooth_render): fixed a nasty hidden bug where
    outline shifting wasn't correctly undone after bitmap rasterization. this
    created problems with certain glyphs (like '"' of certain fonts..) and
    the cache system..

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2001-12-05  David Turner  <[email protected]>
 
+    * src/base/ftglyph.c (FT_Glyph_To_Bitmap): re-ordered code for debugging
+    purposes..
+
+
+    * src/smooth/ftsmooth.c (ft_smooth_render): fixed a nasty hidden bug where
+    outline shifting wasn't correctly undone after bitmap rasterization. this
+    created problems with certain glyphs (like '"' of certain fonts..) and
+    the cache system..
+
+
+2001-12-05  David Turner  <[email protected]>
+
     First of all, a big thanks to Werner and Antoine for their latest work !!
     
     * src/pshinter/pshalgo2.c (psh2_hint_table_init),
--- a/docs/BUGS
+++ b/docs/BUGS
@@ -46,6 +46,7 @@
 BAD-TTNAMEID.H          12-09-2001     Antoine                   N/A
 BAD-T1-CHARMAP          15-06-2001     David                     2.0.5
 BAD-UNIXXX-NAMES        30-07-2001     David                     2.0.5
+GLYPH_TO_BITMAP-BUG     05-12-2001     David                     05-12-2001
 
 --------------------END-OF-CLOSED-BUGS-TABLE----------------------------------
 
@@ -181,6 +182,20 @@
     to implement since I don't have any font that implement these
     "features", and also because I believe that we're running out of bits
     for "load_flag", some other way to set preferences is probably needed.
+
+
+GLYPH_TO_BITMAP-BUG
+
+  Calling FT_Glyph_To_Bitmap sometimes modifies the original glyph outline,
+  creating weird alignment artefacts.
+  
+  this subtle bug was really in the file src/smooth/ftsmooth.c. Basically,
+  the outline was shifted before rendering it into a new bitmap buffer.
+  However, it wasn't properly un-shifted after that operation..
+
+  this was only noticeable with certain glyphs or certain fonts and crept
+  for a long time here..
+  
 
 
 === end of file ===
--- a/include/freetype/cache/ftcimage.h
+++ b/include/freetype/cache/ftcimage.h
@@ -56,18 +56,21 @@
 #define FTC_IMAGE_FORMAT( x )  ( (x) & 7 )
 
 
-#define ftc_image_format_bitmap      0
-#define ftc_image_format_outline     1
+#define ftc_image_format_bitmap      0x0000
+#define ftc_image_format_outline     0x0001
 
-#define ftc_image_flag_monochrome   16
-#define ftc_image_flag_unhinted     32
-#define ftc_image_flag_autohinted   64
-#define ftc_image_flag_unscaled    128
-#define ftc_image_flag_no_sbits    256
+#define ftc_image_format_mask        0x000F
 
+#define ftc_image_flag_monochrome    0x0010
+#define ftc_image_flag_unhinted      0x0020
+#define ftc_image_flag_autohinted    0x0040
+#define ftc_image_flag_unscaled      0x0080
+#define ftc_image_flag_no_sbits      0x0100
+
   /* monochrome bitmap */
 #define ftc_image_mono             ftc_image_format_bitmap | \
                                    ftc_image_flag_monochrome
+
   /* anti-aliased bitmap */
 #define ftc_image_grays            ftc_image_format_bitmap
 
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -574,7 +574,7 @@
     FT_GlyphSlotRec  dummy;
     FT_Error         error;
     FT_Glyph         glyph;
-    FT_BitmapGlyph   bitmap;
+    FT_BitmapGlyph   bitmap = NULL;
 
     const FT_Glyph_Class*  clazz;
 
@@ -598,27 +598,24 @@
     dummy.library = glyph->library;
     dummy.format  = clazz->glyph_format;
 
-    /* if `origin' is set, translate the glyph image */
-    if ( origin )
-      FT_Glyph_Transform( glyph, 0, origin );
-
     /* create result bitmap glyph */
     error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class,
                           (FT_Glyph*)&bitmap );
-    if ( error )
+    if (error)
       goto Exit;
 
+#if 0      
+    /* if `origin' is set, translate the glyph image */
+    if ( origin )
+      FT_Glyph_Transform( glyph, 0, origin );
+#endif
+
     /* prepare dummy slot for rendering */
     error = clazz->glyph_prepare( glyph, &dummy );
     if ( !error )
       error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
 
-    if ( error )
-    {
-      FT_Done_Glyph( FT_GLYPH( bitmap ) );
-      goto Exit;
-    }
-
+#if 0
     if ( !destroy && origin )
     {
       FT_Vector  v;
@@ -628,28 +625,28 @@
       v.y = -origin->y;
       FT_Glyph_Transform( glyph, 0, &v );
     }
+#endif
 
+    if (error)
+      goto Exit;
+
     /* in case of success, copy the bitmap to the glyph bitmap */
-    if ( !error )
-    {
-      error = ft_bitmap_glyph_init( bitmap, &dummy );
-      if ( error )
-      {
-        /* this should never happen, but let's be safe */
-        FT_Done_Glyph( FT_GLYPH( bitmap ) );
-        goto Exit;
-      }
+    error = ft_bitmap_glyph_init( bitmap, &dummy );
+    if ( error )
+      goto Exit;
 
-      /* copy advance */
-      bitmap->root.advance = glyph->advance;
+    /* copy advance */
+    bitmap->root.advance = glyph->advance;
 
-      if ( destroy )
-        FT_Done_Glyph( glyph );
+    if ( destroy )
+      FT_Done_Glyph( glyph );
 
-      *the_glyph = FT_GLYPH( bitmap );
-    }
+    *the_glyph = FT_GLYPH( bitmap );
 
   Exit:
+    if (error && bitmap)
+      FT_Done_Glyph( FT_GLYPH(bitmap) );
+      
     return error;
 
   Bad:
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -2243,7 +2243,7 @@
         error = FT_Err_Unimplemented_Feature;
         while ( renderer )
         {
-          error = renderer->render( renderer, slot, render_mode, 0 );
+          error = renderer->render( renderer, slot, render_mode, NULL );
           if ( !error ||
                FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph )
             break;
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -100,7 +100,7 @@
                     FT_Vector*    origin )
   {
     FT_Error     error;
-    FT_Outline*  outline;
+    FT_Outline*  outline = NULL;
     FT_BBox      cbox;
     FT_UInt      width, height, pitch;
     FT_Bitmap*   bitmap;
@@ -169,6 +169,9 @@
 
     /* render outline into the bitmap */
     error = render->raster_render( render->raster, &params );
+    
+    FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
+
     if ( error )
       goto Exit;
 
@@ -177,6 +180,9 @@
     slot->bitmap_top  = cbox.yMax >> 6;
 
   Exit:
+    if ( outline && origin )
+      FT_Outline_Translate( outline, -origin->x, -origin->y );
+
     return error;
   }