Commit c26f7f975b5f7f58f2b6da3d3308e3915f757a6f

Alexei Podtelezhnikov 2017-09-29T00:13:19

Bitmap metrics presetting [2/2]. * src/base/ftobjs.c (FT_Load_Glyph): Preset the bitmap metrics when appropriate but `FT_Render_Glyph' is not called. * include/freetype/freetype.h (FT_GlyphSlotRec): Document the change.

diff --git a/ChangeLog b/ChangeLog
index dba8499..2549d0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2017-09-29  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	Bitmap metrics presetting [2/2].
+
+	* src/base/ftobjs.c (FT_Load_Glyph): Preset the bitmap metrics when
+	appropriate but `FT_Render_Glyph' is not called.
+	* include/freetype/freetype.h (FT_GlyphSlotRec): Document the change.
+
 2017-09-28  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
 	[smooth, raster] Miscellaneous cleanups.
@@ -38,7 +46,7 @@
 	function.
 
 	* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): New function that
-	calculates prespective bitmap metrics for the given rendering mode.
+	calculates prospective bitmap metrics for the given rendering mode.
 	* include/freetype/internal/ftobjs.h (ft_glyphslot_preset_bitmap):
 	Declare it.
 
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index de4dc39..f6049c0 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -1696,17 +1696,13 @@ FT_BEGIN_HEADER
   /*                         @FT_GLYPH_FORMAT_COMPOSITE, but other values  */
   /*                         are possible.                                 */
   /*                                                                       */
-  /*    bitmap            :: This field is used as a bitmap descriptor     */
-  /*                         when the slot format is                       */
-  /*                         @FT_GLYPH_FORMAT_BITMAP.  Note that the       */
-  /*                         address and content of the bitmap buffer can  */
-  /*                         change between calls of @FT_Load_Glyph and a  */
-  /*                         few other functions.                          */
+  /*    bitmap            :: This field is used as a bitmap descriptor.    */
+  /*                         Note that the address and content of the      */
+  /*                         bitmap buffer can change between calls of     */
+  /*                         @FT_Load_Glyph and a few other functions.     */
   /*                                                                       */
   /*    bitmap_left       :: The bitmap's left bearing expressed in        */
-  /*                         integer pixels.  Only valid if the format is  */
-  /*                         @FT_GLYPH_FORMAT_BITMAP, this is, if the      */
-  /*                         glyph slot contains a bitmap.                 */
+  /*                         integer pixels.                               */
   /*                                                                       */
   /*    bitmap_top        :: The bitmap's top bearing expressed in integer */
   /*                         pixels.  This is the distance from the        */
@@ -1753,7 +1749,9 @@ FT_BEGIN_HEADER
   /*    If @FT_Load_Glyph is called with default flags (see                */
   /*    @FT_LOAD_DEFAULT) the glyph image is loaded in the glyph slot in   */
   /*    its native format (e.g., an outline glyph for TrueType and Type~1  */
-  /*    formats).                                                          */
+  /*    formats).  [Since 2.8.2] The prospective bitmap metrics are        */
+  /*    calculated according to @FT_LOAD_TARGET_XXX and other flags even   */
+  /*    for the outline glyph, even if @FT_LOAD_RENDER is not set.         */
   /*                                                                       */
   /*    This image can later be converted into a bitmap by calling         */
   /*    @FT_Render_Glyph.  This function searches the current renderer for */
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 42ec58e..030c033 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -983,20 +983,22 @@
     FT_TRACE5(( "  linear x advance: %d\n" , slot->linearHoriAdvance ));
     FT_TRACE5(( "  linear y advance: %d\n" , slot->linearVertAdvance ));
 
-    /* do we need to render the image now? */
+    /* do we need to render the image or preset the bitmap now? */
     if ( !error                                    &&
          slot->format != FT_GLYPH_FORMAT_BITMAP    &&
-         slot->format != FT_GLYPH_FORMAT_COMPOSITE &&
-         load_flags & FT_LOAD_RENDER )
+         slot->format != FT_GLYPH_FORMAT_COMPOSITE )
     {
       FT_Render_Mode  mode = FT_LOAD_TARGET_MODE( load_flags );
 
 
-      if ( mode == FT_RENDER_MODE_NORMAL      &&
-           (load_flags & FT_LOAD_MONOCHROME ) )
+      if ( mode == FT_RENDER_MODE_NORMAL   &&
+           load_flags & FT_LOAD_MONOCHROME )
         mode = FT_RENDER_MODE_MONO;
 
-      error = FT_Render_Glyph( slot, mode );
+      if ( load_flags & FT_LOAD_RENDER )
+        error = FT_Render_Glyph( slot, mode );
+      else if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 )
+        ft_glyphslot_preset_bitmap( slot, mode, NULL );
     }
 
   Exit: