< prev index next >

src/java.desktop/share/native/libfreetype/src/cff/cffload.c

Print this page


   1 /***************************************************************************/
   2 /*                                                                         */
   3 /*  cffload.c                                                              */
   4 /*                                                                         */
   5 /*    OpenType and CFF data/program tables loader (body).                  */
   6 /*                                                                         */
   7 /*  Copyright 1996-2018 by                                                 */
   8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
   9 /*                                                                         */
  10 /*  This file is part of the FreeType project, and may only be used,       */
  11 /*  modified, and distributed under the terms of the FreeType project      */
  12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
  13 /*  this file you indicate that you have read the license and              */
  14 /*  understand and accept it fully.                                        */
  15 /*                                                                         */
  16 /***************************************************************************/
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_DEBUG_H
  21 #include FT_INTERNAL_OBJECTS_H
  22 #include FT_INTERNAL_STREAM_H
  23 #include FT_TRUETYPE_TAGS_H
  24 #include FT_TYPE1_TABLES_H
  25 #include FT_INTERNAL_POSTSCRIPT_AUX_H
  26 
  27 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  28 #include FT_MULTIPLE_MASTERS_H
  29 #include FT_SERVICE_MULTIPLE_MASTERS_H
  30 #endif
  31 
  32 #include "cffload.h"
  33 #include "cffparse.h"
  34 
  35 #include "cfferrs.h"
  36 


 179     326, 150, 164, 169, 327, 328, 329, 330,
 180     331, 332, 333, 334, 335, 336, 337, 338,
 181     339, 340, 341, 342, 343, 344, 345, 346,
 182     347, 348, 349, 350, 351, 352, 353, 354,
 183     355, 356, 357, 358, 359, 360, 361, 362,
 184     363, 364, 365, 366, 367, 368, 369, 370,
 185     371, 372, 373, 374, 375, 376, 377, 378
 186   };
 187 
 188 #endif /* 1 */
 189 
 190 
 191   FT_LOCAL_DEF( FT_UShort )
 192   cff_get_standard_encoding( FT_UInt  charcode )
 193   {
 194     return (FT_UShort)( charcode < 256 ? cff_standard_encoding[charcode]
 195                                        : 0 );
 196   }
 197 
 198 
 199   /*************************************************************************/
 200   /*                                                                       */
 201   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
 202   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
 203   /* messages during execution.                                            */
 204   /*                                                                       */
 205 #undef  FT_COMPONENT
 206 #define FT_COMPONENT  trace_cffload
 207 
 208 
 209   /* read an offset from the index's stream current position */
 210   static FT_ULong
 211   cff_index_read_offset( CFF_Index  idx,
 212                          FT_Error  *errorp )
 213   {
 214     FT_Error   error;
 215     FT_Stream  stream = idx->stream;
 216     FT_Byte    tmp[4];
 217     FT_ULong   result = 0;
 218 
 219 
 220     if ( !FT_STREAM_READ( tmp, idx->off_size ) )
 221     {
 222       FT_Int  nn;
 223 
 224 
 225       for ( nn = 0; nn < idx->off_size; nn++ )
 226         result = ( result << 8 ) | tmp[nn];


1381 
1382   /* Compute a blend vector from variation store index and normalized  */
1383   /* vector based on pseudo-code in OpenType Font Variations Overview. */
1384   /*                                                                   */
1385   /* Note: lenNDV == 0 produces a default blend vector, (1,0,0,...).   */
1386   FT_LOCAL_DEF( FT_Error )
1387   cff_blend_build_vector( CFF_Blend  blend,
1388                           FT_UInt    vsindex,
1389                           FT_UInt    lenNDV,
1390                           FT_Fixed*  NDV )
1391   {
1392     FT_Error   error  = FT_Err_Ok;            /* for FT_REALLOC */
1393     FT_Memory  memory = blend->font->memory;  /* for FT_REALLOC */
1394 
1395     FT_UInt       len;
1396     CFF_VStore    vs;
1397     CFF_VarData*  varData;
1398     FT_UInt       master;
1399 
1400 
1401     FT_ASSERT( lenNDV == 0 || NDV );







1402 
1403     blend->builtBV = FALSE;
1404 
1405     vs = &blend->font->vstore;
1406 
1407     /* VStore and fvar must be consistent */
1408     if ( lenNDV != 0 && lenNDV != vs->axisCount )
1409     {
1410       FT_TRACE4(( " cff_blend_build_vector: Axis count mismatch\n" ));
1411       error = FT_THROW( Invalid_File_Format );
1412       goto Exit;
1413     }
1414 
1415     if ( vsindex >= vs->dataCount )
1416     {
1417       FT_TRACE4(( " cff_blend_build_vector: vsindex out of range\n" ));
1418       error = FT_THROW( Invalid_File_Format );
1419       goto Exit;
1420     }
1421 


2063       goto Exit;
2064 
2065     /* if it is a CID font, we stop there */
2066     if ( top->cid_registry != 0xFFFFU )
2067       goto Exit;
2068 
2069     /* Parse the private dictionary, if any.                   */
2070     /*                                                         */
2071     /* CFF2 does not have a private dictionary in the Top DICT */
2072     /* but may have one in a Font DICT.  We need to parse      */
2073     /* the latter here in order to load any local subrs.       */
2074     error = cff_load_private_dict( font, subfont, 0, 0 );
2075     if ( error )
2076       goto Exit;
2077 
2078     if ( !cff2 )
2079     {
2080       /*
2081        * Initialize the random number generator.
2082        *
2083        * . If we have a face-specific seed, use it.
2084        *   If non-zero, update it to a positive value.
2085        *
2086        * . Otherwise, use the seed from the CFF driver.
2087        *   If non-zero, update it to a positive value.
2088        *
2089        * . If the random value is zero, use the seed given by the subfont's
2090        *   `initialRandomSeed' value.
2091        *
2092        */
2093       if ( face->root.internal->random_seed == -1 )
2094       {
2095         PS_Driver  driver = (PS_Driver)FT_FACE_DRIVER( face );
2096 
2097 
2098         subfont->random = (FT_UInt32)driver->random_seed;
2099         if ( driver->random_seed )
2100         {
2101           do
2102           {
2103             driver->random_seed =
2104               (FT_Int32)psaux->cff_random( (FT_UInt32)driver->random_seed );
2105 
2106           } while ( driver->random_seed < 0 );
2107         }
2108       }
2109       else


   1 /****************************************************************************
   2  *
   3  * cffload.c
   4  *
   5  *   OpenType and CFF data/program tables loader (body).
   6  *
   7  * Copyright (C) 1996-2019 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   9  *
  10  * This file is part of the FreeType project, and may only be used,
  11  * modified, and distributed under the terms of the FreeType project
  12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13  * this file you indicate that you have read the license and
  14  * understand and accept it fully.
  15  *
  16  */
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_DEBUG_H
  21 #include FT_INTERNAL_OBJECTS_H
  22 #include FT_INTERNAL_STREAM_H
  23 #include FT_TRUETYPE_TAGS_H
  24 #include FT_TYPE1_TABLES_H
  25 #include FT_INTERNAL_POSTSCRIPT_AUX_H
  26 
  27 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  28 #include FT_MULTIPLE_MASTERS_H
  29 #include FT_SERVICE_MULTIPLE_MASTERS_H
  30 #endif
  31 
  32 #include "cffload.h"
  33 #include "cffparse.h"
  34 
  35 #include "cfferrs.h"
  36 


 179     326, 150, 164, 169, 327, 328, 329, 330,
 180     331, 332, 333, 334, 335, 336, 337, 338,
 181     339, 340, 341, 342, 343, 344, 345, 346,
 182     347, 348, 349, 350, 351, 352, 353, 354,
 183     355, 356, 357, 358, 359, 360, 361, 362,
 184     363, 364, 365, 366, 367, 368, 369, 370,
 185     371, 372, 373, 374, 375, 376, 377, 378
 186   };
 187 
 188 #endif /* 1 */
 189 
 190 
 191   FT_LOCAL_DEF( FT_UShort )
 192   cff_get_standard_encoding( FT_UInt  charcode )
 193   {
 194     return (FT_UShort)( charcode < 256 ? cff_standard_encoding[charcode]
 195                                        : 0 );
 196   }
 197 
 198 
 199   /**************************************************************************
 200    *
 201    * The macro FT_COMPONENT is used in trace mode.  It is an implicit
 202    * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
 203    * messages during execution.
 204    */
 205 #undef  FT_COMPONENT
 206 #define FT_COMPONENT  cffload
 207 
 208 
 209   /* read an offset from the index's stream current position */
 210   static FT_ULong
 211   cff_index_read_offset( CFF_Index  idx,
 212                          FT_Error  *errorp )
 213   {
 214     FT_Error   error;
 215     FT_Stream  stream = idx->stream;
 216     FT_Byte    tmp[4];
 217     FT_ULong   result = 0;
 218 
 219 
 220     if ( !FT_STREAM_READ( tmp, idx->off_size ) )
 221     {
 222       FT_Int  nn;
 223 
 224 
 225       for ( nn = 0; nn < idx->off_size; nn++ )
 226         result = ( result << 8 ) | tmp[nn];


1381 
1382   /* Compute a blend vector from variation store index and normalized  */
1383   /* vector based on pseudo-code in OpenType Font Variations Overview. */
1384   /*                                                                   */
1385   /* Note: lenNDV == 0 produces a default blend vector, (1,0,0,...).   */
1386   FT_LOCAL_DEF( FT_Error )
1387   cff_blend_build_vector( CFF_Blend  blend,
1388                           FT_UInt    vsindex,
1389                           FT_UInt    lenNDV,
1390                           FT_Fixed*  NDV )
1391   {
1392     FT_Error   error  = FT_Err_Ok;            /* for FT_REALLOC */
1393     FT_Memory  memory = blend->font->memory;  /* for FT_REALLOC */
1394 
1395     FT_UInt       len;
1396     CFF_VStore    vs;
1397     CFF_VarData*  varData;
1398     FT_UInt       master;
1399 
1400 
1401     /* protect against malformed fonts */
1402     if ( !( lenNDV == 0 || NDV ) )
1403     {
1404       FT_TRACE4(( " cff_blend_build_vector:"
1405                   " Malformed Normalize Design Vector data\n" ));
1406       error = FT_THROW( Invalid_File_Format );
1407       goto Exit;
1408     }
1409 
1410     blend->builtBV = FALSE;
1411 
1412     vs = &blend->font->vstore;
1413 
1414     /* VStore and fvar must be consistent */
1415     if ( lenNDV != 0 && lenNDV != vs->axisCount )
1416     {
1417       FT_TRACE4(( " cff_blend_build_vector: Axis count mismatch\n" ));
1418       error = FT_THROW( Invalid_File_Format );
1419       goto Exit;
1420     }
1421 
1422     if ( vsindex >= vs->dataCount )
1423     {
1424       FT_TRACE4(( " cff_blend_build_vector: vsindex out of range\n" ));
1425       error = FT_THROW( Invalid_File_Format );
1426       goto Exit;
1427     }
1428 


2070       goto Exit;
2071 
2072     /* if it is a CID font, we stop there */
2073     if ( top->cid_registry != 0xFFFFU )
2074       goto Exit;
2075 
2076     /* Parse the private dictionary, if any.                   */
2077     /*                                                         */
2078     /* CFF2 does not have a private dictionary in the Top DICT */
2079     /* but may have one in a Font DICT.  We need to parse      */
2080     /* the latter here in order to load any local subrs.       */
2081     error = cff_load_private_dict( font, subfont, 0, 0 );
2082     if ( error )
2083       goto Exit;
2084 
2085     if ( !cff2 )
2086     {
2087       /*
2088        * Initialize the random number generator.
2089        *
2090        * - If we have a face-specific seed, use it.
2091        *   If non-zero, update it to a positive value.
2092        *
2093        * - Otherwise, use the seed from the CFF driver.
2094        *   If non-zero, update it to a positive value.
2095        *
2096        * - If the random value is zero, use the seed given by the subfont's
2097        *   `initialRandomSeed' value.
2098        *
2099        */
2100       if ( face->root.internal->random_seed == -1 )
2101       {
2102         PS_Driver  driver = (PS_Driver)FT_FACE_DRIVER( face );
2103 
2104 
2105         subfont->random = (FT_UInt32)driver->random_seed;
2106         if ( driver->random_seed )
2107         {
2108           do
2109           {
2110             driver->random_seed =
2111               (FT_Int32)psaux->cff_random( (FT_UInt32)driver->random_seed );
2112 
2113           } while ( driver->random_seed < 0 );
2114         }
2115       }
2116       else


< prev index next >