godot/thirdparty/freetype/src/gzip/ftgzip.c

/****************************************************************************
 *
 * ftgzip.c
 *
 *   FreeType support for .gz compressed files.
 *
 * This optional component relies on zlib.  It should mainly be used to
 * parse compressed PCF fonts, as found with many X11 server
 * distributions.
 *
 * Copyright (C) 2002-2023 by
 * David Turner, Robert Wilhelm, and Werner Lemberg.
 *
 * This file is part of the FreeType project, and may only be used,
 * modified, and distributed under the terms of the FreeType project
 * license, LICENSE.TXT.  By continuing to use, modify, or distribute
 * this file you indicate that you have read the license and
 * understand and accept it fully.
 *
 */


#include <freetype/internal/ftmemory.h>
#include <freetype/internal/ftstream.h>
#include <freetype/internal/ftdebug.h>
#include <freetype/ftgzip.h>
#include FT_CONFIG_STANDARD_LIBRARY_H


#include <freetype/ftmoderr.h>

#undef FTERRORS_H_

#undef  FT_ERR_PREFIX
#define FT_ERR_PREFIX
#define FT_ERR_BASE

#include <freetype/fterrors.h>


#ifdef FT_CONFIG_OPTION_USE_ZLIB

#ifdef FT_CONFIG_OPTION_SYSTEM_ZLIB

#include <zlib.h>

#else /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */

  /* In this case, we include our own modified sources of the ZLib  */
  /* within the `gzip' component.  The modifications were necessary */
  /* to #include all files without conflicts, as well as preventing */
  /* the definition of `extern' functions that may cause linking    */
  /* conflicts when a program is linked with both FreeType and the  */
  /* original ZLib.                                                 */

#ifndef USE_ZLIB_ZCALLOC
#define MY_ZCALLOC
#endif

  /* Note that our `zlib.h' includes `ftzconf.h' instead of `zconf.h'; */
  /* the main reason is that even a global `zlib.h' includes `zconf.h' */
  /* with                                                              */
  /*                                                                   */
  /*   #include "zconf.h"                                              */
  /*                                                                   */
  /* instead of the expected                                           */
  /*                                                                   */
  /*   #include <zconf.h>                                              */
  /*                                                                   */
  /* so that configuration with `FT_CONFIG_OPTION_SYSTEM_ZLIB' might   */
  /* include the wrong `zconf.h' file, leading to errors.              */

#define ZEXPORT
  /* prevent zlib functions from being visible outside their object files */
#define ZEXTERN

#define HAVE_MEMCPY
#define Z_SOLO
#define Z_FREETYPE

#if defined( _MSC_VER )      /* Visual C++ (and Intel C++)   */
  /* We disable the warning `conversion from XXX to YYY,     */
  /* possible loss of data' in order to compile cleanly with */
  /* the maximum level of warnings: zlib is non-FreeType     */
  /* code.                                                   */
#pragma warning( push )
#pragma warning( disable : 4244 )
#endif /* _MSC_VER */

#if defined( __GNUC__ )
#pragma GCC diagnostic push
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
#endif
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#pragma GCC diagnostic ignored "-Wredundant-decls"
#endif

#include "zutil.c"
#include "inffast.c"
#include "inflate.c"
#include "inftrees.c"
#include "adler32.c"
#include "crc32.c"

#if defined( __GNUC__ )
#pragma GCC diagnostic pop
#endif

#if defined( _MSC_VER )
#pragma warning( pop )
#endif

#endif /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */


/***************************************************************************/
/***************************************************************************/
/*****                                                                 *****/
/*****            Z L I B   M E M O R Y   M A N A G E M E N T          *****/
/*****                                                                 *****/
/***************************************************************************/
/***************************************************************************/

  /* it is better to use FreeType memory routines instead of raw
     'malloc/free' */

  static voidpf
  ft_gzip_alloc( voidpf  opaque,
                 uInt    items,
                 uInt    size )
  {}


  static void
  ft_gzip_free( voidpf  opaque,
                voidpf  address )
  {}

