Commit ae7dc1f62d826083d418e86cce3f66a76dff038a

Alexei Podtelezhnikov 2017-09-28T22:59:31

[smooth, raster] Miscellaneous cleanups. * src/raster/ftrend1.c (ft_raster1_render): Clean up the exit. * src/smooth/ftsmooth.c (ft_smooth_render_generic): Reduce translations and clean up the exit. (ft_smooth_render_lcd, ft_smooth_render_lcd): Remove unused `error'..

diff --git a/ChangeLog b/ChangeLog
index 19f54a9..dba8499 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-09-28  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	[smooth, raster] Miscellaneous cleanups.
+
+	* src/raster/ftrend1.c (ft_raster1_render): Clean up the exit.
+	* src/smooth/ftsmooth.c (ft_smooth_render_generic): Reduce
+	translations and clean up the exit.
+	(ft_smooth_render_lcd, ft_smooth_render_lcd): Remove unused `error'.
+
 2017-09-28  Ben Wagner  <bungeman@google.com>
 
 	[truetype] Really, really fix #52082.
diff --git a/src/raster/ftrend1.c b/src/raster/ftrend1.c
index a5b8153..bbce7bb 100644
--- a/src/raster/ftrend1.c
+++ b/src/raster/ftrend1.c
@@ -97,7 +97,7 @@
                      FT_Render_Mode    mode,
                      const FT_Vector*  origin )
   {
-    FT_Error     error;
+    FT_Error     error   = FT_Err_Ok;
     FT_Outline*  outline = &slot->outline;
     FT_Bitmap*   bitmap  = &slot->bitmap;
     FT_Memory    memory  = render->root.memory;
@@ -152,28 +152,24 @@
     /* set up parameters */
     params.target = bitmap;
     params.source = outline;
-    params.flags  = 0;
+    params.flags  = FT_RASTER_FLAG_DEFAULT;
 
     /* render outline into the bitmap */
     error = render->raster_render( render->raster, &params );
-    if ( error )
-      goto Exit;
-
-    /* everything is fine; the glyph is now officially a bitmap */
-    slot->format = FT_GLYPH_FORMAT_BITMAP;
-
-    error = FT_Err_Ok;
 
   Exit:
-    if ( x_shift || y_shift )
-      FT_Outline_Translate( outline, -x_shift, -y_shift );
-    if ( slot->format != FT_GLYPH_FORMAT_BITMAP      &&
-         slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+    if ( !error )
+      /* everything is fine; the glyph is now officially a bitmap */
+      slot->format = FT_GLYPH_FORMAT_BITMAP;
+    else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
     {
       FT_FREE( bitmap->buffer );
       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
     }
 
+    if ( x_shift || y_shift )
+      FT_Outline_Translate( outline, -x_shift, -y_shift );
+
     return error;
   }
 
diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c
index 50ce44b..7946f28 100644
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -97,7 +97,7 @@
                             const FT_Vector*  origin,
                             FT_Render_Mode    required_mode )
   {
-    FT_Error     error;
+    FT_Error     error   = FT_Err_Ok;
     FT_Outline*  outline = &slot->outline;
     FT_Bitmap*   bitmap  = &slot->bitmap;
     FT_Memory    memory  = render->root.memory;
@@ -240,29 +240,28 @@
       /* by 1/3 pixel.                                               */
       width /= 3;
 
-      FT_Outline_Translate( outline,  21, 0 );
+      bitmap->buffer += width;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
       FT_Outline_Translate( outline, -21, 0 );
+      x_shift -= 21;
       bitmap->buffer += width;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
-      FT_Outline_Translate( outline, -21, 0 );
-      bitmap->buffer += width;
+      FT_Outline_Translate( outline,  42, 0 );
+      x_shift += 42;
+      bitmap->buffer -= 2 * width;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
-      FT_Outline_Translate( outline,  21, 0 );
-      bitmap->buffer -= 2 * width;
-
       /* XXX: Rearrange the bytes according to FT_PIXEL_MODE_LCD.    */
       /* XXX: It is more efficient to render every third byte above. */
 
@@ -293,56 +292,49 @@
       bitmap->pitch *= 3;
       bitmap->rows  /= 3;
 
-      FT_Outline_Translate( outline, 0,  21 );
-      bitmap->buffer += 2 * pitch;
+      bitmap->buffer += pitch;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
-      FT_Outline_Translate( outline, 0, -21 );
-      bitmap->buffer -= pitch;
+      FT_Outline_Translate( outline, 0,  21 );
+      y_shift += 21;
+      bitmap->buffer += pitch;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
-      FT_Outline_Translate( outline, 0, -21 );
-      bitmap->buffer -= pitch;
+      FT_Outline_Translate( outline, 0, -42 );
+      y_shift -= 42;
+      bitmap->buffer -= 2 * pitch;
 
       error = render->raster_render( render->raster, &params );
       if ( error )
         goto Exit;
 
-      FT_Outline_Translate( outline, 0,  21 );
-
       bitmap->pitch /= 3;
       bitmap->rows  *= 3;
     }
     else  /* grayscale */
-    {
       error = render->raster_render( render->raster, &params );
-      if ( error )
-        goto Exit;
-    }
 
 #endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
 
-    /* everything is fine; the glyph is now officially a bitmap */
-    slot->format = FT_GLYPH_FORMAT_BITMAP;
-
-    error = FT_Err_Ok;
-
   Exit:
-    if ( x_shift || y_shift )
-      FT_Outline_Translate( outline, -x_shift, -y_shift );
-    if ( slot->format != FT_GLYPH_FORMAT_BITMAP      &&
-         slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+    if ( !error )
+      /* everything is fine; the glyph is now officially a bitmap */
+      slot->format = FT_GLYPH_FORMAT_BITMAP;
+    else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
     {
       FT_FREE( bitmap->buffer );
       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
     }
 
+    if ( x_shift || y_shift )
+      FT_Outline_Translate( outline, -x_shift, -y_shift );
+
     return error;
   }
 
@@ -369,8 +361,6 @@
                         FT_Render_Mode    mode,
                         const FT_Vector*  origin )
   {
-    FT_Error  error;
-
     return ft_smooth_render_generic( render, slot, mode, origin,
                                      FT_RENDER_MODE_LCD );
   }
@@ -383,8 +373,6 @@
                           FT_Render_Mode    mode,
                           const FT_Vector*  origin )
   {
-    FT_Error  error;
-
     return ft_smooth_render_generic( render, slot, mode, origin,
                                      FT_RENDER_MODE_LCD_V );
   }