tizen 2.3.1 release
[framework/graphics/freetype.git] / src / truetype / ttgxvar.c
index 69b702f..1b35539 100644 (file)
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueType GX Font Variation loader                                    */
 /*                                                                         */
-/*  Copyright 2004-2011 by                                                 */
+/*  Copyright 2004-2014 by                                                 */
 /*  David Turner, Robert Wilhelm, Werner Lemberg, and George Williams.     */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -61,9 +61,9 @@
 
 
 #define FT_Stream_FTell( stream )  \
-          ( (stream)->cursor - (stream)->base )
+          (FT_ULong)( (stream)->cursor - (stream)->base )
 #define FT_Stream_SeekSet( stream, off ) \
-              ( (stream)->cursor = (stream)->base+(off) )
+          ( (stream)->cursor = (stream)->base + (off) )
 
 
   /*************************************************************************/
@@ -91,7 +91,9 @@
   /* indicates that there is a delta for every point without needing to    */
   /* enumerate all of them.                                                */
   /*                                                                       */
-#define ALL_POINTS  (FT_UShort*)( -1 )
+
+  /* ensure that value `0' has the same width as a pointer */
+#define ALL_POINTS  (FT_UShort*)~(FT_PtrDist)0
 
 
 #define GX_PT_POINTS_ARE_WORDS      0x80
     FT_Int     j;
     FT_Int     first;
     FT_Memory  memory = stream->memory;
-    FT_Error   error  = TT_Err_Ok;
+    FT_Error   error  = FT_Err_Ok;
 
     FT_UNUSED( error );
 
     FT_Offset  i;
     FT_UInt    j;
     FT_Memory  memory = stream->memory;
-    FT_Error   error  = TT_Err_Ok;
+    FT_Error   error  = FT_Err_Ok;
 
     FT_UNUSED( error );
 
     FT_Memory       memory = stream->memory;
     GX_Blend        blend  = face->blend;
     GX_AVarSegment  segment;
-    FT_Error        error = TT_Err_Ok;
+    FT_Error        error = FT_Err_Ok;
     FT_ULong        version;
     FT_Long         axisCount;
     FT_Int          i, j;
     if ( gvar_head.version   != (FT_Long)0x00010000L              ||
          gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis )
     {
-      error = TT_Err_Invalid_Table;
+      error = FT_THROW( Invalid_Table );
       goto Exit;
     }
 
                       FT_Fixed*  im_end_coords )
   {
     FT_UInt   i;
-    FT_Fixed  apply;
-    FT_Fixed  temp;
+    FT_Fixed  apply = 0x10000L;
 
 
-    apply = 0x10000L;
     for ( i = 0; i < blend->num_axis; ++i )
     {
       if ( tuple_coords[i] == 0 )
 
       else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) )
         /* not an intermediate tuple */
-        apply = FT_MulDiv( apply,
+        apply = FT_MulFix( apply,
                            blend->normalizedcoords[i] > 0
                              ? blend->normalizedcoords[i]
-                             : -blend->normalizedcoords[i],
-                           0x10000L );
+                             : -blend->normalizedcoords[i] );
 
       else if ( blend->normalizedcoords[i] <= im_start_coords[i] ||
                 blend->normalizedcoords[i] >= im_end_coords[i]   )
       }
 
       else if ( blend->normalizedcoords[i] < tuple_coords[i] )
-      {
-        temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i],
-                          0x10000L,
-                          tuple_coords[i] - im_start_coords[i]);
-        apply = FT_MulDiv( apply, temp, 0x10000L );
-      }
+        apply = FT_MulDiv( apply,
+                           blend->normalizedcoords[i] - im_start_coords[i],
+                           tuple_coords[i] - im_start_coords[i] );
 
       else
-      {
-        temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i],
-                          0x10000L,
-                          im_end_coords[i] - tuple_coords[i] );
-        apply = FT_MulDiv( apply, temp, 0x10000L );
-      }
+        apply = FT_MulDiv( apply,
+                           im_end_coords[i] - blend->normalizedcoords[i],
+                           im_end_coords[i] - tuple_coords[i] );
     }
 
     return apply;
     FT_Stream            stream = face->root.stream;
     FT_Memory            memory = face->root.memory;
     FT_ULong             table_len;
-    FT_Error             error  = TT_Err_Ok;
+    FT_Error             error  = FT_Err_Ok;
     FT_ULong             fvar_start;
     FT_Int               i, j;
     FT_MM_Var*           mmvar = NULL;
            fvar_head.offsetToData + fvar_head.axisCount * 20U +
              fvar_head.instanceCount * fvar_head.instanceSize > table_len )
       {
-        error = TT_Err_Invalid_Table;
+        error = FT_THROW( Invalid_Table );
         goto Exit;
       }
 
       mmvar->num_axis =
         fvar_head.axisCount;
       mmvar->num_designs =