/***************************************************************************/
/***************************************************************************/
/*****                                                                 *****/
/*****               Z L I B   F I L E   D E S C R I P T O R           *****/
/*****                                                                 *****/
/***************************************************************************/
/***************************************************************************/

#define FT_GZIP_BUFFER_SIZE

  FT_GZipFile;


  /* gzip flag byte */
#define FT_GZIP_ASCII_FLAG
#define FT_GZIP_HEAD_CRC
#define FT_GZIP_EXTRA_FIELD
#define FT_GZIP_ORIG_NAME
#define FT_GZIP_COMMENT
#define FT_GZIP_RESERVED


  /* check and skip .gz header - we don't support `transparent' compression */
  static FT_Error
  ft_gzip_check_header( FT_Stream  stream )
  {}


  static FT_Error
  ft_gzip_file_init( FT_GZipFile  zip,
                     FT_Stream    stream,
                     FT_Stream    source )
  {}


  static void
  ft_gzip_file_done( FT_GZipFile  zip )
  {}


  static FT_Error
  ft_gzip_file_reset( FT_GZipFile  zip )
  {}


  static FT_Error
  ft_gzip_file_fill_input( FT_GZipFile  zip )
  {}


  static FT_Error
  ft_gzip_file_fill_output( FT_GZipFile  zip )
  {}


  /* fill output buffer; `count' must be <= FT_GZIP_BUFFER_SIZE */
  static FT_Error
  ft_gzip_file_skip_output( FT_GZipFile  zip,
                            FT_ULong     count )
  {}


  static FT_ULong
  ft_gzip_file_io( FT_GZipFile  zip,
                   FT_ULong     pos,
                   FT_Byte*     buffer,
                   FT_ULong     count )
  {}


/***************************************************************************/
/***************************************************************************/
/*****                                                                 *****/
/*****               G Z   E M B E D D I N G   S T R E A M             *****/
/*****                                                                 *****/
/***************************************************************************/
/***************************************************************************/

  static void
  ft_gzip_stream_close( FT_Stream  stream )
  {}


  static unsigned long
  ft_gzip_stream_io( FT_Stream       stream,
                     unsigned long   offset,
                     unsigned char*  buffer,
                     unsigned long   count )
  {}


  static FT_ULong
  ft_gzip_get_uncompressed_size( FT_Stream  stream )
  {}


  /* documentation is in ftgzip.h */

  FT_EXPORT_DEF( FT_Error )
  FT_Stream_OpenGzip( FT_Stream  stream,
                      FT_Stream  source )
  {}


  /* documentation is in ftgzip.h */

  FT_EXPORT_DEF( FT_Error )
  FT_Gzip_Uncompress( FT_Memory       memory,
                      FT_Byte*        output,
                      FT_ULong*       output_len,
                      const FT_Byte*  input,
                      FT_ULong        input_len )
  {}


#else /* !FT_CONFIG_OPTION_USE_ZLIB */

  FT_EXPORT_DEF( FT_Error )
  FT_Stream_OpenGzip( FT_Stream  stream,
                      FT_Stream  source )
  {
    FT_UNUSED( stream );
    FT_UNUSED( source );

    return FT_THROW( Unimplemented_Feature );
  }


  FT_EXPORT_DEF( FT_Error )
  FT_Gzip_Uncompress( FT_Memory       memory,
                      FT_Byte*        output,
                      FT_ULong*       output_len,
                      const FT_Byte*  input,
                      FT_ULong        input_len )
  {
    FT_UNUSED( memory );
    FT_UNUSED( output );
    FT_UNUSED( output_len );
    FT_UNUSED( input );
    FT_UNUSED( input_len );

    return FT_THROW( Unimplemented_Feature );
  }

#endif /* !FT_CONFIG_OPTION_USE_ZLIB */


/* END */