Commit 5d664b6d5188625d0585086020e99e6223c2afb1

Werner Lemberg 2016-12-17T20:47:42

Use FT_SET_ERROR where useful. Other minor code formatting.

diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index e97fdbf..e93d7e8 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -942,13 +942,14 @@
     /* if it works, fine.                                           */
 
     error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
-    if ( error == 0 )
-      return error;
+    if ( error )
+    {
+      /* let it fall through to normal loader (.ttf, .otf, etc.); */
+      /* we signal this by returning no error and no FT_Face      */
+      *aface = NULL;
+    }
 
-    /* let it fall through to normal loader (.ttf, .otf, etc.); */
-    /* we signal this by returning no error and no FT_Face      */
-    *aface = NULL;
-    return 0;
+    return FT_Err_Ok;
   }
 
 
@@ -982,12 +983,13 @@
     /* try resourcefork based font: LWFN, FFIL */
     error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
                                        face_index, aface );
-    if ( error != 0 || *aface != NULL )
+    if ( error || *aface )
       return error;
 
     /* let it fall through to normal loader (.ttf, .otf, etc.) */
     args.flags    = FT_OPEN_PATHNAME;
     args.pathname = (char*)pathname;
+
     return FT_Open_Face( library, &args, face_index, aface );
   }
 
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 5d347e8..1033421 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1400,7 +1400,7 @@
 
     error = FT_Open_Face( library, &args, face_index, aface );
 
-    if ( error == FT_Err_Ok )
+    if ( !error )
       (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
     else
 #ifdef FT_MACINTOSH
@@ -1758,11 +1758,12 @@
                                   aface );
 
   Exit2:
-    if ( error == FT_ERR( Array_Too_Large ) )
+    if ( FT_ERR_EQ( error, Array_Too_Large ) )
       FT_TRACE2(( "  Abort due to too-short buffer to store"
                   " all POST fragments\n" ));
-    else if ( error == FT_ERR( Invalid_Offset ) )
+    else if ( FT_ERR_EQ( error, Invalid_Offset ) )
       FT_TRACE2(( "  Abort due to invalid offset in a POST fragment\n" ));
+
     if ( error )
       error = FT_ERR( Cannot_Open_Resource );
     FT_FREE( pfb_data );
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index 6a59e83..02e7f84 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -423,7 +423,7 @@ THE SOFTWARE.
       else
         bdfface->family_name = NULL;
 
-      if ( ( error = bdf_interpret_style( face ) ) != 0 )
+      if ( FT_SET_ERROR( bdf_interpret_style( face ) ) )
         goto Exit;
 
       /* the number of glyphs (with one slot for the undefined glyph */
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index e919136..f54df22 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -2301,7 +2301,7 @@
         p->font->comments[p->font->comments_len] = 0;
       }
     }
-    else if ( error == FT_Err_Ok )
+    else if ( !error )
       error = FT_THROW( Invalid_File_Format );
 
     *font = p->font;
diff --git a/src/cff/cf2error.c b/src/cff/cf2error.c
index b5595a3..e3dd69f 100644
--- a/src/cff/cf2error.c
+++ b/src/cff/cf2error.c
@@ -44,7 +44,7 @@
   cf2_setError( FT_Error*  error,
                 FT_Error   value )
   {
-    if ( error && *error == 0 )
+    if ( error && !*error )
       *error = value;
   }
 
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index 60a6e92..c34d8d0 100644
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1260,8 +1260,8 @@ THE SOFTWARE.
       if ( face->accel.constantWidth )
         root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
-      if ( ( error = pcf_interpret_style( face ) ) != 0 )
-         goto Exit;
+      if ( FT_SET_ERROR( pcf_interpret_style( face ) ) )
+        goto Exit;
 
       prop = pcf_find_property( face, "FAMILY_NAME" );
       if ( prop && prop->isString )
diff --git a/src/pfr/pfrobjs.c b/src/pfr/pfrobjs.c
index 06996d6..10a3d2b 100644
--- a/src/pfr/pfrobjs.c
+++ b/src/pfr/pfrobjs.c
@@ -347,7 +347,7 @@
                 size,
                 gindex,
                 ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) != 0 );
-      if ( error == 0 )
+      if ( !error )
         goto Exit;
     }
 
diff --git a/src/psaux/t1decode.c b/src/psaux/t1decode.c
index 119b80f..f755678 100644
--- a/src/psaux/t1decode.c
+++ b/src/psaux/t1decode.c
@@ -752,10 +752,8 @@
           if ( arg_cnt != 0 )
             goto Unexpected_OtherSubr;
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok                                      ||
-               ( error = t1_builder_check_points( builder, 6 ) )
-                 != FT_Err_Ok                                      )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
+               FT_SET_ERROR( t1_builder_check_points( builder, 6 ) )   )
             goto Fail;
 
           decoder->flex_state        = 1;