-        (FT_UInt)-1;           /* meaningless in this context; each glyph */
+        ~0U;                   /* meaningless in this context; each glyph */
                                /* may have a different number of designs  */
                                /* (or tuples, as called by Apple)         */
       mmvar->num_namedstyles =
                    FT_UInt    num_coords,
                    FT_Fixed*  coords )
   {
-    FT_Error    error = TT_Err_Ok;
+    FT_Error    error = FT_Err_Ok;
     GX_Blend    blend;
     FT_MM_Var*  mmvar;
     FT_UInt     i;
 
     if ( num_coords != mmvar->num_axis )
     {
-      error = TT_Err_Invalid_Argument;
+      error = FT_THROW( Invalid_Argument );
       goto Exit;
     }
 
     for ( i = 0; i < num_coords; ++i )
       if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L )
       {
-        error = TT_Err_Invalid_Argument;
+        error = FT_THROW( Invalid_Argument );
         goto Exit;
       }
 
         FT_FREE( face->cvt );
         face->cvt = NULL;
 
-        tt_face_load_cvt( face, face->root.stream );
+        error = tt_face_load_cvt( face, face->root.stream );
         break;
 
       case mcvt_modify:
         /* The original cvt table is in memory.  All we need to do is */
         /* apply the `cvar' table (if any).                           */
-        tt_face_vary_cvt( face, face->root.stream );
+        error = tt_face_vary_cvt( face, face->root.stream );
         break;
 
       case mcvt_retain:
                      FT_UInt    num_coords,
                      FT_Fixed*  coords )
   {
-    FT_Error        error      = TT_Err_Ok;
+    FT_Error        error      = FT_Err_Ok;
     FT_Fixed*       normalized = NULL;
     GX_Blend        blend;
     FT_MM_Var*      mmvar;
 
     if ( num_coords != mmvar->num_axis )
     {
-      error = TT_Err_Invalid_Argument;
+      error = FT_THROW( Invalid_Argument );
       goto Exit;
     }
 
     {
       if ( coords[i] > a->maximum || coords[i] < a->minimum )
       {
-        error = TT_Err_Invalid_Argument;
+        error = FT_THROW( Invalid_Argument );
         goto Exit;
       }
 
       if ( coords[i] < a->def )
-      {
-        normalized[i] = -FT_MulDiv( coords[i] - a->def,
-                                    0x10000L,
-                                    a->minimum - a->def );
-      }
+        normalized[i] = -FT_DivFix( coords[i] - a->def, a->minimum - a->def );
       else if ( a->maximum == a->def )
         normalized[i] = 0;
       else
-      {
-        normalized[i] = FT_MulDiv( coords[i] - a->def,
-                                   0x10000L,
-                                   a->maximum - a->def );
-      }
+        normalized[i] = FT_DivFix( coords[i] - a->def, a->maximum - a->def );
     }
 
     if ( !blend->avar_checked )
           if ( normalized[i] < av->correspondence[j].fromCoord )
           {
             normalized[i] =
-              FT_MulDiv(
-                FT_MulDiv(
-                  normalized[i] - av->correspondence[j - 1].fromCoord,
-                  0x10000L,
-                  av->correspondence[j].fromCoord -
-                    av->correspondence[j - 1].fromCoord ),
-                av->correspondence[j].toCoord -
-                  av->correspondence[j - 1].toCoord,
-                0x10000L ) +
+              FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord,
+                         av->correspondence[j].toCoord -
+                           av->correspondence[j - 1].toCoord,
+                         av->correspondence[j].fromCoord -
+                           av->correspondence[j - 1].fromCoord ) +
               av->correspondence[j - 1].toCoord;
             break;
           }
     {
       FT_TRACE2(( "tt_face_vary_cvt: no blend specified\n" ));
 
-      error = TT_Err_Ok;
+      error = FT_Err_Ok;
       goto Exit;
     }
 
     {
       FT_TRACE2(( "tt_face_vary_cvt: no `cvt ' table\n" ));
 
-      error = TT_Err_Ok;
+      error = FT_Err_Ok;
       goto Exit;
     }
 
     {
       FT_TRACE2(( "is missing\n" ));
 
-      error = TT_Err_Ok;
+      error = FT_Err_Ok;
       goto Exit;
     }
 
     if ( FT_FRAME_ENTER( table_len ) )
     {
-      error = TT_Err_Ok;
+      error = FT_Err_Ok;
       goto Exit;
     }
 
     {
       FT_TRACE2(( "bad table version\n" ));
 
-      error = TT_Err_Ok;
+      error = FT_Err_Ok;
       goto FExit;
     }
 
 
 
     if ( !face->doblend || blend == NULL )
-      return TT_Err_Invalid_Argument;
+      return FT_THROW( Invalid_Argument );
 
     /* to be freed by the caller */
     if ( FT_NEW_ARRAY( delta_xy, n_points ) )
     if ( glyph_index >= blend->gv_glyphcnt      ||
          blend->glyphoffsets[glyph_index] ==
            blend->glyphoffsets[glyph_index + 1] )
-      return TT_Err_Ok;               /* no variation data for this glyph */
+      return FT_Err_Ok;               /* no variation data for this glyph */
 
     if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] )   ||
          FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] -
       }
       else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount )
       {
-        error = TT_Err_Invalid_Table;
+        error = FT_THROW( Invalid_Table );
         goto Fail3;
       }
       else