[FREETYPE] Update to v2.9.0 and use this as a chance to slim down our lib a bit....
[reactos.git] / sdk / lib / 3rdparty / freetype / src / cff / cffload.c
index 1242038..ba49793 100644 (file)
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType and CFF data/program tables loader (body).                  */
 /*                                                                         */
-/*  Copyright 1996-2017 by                                                 */
+/*  Copyright 1996-2018 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -22,6 +22,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_TRUETYPE_TAGS_H
 #include FT_TYPE1_TABLES_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
 
 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
 #include FT_MULTIPLE_MASTERS_H
 
     if ( numOperands > count )
     {
-      FT_TRACE4(( " cff_blend_doBlend: Stack underflow %d args\n", count ));
+      FT_TRACE4(( " cff_blend_doBlend: Stack underflow %d argument%s\n",
+                  count,
+                  count == 1 ? "" : "s" ));
 
       error = FT_THROW( Stack_Underflow );
       goto Exit;
     for ( i = 0; i < numBlends; i++ )
     {
       const FT_Int32*  weight = &blend->BV[1];
-      FT_Int32         sum;
+      FT_UInt32        sum;
 
 
       /* convert inputs to 16.16 fixed point */
-      sum = cff_parse_num( parser, &parser->stack[i + base] ) * 65536;
+      sum = cff_parse_num( parser, &parser->stack[i + base] ) * 0x10000;
 
       for ( j = 1; j < blend->lenBV; j++ )
-        sum = ADD_INT32(
-                sum,
-                FT_MulFix(
-                  *weight++,
-                  cff_parse_num( parser,
-                                 &parser->stack[delta++] ) * 65536 ) );
+        sum += cff_parse_num( parser, &parser->stack[delta++] ) * *weight++;
 
       /* point parser stack to new value on blend_stack */
       parser->stack[i + base] = subFont->blend_top;
       /* opcode in both CFF and CFF2 DICTs.  See `cff_parse_num' for    */
       /* decode of this, which rounds to an integer.                    */
       *subFont->blend_top++ = 255;
-      *subFont->blend_top++ = ( (FT_UInt32)sum & 0xFF000000U ) >> 24;
-      *subFont->blend_top++ = ( (FT_UInt32)sum & 0x00FF0000U ) >> 16;
-      *subFont->blend_top++ = ( (FT_UInt32)sum & 0x0000FF00U ) >>  8;
-      *subFont->blend_top++ =   (FT_UInt32)sum & 0x000000FFU;
+      *subFont->blend_top++ = (FT_Byte)( sum >> 24 );
+      *subFont->blend_top++ = (FT_Byte)( sum >> 16 );
+      *subFont->blend_top++ = (FT_Byte)( sum >>  8 );
+      *subFont->blend_top++ = (FT_Byte)sum;
     }
 
     /* leave only numBlends results on parser stack */
                           FT_UInt    lenNDV,
                           FT_Fixed*  NDV )
   {
-    if ( !blend->builtBV                             ||
-         blend->lastVsindex != vsindex               ||
-         blend->lenNDV != lenNDV                     ||
-         ( lenNDV                                  &&
-           memcmp( NDV,
-                   blend->lastNDV,
-                   lenNDV * sizeof ( *NDV ) ) != 0 ) )
+    if ( !blend->builtBV                                ||
+         blend->lastVsindex != vsindex                  ||
+         blend->lenNDV != lenNDV                        ||
+         ( lenNDV                                     &&
+           ft_memcmp( NDV,
+                      blend->lastNDV,
+                      lenNDV * sizeof ( *NDV ) ) != 0 ) )
     {
       /* need to build blend vector */
       return TRUE;
     FT_Service_MultiMasters  mm = (FT_Service_MultiMasters)face->mm;
 
 
-    mm->done_blend( FT_FACE( face ) );
+    if (mm)
+      mm->done_blend( FT_FACE( face ) );
   }
 
 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
   }
 
 
-  FT_LOCAL_DEF( FT_UInt32 )
-  cff_random( FT_UInt32  r )
-  {
-    /* a 32bit version of the `xorshift' algorithm */
-    r ^= r << 13;
-    r ^= r >> 17;
-    r ^= r << 5;
-
-    return r;
-  }
-
-
   /* There are 3 ways to call this function, distinguished by code.  */
   /*                                                                 */
   /* . CFF_CODE_TOPDICT for either a CFF Top DICT or a CFF Font DICT */
     CFF_FontRecDict  top  = &subfont->font_dict;
     CFF_Private      priv = &subfont->private_dict;
 
+    PSAux_Service  psaux = (PSAux_Service)face->psaux;
+
     FT_Bool  cff2      = FT_BOOL( code == CFF2_CODE_TOPDICT  ||
                                   code == CFF2_CODE_FONTDICT );
     FT_UInt  stackSize = cff2 ? CFF2_DEFAULT_STACK
        */
       if ( face->root.internal->random_seed == -1 )
       {
-        CFF_Driver  driver = (CFF_Driver)FT_FACE_DRIVER( face );
+        PS_Driver  driver = (PS_Driver)FT_FACE_DRIVER( face );
 
 
         subfont->random = (FT_UInt32)driver->random_seed;
           do
           {
             driver->random_seed =
-              (FT_Int32)cff_random( (FT_UInt32)driver->random_seed );
+              (FT_Int32)psaux->cff_random( (FT_UInt32)driver->random_seed );
 
           } while ( driver->random_seed < 0 );
         }
           do
           {
             face->root.internal->random_seed =
-              (FT_Int32)cff_random( (FT_UInt32)face->root.internal->random_seed );
+              (FT_Int32)psaux->cff_random(
+                (FT_UInt32)face->root.internal->random_seed );
 
           } while ( face->root.internal->random_seed < 0 );
         }
       font->cf2_instance.finalizer( font->cf2_instance.data );
       FT_FREE( font->cf2_instance.data );
     }
+
+    FT_FREE( font->font_extra );
   }