< prev index next >

src/java.desktop/share/native/libfreetype/src/sfnt/sfwoff.c

Print this page


   1 /****************************************************************************
   2  *
   3  * sfwoff.c
   4  *
   5  *   WOFF format management (base).
   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 "sfwoff.h"
  21 #include FT_TRUETYPE_TAGS_H
  22 #include FT_INTERNAL_DEBUG_H
  23 #include FT_INTERNAL_STREAM_H
  24 #include FT_GZIP_H
  25 
  26 
  27   /**************************************************************************


 354 
 355       if ( table->CompLength == table->OrigLength )
 356       {
 357         /* Uncompressed data; just copy. */
 358         ft_memcpy( sfnt + table->OrigOffset,
 359                    stream->cursor,
 360                    table->OrigLength );
 361       }
 362       else
 363       {
 364 #ifdef FT_CONFIG_OPTION_USE_ZLIB
 365 
 366         /* Uncompress with zlib. */
 367         FT_ULong  output_len = table->OrigLength;
 368 
 369 
 370         error = FT_Gzip_Uncompress( memory,
 371                                     sfnt + table->OrigOffset, &output_len,
 372                                     stream->cursor, table->CompLength );
 373         if ( error )
 374           goto Exit;
 375         if ( output_len != table->OrigLength )
 376         {
 377           FT_ERROR(( "woff_font_open: compressed table length mismatch\n" ));
 378           error = FT_THROW( Invalid_Table );
 379           goto Exit;
 380         }
 381 
 382 #else /* !FT_CONFIG_OPTION_USE_ZLIB */
 383 
 384         error = FT_THROW( Unimplemented_Feature );
 385         goto Exit;
 386 
 387 #endif /* !FT_CONFIG_OPTION_USE_ZLIB */
 388       }
 389 
 390       FT_FRAME_EXIT();
 391 
 392       /* We don't check whether the padding bytes in the WOFF file are     */
 393       /* actually '\0'.  For the output, however, we do set them properly. */
 394       sfnt_offset = table->OrigOffset + table->OrigLength;
 395       while ( sfnt_offset & 3 )
 396       {
 397         sfnt[sfnt_offset] = '\0';
 398         sfnt_offset++;
 399       }
 400     }
 401 
 402     /* Ok!  Finally ready.  Swap out stream and return. */
 403     FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize );
 404     sfnt_stream->memory = stream->memory;
 405     sfnt_stream->close  = sfnt_stream_close;


 407     FT_Stream_Free(
 408       face->root.stream,
 409       ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
 410 
 411     face->root.stream = sfnt_stream;
 412 
 413     face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
 414 
 415   Exit:
 416     FT_FREE( tables );
 417     FT_FREE( indices );
 418 
 419     if ( error )
 420     {
 421       FT_FREE( sfnt );
 422       FT_Stream_Close( sfnt_stream );
 423       FT_FREE( sfnt_stream );
 424     }
 425 
 426     return error;




 427   }
 428 
 429 
 430 #undef WRITE_USHORT
 431 #undef WRITE_ULONG
 432 
 433 
 434 /* END */
   1 /****************************************************************************
   2  *
   3  * sfwoff.c
   4  *
   5  *   WOFF format management (base).
   6  *
   7  * Copyright (C) 1996-2020 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 "sfwoff.h"
  21 #include FT_TRUETYPE_TAGS_H
  22 #include FT_INTERNAL_DEBUG_H
  23 #include FT_INTERNAL_STREAM_H
  24 #include FT_GZIP_H
  25 
  26 
  27   /**************************************************************************


 354 
 355       if ( table->CompLength == table->OrigLength )
 356       {
 357         /* Uncompressed data; just copy. */
 358         ft_memcpy( sfnt + table->OrigOffset,
 359                    stream->cursor,
 360                    table->OrigLength );
 361       }
 362       else
 363       {
 364 #ifdef FT_CONFIG_OPTION_USE_ZLIB
 365 
 366         /* Uncompress with zlib. */
 367         FT_ULong  output_len = table->OrigLength;
 368 
 369 
 370         error = FT_Gzip_Uncompress( memory,
 371                                     sfnt + table->OrigOffset, &output_len,
 372                                     stream->cursor, table->CompLength );
 373         if ( error )
 374           goto Exit1;
 375         if ( output_len != table->OrigLength )
 376         {
 377           FT_ERROR(( "woff_font_open: compressed table length mismatch\n" ));
 378           error = FT_THROW( Invalid_Table );
 379           goto Exit1;
 380         }
 381 
 382 #else /* !FT_CONFIG_OPTION_USE_ZLIB */
 383 
 384         error = FT_THROW( Unimplemented_Feature );
 385         goto Exit1;
 386 
 387 #endif /* !FT_CONFIG_OPTION_USE_ZLIB */
 388       }
 389 
 390       FT_FRAME_EXIT();
 391 
 392       /* We don't check whether the padding bytes in the WOFF file are     */
 393       /* actually '\0'.  For the output, however, we do set them properly. */
 394       sfnt_offset = table->OrigOffset + table->OrigLength;
 395       while ( sfnt_offset & 3 )
 396       {
 397         sfnt[sfnt_offset] = '\0';
 398         sfnt_offset++;
 399       }
 400     }
 401 
 402     /* Ok!  Finally ready.  Swap out stream and return. */
 403     FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize );
 404     sfnt_stream->memory = stream->memory;
 405     sfnt_stream->close  = sfnt_stream_close;


 407     FT_Stream_Free(
 408       face->root.stream,
 409       ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
 410 
 411     face->root.stream = sfnt_stream;
 412 
 413     face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
 414 
 415   Exit:
 416     FT_FREE( tables );
 417     FT_FREE( indices );
 418 
 419     if ( error )
 420     {
 421       FT_FREE( sfnt );
 422       FT_Stream_Close( sfnt_stream );
 423       FT_FREE( sfnt_stream );
 424     }
 425 
 426     return error;
 427 
 428   Exit1:
 429     FT_FRAME_EXIT();
 430     goto Exit;
 431   }
 432 
 433 
 434 #undef WRITE_USHORT
 435 #undef WRITE_ULONG
 436 
 437 
 438 /* END */
< prev index next >