@@ -1200,8 +1198,7 @@
         case op_hlineto:
           FT_TRACE4(( " hlineto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
             goto Fail;
 
           x += top[0];
@@ -1222,10 +1219,8 @@
         case op_hvcurveto:
           FT_TRACE4(( " hvcurveto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok                                      ||
-               ( error = t1_builder_check_points( builder, 3 ) )
-                 != FT_Err_Ok                                      )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
+               FT_SET_ERROR( t1_builder_check_points( builder, 3 ) )   )
             goto Fail;
 
           x += top[0];
@@ -1240,16 +1235,14 @@
         case op_rlineto:
           FT_TRACE4(( " rlineto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
             goto Fail;
 
           x += top[0];
           y += top[1];
 
         Add_Line:
-          if ( ( error = t1_builder_add_point1( builder, x, y ) )
-                 != FT_Err_Ok )
+          if ( FT_SET_ERROR( t1_builder_add_point1( builder, x, y ) ) )
             goto Fail;
           break;
 
@@ -1269,10 +1262,8 @@
         case op_rrcurveto:
           FT_TRACE4(( " rrcurveto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok                                      ||
-               ( error = t1_builder_check_points( builder, 3 ) )
-                 != FT_Err_Ok                                      )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
+               FT_SET_ERROR( t1_builder_check_points( builder, 3 ) )   )
             goto Fail;
 
           x += top[0];
@@ -1291,10 +1282,8 @@
         case op_vhcurveto:
           FT_TRACE4(( " vhcurveto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok                                      ||
-               ( error = t1_builder_check_points( builder, 3 ) )
-                 != FT_Err_Ok                                      )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
+               FT_SET_ERROR( t1_builder_check_points( builder, 3 ) )   )
             goto Fail;
 
           y += top[0];
@@ -1309,8 +1298,7 @@
         case op_vlineto:
           FT_TRACE4(( " vlineto" ));
 
-          if ( ( error = t1_builder_start_point( builder, x, y ) )
-                 != FT_Err_Ok )
+          if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
             goto Fail;
 
           y += top[0];
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index 24b06e0..2dda36d 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -3756,7 +3756,7 @@
               error = clazz->validate( cmap, FT_VALIDATOR( &valid ) );
             }
 
-            if ( valid.validator.error == 0 )
+            if ( !valid.validator.error )
             {
               FT_CMap  ttcmap;
 
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index d3e763b..fd7e2b6 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1796,11 +1796,11 @@
 
         /* this call provides additional offsets */
         /* for each component's translation      */
-        if ( ( error = TT_Vary_Apply_Glyph_Deltas(
-                         face,
-                         glyph_index,
-                         &outline,
-                         (FT_UInt)outline.n_points ) ) != 0 )
+        if ( FT_SET_ERROR( TT_Vary_Apply_Glyph_Deltas(
+                             face,
+                             glyph_index,
+                             &outline,
+                             (FT_UInt)outline.n_points ) ) )
           goto Exit1;
 
         subglyph = gloader->current.subglyphs;
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 8746b25..06080d7 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -954,10 +954,10 @@
 
     FT_TRACE2(( "GVAR " ));
 
-    if ( ( error = face->goto_table( face,
-                                     TTAG_gvar,
-                                     stream,
-                                     &table_len ) ) != 0 )
+    if ( FT_SET_ERROR( face->goto_table( face,
+                                         TTAG_gvar,
+                                         stream,
+                                         &table_len ) ) )
     {
       FT_TRACE2(( "is missing\n" ));
       goto Exit;
@@ -1322,12 +1322,12 @@
       FT_TRACE2(( "FVAR " ));
 
       /* both `fvar' and `gvar' must be present */
-      if ( ( error = face->goto_table( face, TTAG_gvar,
-                                       stream, &table_len ) ) != 0 )
+      if ( FT_SET_ERROR( face->goto_table( face, TTAG_gvar,
+                                           stream, &table_len ) ) )
       {
         /* CFF2 is an alternate to gvar here */
-        if ( ( error = face->goto_table( face, TTAG_CFF2,
-                                         stream, &table_len ) ) != 0 )
+        if ( FT_SET_ERROR( face->goto_table( face, TTAG_CFF2,
+                                             stream, &table_len ) ) )
         {
           FT_TRACE1(( "\n"
                       "TT_Get_MM_Var: `gvar' or `CFF2' table is missing\n" ));
@@ -1335,8 +1335,8 @@
         }
       }
 
-      if ( ( error = face->goto_table( face, TTAG_fvar,
-                                       stream, &table_len ) ) != 0 )
+      if ( FT_SET_ERROR( face->goto_table( face, TTAG_fvar,
+                                           stream, &table_len ) ) )
       {
         FT_TRACE1(( "is missing\n" ));
         goto Exit;
@@ -1589,7 +1589,7 @@
 
     if ( face->blend == NULL )
     {
-      if ( ( error = TT_Get_MM_Var( face, NULL ) ) != 0 )
+      if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) )
         goto Exit;
     }
 
@@ -1624,7 +1624,7 @@
     FT_TRACE5(( "\n" ));
 
     if ( !face->isCFF2 && blend->glyphoffsets == NULL )
-      if ( ( error = ft_var_load_gvar( face ) ) != 0 )
+      if ( FT_SET_ERROR( ft_var_load_gvar( face ) ) )
         goto Exit;
 
     if ( blend->normalizedcoords == NULL )
@@ -1740,7 +1740,7 @@
 
     if ( face->blend == NULL )
     {
-      if ( ( error = TT_Get_MM_Var( face, NULL ) ) != 0 )
+      if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) )
         return error;
     }
 
@@ -1805,7 +1805,7 @@
 
     if ( face->blend == NULL )
     {
-      if ( ( error = TT_Get_MM_Var( face, NULL ) ) != 0 )
+      if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) )
         goto Exit;
     }