From eb39cdb2efbc66e4566ba1f150cab7983362e13f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 31 Mar 2017 12:26:15 -0700 Subject: Pull in FreeType via DEPS instead. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=pdfium:688 Change-Id: I7787b29d0fedc48f1360ab041d43829d0e805462 Change-Id: I7787b29d0fedc48f1360ab041d43829d0e805462 Reviewed-on: https://pdfium-review.googlesource.com/3331 Commit-Queue: Lei Zhang Reviewed-by: dsinclair Reviewed-by: Nicolás Peña --- third_party/freetype/src/base/basepic.c | 108 - third_party/freetype/src/base/basepic.h | 91 - third_party/freetype/src/base/ftadvanc.c | 171 - third_party/freetype/src/base/ftbase.c | 42 - third_party/freetype/src/base/ftbase.h | 74 - third_party/freetype/src/base/ftbitmap.c | 809 ----- third_party/freetype/src/base/ftcalc.c | 1003 ------ third_party/freetype/src/base/ftdbgmem.c | 999 ------ third_party/freetype/src/base/ftfntfmt.c | 55 - third_party/freetype/src/base/ftfstype.c | 62 - third_party/freetype/src/base/ftgloadr.c | 406 --- third_party/freetype/src/base/ftglyph.c | 633 ---- third_party/freetype/src/base/fthash.c | 339 -- third_party/freetype/src/base/ftinit.c | 397 --- third_party/freetype/src/base/ftlcdfil.c | 383 --- third_party/freetype/src/base/ftmm.c | 402 --- third_party/freetype/src/base/ftobjs.c | 5112 ------------------------------ third_party/freetype/src/base/ftoutln.c | 1108 ------- third_party/freetype/src/base/ftpic.c | 55 - third_party/freetype/src/base/ftrfork.c | 937 ------ third_party/freetype/src/base/ftsnames.c | 94 - third_party/freetype/src/base/ftstream.c | 860 ----- third_party/freetype/src/base/ftsystem.c | 320 -- third_party/freetype/src/base/fttrigon.c | 526 --- third_party/freetype/src/base/fttype1.c | 127 - third_party/freetype/src/base/ftutil.c | 441 --- 26 files changed, 15554 deletions(-) delete mode 100644 third_party/freetype/src/base/basepic.c delete mode 100644 third_party/freetype/src/base/basepic.h delete mode 100644 third_party/freetype/src/base/ftadvanc.c delete mode 100644 third_party/freetype/src/base/ftbase.c delete mode 100644 third_party/freetype/src/base/ftbase.h delete mode 100644 third_party/freetype/src/base/ftbitmap.c delete mode 100644 third_party/freetype/src/base/ftcalc.c delete mode 100644 third_party/freetype/src/base/ftdbgmem.c delete mode 100644 third_party/freetype/src/base/ftfntfmt.c delete mode 100644 third_party/freetype/src/base/ftfstype.c delete mode 100644 third_party/freetype/src/base/ftgloadr.c delete mode 100644 third_party/freetype/src/base/ftglyph.c delete mode 100644 third_party/freetype/src/base/fthash.c delete mode 100644 third_party/freetype/src/base/ftinit.c delete mode 100644 third_party/freetype/src/base/ftlcdfil.c delete mode 100644 third_party/freetype/src/base/ftmm.c delete mode 100644 third_party/freetype/src/base/ftobjs.c delete mode 100644 third_party/freetype/src/base/ftoutln.c delete mode 100644 third_party/freetype/src/base/ftpic.c delete mode 100644 third_party/freetype/src/base/ftrfork.c delete mode 100644 third_party/freetype/src/base/ftsnames.c delete mode 100644 third_party/freetype/src/base/ftstream.c delete mode 100644 third_party/freetype/src/base/ftsystem.c delete mode 100644 third_party/freetype/src/base/fttrigon.c delete mode 100644 third_party/freetype/src/base/fttype1.c delete mode 100644 third_party/freetype/src/base/ftutil.c (limited to 'third_party/freetype/src/base') diff --git a/third_party/freetype/src/base/basepic.c b/third_party/freetype/src/base/basepic.c deleted file mode 100644 index 57fb8169ad..0000000000 --- a/third_party/freetype/src/base/basepic.c +++ /dev/null @@ -1,108 +0,0 @@ -/***************************************************************************/ -/* */ -/* basepic.c */ -/* */ -/* The FreeType position independent code services for base. */ -/* */ -/* Copyright 2009-2017 by */ -/* Oran Agra and Mickey Gabel. */ -/* */ -/* 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 -#include FT_FREETYPE_H -#include FT_INTERNAL_OBJECTS_H -#include "basepic.h" - - -#ifdef FT_CONFIG_OPTION_PIC - - /* forward declaration of PIC init functions from ftglyph.c */ - void - FT_Init_Class_ft_outline_glyph_class( FT_Glyph_Class* clazz ); - - void - FT_Init_Class_ft_bitmap_glyph_class( FT_Glyph_Class* clazz ); - -#ifdef FT_CONFIG_OPTION_MAC_FONTS - /* forward declaration of PIC init function from ftrfork.c */ - /* (not modularized) */ - void - FT_Init_Table_ft_raccess_guess_table( ft_raccess_guess_rec* record ); -#endif - - /* forward declaration of PIC init functions from ftinit.c */ - FT_Error - ft_create_default_module_classes( FT_Library library ); - - void - ft_destroy_default_module_classes( FT_Library library ); - - - void - ft_base_pic_free( FT_Library library ) - { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Memory memory = library->memory; - - - if ( pic_container->base ) - { - /* destroy default module classes */ - /* (in case FT_Add_Default_Modules was used) */ - ft_destroy_default_module_classes( library ); - - FT_FREE( pic_container->base ); - pic_container->base = NULL; - } - } - - - FT_Error - ft_base_pic_init( FT_Library library ) - { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error = FT_Err_Ok; - BasePIC* container = NULL; - FT_Memory memory = library->memory; - - - /* allocate pointer, clear and set global container pointer */ - if ( FT_ALLOC( container, sizeof ( *container ) ) ) - return error; - FT_MEM_SET( container, 0, sizeof ( *container ) ); - pic_container->base = container; - - /* initialize default modules list and pointers */ - error = ft_create_default_module_classes( library ); - if ( error ) - goto Exit; - - /* initialize pointer table - */ - /* this is how the module usually expects this data */ - FT_Init_Class_ft_outline_glyph_class( - &container->ft_outline_glyph_class ); - FT_Init_Class_ft_bitmap_glyph_class( - &container->ft_bitmap_glyph_class ); -#ifdef FT_CONFIG_OPTION_MAC_FONTS - FT_Init_Table_ft_raccess_guess_table( - (ft_raccess_guess_rec*)&container->ft_raccess_guess_table ); -#endif - - Exit: - if ( error ) - ft_base_pic_free( library ); - return error; - } - -#endif /* FT_CONFIG_OPTION_PIC */ - - -/* END */ diff --git a/third_party/freetype/src/base/basepic.h b/third_party/freetype/src/base/basepic.h deleted file mode 100644 index 258d4ce2ba..0000000000 --- a/third_party/freetype/src/base/basepic.h +++ /dev/null @@ -1,91 +0,0 @@ -/***************************************************************************/ -/* */ -/* basepic.h */ -/* */ -/* The FreeType position independent code services for base. */ -/* */ -/* Copyright 2009-2017 by */ -/* Oran Agra and Mickey Gabel. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#ifndef BASEPIC_H_ -#define BASEPIC_H_ - - -#include FT_INTERNAL_PIC_H - - -#ifndef FT_CONFIG_OPTION_PIC - -#define FT_OUTLINE_GLYPH_CLASS_GET &ft_outline_glyph_class -#define FT_BITMAP_GLYPH_CLASS_GET &ft_bitmap_glyph_class -#define FT_DEFAULT_MODULES_GET ft_default_modules - -#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#define FT_RACCESS_GUESS_TABLE_GET ft_raccess_guess_table -#endif - -#else /* FT_CONFIG_OPTION_PIC */ - -#include FT_GLYPH_H - -#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#include FT_INTERNAL_RFORK_H -#endif - - -FT_BEGIN_HEADER - - typedef struct BasePIC_ - { - FT_Module_Class** default_module_classes; - FT_Glyph_Class ft_outline_glyph_class; - FT_Glyph_Class ft_bitmap_glyph_class; - -#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK - ft_raccess_guess_rec ft_raccess_guess_table[FT_RACCESS_N_RULES]; -#endif - - } BasePIC; - - -#define GET_PIC( lib ) ( (BasePIC*)( (lib)->pic_container.base ) ) - -#define FT_OUTLINE_GLYPH_CLASS_GET \ - ( &GET_PIC( library )->ft_outline_glyph_class ) -#define FT_BITMAP_GLYPH_CLASS_GET \ - ( &GET_PIC( library )->ft_bitmap_glyph_class ) -#define FT_DEFAULT_MODULES_GET \ - ( GET_PIC( library )->default_module_classes ) - -#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#define FT_RACCESS_GUESS_TABLE_GET \ - ( GET_PIC( library )->ft_raccess_guess_table ) -#endif - - - /* see basepic.c for the implementation */ - void - ft_base_pic_free( FT_Library library ); - - FT_Error - ft_base_pic_init( FT_Library library ); - -FT_END_HEADER - -#endif /* FT_CONFIG_OPTION_PIC */ - - /* */ - -#endif /* BASEPIC_H_ */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftadvanc.c b/third_party/freetype/src/base/ftadvanc.c deleted file mode 100644 index 1557607fc5..0000000000 --- a/third_party/freetype/src/base/ftadvanc.c +++ /dev/null @@ -1,171 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftadvanc.c */ -/* */ -/* Quick computation of advance widths (body). */ -/* */ -/* Copyright 2008-2017 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 -#include FT_INTERNAL_DEBUG_H - -#include FT_ADVANCES_H -#include FT_INTERNAL_OBJECTS_H - - - static FT_Error - _ft_face_scale_advances( FT_Face face, - FT_Fixed* advances, - FT_UInt count, - FT_Int32 flags ) - { - FT_Fixed scale; - FT_UInt nn; - - - if ( flags & FT_LOAD_NO_SCALE ) - return FT_Err_Ok; - - if ( !face->size ) - return FT_THROW( Invalid_Size_Handle ); - - if ( flags & FT_LOAD_VERTICAL_LAYOUT ) - scale = face->size->metrics.y_scale; - else - scale = face->size->metrics.x_scale; - - /* this must be the same scaling as to get linear{Hori,Vert}Advance */ - /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */ - - for ( nn = 0; nn < count; nn++ ) - advances[nn] = FT_MulDiv( advances[nn], scale, 64 ); - - return FT_Err_Ok; - } - - - /* at the moment, we can perform fast advance retrieval only in */ - /* the following cases: */ - /* */ - /* - unscaled load */ - /* - unhinted load */ - /* - light-hinted load */ - /* - if a variations font, it must have an `HVAR' or `VVAR' */ - /* table (thus the old MM or GX fonts don't qualify; this */ - /* gets checked by the driver-specific functions) */ - -#define LOAD_ADVANCE_FAST_CHECK( face, flags ) \ - ( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) || \ - FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT ) - - - /* documentation is in ftadvanc.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Advance( FT_Face face, - FT_UInt gindex, - FT_Int32 flags, - FT_Fixed *padvance ) - { - FT_Face_GetAdvancesFunc func; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !padvance ) - return FT_THROW( Invalid_Argument ); - - if ( gindex >= (FT_UInt)face->num_glyphs ) - return FT_THROW( Invalid_Glyph_Index ); - - func = face->driver->clazz->get_advances; - if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) ) - { - FT_Error error; - - - error = func( face, gindex, 1, flags, padvance ); - if ( !error ) - return _ft_face_scale_advances( face, padvance, 1, flags ); - - if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) - return error; - } - - return FT_Get_Advances( face, gindex, 1, flags, padvance ); - } - - - /* documentation is in ftadvanc.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Advances( FT_Face face, - FT_UInt start, - FT_UInt count, - FT_Int32 flags, - FT_Fixed *padvances ) - { - FT_Face_GetAdvancesFunc func; - FT_UInt num, end, nn; - FT_Error error = FT_Err_Ok; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !padvances ) - return FT_THROW( Invalid_Argument ); - - num = (FT_UInt)face->num_glyphs; - end = start + count; - if ( start >= num || end < start || end > num ) - return FT_THROW( Invalid_Glyph_Index ); - - if ( count == 0 ) - return FT_Err_Ok; - - func = face->driver->clazz->get_advances; - if ( func && LOAD_ADVANCE_FAST_CHECK( face, flags ) ) - { - error = func( face, start, count, flags, padvances ); - if ( !error ) - return _ft_face_scale_advances( face, padvances, count, flags ); - - if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) - return error; - } - - error = FT_Err_Ok; - - if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) - return FT_THROW( Unimplemented_Feature ); - - flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY; - for ( nn = 0; nn < count; nn++ ) - { - error = FT_Load_Glyph( face, start + nn, flags ); - if ( error ) - break; - - /* scale from 26.6 to 16.16 */ - padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) - ? face->glyph->advance.y * 1024 - : face->glyph->advance.x * 1024; - } - - return error; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftbase.c b/third_party/freetype/src/base/ftbase.c deleted file mode 100644 index 993ac72286..0000000000 --- a/third_party/freetype/src/base/ftbase.c +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftbase.c */ -/* */ -/* Single object library component (body only). */ -/* */ -/* Copyright 1996-2017 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 - -#define FT_MAKE_OPTION_SINGLE_OBJECT - -#include "ftpic.c" -#include "basepic.c" -#include "ftadvanc.c" -#include "ftcalc.c" -#include "ftdbgmem.c" -#include "ftgloadr.c" -#include "fthash.c" -#include "ftobjs.c" -#include "ftoutln.c" -#include "ftrfork.c" -#include "ftsnames.c" -#include "ftstream.c" -#include "fttrigon.c" -#include "ftutil.c" - -#ifdef FT_MACINTOSH -#include "ftmac.c" -#endif - -/* END */ diff --git a/third_party/freetype/src/base/ftbase.h b/third_party/freetype/src/base/ftbase.h deleted file mode 100644 index 2072284f06..0000000000 --- a/third_party/freetype/src/base/ftbase.h +++ /dev/null @@ -1,74 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftbase.h */ -/* */ -/* The FreeType private functions used in base module (specification). */ -/* */ -/* Copyright 2008-2017 by */ -/* David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - -#ifndef FTBASE_H_ -#define FTBASE_H_ - - -#include -#include FT_INTERNAL_OBJECTS_H - - -FT_BEGIN_HEADER - - - /* MacOS resource fork cannot exceed 16MB at least for Carbon code; */ - /* see https://support.microsoft.com/en-us/kb/130437 */ -#define FT_MAC_RFORK_MAX_LEN 0x00FFFFFFUL - - - /* Assume the stream is sfnt-wrapped PS Type1 or sfnt-wrapped CID-keyed */ - /* font, and try to load a face specified by the face_index. */ - FT_LOCAL( FT_Error ) - open_face_PS_from_sfnt_stream( FT_Library library, - FT_Stream stream, - FT_Long face_index, - FT_Int num_params, - FT_Parameter *params, - FT_Face *aface ); - - - /* Create a new FT_Face given a buffer and a driver name. */ - /* From ftmac.c. */ - FT_LOCAL( FT_Error ) - open_face_from_buffer( FT_Library library, - FT_Byte* base, - FT_ULong size, - FT_Long face_index, - const char* driver_name, - FT_Face *aface ); - - -#if defined( FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK ) && \ - !defined( FT_MACINTOSH ) - /* Mac OS X/Darwin kernel often changes recommended method to access */ - /* the resource fork and older methods makes the kernel issue the */ - /* warning of deprecated method. To calm it down, the methods based */ - /* on Darwin VFS should be grouped and skip the rest methods after */ - /* the case the resource is opened but found to lack a font in it. */ - FT_LOCAL( FT_Bool ) - ft_raccess_rule_by_darwin_vfs( FT_Library library, FT_UInt rule_index ); -#endif - - -FT_END_HEADER - -#endif /* FTBASE_H_ */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftbitmap.c b/third_party/freetype/src/base/ftbitmap.c deleted file mode 100644 index 88c88c4c1b..0000000000 --- a/third_party/freetype/src/base/ftbitmap.c +++ /dev/null @@ -1,809 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftbitmap.c */ -/* */ -/* FreeType utility functions for bitmaps (body). */ -/* */ -/* Copyright 2004-2017 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 -#include FT_INTERNAL_DEBUG_H - -#include FT_BITMAP_H -#include FT_IMAGE_H -#include FT_INTERNAL_OBJECTS_H - - - static - const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( void ) - FT_Bitmap_Init( FT_Bitmap *abitmap ) - { - if ( abitmap ) - *abitmap = null_bitmap; - } - - - /* deprecated function name; retained for ABI compatibility */ - - FT_EXPORT_DEF( void ) - FT_Bitmap_New( FT_Bitmap *abitmap ) - { - if ( abitmap ) - *abitmap = null_bitmap; - } - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Bitmap_Copy( FT_Library library, - const FT_Bitmap *source, - FT_Bitmap *target) - { - FT_Memory memory; - FT_Error error = FT_Err_Ok; - - FT_Int pitch; - FT_ULong size; - - FT_Int source_pitch_sign, target_pitch_sign; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !source || !target ) - return FT_THROW( Invalid_Argument ); - - if ( source == target ) - return FT_Err_Ok; - - source_pitch_sign = source->pitch < 0 ? -1 : 1; - target_pitch_sign = target->pitch < 0 ? -1 : 1; - - if ( !source->buffer ) - { - *target = *source; - if ( source_pitch_sign != target_pitch_sign ) - target->pitch = -target->pitch; - - return FT_Err_Ok; - } - - memory = library->memory; - pitch = source->pitch; - - if ( pitch < 0 ) - pitch = -pitch; - size = (FT_ULong)pitch * source->rows; - - if ( target->buffer ) - { - FT_Int target_pitch = target->pitch; - FT_ULong target_size; - - - if ( target_pitch < 0 ) - target_pitch = -target_pitch; - target_size = (FT_ULong)target_pitch * target->rows; - - if ( target_size != size ) - (void)FT_QREALLOC( target->buffer, target_size, size ); - } - else - (void)FT_QALLOC( target->buffer, size ); - - if ( !error ) - { - unsigned char *p; - - - p = target->buffer; - *target = *source; - target->buffer = p; - - if ( source_pitch_sign == target_pitch_sign ) - FT_MEM_COPY( target->buffer, source->buffer, size ); - else - { - /* take care of bitmap flow */ - FT_UInt i; - FT_Byte* s = source->buffer; - FT_Byte* t = target->buffer; - - - t += (FT_ULong)pitch * ( target->rows - 1 ); - - for ( i = target->rows; i > 0; i-- ) - { - FT_ARRAY_COPY( t, s, pitch ); - - s += pitch; - t -= pitch; - } - } - } - - return error; - } - - - /* Enlarge `bitmap' horizontally and vertically by `xpixels' */ - /* and `ypixels', respectively. */ - - static FT_Error - ft_bitmap_assure_buffer( FT_Memory memory, - FT_Bitmap* bitmap, - FT_UInt xpixels, - FT_UInt ypixels ) - { - FT_Error error; - int pitch; - int new_pitch; - FT_UInt bpp; - FT_UInt i, width, height; - unsigned char* buffer = NULL; - - - width = bitmap->width; - height = bitmap->rows; - pitch = bitmap->pitch; - if ( pitch < 0 ) - pitch = -pitch; - - switch ( bitmap->pixel_mode ) - { - case FT_PIXEL_MODE_MONO: - bpp = 1; - new_pitch = (int)( ( width + xpixels + 7 ) >> 3 ); - break; - case FT_PIXEL_MODE_GRAY2: - bpp = 2; - new_pitch = (int)( ( width + xpixels + 3 ) >> 2 ); - break; - case FT_PIXEL_MODE_GRAY4: - bpp = 4; - new_pitch = (int)( ( width + xpixels + 1 ) >> 1 ); - break; - case FT_PIXEL_MODE_GRAY: - case FT_PIXEL_MODE_LCD: - case FT_PIXEL_MODE_LCD_V: - bpp = 8; - new_pitch = (int)( width + xpixels ); - break; - default: - return FT_THROW( Invalid_Glyph_Format ); - } - - /* if no need to allocate memory */ - if ( ypixels == 0 && new_pitch <= pitch ) - { - /* zero the padding */ - FT_UInt bit_width = (FT_UInt)pitch * 8; - FT_UInt bit_last = ( width + xpixels ) * bpp; - - - if ( bit_last < bit_width ) - { - FT_Byte* line = bitmap->buffer + ( bit_last >> 3 ); - FT_Byte* end = bitmap->buffer + pitch; - FT_UInt shift = bit_last & 7; - FT_UInt mask = 0xFF00U >> shift; - FT_UInt count = height; - - - for ( ; count > 0; count--, line += pitch, end += pitch ) - { - FT_Byte* write = line; - - - if ( shift > 0 ) - { - write[0] = (FT_Byte)( write[0] & mask ); - write++; - } - if ( write < end ) - FT_MEM_ZERO( write, end - write ); - } - } - - return FT_Err_Ok; - } - - /* otherwise allocate new buffer */ - if ( FT_QALLOC_MULT( buffer, new_pitch, bitmap->rows + ypixels ) ) - return error; - - /* new rows get added at the top of the bitmap, */ - /* thus take care of the flow direction */ - if ( bitmap->pitch > 0 ) - { - FT_UInt len = ( width * bpp + 7 ) >> 3; - - - for ( i = 0; i < bitmap->rows; i++ ) - FT_MEM_COPY( buffer + (FT_UInt)new_pitch * ( ypixels + i ), - bitmap->buffer + (FT_UInt)pitch * i, - len ); - } - else - { - FT_UInt len = ( width * bpp + 7 ) >> 3; - - - for ( i = 0; i < bitmap->rows; i++ ) - FT_MEM_COPY( buffer + (FT_UInt)new_pitch * i, - bitmap->buffer + (FT_UInt)pitch * i, - len ); - } - - FT_FREE( bitmap->buffer ); - bitmap->buffer = buffer; - - if ( bitmap->pitch < 0 ) - new_pitch = -new_pitch; - - /* set pitch only, width and height are left untouched */ - bitmap->pitch = new_pitch; - - return FT_Err_Ok; - } - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Bitmap_Embolden( FT_Library library, - FT_Bitmap* bitmap, - FT_Pos xStrength, - FT_Pos yStrength ) - { - FT_Error error; - unsigned char* p; - FT_Int i, x, pitch; - FT_UInt y; - FT_Int xstr, ystr; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !bitmap || !bitmap->buffer ) - return FT_THROW( Invalid_Argument ); - - if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) || - ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) ) - return FT_THROW( Invalid_Argument ); - - xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6; - ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6; - - if ( xstr == 0 && ystr == 0 ) - return FT_Err_Ok; - else if ( xstr < 0 || ystr < 0 ) - return FT_THROW( Invalid_Argument ); - - switch ( bitmap->pixel_mode ) - { - case FT_PIXEL_MODE_GRAY2: - case FT_PIXEL_MODE_GRAY4: - { - FT_Bitmap tmp; - - - /* convert to 8bpp */ - FT_Bitmap_Init( &tmp ); - error = FT_Bitmap_Convert( library, bitmap, &tmp, 1 ); - if ( error ) - return error; - - FT_Bitmap_Done( library, bitmap ); - *bitmap = tmp; - } - break; - - case FT_PIXEL_MODE_MONO: - if ( xstr > 8 ) - xstr = 8; - break; - - case FT_PIXEL_MODE_LCD: - xstr *= 3; - break; - - case FT_PIXEL_MODE_LCD_V: - ystr *= 3; - break; - - case FT_PIXEL_MODE_BGRA: - /* We don't embolden color glyphs. */ - return FT_Err_Ok; - } - - error = ft_bitmap_assure_buffer( library->memory, bitmap, - (FT_UInt)xstr, (FT_UInt)ystr ); - if ( error ) - return error; - - /* take care of bitmap flow */ - pitch = bitmap->pitch; - if ( pitch > 0 ) - p = bitmap->buffer + pitch * ystr; - else - { - pitch = -pitch; - p = bitmap->buffer + (FT_UInt)pitch * ( bitmap->rows - 1 ); - } - - /* for each row */ - for ( y = 0; y < bitmap->rows; y++ ) - { - /* - * Horizontally: - * - * From the last pixel on, make each pixel or'ed with the - * `xstr' pixels before it. - */ - for ( x = pitch - 1; x >= 0; x-- ) - { - unsigned char tmp; - - - tmp = p[x]; - for ( i = 1; i <= xstr; i++ ) - { - if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO ) - { - p[x] |= tmp >> i; - - /* the maximum value of 8 for `xstr' comes from here */ - if ( x > 0 ) - p[x] |= p[x - 1] << ( 8 - i ); - -#if 0 - if ( p[x] == 0xFF ) - break; -#endif - } - else - { - if ( x - i >= 0 ) - { - if ( p[x] + p[x - i] > bitmap->num_grays - 1 ) - { - p[x] = (unsigned char)( bitmap->num_grays - 1 ); - break; - } - else - { - p[x] = (unsigned char)( p[x] + p[x - i] ); - if ( p[x] == bitmap->num_grays - 1 ) - break; - } - } - else - break; - } - } - } - - /* - * Vertically: - * - * Make the above `ystr' rows or'ed with it. - */ - for ( x = 1; x <= ystr; x++ ) - { - unsigned char* q; - - - q = p - bitmap->pitch * x; - for ( i = 0; i < pitch; i++ ) - q[i] |= p[i]; - } - - p += bitmap->pitch; - } - - bitmap->width += (FT_UInt)xstr; - bitmap->rows += (FT_UInt)ystr; - - return FT_Err_Ok; - } - - - static FT_Byte - ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra ) - { - FT_UInt a = bgra[3]; - FT_UInt l; - - - /* Short-circuit transparent color to avoid division by zero. */ - if ( !a ) - return 0; - - /* - * Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722 - * coefficients for RGB channels *on the linear colors*. - * A gamma of 2.2 is fair to assume. And then, we need to - * undo the premultiplication too. - * - * http://accessibility.kde.org/hsl-adjusted.php - * - * We do the computation with integers only, applying a gamma of 2.0. - * We guarantee 32-bit arithmetic to avoid overflow but the resulting - * luminosity fits into 16 bits. - * - */ - - l = ( 4732UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] + - 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] + - 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2] ) >> 16; - - /* - * Final transparency can be determined as follows. - * - * - If alpha is zero, we want 0. - * - If alpha is zero and luminosity is zero, we want 255. - * - If alpha is zero and luminosity is one, we want 0. - * - * So the formula is a * (1 - l) = a - l * a. - * - * We still need to undo premultiplication by dividing l by a*a. - * - */ - - return (FT_Byte)( a - l / a ); - } - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Bitmap_Convert( FT_Library library, - const FT_Bitmap *source, - FT_Bitmap *target, - FT_Int alignment ) - { - FT_Error error = FT_Err_Ok; - FT_Memory memory; - - FT_Byte* s; - FT_Byte* t; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !source || !target ) - return FT_THROW( Invalid_Argument ); - - memory = library->memory; - - switch ( source->pixel_mode ) - { - case FT_PIXEL_MODE_MONO: - case FT_PIXEL_MODE_GRAY: - case FT_PIXEL_MODE_GRAY2: - case FT_PIXEL_MODE_GRAY4: - case FT_PIXEL_MODE_LCD: - case FT_PIXEL_MODE_LCD_V: - case FT_PIXEL_MODE_BGRA: - { - FT_Int pad, old_target_pitch, target_pitch; - FT_ULong old_size; - - - old_target_pitch = target->pitch; - if ( old_target_pitch < 0 ) - old_target_pitch = -old_target_pitch; - - old_size = target->rows * (FT_UInt)old_target_pitch; - - target->pixel_mode = FT_PIXEL_MODE_GRAY; - target->rows = source->rows; - target->width = source->width; - - pad = 0; - if ( alignment > 0 ) - { - pad = (FT_Int)source->width % alignment; - if ( pad != 0 ) - pad = alignment - pad; - } - - target_pitch = (FT_Int)source->width + pad; - - if ( target_pitch > 0 && - (FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch ) - return FT_THROW( Invalid_Argument ); - - if ( target->rows * (FT_ULong)target_pitch > old_size && - FT_QREALLOC( target->buffer, - old_size, target->rows * (FT_UInt)target_pitch ) ) - return error; - - target->pitch = target->pitch < 0 ? -target_pitch : target_pitch; - } - break; - - default: - error = FT_THROW( Invalid_Argument ); - } - - s = source->buffer; - t = target->buffer; - - /* take care of bitmap flow */ - if ( source->pitch < 0 ) - s -= source->pitch * (FT_Int)( source->rows - 1 ); - if ( target->pitch < 0 ) - t -= target->pitch * (FT_Int)( target->rows - 1 ); - - switch ( source->pixel_mode ) - { - case FT_PIXEL_MODE_MONO: - { - FT_UInt i; - - - target->num_grays = 2; - - for ( i = source->rows; i > 0; i-- ) - { - FT_Byte* ss = s; - FT_Byte* tt = t; - FT_UInt j; - - - /* get the full bytes */ - for ( j = source->width >> 3; j > 0; j-- ) - { - FT_Int val = ss[0]; /* avoid a byte->int cast on each line */ - - - tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 ); - tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 ); - tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 ); - tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 ); - tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 ); - tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 ); - tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 ); - tt[7] = (FT_Byte)( val & 0x01 ); - - tt += 8; - ss += 1; - } - - /* get remaining pixels (if any) */ - j = source->width & 7; - if ( j > 0 ) - { - FT_Int val = *ss; - - - for ( ; j > 0; j-- ) - { - tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7); - val <<= 1; - tt += 1; - } - } - - s += source->pitch; - t += target->pitch; - } - } - break; - - - case FT_PIXEL_MODE_GRAY: - case FT_PIXEL_MODE_LCD: - case FT_PIXEL_MODE_LCD_V: - { - FT_UInt width = source->width; - FT_UInt i; - - - target->num_grays = 256; - - for ( i = source->rows; i > 0; i-- ) - { - FT_ARRAY_COPY( t, s, width ); - - s += source->pitch; - t += target->pitch; - } - } - break; - - - case FT_PIXEL_MODE_GRAY2: - { - FT_UInt i; - - - target->num_grays = 4; - - for ( i = source->rows; i > 0; i-- ) - { - FT_Byte* ss = s; - FT_Byte* tt = t; - FT_UInt j; - - - /* get the full bytes */ - for ( j = source->width >> 2; j > 0; j-- ) - { - FT_Int val = ss[0]; - - - tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 ); - tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 ); - tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 ); - tt[3] = (FT_Byte)( ( val & 0x03 ) ); - - ss += 1; - tt += 4; - } - - j = source->width & 3; - if ( j > 0 ) - { - FT_Int val = ss[0]; - - - for ( ; j > 0; j-- ) - { - tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 ); - val <<= 2; - tt += 1; - } - } - - s += source->pitch; - t += target->pitch; - } - } - break; - - - case FT_PIXEL_MODE_GRAY4: - { - FT_UInt i; - - - target->num_grays = 16; - - for ( i = source->rows; i > 0; i-- ) - { - FT_Byte* ss = s; - FT_Byte* tt = t; - FT_UInt j; - - - /* get the full bytes */ - for ( j = source->width >> 1; j > 0; j-- ) - { - FT_Int val = ss[0]; - - - tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 ); - tt[1] = (FT_Byte)( ( val & 0x0F ) ); - - ss += 1; - tt += 2; - } - - if ( source->width & 1 ) - tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 ); - - s += source->pitch; - t += target->pitch; - } - } - break; - - - case FT_PIXEL_MODE_BGRA: - { - FT_UInt i; - - - target->num_grays = 256; - - for ( i = source->rows; i > 0; i-- ) - { - FT_Byte* ss = s; - FT_Byte* tt = t; - FT_UInt j; - - - for ( j = source->width; j > 0; j-- ) - { - tt[0] = ft_gray_for_premultiplied_srgb_bgra( ss ); - - ss += 4; - tt += 1; - } - - s += source->pitch; - t += target->pitch; - } - } - break; - - default: - ; - } - - return error; - } - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ) - { - if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP && - !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) - { - FT_Bitmap bitmap; - FT_Error error; - - - FT_Bitmap_Init( &bitmap ); - error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap ); - if ( error ) - return error; - - slot->bitmap = bitmap; - slot->internal->flags |= FT_GLYPH_OWN_BITMAP; - } - - return FT_Err_Ok; - } - - - /* documentation is in ftbitmap.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Bitmap_Done( FT_Library library, - FT_Bitmap *bitmap ) - { - FT_Memory memory; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !bitmap ) - return FT_THROW( Invalid_Argument ); - - memory = library->memory; - - FT_FREE( bitmap->buffer ); - *bitmap = null_bitmap; - - return FT_Err_Ok; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftcalc.c b/third_party/freetype/src/base/ftcalc.c deleted file mode 100644 index f0525502f3..0000000000 --- a/third_party/freetype/src/base/ftcalc.c +++ /dev/null @@ -1,1003 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftcalc.c */ -/* */ -/* Arithmetic computations (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* Support for 1-complement arithmetic has been totally dropped in this */ - /* release. You can still write your own code if you need it. */ - /* */ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /* Implementing basic computation routines. */ - /* */ - /* FT_MulDiv(), FT_MulFix(), FT_DivFix(), FT_RoundFix(), FT_CeilFix(), */ - /* and FT_FloorFix() are declared in freetype.h. */ - /* */ - /*************************************************************************/ - - -#include -#include FT_GLYPH_H -#include FT_TRIGONOMETRY_H -#include FT_INTERNAL_CALC_H -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_OBJECTS_H - - -#ifdef FT_MULFIX_ASSEMBLER -#undef FT_MulFix -#endif - -/* we need to emulate a 64-bit data type if a real one isn't available */ - -#ifndef FT_LONG64 - - typedef struct FT_Int64_ - { - FT_UInt32 lo; - FT_UInt32 hi; - - } FT_Int64; - -#endif /* !FT_LONG64 */ - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_calc - - - /* transfer sign leaving a positive number */ -#define FT_MOVE_SIGN( x, s ) \ - FT_BEGIN_STMNT \ - if ( x < 0 ) \ - { \ - x = -x; \ - s = -s; \ - } \ - FT_END_STMNT - - /* The following three functions are available regardless of whether */ - /* FT_LONG64 is defined. */ - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_RoundFix( FT_Fixed a ) - { - return ( a + 0x8000L - ( a < 0 ) ) & ~0xFFFFL; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_CeilFix( FT_Fixed a ) - { - return ( a + 0xFFFFL ) & ~0xFFFFL; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_FloorFix( FT_Fixed a ) - { - return a & ~0xFFFFL; - } - -#ifndef FT_MSB - - FT_BASE_DEF ( FT_Int ) - FT_MSB( FT_UInt32 z ) - { - FT_Int shift = 0; - - - /* determine msb bit index in `shift' */ - if ( z & 0xFFFF0000UL ) - { - z >>= 16; - shift += 16; - } - if ( z & 0x0000FF00UL ) - { - z >>= 8; - shift += 8; - } - if ( z & 0x000000F0UL ) - { - z >>= 4; - shift += 4; - } - if ( z & 0x0000000CUL ) - { - z >>= 2; - shift += 2; - } - if ( z & 0x00000002UL ) - { - /* z >>= 1; */ - shift += 1; - } - - return shift; - } - -#endif /* !FT_MSB */ - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_Fixed ) - FT_Hypot( FT_Fixed x, - FT_Fixed y ) - { - FT_Vector v; - - - v.x = x; - v.y = y; - - return FT_Vector_Length( &v ); - } - - -#ifdef FT_LONG64 - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_MulDiv( FT_Long a_, - FT_Long b_, - FT_Long c_ ) - { - FT_Int s = 1; - FT_UInt64 a, b, c, d; - FT_Long d_; - - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - FT_MOVE_SIGN( c_, s ); - - a = (FT_UInt64)a_; - b = (FT_UInt64)b_; - c = (FT_UInt64)c_; - - d = c > 0 ? ( a * b + ( c >> 1 ) ) / c - : 0x7FFFFFFFUL; - - d_ = (FT_Long)d; - - return s < 0 ? -d_ : d_; - } - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_Long ) - FT_MulDiv_No_Round( FT_Long a_, - FT_Long b_, - FT_Long c_ ) - { - FT_Int s = 1; - FT_UInt64 a, b, c, d; - FT_Long d_; - - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - FT_MOVE_SIGN( c_, s ); - - a = (FT_UInt64)a_; - b = (FT_UInt64)b_; - c = (FT_UInt64)c_; - - d = c > 0 ? a * b / c - : 0x7FFFFFFFUL; - - d_ = (FT_Long)d; - - return s < 0 ? -d_ : d_; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_MulFix( FT_Long a_, - FT_Long b_ ) - { -#ifdef FT_MULFIX_ASSEMBLER - - return FT_MULFIX_ASSEMBLER( (FT_Int32)a_, (FT_Int32)b_ ); - -#else - - FT_Int64 ab = (FT_Int64)a_ * (FT_Int64)b_; - - /* this requires arithmetic right shift of signed numbers */ - return (FT_Long)( ( ab + 0x8000L - ( ab < 0 ) ) >> 16 ); - -#endif /* FT_MULFIX_ASSEMBLER */ - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_DivFix( FT_Long a_, - FT_Long b_ ) - { - FT_Int s = 1; - FT_UInt64 a, b, q; - FT_Long q_; - - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - - a = (FT_UInt64)a_; - b = (FT_UInt64)b_; - - q = b > 0 ? ( ( a << 16 ) + ( b >> 1 ) ) / b - : 0x7FFFFFFFUL; - - q_ = (FT_Long)q; - - return s < 0 ? -q_ : q_; - } - - -#else /* !FT_LONG64 */ - - - static void - ft_multo64( FT_UInt32 x, - FT_UInt32 y, - FT_Int64 *z ) - { - FT_UInt32 lo1, hi1, lo2, hi2, lo, hi, i1, i2; - - - lo1 = x & 0x0000FFFFU; hi1 = x >> 16; - lo2 = y & 0x0000FFFFU; hi2 = y >> 16; - - lo = lo1 * lo2; - i1 = lo1 * hi2; - i2 = lo2 * hi1; - hi = hi1 * hi2; - - /* Check carry overflow of i1 + i2 */ - i1 += i2; - hi += (FT_UInt32)( i1 < i2 ) << 16; - - hi += i1 >> 16; - i1 = i1 << 16; - - /* Check carry overflow of i1 + lo */ - lo += i1; - hi += ( lo < i1 ); - - z->lo = lo; - z->hi = hi; - } - - - static FT_UInt32 - ft_div64by32( FT_UInt32 hi, - FT_UInt32 lo, - FT_UInt32 y ) - { - FT_UInt32 r, q; - FT_Int i; - - - if ( hi >= y ) - return (FT_UInt32)0x7FFFFFFFL; - - /* We shift as many bits as we can into the high register, perform */ - /* 32-bit division with modulo there, then work through the remaining */ - /* bits with long division. This optimization is especially noticeable */ - /* for smaller dividends that barely use the high register. */ - - i = 31 - FT_MSB( hi ); - r = ( hi << i ) | ( lo >> ( 32 - i ) ); lo <<= i; /* left 64-bit shift */ - q = r / y; - r -= q * y; /* remainder */ - - i = 32 - i; /* bits remaining in low register */ - do - { - q <<= 1; - r = ( r << 1 ) | ( lo >> 31 ); lo <<= 1; - - if ( r >= y ) - { - r -= y; - q |= 1; - } - } while ( --i ); - - return q; - } - - - static void - FT_Add64( FT_Int64* x, - FT_Int64* y, - FT_Int64 *z ) - { - FT_UInt32 lo, hi; - - - lo = x->lo + y->lo; - hi = x->hi + y->hi + ( lo < x->lo ); - - z->lo = lo; - z->hi = hi; - } - - - /* The FT_MulDiv function has been optimized thanks to ideas from */ - /* Graham Asher and Alexei Podtelezhnikov. The trick is to optimize */ - /* a rather common case when everything fits within 32-bits. */ - /* */ - /* We compute 'a*b+c/2', then divide it by 'c' (all positive values). */ - /* */ - /* The product of two positive numbers never exceeds the square of */ - /* its mean values. Therefore, we always avoid the overflow by */ - /* imposing */ - /* */ - /* (a + b) / 2 <= sqrt(X - c/2) , */ - /* */ - /* where X = 2^32 - 1, the maximum unsigned 32-bit value, and using */ - /* unsigned arithmetic. Now we replace `sqrt' with a linear function */ - /* that is smaller or equal for all values of c in the interval */ - /* [0;X/2]; it should be equal to sqrt(X) and sqrt(3X/4) at the */ - /* endpoints. Substituting the linear solution and explicit numbers */ - /* we get */ - /* */ - /* a + b <= 131071.99 - c / 122291.84 . */ - /* */ - /* In practice, we should use a faster and even stronger inequality */ - /* */ - /* a + b <= 131071 - (c >> 16) */ - /* */ - /* or, alternatively, */ - /* */ - /* a + b <= 129894 - (c >> 17) . */ - /* */ - /* FT_MulFix, on the other hand, is optimized for a small value of */ - /* the first argument, when the second argument can be much larger. */ - /* This can be achieved by scaling the second argument and the limit */ - /* in the above inequalities. For example, */ - /* */ - /* a + (b >> 8) <= (131071 >> 4) */ - /* */ - /* covers the practical range of use. The actual test below is a bit */ - /* tighter to avoid the border case overflows. */ - /* */ - /* In the case of FT_DivFix, the exact overflow check */ - /* */ - /* a << 16 <= X - c/2 */ - /* */ - /* is scaled down by 2^16 and we use */ - /* */ - /* a <= 65535 - (c >> 17) . */ - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_MulDiv( FT_Long a_, - FT_Long b_, - FT_Long c_ ) - { - FT_Int s = 1; - FT_UInt32 a, b, c; - - - /* XXX: this function does not allow 64-bit arguments */ - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - FT_MOVE_SIGN( c_, s ); - - a = (FT_UInt32)a_; - b = (FT_UInt32)b_; - c = (FT_UInt32)c_; - - if ( c == 0 ) - a = 0x7FFFFFFFUL; - - else if ( a + b <= 129894UL - ( c >> 17 ) ) - a = ( a * b + ( c >> 1 ) ) / c; - - else - { - FT_Int64 temp, temp2; - - - ft_multo64( a, b, &temp ); - - temp2.hi = 0; - temp2.lo = c >> 1; - - FT_Add64( &temp, &temp2, &temp ); - - /* last attempt to ditch long division */ - a = ( temp.hi == 0 ) ? temp.lo / c - : ft_div64by32( temp.hi, temp.lo, c ); - } - - a_ = (FT_Long)a; - - return s < 0 ? -a_ : a_; - } - - - FT_BASE_DEF( FT_Long ) - FT_MulDiv_No_Round( FT_Long a_, - FT_Long b_, - FT_Long c_ ) - { - FT_Int s = 1; - FT_UInt32 a, b, c; - - - /* XXX: this function does not allow 64-bit arguments */ - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - FT_MOVE_SIGN( c_, s ); - - a = (FT_UInt32)a_; - b = (FT_UInt32)b_; - c = (FT_UInt32)c_; - - if ( c == 0 ) - a = 0x7FFFFFFFUL; - - else if ( a + b <= 131071UL ) - a = a * b / c; - - else - { - FT_Int64 temp; - - - ft_multo64( a, b, &temp ); - - /* last attempt to ditch long division */ - a = ( temp.hi == 0 ) ? temp.lo / c - : ft_div64by32( temp.hi, temp.lo, c ); - } - - a_ = (FT_Long)a; - - return s < 0 ? -a_ : a_; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_MulFix( FT_Long a_, - FT_Long b_ ) - { -#ifdef FT_MULFIX_ASSEMBLER - - return FT_MULFIX_ASSEMBLER( a_, b_ ); - -#elif 0 - - /* - * This code is nonportable. See comment below. - * - * However, on a platform where right-shift of a signed quantity fills - * the leftmost bits by copying the sign bit, it might be faster. - */ - - FT_Long sa, sb; - FT_UInt32 a, b; - - - /* - * This is a clever way of converting a signed number `a' into its - * absolute value (stored back into `a') and its sign. The sign is - * stored in `sa'; 0 means `a' was positive or zero, and -1 means `a' - * was negative. (Similarly for `b' and `sb'). - * - * Unfortunately, it doesn't work (at least not portably). - * - * It makes the assumption that right-shift on a negative signed value - * fills the leftmost bits by copying the sign bit. This is wrong. - * According to K&R 2nd ed, section `A7.8 Shift Operators' on page 206, - * the result of right-shift of a negative signed value is - * implementation-defined. At least one implementation fills the - * leftmost bits with 0s (i.e., it is exactly the same as an unsigned - * right shift). This means that when `a' is negative, `sa' ends up - * with the value 1 rather than -1. After that, everything else goes - * wrong. - */ - sa = ( a_ >> ( sizeof ( a_ ) * 8 - 1 ) ); - a = ( a_ ^ sa ) - sa; - sb = ( b_ >> ( sizeof ( b_ ) * 8 - 1 ) ); - b = ( b_ ^ sb ) - sb; - - a = (FT_UInt32)a_; - b = (FT_UInt32)b_; - - if ( a + ( b >> 8 ) <= 8190UL ) - a = ( a * b + 0x8000U ) >> 16; - else - { - FT_UInt32 al = a & 0xFFFFUL; - - - a = ( a >> 16 ) * b + al * ( b >> 16 ) + - ( ( al * ( b & 0xFFFFUL ) + 0x8000UL ) >> 16 ); - } - - sa ^= sb; - a = ( a ^ sa ) - sa; - - return (FT_Long)a; - -#else /* 0 */ - - FT_Int s = 1; - FT_UInt32 a, b; - - - /* XXX: this function does not allow 64-bit arguments */ - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - - a = (FT_UInt32)a_; - b = (FT_UInt32)b_; - - if ( a + ( b >> 8 ) <= 8190UL ) - a = ( a * b + 0x8000UL ) >> 16; - else - { - FT_UInt32 al = a & 0xFFFFUL; - - - a = ( a >> 16 ) * b + al * ( b >> 16 ) + - ( ( al * ( b & 0xFFFFUL ) + 0x8000UL ) >> 16 ); - } - - a_ = (FT_Long)a; - - return s < 0 ? -a_ : a_; - -#endif /* 0 */ - - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_DivFix( FT_Long a_, - FT_Long b_ ) - { - FT_Int s = 1; - FT_UInt32 a, b, q; - FT_Long q_; - - - /* XXX: this function does not allow 64-bit arguments */ - - FT_MOVE_SIGN( a_, s ); - FT_MOVE_SIGN( b_, s ); - - a = (FT_UInt32)a_; - b = (FT_UInt32)b_; - - if ( b == 0 ) - { - /* check for division by 0 */ - q = 0x7FFFFFFFUL; - } - else if ( a <= 65535UL - ( b >> 17 ) ) - { - /* compute result directly */ - q = ( ( a << 16 ) + ( b >> 1 ) ) / b; - } - else - { - /* we need more bits; we have to do it by hand */ - FT_Int64 temp, temp2; - - - temp.hi = a >> 16; - temp.lo = a << 16; - temp2.hi = 0; - temp2.lo = b >> 1; - - FT_Add64( &temp, &temp2, &temp ); - q = ft_div64by32( temp.hi, temp.lo, b ); - } - - q_ = (FT_Long)q; - - return s < 0 ? -q_ : q_; - } - - -#endif /* !FT_LONG64 */ - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( void ) - FT_Matrix_Multiply( const FT_Matrix* a, - FT_Matrix *b ) - { - FT_Fixed xx, xy, yx, yy; - - - if ( !a || !b ) - return; - - xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx ); - xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy ); - yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx ); - yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy ); - - b->xx = xx; b->xy = xy; - b->yx = yx; b->yy = yy; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Matrix_Invert( FT_Matrix* matrix ) - { - FT_Pos delta, xx, yy; - - - if ( !matrix ) - return FT_THROW( Invalid_Argument ); - - /* compute discriminant */ - delta = FT_MulFix( matrix->xx, matrix->yy ) - - FT_MulFix( matrix->xy, matrix->yx ); - - if ( !delta ) - return FT_THROW( Invalid_Argument ); /* matrix can't be inverted */ - - matrix->xy = - FT_DivFix( matrix->xy, delta ); - matrix->yx = - FT_DivFix( matrix->yx, delta ); - - xx = matrix->xx; - yy = matrix->yy; - - matrix->xx = FT_DivFix( yy, delta ); - matrix->yy = FT_DivFix( xx, delta ); - - return FT_Err_Ok; - } - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( void ) - FT_Matrix_Multiply_Scaled( const FT_Matrix* a, - FT_Matrix *b, - FT_Long scaling ) - { - FT_Fixed xx, xy, yx, yy; - - FT_Long val = 0x10000L * scaling; - - - if ( !a || !b ) - return; - - xx = FT_MulDiv( a->xx, b->xx, val ) + FT_MulDiv( a->xy, b->yx, val ); - xy = FT_MulDiv( a->xx, b->xy, val ) + FT_MulDiv( a->xy, b->yy, val ); - yx = FT_MulDiv( a->yx, b->xx, val ) + FT_MulDiv( a->yy, b->yx, val ); - yy = FT_MulDiv( a->yx, b->xy, val ) + FT_MulDiv( a->yy, b->yy, val ); - - b->xx = xx; b->xy = xy; - b->yx = yx; b->yy = yy; - } - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( void ) - FT_Vector_Transform_Scaled( FT_Vector* vector, - const FT_Matrix* matrix, - FT_Long scaling ) - { - FT_Pos xz, yz; - - FT_Long val = 0x10000L * scaling; - - - if ( !vector || !matrix ) - return; - - xz = FT_MulDiv( vector->x, matrix->xx, val ) + - FT_MulDiv( vector->y, matrix->xy, val ); - - yz = FT_MulDiv( vector->x, matrix->yx, val ) + - FT_MulDiv( vector->y, matrix->yy, val ); - - vector->x = xz; - vector->y = yz; - } - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_UInt32 ) - FT_Vector_NormLen( FT_Vector* vector ) - { - FT_Int32 x_ = vector->x; - FT_Int32 y_ = vector->y; - FT_Int32 b, z; - FT_UInt32 x, y, u, v, l; - FT_Int sx = 1, sy = 1, shift; - - - FT_MOVE_SIGN( x_, sx ); - FT_MOVE_SIGN( y_, sy ); - - x = (FT_UInt32)x_; - y = (FT_UInt32)y_; - - /* trivial cases */ - if ( x == 0 ) - { - if ( y > 0 ) - vector->y = sy * 0x10000; - return y; - } - else if ( y == 0 ) - { - if ( x > 0 ) - vector->x = sx * 0x10000; - return x; - } - - /* Estimate length and prenormalize by shifting so that */ - /* the new approximate length is between 2/3 and 4/3. */ - /* The magic constant 0xAAAAAAAAUL (2/3 of 2^32) helps */ - /* achieve this in 16.16 fixed-point representation. */ - l = x > y ? x + ( y >> 1 ) - : y + ( x >> 1 ); - - shift = 31 - FT_MSB( l ); - shift -= 15 + ( l >= ( 0xAAAAAAAAUL >> shift ) ); - - if ( shift > 0 ) - { - x <<= shift; - y <<= shift; - - /* re-estimate length for tiny vectors */ - l = x > y ? x + ( y >> 1 ) - : y + ( x >> 1 ); - } - else - { - x >>= -shift; - y >>= -shift; - l >>= -shift; - } - - /* lower linear approximation for reciprocal length minus one */ - b = 0x10000 - (FT_Int32)l; - - x_ = (FT_Int32)x; - y_ = (FT_Int32)y; - - /* Newton's iterations */ - do - { - u = (FT_UInt32)( x_ + ( x_ * b >> 16 ) ); - v = (FT_UInt32)( y_ + ( y_ * b >> 16 ) ); - - /* Normalized squared length in the parentheses approaches 2^32. */ - /* On two's complement systems, converting to signed gives the */ - /* difference with 2^32 even if the expression wraps around. */ - z = -(FT_Int32)( u * u + v * v ) / 0x200; - z = z * ( ( 0x10000 + b ) >> 8 ) / 0x10000; - - b += z; - - } while ( z > 0 ); - - vector->x = sx < 0 ? -(FT_Pos)u : (FT_Pos)u; - vector->y = sy < 0 ? -(FT_Pos)v : (FT_Pos)v; - - /* Conversion to signed helps to recover from likely wrap around */ - /* in calculating the prenormalized length, because it gives the */ - /* correct difference with 2^32 on two's complement systems. */ - l = (FT_UInt32)( 0x10000 + (FT_Int32)( u * x + v * y ) / 0x10000 ); - if ( shift > 0 ) - l = ( l + ( 1 << ( shift - 1 ) ) ) >> shift; - else - l <<= -shift; - - return l; - } - - -#if 0 - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_Int32 ) - FT_SqrtFixed( FT_Int32 x ) - { - FT_UInt32 root, rem_hi, rem_lo, test_div; - FT_Int count; - - - root = 0; - - if ( x > 0 ) - { - rem_hi = 0; - rem_lo = (FT_UInt32)x; - count = 24; - do - { - rem_hi = ( rem_hi << 2 ) | ( rem_lo >> 30 ); - rem_lo <<= 2; - root <<= 1; - test_div = ( root << 1 ) + 1; - - if ( rem_hi >= test_div ) - { - rem_hi -= test_div; - root += 1; - } - } while ( --count ); - } - - return (FT_Int32)root; - } - -#endif /* 0 */ - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_Int ) - ft_corner_orientation( FT_Pos in_x, - FT_Pos in_y, - FT_Pos out_x, - FT_Pos out_y ) - { -#ifdef FT_LONG64 - - FT_Int64 delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x; - - - return ( delta > 0 ) - ( delta < 0 ); - -#else - - FT_Int result; - - - if ( (FT_ULong)FT_ABS( in_x ) + (FT_ULong)FT_ABS( out_y ) <= 131071UL && - (FT_ULong)FT_ABS( in_y ) + (FT_ULong)FT_ABS( out_x ) <= 131071UL ) - { - FT_Long z1 = in_x * out_y; - FT_Long z2 = in_y * out_x; - - - if ( z1 > z2 ) - result = +1; - else if ( z1 < z2 ) - result = -1; - else - result = 0; - } - else /* products might overflow 32 bits */ - { - FT_Int64 z1, z2; - - - /* XXX: this function does not allow 64-bit arguments */ - ft_multo64( (FT_UInt32)in_x, (FT_UInt32)out_y, &z1 ); - ft_multo64( (FT_UInt32)in_y, (FT_UInt32)out_x, &z2 ); - - if ( z1.hi > z2.hi ) - result = +1; - else if ( z1.hi < z2.hi ) - result = -1; - else if ( z1.lo > z2.lo ) - result = +1; - else if ( z1.lo < z2.lo ) - result = -1; - else - result = 0; - } - - /* XXX: only the sign of return value, +1/0/-1 must be used */ - return result; - -#endif - } - - - /* documentation is in ftcalc.h */ - - FT_BASE_DEF( FT_Int ) - ft_corner_is_flat( FT_Pos in_x, - FT_Pos in_y, - FT_Pos out_x, - FT_Pos out_y ) - { - FT_Pos ax = in_x + out_x; - FT_Pos ay = in_y + out_y; - - FT_Pos d_in, d_out, d_hypot; - - - /* The idea of this function is to compare the length of the */ - /* hypotenuse with the `in' and `out' length. The `corner' */ - /* represented by `in' and `out' is flat if the hypotenuse's */ - /* length isn't too large. */ - /* */ - /* This approach has the advantage that the angle between */ - /* `in' and `out' is not checked. In case one of the two */ - /* vectors is `dominant', this is, much larger than the */ - /* other vector, we thus always have a flat corner. */ - /* */ - /* hypotenuse */ - /* x---------------------------x */ - /* \ / */ - /* \ / */ - /* in \ / out */ - /* \ / */ - /* o */ - /* Point */ - - d_in = FT_HYPOT( in_x, in_y ); - d_out = FT_HYPOT( out_x, out_y ); - d_hypot = FT_HYPOT( ax, ay ); - - /* now do a simple length comparison: */ - /* */ - /* d_in + d_out < 17/16 d_hypot */ - - return ( d_in + d_out - d_hypot ) < ( d_hypot >> 4 ); - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftdbgmem.c b/third_party/freetype/src/base/ftdbgmem.c deleted file mode 100644 index 242246bfd1..0000000000 --- a/third_party/freetype/src/base/ftdbgmem.c +++ /dev/null @@ -1,999 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftdbgmem.c */ -/* */ -/* Memory debugger (body). */ -/* */ -/* Copyright 2001-2017 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 -#include FT_CONFIG_CONFIG_H -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_MEMORY_H -#include FT_SYSTEM_H -#include FT_ERRORS_H -#include FT_TYPES_H - - -#ifdef FT_DEBUG_MEMORY - -#define KEEPALIVE /* `Keep alive' means that freed blocks aren't released - * to the heap. This is useful to detect double-frees - * or weird heap corruption, but it uses large amounts of - * memory, however. - */ - -#include FT_CONFIG_STANDARD_LIBRARY_H - - FT_BASE_DEF( const char* ) _ft_debug_file = NULL; - FT_BASE_DEF( long ) _ft_debug_lineno = 0; - - extern void - FT_DumpMemory( FT_Memory memory ); - - - typedef struct FT_MemSourceRec_* FT_MemSource; - typedef struct FT_MemNodeRec_* FT_MemNode; - typedef struct FT_MemTableRec_* FT_MemTable; - - -#define FT_MEM_VAL( addr ) ( (FT_PtrDist)(FT_Pointer)( addr ) ) - - /* - * This structure holds statistics for a single allocation/release - * site. This is useful to know where memory operations happen the - * most. - */ - typedef struct FT_MemSourceRec_ - { - const char* file_name; - long line_no; - - FT_Long cur_blocks; /* current number of allocated blocks */ - FT_Long max_blocks; /* max. number of allocated blocks */ - FT_Long all_blocks; /* total number of blocks allocated */ - - FT_Long cur_size; /* current cumulative allocated size */ - FT_Long max_size; /* maximum cumulative allocated size */ - FT_Long all_size; /* total cumulative allocated size */ - - FT_Long cur_max; /* current maximum allocated size */ - - FT_UInt32 hash; - FT_MemSource link; - - } FT_MemSourceRec; - - - /* - * We don't need a resizable array for the memory sources because - * their number is pretty limited within FreeType. - */ -#define FT_MEM_SOURCE_BUCKETS 128 - - /* - * This structure holds information related to a single allocated - * memory block. If KEEPALIVE is defined, blocks that are freed by - * FreeType are never released to the system. Instead, their `size' - * field is set to `-size'. This is mainly useful to detect double - * frees, at the price of a large memory footprint during execution. - */ - typedef struct FT_MemNodeRec_ - { - FT_Byte* address; - FT_Long size; /* < 0 if the block was freed */ - - FT_MemSource source; - -#ifdef KEEPALIVE - const char* free_file_name; - FT_Long free_line_no; -#endif - - FT_MemNode link; - - } FT_MemNodeRec; - - - /* - * The global structure, containing compound statistics and all hash - * tables. - */ - typedef struct FT_MemTableRec_ - { - FT_Long size; - FT_Long nodes; - FT_MemNode* buckets; - - FT_Long alloc_total; - FT_Long alloc_current; - FT_Long alloc_max; - FT_Long alloc_count; - - FT_Bool bound_total; - FT_Long alloc_total_max; - - FT_Bool bound_count; - FT_Long alloc_count_max; - - FT_MemSource sources[FT_MEM_SOURCE_BUCKETS]; - - FT_Bool keep_alive; - - FT_Memory memory; - FT_Pointer memory_user; - FT_Alloc_Func alloc; - FT_Free_Func free; - FT_Realloc_Func realloc; - - } FT_MemTableRec; - - -#define FT_MEM_SIZE_MIN 7 -#define FT_MEM_SIZE_MAX 13845163 - -#define FT_FILENAME( x ) ( (x) ? (x) : "unknown file" ) - - - /* - * Prime numbers are ugly to handle. It would be better to implement - * L-Hashing, which is 10% faster and doesn't require divisions. - */ - static const FT_Int ft_mem_primes[] = - { - 7, - 11, - 19, - 37, - 73, - 109, - 163, - 251, - 367, - 557, - 823, - 1237, - 1861, - 2777, - 4177, - 6247, - 9371, - 14057, - 21089, - 31627, - 47431, - 71143, - 106721, - 160073, - 240101, - 360163, - 540217, - 810343, - 1215497, - 1823231, - 2734867, - 4102283, - 6153409, - 9230113, - 13845163, - }; - - - static FT_Long - ft_mem_closest_prime( FT_Long num ) - { - size_t i; - - - for ( i = 0; - i < sizeof ( ft_mem_primes ) / sizeof ( ft_mem_primes[0] ); i++ ) - if ( ft_mem_primes[i] > num ) - return ft_mem_primes[i]; - - return FT_MEM_SIZE_MAX; - } - - - static void - ft_mem_debug_panic( const char* fmt, - ... ) - { - va_list ap; - - - printf( "FreeType.Debug: " ); - - va_start( ap, fmt ); - vprintf( fmt, ap ); - va_end( ap ); - - printf( "\n" ); - exit( EXIT_FAILURE ); - } - - - static FT_Pointer - ft_mem_table_alloc( FT_MemTable table, - FT_Long size ) - { - FT_Memory memory = table->memory; - FT_Pointer block; - - - memory->user = table->memory_user; - block = table->alloc( memory, size ); - memory->user = table; - - return block; - } - - - static void - ft_mem_table_free( FT_MemTable table, - FT_Pointer block ) - { - FT_Memory memory = table->memory; - - - memory->user = table->memory_user; - table->free( memory, block ); - memory->user = table; - } - - - static void - ft_mem_table_resize( FT_MemTable table ) - { - FT_Long new_size; - - - new_size = ft_mem_closest_prime( table->nodes ); - if ( new_size != table->size ) - { - FT_MemNode* new_buckets; - FT_Long i; - - - new_buckets = (FT_MemNode *) - ft_mem_table_alloc( - table, - new_size * (FT_Long)sizeof ( FT_MemNode ) ); - if ( !new_buckets ) - return; - - FT_ARRAY_ZERO( new_buckets, new_size ); - - for ( i = 0; i < table->size; i++ ) - { - FT_MemNode node, next, *pnode; - FT_PtrDist hash; - - - node = table->buckets[i]; - while ( node ) - { - next = node->link; - hash = FT_MEM_VAL( node->address ) % (FT_PtrDist)new_size; - pnode = new_buckets + hash; - - node->link = pnode[0]; - pnode[0] = node; - - node = next; - } - } - - if ( table->buckets ) - ft_mem_table_free( table, table->buckets ); - - table->buckets = new_buckets; - table->size = new_size; - } - } - - - static FT_MemTable - ft_mem_table_new( FT_Memory memory ) - { - FT_MemTable table; - - - table = (FT_MemTable)memory->alloc( memory, sizeof ( *table ) ); - if ( !table ) - goto Exit; - - FT_ZERO( table ); - - table->size = FT_MEM_SIZE_MIN; - table->nodes = 0; - - table->memory = memory; - - table->memory_user = memory->user; - - table->alloc = memory->alloc; - table->realloc = memory->realloc; - table->free = memory->free; - - table->buckets = (FT_MemNode *) - memory->alloc( - memory, - table->size * (FT_Long)sizeof ( FT_MemNode ) ); - if ( table->buckets ) - FT_ARRAY_ZERO( table->buckets, table->size ); - else - { - memory->free( memory, table ); - table = NULL; - } - - Exit: - return table; - } - - - static void - ft_mem_table_destroy( FT_MemTable table ) - { - FT_Long i; - FT_Long leak_count = 0; - FT_Long leaks = 0; - - - FT_DumpMemory( table->memory ); - - /* remove all blocks from the table, revealing leaked ones */ - for ( i = 0; i < table->size; i++ ) - { - FT_MemNode *pnode = table->buckets + i, next, node = *pnode; - - - while ( node ) - { - next = node->link; - node->link = NULL; - - if ( node->size > 0 ) - { - printf( - "leaked memory block at address %p, size %8ld in (%s:%ld)\n", - (void*)node->address, - node->size, - FT_FILENAME( node->source->file_name ), - node->source->line_no ); - - leak_count++; - leaks += node->size; - - ft_mem_table_free( table, node->address ); - } - - node->address = NULL; - node->size = 0; - - ft_mem_table_free( table, node ); - node = next; - } - table->buckets[i] = NULL; - } - - ft_mem_table_free( table, table->buckets ); - table->buckets = NULL; - - table->size = 0; - table->nodes = 0; - - /* remove all sources */ - for ( i = 0; i < FT_MEM_SOURCE_BUCKETS; i++ ) - { - FT_MemSource source, next; - - - for ( source = table->sources[i]; source != NULL; source = next ) - { - next = source->link; - ft_mem_table_free( table, source ); - } - - table->sources[i] = NULL; - } - - printf( "FreeType: total memory allocations = %ld\n", - table->alloc_total ); - printf( "FreeType: maximum memory footprint = %ld\n", - table->alloc_max ); - - ft_mem_table_free( table, table ); - - if ( leak_count > 0 ) - ft_mem_debug_panic( - "FreeType: %ld bytes of memory leaked in %ld blocks\n", - leaks, leak_count ); - - printf( "FreeType: no memory leaks detected\n" ); - } - - - static FT_MemNode* - ft_mem_table_get_nodep( FT_MemTable table, - FT_Byte* address ) - { - FT_PtrDist hash; - FT_MemNode *pnode, node; - - - hash = FT_MEM_VAL( address ); - pnode = table->buckets + ( hash % (FT_PtrDist)table->size ); - - for (;;) - { - node = pnode[0]; - if ( !node ) - break; - - if ( node->address == address ) - break; - - pnode = &node->link; - } - return pnode; - } - - - static FT_MemSource - ft_mem_table_get_source( FT_MemTable table ) - { - FT_UInt32 hash; - FT_MemSource node, *pnode; - - - /* cast to FT_PtrDist first since void* can be larger */ - /* than FT_UInt32 and GCC 4.1.1 emits a warning */ - hash = (FT_UInt32)(FT_PtrDist)(void*)_ft_debug_file + - (FT_UInt32)( 5 * _ft_debug_lineno ); - pnode = &table->sources[hash % FT_MEM_SOURCE_BUCKETS]; - - for (;;) - { - node = *pnode; - if ( !node ) - break; - - if ( node->file_name == _ft_debug_file && - node->line_no == _ft_debug_lineno ) - goto Exit; - - pnode = &node->link; - } - - node = (FT_MemSource)ft_mem_table_alloc( table, sizeof ( *node ) ); - if ( !node ) - ft_mem_debug_panic( - "not enough memory to perform memory debugging\n" ); - - node->file_name = _ft_debug_file; - node->line_no = _ft_debug_lineno; - - node->cur_blocks = 0; - node->max_blocks = 0; - node->all_blocks = 0; - - node->cur_size = 0; - node->max_size = 0; - node->all_size = 0; - - node->cur_max = 0; - - node->link = NULL; - node->hash = hash; - *pnode = node; - - Exit: - return node; - } - - - static void - ft_mem_table_set( FT_MemTable table, - FT_Byte* address, - FT_Long size, - FT_Long delta ) - { - FT_MemNode *pnode, node; - - - if ( table ) - { - FT_MemSource source; - - - pnode = ft_mem_table_get_nodep( table, address ); - node = *pnode; - if ( node ) - { - if ( node->size < 0 ) - { - /* This block was already freed. Our memory is now completely */ - /* corrupted! */ - /* This can only happen in keep-alive mode. */ - ft_mem_debug_panic( - "memory heap corrupted (allocating freed block)" ); - } - else - { - /* This block was already allocated. This means that our memory */ - /* is also corrupted! */ - ft_mem_debug_panic( - "memory heap corrupted (re-allocating allocated block at" - " %p, of size %ld)\n" - "org=%s:%d new=%s:%d\n", - node->address, node->size, - FT_FILENAME( node->source->file_name ), node->source->line_no, - FT_FILENAME( _ft_debug_file ), _ft_debug_lineno ); - } - } - - /* we need to create a new node in this table */ - node = (FT_MemNode)ft_mem_table_alloc( table, sizeof ( *node ) ); - if ( !node ) - ft_mem_debug_panic( "not enough memory to run memory tests" ); - - node->address = address; - node->size = size; - node->source = source = ft_mem_table_get_source( table ); - - if ( delta == 0 ) - { - /* this is an allocation */ - source->all_blocks++; - source->cur_blocks++; - if ( source->cur_blocks > source->max_blocks ) - source->max_blocks = source->cur_blocks; - } - - if ( size > source->cur_max ) - source->cur_max = size; - - if ( delta != 0 ) - { - /* we are growing or shrinking a reallocated block */ - source->cur_size += delta; - table->alloc_current += delta; - } - else - { - /* we are allocating a new block */ - source->cur_size += size; - table->alloc_current += size; - } - - source->all_size += size; - - if ( source->cur_size > source->max_size ) - source->max_size = source->cur_size; - - node->free_file_name = NULL; - node->free_line_no = 0; - - node->link = pnode[0]; - - pnode[0] = node; - table->nodes++; - - table->alloc_total += size; - - if ( table->alloc_current > table->alloc_max ) - table->alloc_max = table->alloc_current; - - if ( table->nodes * 3 < table->size || - table->size * 3 < table->nodes ) - ft_mem_table_resize( table ); - } - } - - - static void - ft_mem_table_remove( FT_MemTable table, - FT_Byte* address, - FT_Long delta ) - { - if ( table ) - { - FT_MemNode *pnode, node; - - - pnode = ft_mem_table_get_nodep( table, address ); - node = *pnode; - if ( node ) - { - FT_MemSource source; - - - if ( node->size < 0 ) - ft_mem_debug_panic( - "freeing memory block at %p more than once at (%s:%ld)\n" - "block allocated at (%s:%ld) and released at (%s:%ld)", - address, - FT_FILENAME( _ft_debug_file ), _ft_debug_lineno, - FT_FILENAME( node->source->file_name ), node->source->line_no, - FT_FILENAME( node->free_file_name ), node->free_line_no ); - - /* scramble the node's content for additional safety */ - FT_MEM_SET( address, 0xF3, node->size ); - - if ( delta == 0 ) - { - source = node->source; - - source->cur_blocks--; - source->cur_size -= node->size; - - table->alloc_current -= node->size; - } - - if ( table->keep_alive ) - { - /* we simply invert the node's size to indicate that the node */ - /* was freed. */ - node->size = -node->size; - node->free_file_name = _ft_debug_file; - node->free_line_no = _ft_debug_lineno; - } - else - { - table->nodes--; - - *pnode = node->link; - - node->size = 0; - node->source = NULL; - - ft_mem_table_free( table, node ); - - if ( table->nodes * 3 < table->size || - table->size * 3 < table->nodes ) - ft_mem_table_resize( table ); - } - } - else - ft_mem_debug_panic( - "trying to free unknown block at %p in (%s:%ld)\n", - address, - FT_FILENAME( _ft_debug_file ), _ft_debug_lineno ); - } - } - - - static FT_Pointer - ft_mem_debug_alloc( FT_Memory memory, - FT_Long size ) - { - FT_MemTable table = (FT_MemTable)memory->user; - FT_Byte* block; - - - if ( size <= 0 ) - ft_mem_debug_panic( "negative block size allocation (%ld)", size ); - - /* return NULL if the maximum number of allocations was reached */ - if ( table->bound_count && - table->alloc_count >= table->alloc_count_max ) - return NULL; - - /* return NULL if this allocation would overflow the maximum heap size */ - if ( table->bound_total && - table->alloc_total_max - table->alloc_current > size ) - return NULL; - - block = (FT_Byte *)ft_mem_table_alloc( table, size ); - if ( block ) - { - ft_mem_table_set( table, block, size, 0 ); - - table->alloc_count++; - } - - _ft_debug_file = ""; - _ft_debug_lineno = 0; - - return (FT_Pointer)block; - } - - - static void - ft_mem_debug_free( FT_Memory memory, - FT_Pointer block ) - { - FT_MemTable table = (FT_MemTable)memory->user; - - - if ( !block ) - ft_mem_debug_panic( "trying to free NULL in (%s:%ld)", - FT_FILENAME( _ft_debug_file ), - _ft_debug_lineno ); - - ft_mem_table_remove( table, (FT_Byte*)block, 0 ); - - if ( !table->keep_alive ) - ft_mem_table_free( table, block ); - - table->alloc_count--; - - _ft_debug_file = ""; - _ft_debug_lineno = 0; - } - - - static FT_Pointer - ft_mem_debug_realloc( FT_Memory memory, - FT_Long cur_size, - FT_Long new_size, - FT_Pointer block ) - { - FT_MemTable table = (FT_MemTable)memory->user; - FT_MemNode node, *pnode; - FT_Pointer new_block; - FT_Long delta; - - const char* file_name = FT_FILENAME( _ft_debug_file ); - FT_Long line_no = _ft_debug_lineno; - - - /* unlikely, but possible */ - if ( new_size == cur_size ) - return block; - - /* the following is valid according to ANSI C */ -#if 0 - if ( !block || !cur_size ) - ft_mem_debug_panic( "trying to reallocate NULL in (%s:%ld)", - file_name, line_no ); -#endif - - /* while the following is allowed in ANSI C also, we abort since */ - /* such case should be handled by FreeType. */ - if ( new_size <= 0 ) - ft_mem_debug_panic( - "trying to reallocate %p to size 0 (current is %ld) in (%s:%ld)", - block, cur_size, file_name, line_no ); - - /* check `cur_size' value */ - pnode = ft_mem_table_get_nodep( table, (FT_Byte*)block ); - node = *pnode; - if ( !node ) - ft_mem_debug_panic( - "trying to reallocate unknown block at %p in (%s:%ld)", - block, file_name, line_no ); - - if ( node->size <= 0 ) - ft_mem_debug_panic( - "trying to reallocate freed block at %p in (%s:%ld)", - block, file_name, line_no ); - - if ( node->size != cur_size ) - ft_mem_debug_panic( "invalid ft_realloc request for %p. cur_size is " - "%ld instead of %ld in (%s:%ld)", - block, cur_size, node->size, file_name, line_no ); - - /* return NULL if the maximum number of allocations was reached */ - if ( table->bound_count && - table->alloc_count >= table->alloc_count_max ) - return NULL; - - delta = new_size - cur_size; - - /* return NULL if this allocation would overflow the maximum heap size */ - if ( delta > 0 && - table->bound_total && - table->alloc_current + delta > table->alloc_total_max ) - return NULL; - - new_block = (FT_Pointer)ft_mem_table_alloc( table, new_size ); - if ( !new_block ) - return NULL; - - ft_mem_table_set( table, (FT_Byte*)new_block, new_size, delta ); - - ft_memcpy( new_block, block, cur_size < new_size ? (size_t)cur_size - : (size_t)new_size ); - - ft_mem_table_remove( table, (FT_Byte*)block, delta ); - - _ft_debug_file = ""; - _ft_debug_lineno = 0; - - if ( !table->keep_alive ) - ft_mem_table_free( table, block ); - - return new_block; - } - - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ) - { - FT_MemTable table; - FT_Int result = 0; - - - if ( getenv( "FT2_DEBUG_MEMORY" ) ) - { - table = ft_mem_table_new( memory ); - if ( table ) - { - const char* p; - - - memory->user = table; - memory->alloc = ft_mem_debug_alloc; - memory->realloc = ft_mem_debug_realloc; - memory->free = ft_mem_debug_free; - - p = getenv( "FT2_ALLOC_TOTAL_MAX" ); - if ( p ) - { - FT_Long total_max = ft_strtol( p, NULL, 10 ); - - - if ( total_max > 0 ) - { - table->bound_total = 1; - table->alloc_total_max = total_max; - } - } - - p = getenv( "FT2_ALLOC_COUNT_MAX" ); - if ( p ) - { - FT_Long total_count = ft_strtol( p, NULL, 10 ); - - - if ( total_count > 0 ) - { - table->bound_count = 1; - table->alloc_count_max = total_count; - } - } - - p = getenv( "FT2_KEEP_ALIVE" ); - if ( p ) - { - FT_Long keep_alive = ft_strtol( p, NULL, 10 ); - - - if ( keep_alive > 0 ) - table->keep_alive = 1; - } - - result = 1; - } - } - return result; - } - - - extern void - ft_mem_debug_done( FT_Memory memory ) - { - FT_MemTable table = (FT_MemTable)memory->user; - - - if ( table ) - { - memory->free = table->free; - memory->realloc = table->realloc; - memory->alloc = table->alloc; - - ft_mem_table_destroy( table ); - memory->user = NULL; - } - } - - - static int - ft_mem_source_compare( const void* p1, - const void* p2 ) - { - FT_MemSource s1 = *(FT_MemSource*)p1; - FT_MemSource s2 = *(FT_MemSource*)p2; - - - if ( s2->max_size > s1->max_size ) - return 1; - else if ( s2->max_size < s1->max_size ) - return -1; - else - return 0; - } - - - extern void - FT_DumpMemory( FT_Memory memory ) - { - FT_MemTable table = (FT_MemTable)memory->user; - - - if ( table ) - { - FT_MemSource* bucket = table->sources; - FT_MemSource* limit = bucket + FT_MEM_SOURCE_BUCKETS; - FT_MemSource* sources; - FT_Int nn, count; - const char* fmt; - - - count = 0; - for ( ; bucket < limit; bucket++ ) - { - FT_MemSource source = *bucket; - - - for ( ; source; source = source->link ) - count++; - } - - sources = (FT_MemSource*) - ft_mem_table_alloc( - table, count * (FT_Long)sizeof ( *sources ) ); - - count = 0; - for ( bucket = table->sources; bucket < limit; bucket++ ) - { - FT_MemSource source = *bucket; - - - for ( ; source; source = source->link ) - sources[count++] = source; - } - - ft_qsort( sources, - (size_t)count, - sizeof ( *sources ), - ft_mem_source_compare ); - - printf( "FreeType Memory Dump: " - "current=%ld max=%ld total=%ld count=%ld\n", - table->alloc_current, table->alloc_max, - table->alloc_total, table->alloc_count ); - printf( " block block sizes sizes sizes source\n" ); - printf( " count high sum highsum max location\n" ); - printf( "-------------------------------------------------\n" ); - - fmt = "%6ld %6ld %8ld %8ld %8ld %s:%d\n"; - - for ( nn = 0; nn < count; nn++ ) - { - FT_MemSource source = sources[nn]; - - - printf( fmt, - source->cur_blocks, source->max_blocks, - source->cur_size, source->max_size, source->cur_max, - FT_FILENAME( source->file_name ), - source->line_no ); - } - printf( "------------------------------------------------\n" ); - - ft_mem_table_free( table, sources ); - } - } - -#else /* !FT_DEBUG_MEMORY */ - - /* ANSI C doesn't like empty source files */ - typedef int _debug_mem_dummy; - -#endif /* !FT_DEBUG_MEMORY */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftfntfmt.c b/third_party/freetype/src/base/ftfntfmt.c deleted file mode 100644 index dcbeba0053..0000000000 --- a/third_party/freetype/src/base/ftfntfmt.c +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftfntfmt.c */ -/* */ -/* FreeType utility file for font formats (body). */ -/* */ -/* Copyright 2002-2017 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 -#include FT_FONT_FORMATS_H -#include FT_INTERNAL_OBJECTS_H -#include FT_SERVICE_FONT_FORMAT_H - - - /* documentation is in ftfntfmt.h */ - - FT_EXPORT_DEF( const char* ) - FT_Get_Font_Format( FT_Face face ) - { - const char* result = NULL; - - - if ( face ) - FT_FACE_FIND_SERVICE( face, result, FONT_FORMAT ); - - return result; - } - - - /* deprecated function name; retained for ABI compatibility */ - - FT_EXPORT_DEF( const char* ) - FT_Get_X11_Font_Format( FT_Face face ) - { - const char* result = NULL; - - - if ( face ) - FT_FACE_FIND_SERVICE( face, result, FONT_FORMAT ); - - return result; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftfstype.c b/third_party/freetype/src/base/ftfstype.c deleted file mode 100644 index cec4fb3025..0000000000 --- a/third_party/freetype/src/base/ftfstype.c +++ /dev/null @@ -1,62 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftfstype.c */ -/* */ -/* FreeType utility file to access FSType data (body). */ -/* */ -/* Copyright 2008-2017 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 -#include FT_TYPE1_TABLES_H -#include FT_TRUETYPE_TABLES_H -#include FT_INTERNAL_SERVICE_H -#include FT_SERVICE_POSTSCRIPT_INFO_H - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UShort ) - FT_Get_FSType_Flags( FT_Face face ) - { - TT_OS2* os2; - - - /* first, try to get the fs_type directly from the font */ - if ( face ) - { - FT_Service_PsInfo service = NULL; - - - FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); - - if ( service && service->ps_get_font_extra ) - { - PS_FontExtraRec extra; - - - if ( !service->ps_get_font_extra( face, &extra ) && - extra.fs_type != 0 ) - return extra.fs_type; - } - } - - /* look at FSType before fsType for Type42 */ - - if ( ( os2 = (TT_OS2*)FT_Get_Sfnt_Table( face, FT_SFNT_OS2 ) ) != NULL && - os2->version != 0xFFFFU ) - return os2->fsType; - - return 0; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftgloadr.c b/third_party/freetype/src/base/ftgloadr.c deleted file mode 100644 index 8134003b4b..0000000000 --- a/third_party/freetype/src/base/ftgloadr.c +++ /dev/null @@ -1,406 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftgloadr.c */ -/* */ -/* The FreeType glyph loader (body). */ -/* */ -/* Copyright 2002-2017 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 -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_GLYPH_LOADER_H -#include FT_INTERNAL_MEMORY_H -#include FT_INTERNAL_OBJECTS_H - -#undef FT_COMPONENT -#define FT_COMPONENT trace_gloader - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** *****/ - /***** G L Y P H L O A D E R *****/ - /***** *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /* The glyph loader is a simple object which is used to load a set of */ - /* glyphs easily. It is critical for the correct loading of composites. */ - /* */ - /* Ideally, one can see it as a stack of abstract `glyph' objects. */ - /* */ - /* loader.base Is really the bottom of the stack. It describes a */ - /* single glyph image made of the juxtaposition of */ - /* several glyphs (those `in the stack'). */ - /* */ - /* loader.current Describes the top of the stack, on which a new */ - /* glyph can be loaded. */ - /* */ - /* Rewind Clears the stack. */ - /* Prepare Set up `loader.current' for addition of a new glyph */ - /* image. */ - /* Add Add the `current' glyph image to the `base' one, */ - /* and prepare for another one. */ - /* */ - /* The glyph loader is now a base object. Each driver used to */ - /* re-implement it in one way or the other, which wasted code and */ - /* energy. */ - /* */ - /*************************************************************************/ - - - /* create a new glyph loader */ - FT_BASE_DEF( FT_Error ) - FT_GlyphLoader_New( FT_Memory memory, - FT_GlyphLoader *aloader ) - { - FT_GlyphLoader loader = NULL; - FT_Error error; - - - if ( !FT_NEW( loader ) ) - { - loader->memory = memory; - *aloader = loader; - } - return error; - } - - - /* rewind the glyph loader - reset counters to 0 */ - FT_BASE_DEF( void ) - FT_GlyphLoader_Rewind( FT_GlyphLoader loader ) - { - FT_GlyphLoad base = &loader->base; - FT_GlyphLoad current = &loader->current; - - - base->outline.n_points = 0; - base->outline.n_contours = 0; - base->num_subglyphs = 0; - - *current = *base; - } - - - /* reset the glyph loader, frees all allocated tables */ - /* and starts from zero */ - FT_BASE_DEF( void ) - FT_GlyphLoader_Reset( FT_GlyphLoader loader ) - { - FT_Memory memory = loader->memory; - - - FT_FREE( loader->base.outline.points ); - FT_FREE( loader->base.outline.tags ); - FT_FREE( loader->base.outline.contours ); - FT_FREE( loader->base.extra_points ); - FT_FREE( loader->base.subglyphs ); - - loader->base.extra_points2 = NULL; - - loader->max_points = 0; - loader->max_contours = 0; - loader->max_subglyphs = 0; - - FT_GlyphLoader_Rewind( loader ); - } - - - /* delete a glyph loader */ - FT_BASE_DEF( void ) - FT_GlyphLoader_Done( FT_GlyphLoader loader ) - { - if ( loader ) - { - FT_Memory memory = loader->memory; - - - FT_GlyphLoader_Reset( loader ); - FT_FREE( loader ); - } - } - - - /* re-adjust the `current' outline fields */ - static void - FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader ) - { - FT_Outline* base = &loader->base.outline; - FT_Outline* current = &loader->current.outline; - - - current->points = base->points + base->n_points; - current->tags = base->tags + base->n_points; - current->contours = base->contours + base->n_contours; - - /* handle extra points table - if any */ - if ( loader->use_extra ) - { - loader->current.extra_points = loader->base.extra_points + - base->n_points; - - loader->current.extra_points2 = loader->base.extra_points2 + - base->n_points; - } - } - - - FT_BASE_DEF( FT_Error ) - FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader ) - { - FT_Error error; - FT_Memory memory = loader->memory; - - - if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) ) - { - loader->use_extra = 1; - loader->base.extra_points2 = loader->base.extra_points + - loader->max_points; - - FT_GlyphLoader_Adjust_Points( loader ); - } - return error; - } - - - /* re-adjust the `current' subglyphs field */ - static void - FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader ) - { - FT_GlyphLoad base = &loader->base; - FT_GlyphLoad current = &loader->current; - - - current->subglyphs = base->subglyphs + base->num_subglyphs; - } - - - /* Ensure that we can add `n_points' and `n_contours' to our glyph. */ - /* This function reallocates its outline tables if necessary. Note that */ - /* it DOESN'T change the number of points within the loader! */ - /* */ - FT_BASE_DEF( FT_Error ) - FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader, - FT_UInt n_points, - FT_UInt n_contours ) - { - FT_Memory memory = loader->memory; - FT_Error error = FT_Err_Ok; - FT_Outline* base = &loader->base.outline; - FT_Outline* current = &loader->current.outline; - FT_Bool adjust = 0; - - FT_UInt new_max, old_max; - - - /* check points & tags */ - new_max = (FT_UInt)base->n_points + (FT_UInt)current->n_points + - n_points; - old_max = loader->max_points; - - if ( new_max > old_max ) - { - new_max = FT_PAD_CEIL( new_max, 8 ); - - if ( new_max > FT_OUTLINE_POINTS_MAX ) - return FT_THROW( Array_Too_Large ); - - if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) || - FT_RENEW_ARRAY( base->tags, old_max, new_max ) ) - goto Exit; - - if ( loader->use_extra ) - { - if ( FT_RENEW_ARRAY( loader->base.extra_points, - old_max * 2, new_max * 2 ) ) - goto Exit; - - FT_ARRAY_MOVE( loader->base.extra_points + new_max, - loader->base.extra_points + old_max, - old_max ); - - loader->base.extra_points2 = loader->base.extra_points + new_max; - } - - adjust = 1; - loader->max_points = new_max; - } - - /* check contours */ - old_max = loader->max_contours; - new_max = (FT_UInt)base->n_contours + (FT_UInt)current->n_contours + - n_contours; - if ( new_max > old_max ) - { - new_max = FT_PAD_CEIL( new_max, 4 ); - - if ( new_max > FT_OUTLINE_CONTOURS_MAX ) - return FT_THROW( Array_Too_Large ); - - if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) ) - goto Exit; - - adjust = 1; - loader->max_contours = new_max; - } - - if ( adjust ) - FT_GlyphLoader_Adjust_Points( loader ); - - Exit: - if ( error ) - FT_GlyphLoader_Reset( loader ); - - return error; - } - - - /* Ensure that we can add `n_subglyphs' to our glyph. this function */ - /* reallocates its subglyphs table if necessary. Note that it DOES */ - /* NOT change the number of subglyphs within the loader! */ - /* */ - FT_BASE_DEF( FT_Error ) - FT_GlyphLoader_CheckSubGlyphs( FT_GlyphLoader loader, - FT_UInt n_subs ) - { - FT_Memory memory = loader->memory; - FT_Error error = FT_Err_Ok; - FT_UInt new_max, old_max; - - FT_GlyphLoad base = &loader->base; - FT_GlyphLoad current = &loader->current; - - - new_max = base->num_subglyphs + current->num_subglyphs + n_subs; - old_max = loader->max_subglyphs; - if ( new_max > old_max ) - { - new_max = FT_PAD_CEIL( new_max, 2 ); - if ( FT_RENEW_ARRAY( base->subglyphs, old_max, new_max ) ) - goto Exit; - - loader->max_subglyphs = new_max; - - FT_GlyphLoader_Adjust_Subglyphs( loader ); - } - - Exit: - return error; - } - - - /* prepare loader for the addition of a new glyph on top of the base one */ - FT_BASE_DEF( void ) - FT_GlyphLoader_Prepare( FT_GlyphLoader loader ) - { - FT_GlyphLoad current = &loader->current; - - - current->outline.n_points = 0; - current->outline.n_contours = 0; - current->num_subglyphs = 0; - - FT_GlyphLoader_Adjust_Points ( loader ); - FT_GlyphLoader_Adjust_Subglyphs( loader ); - } - - - /* add current glyph to the base image -- and prepare for another */ - FT_BASE_DEF( void ) - FT_GlyphLoader_Add( FT_GlyphLoader loader ) - { - FT_GlyphLoad base; - FT_GlyphLoad current; - - FT_Int n_curr_contours; - FT_Int n_base_points; - FT_Int n; - - - if ( !loader ) - return; - - base = &loader->base; - current = &loader->current; - - n_curr_contours = current->outline.n_contours; - n_base_points = base->outline.n_points; - - base->outline.n_points = - (short)( base->outline.n_points + current->outline.n_points ); - base->outline.n_contours = - (short)( base->outline.n_contours + current->outline.n_contours ); - - base->num_subglyphs += current->num_subglyphs; - - /* adjust contours count in newest outline */ - for ( n = 0; n < n_curr_contours; n++ ) - current->outline.contours[n] = - (short)( current->outline.contours[n] + n_base_points ); - - /* prepare for another new glyph image */ - FT_GlyphLoader_Prepare( loader ); - } - - - FT_BASE_DEF( FT_Error ) - FT_GlyphLoader_CopyPoints( FT_GlyphLoader target, - FT_GlyphLoader source ) - { - FT_Error error; - FT_UInt num_points = (FT_UInt)source->base.outline.n_points; - FT_UInt num_contours = (FT_UInt)source->base.outline.n_contours; - - - error = FT_GlyphLoader_CheckPoints( target, num_points, num_contours ); - if ( !error ) - { - FT_Outline* out = &target->base.outline; - FT_Outline* in = &source->base.outline; - - - FT_ARRAY_COPY( out->points, in->points, - num_points ); - FT_ARRAY_COPY( out->tags, in->tags, - num_points ); - FT_ARRAY_COPY( out->contours, in->contours, - num_contours ); - - /* do we need to copy the extra points? */ - if ( target->use_extra && source->use_extra ) - { - FT_ARRAY_COPY( target->base.extra_points, source->base.extra_points, - num_points ); - FT_ARRAY_COPY( target->base.extra_points2, source->base.extra_points2, - num_points ); - } - - out->n_points = (short)num_points; - out->n_contours = (short)num_contours; - - FT_GlyphLoader_Adjust_Points( target ); - } - - return error; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftglyph.c b/third_party/freetype/src/base/ftglyph.c deleted file mode 100644 index 9bfb330508..0000000000 --- a/third_party/freetype/src/base/ftglyph.c +++ /dev/null @@ -1,633 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftglyph.c */ -/* */ -/* FreeType convenience functions to handle glyphs (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* This file contains the definition of several convenience functions */ - /* that can be used by client applications to easily retrieve glyph */ - /* bitmaps and outlines from a given face. */ - /* */ - /* These functions should be optional if you are writing a font server */ - /* or text layout engine on top of FreeType. However, they are pretty */ - /* handy for many other simple uses of the library. */ - /* */ - /*************************************************************************/ - - -#include -#include FT_INTERNAL_DEBUG_H - -#include FT_GLYPH_H -#include FT_OUTLINE_H -#include FT_BITMAP_H -#include FT_INTERNAL_OBJECTS_H - -#include "basepic.h" - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_glyph - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** FT_BitmapGlyph support ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - FT_CALLBACK_DEF( FT_Error ) - ft_bitmap_glyph_init( FT_Glyph bitmap_glyph, - FT_GlyphSlot slot ) - { - FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; - FT_Error error = FT_Err_Ok; - FT_Library library = FT_GLYPH( glyph )->library; - - - if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) - { - error = FT_THROW( Invalid_Glyph_Format ); - goto Exit; - } - - glyph->left = slot->bitmap_left; - glyph->top = slot->bitmap_top; - - /* do lazy copying whenever possible */ - if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) - { - glyph->bitmap = slot->bitmap; - slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; - } - else - { - FT_Bitmap_Init( &glyph->bitmap ); - error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap ); - } - - Exit: - return error; - } - - - FT_CALLBACK_DEF( FT_Error ) - ft_bitmap_glyph_copy( FT_Glyph bitmap_source, - FT_Glyph bitmap_target ) - { - FT_Library library = bitmap_source->library; - FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source; - FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target; - - - target->left = source->left; - target->top = source->top; - - return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap ); - } - - - FT_CALLBACK_DEF( void ) - ft_bitmap_glyph_done( FT_Glyph bitmap_glyph ) - { - FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; - FT_Library library = FT_GLYPH( glyph )->library; - - - FT_Bitmap_Done( library, &glyph->bitmap ); - } - - - FT_CALLBACK_DEF( void ) - ft_bitmap_glyph_bbox( FT_Glyph bitmap_glyph, - FT_BBox* cbox ) - { - FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; - - - cbox->xMin = glyph->left * 64; - cbox->xMax = cbox->xMin + (FT_Pos)( glyph->bitmap.width * 64 ); - cbox->yMax = glyph->top * 64; - cbox->yMin = cbox->yMax - (FT_Pos)( glyph->bitmap.rows * 64 ); - } - - - FT_DEFINE_GLYPH( - ft_bitmap_glyph_class, - - sizeof ( FT_BitmapGlyphRec ), - FT_GLYPH_FORMAT_BITMAP, - - ft_bitmap_glyph_init, /* FT_Glyph_InitFunc glyph_init */ - ft_bitmap_glyph_done, /* FT_Glyph_DoneFunc glyph_done */ - ft_bitmap_glyph_copy, /* FT_Glyph_CopyFunc glyph_copy */ - NULL, /* FT_Glyph_TransformFunc glyph_transform */ - ft_bitmap_glyph_bbox, /* FT_Glyph_GetBBoxFunc glyph_bbox */ - NULL /* FT_Glyph_PrepareFunc glyph_prepare */ - ) - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** FT_OutlineGlyph support ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - FT_CALLBACK_DEF( FT_Error ) - ft_outline_glyph_init( FT_Glyph outline_glyph, - FT_GlyphSlot slot ) - { - FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; - FT_Error error = FT_Err_Ok; - FT_Library library = FT_GLYPH( glyph )->library; - FT_Outline* source = &slot->outline; - FT_Outline* target = &glyph->outline; - - - /* check format in glyph slot */ - if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) - { - error = FT_THROW( Invalid_Glyph_Format ); - goto Exit; - } - - /* allocate new outline */ - error = FT_Outline_New( library, - (FT_UInt)source->n_points, - source->n_contours, - &glyph->outline ); - if ( error ) - goto Exit; - - FT_Outline_Copy( source, target ); - - Exit: - return error; - } - - - FT_CALLBACK_DEF( void ) - ft_outline_glyph_done( FT_Glyph outline_glyph ) - { - FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; - - - FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline ); - } - - - FT_CALLBACK_DEF( FT_Error ) - ft_outline_glyph_copy( FT_Glyph outline_source, - FT_Glyph outline_target ) - { - FT_OutlineGlyph source = (FT_OutlineGlyph)outline_source; - FT_OutlineGlyph target = (FT_OutlineGlyph)outline_target; - FT_Error error; - FT_Library library = FT_GLYPH( source )->library; - - - error = FT_Outline_New( library, - (FT_UInt)source->outline.n_points, - source->outline.n_contours, - &target->outline ); - if ( !error ) - FT_Outline_Copy( &source->outline, &target->outline ); - - return error; - } - - - FT_CALLBACK_DEF( void ) - ft_outline_glyph_transform( FT_Glyph outline_glyph, - const FT_Matrix* matrix, - const FT_Vector* delta ) - { - FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; - - - if ( matrix ) - FT_Outline_Transform( &glyph->outline, matrix ); - - if ( delta ) - FT_Outline_Translate( &glyph->outline, delta->x, delta->y ); - } - - - FT_CALLBACK_DEF( void ) - ft_outline_glyph_bbox( FT_Glyph outline_glyph, - FT_BBox* bbox ) - { - FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; - - - FT_Outline_Get_CBox( &glyph->outline, bbox ); - } - - - FT_CALLBACK_DEF( FT_Error ) - ft_outline_glyph_prepare( FT_Glyph outline_glyph, - FT_GlyphSlot slot ) - { - FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; - - - slot->format = FT_GLYPH_FORMAT_OUTLINE; - slot->outline = glyph->outline; - slot->outline.flags &= ~FT_OUTLINE_OWNER; - - return FT_Err_Ok; - } - - - FT_DEFINE_GLYPH( - ft_outline_glyph_class, - - sizeof ( FT_OutlineGlyphRec ), - FT_GLYPH_FORMAT_OUTLINE, - - ft_outline_glyph_init, /* FT_Glyph_InitFunc glyph_init */ - ft_outline_glyph_done, /* FT_Glyph_DoneFunc glyph_done */ - ft_outline_glyph_copy, /* FT_Glyph_CopyFunc glyph_copy */ - ft_outline_glyph_transform, /* FT_Glyph_TransformFunc glyph_transform */ - ft_outline_glyph_bbox, /* FT_Glyph_GetBBoxFunc glyph_bbox */ - ft_outline_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */ - ) - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** FT_Glyph class and API ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - static FT_Error - ft_new_glyph( FT_Library library, - const FT_Glyph_Class* clazz, - FT_Glyph* aglyph ) - { - FT_Memory memory = library->memory; - FT_Error error; - FT_Glyph glyph = NULL; - - - *aglyph = NULL; - - if ( !FT_ALLOC( glyph, clazz->glyph_size ) ) - { - glyph->library = library; - glyph->clazz = clazz; - glyph->format = clazz->glyph_format; - - *aglyph = glyph; - } - - return error; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Glyph_Copy( FT_Glyph source, - FT_Glyph *target ) - { - FT_Glyph copy; - FT_Error error; - const FT_Glyph_Class* clazz; - - - /* check arguments */ - if ( !target || !source || !source->clazz ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - *target = NULL; - - if ( !source || !source->clazz ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - clazz = source->clazz; - error = ft_new_glyph( source->library, clazz, © ); - if ( error ) - goto Exit; - - copy->advance = source->advance; - copy->format = source->format; - - if ( clazz->glyph_copy ) - error = clazz->glyph_copy( source, copy ); - - if ( error ) - FT_Done_Glyph( copy ); - else - *target = copy; - - Exit: - return error; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Glyph( FT_GlyphSlot slot, - FT_Glyph *aglyph ) - { - FT_Library library; - FT_Error error; - FT_Glyph glyph; - - const FT_Glyph_Class* clazz = NULL; - - - if ( !slot ) - return FT_THROW( Invalid_Slot_Handle ); - - library = slot->library; - - if ( !aglyph ) - return FT_THROW( Invalid_Argument ); - - /* if it is a bitmap, that's easy :-) */ - if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) - clazz = FT_BITMAP_GLYPH_CLASS_GET; - - /* if it is an outline */ - else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) - clazz = FT_OUTLINE_GLYPH_CLASS_GET; - - else - { - /* try to find a renderer that supports the glyph image format */ - FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); - - - if ( render ) - clazz = &render->glyph_class; - } - - if ( !clazz ) - { - error = FT_THROW( Invalid_Glyph_Format ); - goto Exit; - } - - /* create FT_Glyph object */ - error = ft_new_glyph( library, clazz, &glyph ); - if ( error ) - goto Exit; - - /* copy advance while converting 26.6 to 16.16 format */ - glyph->advance.x = slot->advance.x * 1024; - glyph->advance.y = slot->advance.y * 1024; - - /* now import the image from the glyph slot */ - error = clazz->glyph_init( glyph, slot ); - - /* if an error occurred, destroy the glyph */ - if ( error ) - FT_Done_Glyph( glyph ); - else - *aglyph = glyph; - - Exit: - return error; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Glyph_Transform( FT_Glyph glyph, - FT_Matrix* matrix, - FT_Vector* delta ) - { - FT_Error error = FT_Err_Ok; - - - if ( !glyph || !glyph->clazz ) - error = FT_THROW( Invalid_Argument ); - else - { - const FT_Glyph_Class* clazz = glyph->clazz; - - - if ( clazz->glyph_transform ) - { - /* transform glyph image */ - clazz->glyph_transform( glyph, matrix, delta ); - - /* transform advance vector */ - if ( matrix ) - FT_Vector_Transform( &glyph->advance, matrix ); - } - else - error = FT_THROW( Invalid_Glyph_Format ); - } - return error; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( void ) - FT_Glyph_Get_CBox( FT_Glyph glyph, - FT_UInt bbox_mode, - FT_BBox *acbox ) - { - const FT_Glyph_Class* clazz; - - - if ( !acbox ) - return; - - acbox->xMin = acbox->yMin = acbox->xMax = acbox->yMax = 0; - - if ( !glyph || !glyph->clazz ) - return; - - clazz = glyph->clazz; - if ( !clazz->glyph_bbox ) - return; - - /* retrieve bbox in 26.6 coordinates */ - clazz->glyph_bbox( glyph, acbox ); - - /* perform grid fitting if needed */ - if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT || - bbox_mode == FT_GLYPH_BBOX_PIXELS ) - { - acbox->xMin = FT_PIX_FLOOR( acbox->xMin ); - acbox->yMin = FT_PIX_FLOOR( acbox->yMin ); - acbox->xMax = FT_PIX_CEIL( acbox->xMax ); - acbox->yMax = FT_PIX_CEIL( acbox->yMax ); - } - - /* convert to integer pixels if needed */ - if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE || - bbox_mode == FT_GLYPH_BBOX_PIXELS ) - { - acbox->xMin >>= 6; - acbox->yMin >>= 6; - acbox->xMax >>= 6; - acbox->yMax >>= 6; - } - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, - FT_Render_Mode render_mode, - FT_Vector* origin, - FT_Bool destroy ) - { - FT_GlyphSlotRec dummy; - FT_GlyphSlot_InternalRec dummy_internal; - FT_Error error = FT_Err_Ok; - FT_Glyph b, glyph; - FT_BitmapGlyph bitmap = NULL; - const FT_Glyph_Class* clazz; - - /* FT_BITMAP_GLYPH_CLASS_GET dereferences `library' in PIC mode */ - FT_Library library; - - - /* check argument */ - if ( !the_glyph ) - goto Bad; - glyph = *the_glyph; - if ( !glyph ) - goto Bad; - - clazz = glyph->clazz; - library = glyph->library; - if ( !library || !clazz ) - goto Bad; - - /* when called with a bitmap glyph, do nothing and return successfully */ - if ( clazz == FT_BITMAP_GLYPH_CLASS_GET ) - goto Exit; - - if ( !clazz->glyph_prepare ) - goto Bad; - - /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */ - /* then calling FT_Render_Glyph_Internal() */ - - FT_ZERO( &dummy ); - FT_ZERO( &dummy_internal ); - dummy.internal = &dummy_internal; - dummy.library = library; - dummy.format = clazz->glyph_format; - - /* create result bitmap glyph */ - error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, &b ); - if ( error ) - goto Exit; - bitmap = (FT_BitmapGlyph)b; - -#if 1 - /* if `origin' is set, translate the glyph image */ - if ( origin ) - FT_Glyph_Transform( glyph, 0, origin ); -#else - FT_UNUSED( origin ); -#endif - - /* prepare dummy slot for rendering */ - error = clazz->glyph_prepare( glyph, &dummy ); - if ( !error ) - error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode ); - -#if 1 - if ( !destroy && origin ) - { - FT_Vector v; - - - v.x = -origin->x; - v.y = -origin->y; - FT_Glyph_Transform( glyph, 0, &v ); - } -#endif - - if ( error ) - goto Exit; - - /* in case of success, copy the bitmap to the glyph bitmap */ - error = ft_bitmap_glyph_init( (FT_Glyph)bitmap, &dummy ); - if ( error ) - goto Exit; - - /* copy advance */ - bitmap->root.advance = glyph->advance; - - if ( destroy ) - FT_Done_Glyph( glyph ); - - *the_glyph = FT_GLYPH( bitmap ); - - Exit: - if ( error && bitmap ) - FT_Done_Glyph( FT_GLYPH( bitmap ) ); - - return error; - - Bad: - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - - /* documentation is in ftglyph.h */ - - FT_EXPORT_DEF( void ) - FT_Done_Glyph( FT_Glyph glyph ) - { - if ( glyph ) - { - FT_Memory memory = glyph->library->memory; - const FT_Glyph_Class* clazz = glyph->clazz; - - - if ( clazz->glyph_done ) - clazz->glyph_done( glyph ); - - FT_FREE( glyph ); - } - } - - -/* END */ diff --git a/third_party/freetype/src/base/fthash.c b/third_party/freetype/src/base/fthash.c deleted file mode 100644 index 21bc8dd5b4..0000000000 --- a/third_party/freetype/src/base/fthash.c +++ /dev/null @@ -1,339 +0,0 @@ -/***************************************************************************/ -/* */ -/* fthash.c */ -/* */ -/* Hashing functions (body). */ -/* */ -/***************************************************************************/ - -/* - * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001-2015 - * Francesco Zappa Nardelli - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT - * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - /*************************************************************************/ - /* */ - /* This file is based on code from bdf.c,v 1.22 2000/03/16 20:08:50 */ - /* */ - /* taken from Mark Leisher's xmbdfed package */ - /* */ - /*************************************************************************/ - - -#include -#include FT_INTERNAL_HASH_H -#include FT_INTERNAL_MEMORY_H - - -#define INITIAL_HT_SIZE 241 - - - static FT_ULong - hash_str_lookup( FT_Hashkey* key ) - { - const char* kp = key->str; - FT_ULong res = 0; - - - /* Mocklisp hash function. */ - while ( *kp ) - res = ( res << 5 ) - res + (FT_ULong)*kp++; - - return res; - } - - - static FT_ULong - hash_num_lookup( FT_Hashkey* key ) - { - FT_ULong num = (FT_ULong)key->num; - FT_ULong res; - - - /* Mocklisp hash function. */ - res = num & 0xFF; - res = ( res << 5 ) - res + ( ( num >> 8 ) & 0xFF ); - res = ( res << 5 ) - res + ( ( num >> 16 ) & 0xFF ); - res = ( res << 5 ) - res + ( ( num >> 24 ) & 0xFF ); - - return res; - } - - - static FT_Bool - hash_str_compare( FT_Hashkey* a, - FT_Hashkey* b ) - { - if ( a->str[0] == b->str[0] && - ft_strcmp( a->str, b->str ) == 0 ) - return 1; - - return 0; - } - - - static FT_Bool - hash_num_compare( FT_Hashkey* a, - FT_Hashkey* b ) - { - if ( a->num == b->num ) - return 1; - - return 0; - } - - - static FT_Hashnode* - hash_bucket( FT_Hashkey key, - FT_Hash hash ) - { - FT_ULong res = 0; - FT_Hashnode* bp = hash->table; - FT_Hashnode* ndp; - - - res = (hash->lookup)( &key ); - - ndp = bp + ( res % hash->size ); - while ( *ndp ) - { - if ( (hash->compare)( &(*ndp)->key, &key ) ) - break; - - ndp--; - if ( ndp < bp ) - ndp = bp + ( hash->size - 1 ); - } - - return ndp; - } - - - static FT_Error - hash_rehash( FT_Hash hash, - FT_Memory memory ) - { - FT_Hashnode* obp = hash->table; - FT_Hashnode* bp; - FT_Hashnode* nbp; - - FT_UInt i, sz = hash->size; - FT_Error error = FT_Err_Ok; - - - hash->size <<= 1; - hash->limit = hash->size / 3; - - if ( FT_NEW_ARRAY( hash->table, hash->size ) ) - goto Exit; - - for ( i = 0, bp = obp; i < sz; i++, bp++ ) - { - if ( *bp ) - { - nbp = hash_bucket( (*bp)->key, hash ); - *nbp = *bp; - } - } - - FT_FREE( obp ); - - Exit: - return error; - } - - - static FT_Error - hash_init( FT_Hash hash, - FT_Bool is_num, - FT_Memory memory ) - { - FT_UInt sz = INITIAL_HT_SIZE; - FT_Error error; - - - hash->size = sz; - hash->limit = sz / 3; - hash->used = 0; - - if ( is_num ) - { - hash->lookup = hash_num_lookup; - hash->compare = hash_num_compare; - } - else - { - hash->lookup = hash_str_lookup; - hash->compare = hash_str_compare; - } - - FT_MEM_NEW_ARRAY( hash->table, sz ); - - return error; - } - - - FT_Error - ft_hash_str_init( FT_Hash hash, - FT_Memory memory ) - { - return hash_init( hash, 0, memory ); - } - - - FT_Error - ft_hash_num_init( FT_Hash hash, - FT_Memory memory ) - { - return hash_init( hash, 1, memory ); - } - - - void - ft_hash_str_free( FT_Hash hash, - FT_Memory memory ) - { - if ( hash ) - { - FT_UInt sz = hash->size; - FT_Hashnode* bp = hash->table; - FT_UInt i; - - - for ( i = 0; i < sz; i++, bp++ ) - FT_FREE( *bp ); - - FT_FREE( hash->table ); - } - } - - - /* `ft_hash_num_free' is the same as `ft_hash_str_free' */ - - - static FT_Error - hash_insert( FT_Hashkey key, - size_t data, - FT_Hash hash, - FT_Memory memory ) - { - FT_Hashnode nn; - FT_Hashnode* bp = hash_bucket( key, hash ); - FT_Error error = FT_Err_Ok; - - - nn = *bp; - if ( !nn ) - { - if ( FT_NEW( nn ) ) - goto Exit; - *bp = nn; - - nn->key = key; - nn->data = data; - - if ( hash->used >= hash->limit ) - { - error = hash_rehash( hash, memory ); - if ( error ) - goto Exit; - } - - hash->used++; - } - else - nn->data = data; - - Exit: - return error; - } - - - FT_Error - ft_hash_str_insert( const char* key, - size_t data, - FT_Hash hash, - FT_Memory memory ) - { - FT_Hashkey hk; - - - hk.str = key; - - return hash_insert( hk, data, hash, memory ); - } - - - FT_Error - ft_hash_num_insert( FT_Int num, - size_t data, - FT_Hash hash, - FT_Memory memory ) - { - FT_Hashkey hk; - - - hk.num = num; - - return hash_insert( hk, data, hash, memory ); - } - - - static size_t* - hash_lookup( FT_Hashkey key, - FT_Hash hash ) - { - FT_Hashnode* np = hash_bucket( key, hash ); - - - return (*np) ? &(*np)->data - : NULL; - } - - - size_t* - ft_hash_str_lookup( const char* key, - FT_Hash hash ) - { - FT_Hashkey hk; - - - hk.str = key; - - return hash_lookup( hk, hash ); - } - - - size_t* - ft_hash_num_lookup( FT_Int num, - FT_Hash hash ) - { - FT_Hashkey hk; - - - hk.num = num; - - return hash_lookup( hk, hash ); - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftinit.c b/third_party/freetype/src/base/ftinit.c deleted file mode 100644 index 1c4b76f567..0000000000 --- a/third_party/freetype/src/base/ftinit.c +++ /dev/null @@ -1,397 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftinit.c */ -/* */ -/* FreeType initialization layer (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* The purpose of this file is to implement the following two */ - /* functions: */ - /* */ - /* FT_Add_Default_Modules(): */ - /* This function is used to add the set of default modules to a */ - /* fresh new library object. The set is taken from the header file */ - /* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */ - /* Build System' for more information. */ - /* */ - /* FT_Init_FreeType(): */ - /* This function creates a system object for the current platform, */ - /* builds a library out of it, then calls FT_Default_Drivers(). */ - /* */ - /* Note that even if FT_Init_FreeType() uses the implementation of the */ - /* system object defined at build time, client applications are still */ - /* able to provide their own `ftsystem.c'. */ - /* */ - /*************************************************************************/ - - -#include -#include FT_CONFIG_CONFIG_H -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_DEBUG_H -#include FT_MODULE_H -#include "basepic.h" - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_init - - -#ifndef FT_CONFIG_OPTION_PIC - - -#undef FT_USE_MODULE -#ifdef __cplusplus -#define FT_USE_MODULE( type, x ) extern "C" const type x; -#else -#define FT_USE_MODULE( type, x ) extern const type x; -#endif - -#include FT_CONFIG_MODULES_H - -#undef FT_USE_MODULE -#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), - - static - const FT_Module_Class* const ft_default_modules[] = - { -#include FT_CONFIG_MODULES_H - 0 - }; - - -#else /* FT_CONFIG_OPTION_PIC */ - - -#ifdef __cplusplus -#define FT_EXTERNC extern "C" -#else -#define FT_EXTERNC extern -#endif - - /* declare the module's class creation/destruction functions */ -#undef FT_USE_MODULE -#define FT_USE_MODULE( type, x ) \ - FT_EXTERNC FT_Error \ - FT_Create_Class_ ## x( FT_Library library, \ - FT_Module_Class* *output_class ); \ - FT_EXTERNC void \ - FT_Destroy_Class_ ## x( FT_Library library, \ - FT_Module_Class* clazz ); - -#include FT_CONFIG_MODULES_H - - /* count all module classes */ -#undef FT_USE_MODULE -#define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x, - - enum - { -#include FT_CONFIG_MODULES_H - FT_NUM_MODULE_CLASSES - }; - - /* destroy all module classes */ -#undef FT_USE_MODULE -#define FT_USE_MODULE( type, x ) \ - if ( classes[i] ) \ - { \ - FT_Destroy_Class_ ## x( library, classes[i] ); \ - } \ - i++; - - - FT_BASE_DEF( void ) - ft_destroy_default_module_classes( FT_Library library ) - { - FT_Module_Class* *classes; - FT_Memory memory; - FT_UInt i; - BasePIC* pic_container = (BasePIC*)library->pic_container.base; - - - if ( !pic_container->default_module_classes ) - return; - - memory = library->memory; - classes = pic_container->default_module_classes; - i = 0; - -#include FT_CONFIG_MODULES_H - - FT_FREE( classes ); - pic_container->default_module_classes = NULL; - } - - - /* initialize all module classes and the pointer table */ -#undef FT_USE_MODULE -#define FT_USE_MODULE( type, x ) \ - error = FT_Create_Class_ ## x( library, &clazz ); \ - if ( error ) \ - goto Exit; \ - classes[i++] = clazz; - - - FT_BASE_DEF( FT_Error ) - ft_create_default_module_classes( FT_Library library ) - { - FT_Error error; - FT_Memory memory; - FT_Module_Class* *classes = NULL; - FT_Module_Class* clazz; - FT_UInt i; - BasePIC* pic_container = (BasePIC*)library->pic_container.base; - - - memory = library->memory; - - pic_container->default_module_classes = NULL; - - if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) * - ( FT_NUM_MODULE_CLASSES + 1 ) ) ) - return error; - - /* initialize all pointers to 0, especially the last one */ - for ( i = 0; i < FT_NUM_MODULE_CLASSES; i++ ) - classes[i] = NULL; - classes[FT_NUM_MODULE_CLASSES] = NULL; - - i = 0; - -#include FT_CONFIG_MODULES_H - - Exit: - if ( error ) - ft_destroy_default_module_classes( library ); - else - pic_container->default_module_classes = classes; - - return error; - } - - -#endif /* FT_CONFIG_OPTION_PIC */ - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( void ) - FT_Add_Default_Modules( FT_Library library ) - { - FT_Error error; - const FT_Module_Class* const* cur; - - - /* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */ -#ifdef FT_CONFIG_OPTION_PIC - if ( !library ) - return; -#endif - - /* GCC 4.6 warns the type difference: - * FT_Module_Class** != const FT_Module_Class* const* - */ - cur = (const FT_Module_Class* const*)FT_DEFAULT_MODULES_GET; - - /* test for valid `library' delayed to FT_Add_Module() */ - while ( *cur ) - { - error = FT_Add_Module( library, *cur ); - /* notify errors, but don't stop */ - if ( error ) - FT_TRACE0(( "FT_Add_Default_Module:" - " Cannot install `%s', error = 0x%x\n", - (*cur)->module_name, error )); - cur++; - } - } - - -#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES - -#define MAX_LENGTH 128 - - /* - * Set default properties derived from the `FREETYPE_PROPERTIES' - * environment variable. - * - * `FREETYPE_PROPERTIES' has the following syntax form (broken here into - * multiple lines for better readability) - * - * - * ':' - * '=' - * - * ':' - * '=' - * ... - * - * Example: - * - * FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ - * cff:no-stem-darkening=1 \ - * autofitter:warping=1 - * - */ - - static void - ft_set_default_properties( FT_Library library ) - { - const char* env; - const char* p; - const char* q; - - char module_name[MAX_LENGTH + 1]; - char property_name[MAX_LENGTH + 1]; - char property_value[MAX_LENGTH + 1]; - - int i; - - - env = ft_getenv( "FREETYPE_PROPERTIES" ); - if ( !env ) - return; - - for ( p = env; *p; p++ ) - { - /* skip leading whitespace and separators */ - if ( *p == ' ' || *p == '\t' ) - continue; - - /* read module name, followed by `:' */ - q = p; - for ( i = 0; i < MAX_LENGTH; i++ ) - { - if ( !*p || *p == ':' ) - break; - module_name[i] = *p++; - } - module_name[i] = '\0'; - - if ( !*p || *p != ':' || p == q ) - break; - - /* read property name, followed by `=' */ - q = ++p; - for ( i = 0; i < MAX_LENGTH; i++ ) - { - if ( !*p || *p == '=' ) - break; - property_name[i] = *p++; - } - property_name[i] = '\0'; - - if ( !*p || *p != '=' || p == q ) - break; - - /* read property value, followed by whitespace (if any) */ - q = ++p; - for ( i = 0; i < MAX_LENGTH; i++ ) - { - if ( !*p || *p == ' ' || *p == '\t' ) - break; - property_value[i] = *p++; - } - property_value[i] = '\0'; - - if ( !( *p == '\0' || *p == ' ' || *p == '\t' ) || p == q ) - break; - - /* we completely ignore errors */ - ft_property_string_set( library, - module_name, - property_name, - property_value ); - } - } - -#else - - static void - ft_set_default_properties( FT_Library library ) - { - FT_UNUSED( library ); - } - -#endif - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Init_FreeType( FT_Library *alibrary ) - { - FT_Error error; - FT_Memory memory; - - - /* check of `alibrary' delayed to `FT_New_Library' */ - - /* First of all, allocate a new system object -- this function is part */ - /* of the system-specific component, i.e. `ftsystem.c'. */ - - memory = FT_New_Memory(); - if ( !memory ) - { - FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" )); - return FT_THROW( Unimplemented_Feature ); - } - - /* build a library out of it, then fill it with the set of */ - /* default drivers. */ - - error = FT_New_Library( memory, alibrary ); - if ( error ) - FT_Done_Memory( memory ); - else - FT_Add_Default_Modules( *alibrary ); - - ft_set_default_properties( *alibrary ); - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Done_FreeType( FT_Library library ) - { - FT_Memory memory; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - memory = library->memory; - - /* Discard the library object */ - FT_Done_Library( library ); - - /* discard memory manager */ - FT_Done_Memory( memory ); - - return FT_Err_Ok; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftlcdfil.c b/third_party/freetype/src/base/ftlcdfil.c deleted file mode 100644 index f8e1709e92..0000000000 --- a/third_party/freetype/src/base/ftlcdfil.c +++ /dev/null @@ -1,383 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftlcdfil.c */ -/* */ -/* FreeType API for color filtering of subpixel bitmap glyphs (body). */ -/* */ -/* Copyright 2006-2017 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 -#include FT_INTERNAL_DEBUG_H - -#include FT_LCD_FILTER_H -#include FT_IMAGE_H -#include FT_INTERNAL_OBJECTS_H - - -#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING - -/* define USE_LEGACY to implement the legacy filter */ -#define USE_LEGACY - - /* FIR filter used by the default and light filters */ - static void - _ft_lcd_filter_fir( FT_Bitmap* bitmap, - FT_Render_Mode mode, - FT_Library library ) - { - FT_Byte* weights = library->lcd_weights; - FT_UInt width = (FT_UInt)bitmap->width; - FT_UInt height = (FT_UInt)bitmap->rows; - - - /* horizontal in-place FIR filter */ - if ( mode == FT_RENDER_MODE_LCD && width >= 4 ) - { - FT_Byte* line = bitmap->buffer; - - - /* take care of bitmap flow */ - if ( bitmap->pitch < 0 ) - line -= bitmap->pitch * (FT_Int)( bitmap->rows - 1 ); - - /* `fir' and `pix' must be at least 32 bit wide, since the sum of */ - /* the values in `weights' can exceed 0xFF */ - - for ( ; height > 0; height--, line += bitmap->pitch ) - { - FT_UInt fir[4]; /* below, `pix' is used as the 5th element */ - FT_UInt val1, xx; - - - val1 = line[0]; - fir[0] = weights[2] * val1; - fir[1] = weights[3] * val1; - fir[2] = weights[4] * val1; - fir[3] = 0; - - val1 = line[1]; - fir[0] += weights[1] * val1; - fir[1] += weights[2] * val1; - fir[2] += weights[3] * val1; - fir[3] += weights[4] * val1; - - for ( xx = 2; xx < width; xx++ ) - { - FT_UInt val, pix; - - - val = line[xx]; - pix = fir[0] + weights[0] * val; - fir[0] = fir[1] + weights[1] * val; - fir[1] = fir[2] + weights[2] * val; - fir[2] = fir[3] + weights[3] * val; - fir[3] = weights[4] * val; - - pix >>= 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - line[xx - 2] = (FT_Byte)pix; - } - - { - FT_UInt pix; - - - pix = fir[0] >> 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - line[xx - 2] = (FT_Byte)pix; - - pix = fir[1] >> 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - line[xx - 1] = (FT_Byte)pix; - } - } - } - - /* vertical in-place FIR filter */ - else if ( mode == FT_RENDER_MODE_LCD_V && height >= 4 ) - { - FT_Byte* column = bitmap->buffer; - FT_Int pitch = bitmap->pitch; - - - /* take care of bitmap flow */ - if ( bitmap->pitch < 0 ) - column -= bitmap->pitch * (FT_Int)( bitmap->rows - 1 ); - - for ( ; width > 0; width--, column++ ) - { - FT_Byte* col = column; - FT_UInt fir[4]; /* below, `pix' is used as the 5th element */ - FT_UInt val1, yy; - - - val1 = col[0]; - fir[0] = weights[2] * val1; - fir[1] = weights[3] * val1; - fir[2] = weights[4] * val1; - fir[3] = 0; - col += pitch; - - val1 = col[0]; - fir[0] += weights[1] * val1; - fir[1] += weights[2] * val1; - fir[2] += weights[3] * val1; - fir[3] += weights[4] * val1; - col += pitch; - - for ( yy = 2; yy < height; yy++ ) - { - FT_UInt val, pix; - - - val = col[0]; - pix = fir[0] + weights[0] * val; - fir[0] = fir[1] + weights[1] * val; - fir[1] = fir[2] + weights[2] * val; - fir[2] = fir[3] + weights[3] * val; - fir[3] = weights[4] * val; - - pix >>= 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - col[-2 * pitch] = (FT_Byte)pix; - col += pitch; - } - - { - FT_UInt pix; - - - pix = fir[0] >> 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - col[-2 * pitch] = (FT_Byte)pix; - - pix = fir[1] >> 8; - pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); - col[-pitch] = (FT_Byte)pix; - } - } - } - } - - -#ifdef USE_LEGACY - - /* intra-pixel filter used by the legacy filter */ - static void - _ft_lcd_filter_legacy( FT_Bitmap* bitmap, - FT_Render_Mode mode, - FT_Library library ) - { - FT_UInt width = (FT_UInt)bitmap->width; - FT_UInt height = (FT_UInt)bitmap->rows; - FT_Int pitch = bitmap->pitch; - - static const unsigned int filters[3][3] = - { - { 65538 * 9/13, 65538 * 1/6, 65538 * 1/13 }, - { 65538 * 3/13, 65538 * 4/6, 65538 * 3/13 }, - { 65538 * 1/13, 65538 * 1/6, 65538 * 9/13 } - }; - - FT_UNUSED( library ); - - - /* horizontal in-place intra-pixel filter */ - if ( mode == FT_RENDER_MODE_LCD && width >= 3 ) - { - FT_Byte* line = bitmap->buffer; - - - /* take care of bitmap flow */ - if ( bitmap->pitch < 0 ) - line -= bitmap->pitch * (FT_Int)( bitmap->rows - 1 ); - - for ( ; height > 0; height--, line += pitch ) - { - FT_UInt xx; - - - for ( xx = 0; xx < width; xx += 3 ) - { - FT_UInt r = 0; - FT_UInt g = 0; - FT_UInt b = 0; - FT_UInt p; - - - p = line[xx]; - r += filters[0][0] * p; - g += filters[0][1] * p; - b += filters[0][2] * p; - - p = line[xx + 1]; - r += filters[1][0] * p; - g += filters[1][1] * p; - b += filters[1][2] * p; - - p = line[xx + 2]; - r += filters[2][0] * p; - g += filters[2][1] * p; - b += filters[2][2] * p; - - line[xx] = (FT_Byte)( r / 65536 ); - line[xx + 1] = (FT_Byte)( g / 65536 ); - line[xx + 2] = (FT_Byte)( b / 65536 ); - } - } - } - else if ( mode == FT_RENDER_MODE_LCD_V && height >= 3 ) - { - FT_Byte* column = bitmap->buffer; - - - /* take care of bitmap flow */ - if ( bitmap->pitch < 0 ) - column -= bitmap->pitch * (FT_Int)( bitmap->rows - 1 ); - - for ( ; width > 0; width--, column++ ) - { - FT_Byte* col = column; - FT_Byte* col_end = col + (FT_Int)height * pitch; - - - for ( ; col < col_end; col += 3 * pitch ) - { - FT_UInt r = 0; - FT_UInt g = 0; - FT_UInt b = 0; - FT_UInt p; - - - p = col[0]; - r += filters[0][0] * p; - g += filters[0][1] * p; - b += filters[0][2] * p; - - p = col[pitch]; - r += filters[1][0] * p; - g += filters[1][1] * p; - b += filters[1][2] * p; - - p = col[pitch * 2]; - r += filters[2][0] * p; - g += filters[2][1] * p; - b += filters[2][2] * p; - - col[0] = (FT_Byte)( r / 65536 ); - col[pitch] = (FT_Byte)( g / 65536 ); - col[2 * pitch] = (FT_Byte)( b / 65536 ); - } - } - } - } - -#endif /* USE_LEGACY */ - - - FT_EXPORT_DEF( FT_Error ) - FT_Library_SetLcdFilterWeights( FT_Library library, - unsigned char *weights ) - { - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !weights ) - return FT_THROW( Invalid_Argument ); - - ft_memcpy( library->lcd_weights, weights, 5 ); - library->lcd_filter_func = _ft_lcd_filter_fir; - library->lcd_extra = 2; - - return FT_Err_Ok; - } - - - FT_EXPORT_DEF( FT_Error ) - FT_Library_SetLcdFilter( FT_Library library, - FT_LcdFilter filter ) - { - static const FT_Byte default_filter[5] = - { 0x08, 0x4d, 0x56, 0x4d, 0x08 }; - static const FT_Byte light_filter[5] = - { 0x00, 0x55, 0x56, 0x55, 0x00 }; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - switch ( filter ) - { - case FT_LCD_FILTER_NONE: - library->lcd_filter_func = NULL; - library->lcd_extra = 0; - break; - - case FT_LCD_FILTER_DEFAULT: - ft_memcpy( library->lcd_weights, default_filter, 5 ); - library->lcd_filter_func = _ft_lcd_filter_fir; - library->lcd_extra = 2; - break; - - case FT_LCD_FILTER_LIGHT: - ft_memcpy( library->lcd_weights, light_filter, 5 ); - library->lcd_filter_func = _ft_lcd_filter_fir; - library->lcd_extra = 2; - break; - -#ifdef USE_LEGACY - - case FT_LCD_FILTER_LEGACY: - case FT_LCD_FILTER_LEGACY1: - library->lcd_filter_func = _ft_lcd_filter_legacy; - library->lcd_extra = 0; - break; - -#endif - - default: - return FT_THROW( Invalid_Argument ); - } - - library->lcd_filter = filter; - - return FT_Err_Ok; - } - -#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - - FT_EXPORT_DEF( FT_Error ) - FT_Library_SetLcdFilterWeights( FT_Library library, - unsigned char *weights ) - { - FT_UNUSED( library ); - FT_UNUSED( weights ); - - return FT_THROW( Unimplemented_Feature ); - } - - - FT_EXPORT_DEF( FT_Error ) - FT_Library_SetLcdFilter( FT_Library library, - FT_LcdFilter filter ) - { - FT_UNUSED( library ); - FT_UNUSED( filter ); - - return FT_THROW( Unimplemented_Feature ); - } - -#endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftmm.c b/third_party/freetype/src/base/ftmm.c deleted file mode 100644 index b8db3c5662..0000000000 --- a/third_party/freetype/src/base/ftmm.c +++ /dev/null @@ -1,402 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftmm.c */ -/* */ -/* Multiple Master font support (body). */ -/* */ -/* Copyright 1996-2017 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 -#include FT_INTERNAL_DEBUG_H - -#include FT_MULTIPLE_MASTERS_H -#include FT_INTERNAL_OBJECTS_H -#include FT_SERVICE_MULTIPLE_MASTERS_H -#include FT_SERVICE_METRICS_VARIATIONS_H - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_mm - - - static FT_Error - ft_face_get_mm_service( FT_Face face, - FT_Service_MultiMasters *aservice ) - { - FT_Error error; - - - *aservice = NULL; - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - error = FT_ERR( Invalid_Argument ); - - if ( FT_HAS_MULTIPLE_MASTERS( face ) ) - { - FT_FACE_LOOKUP_SERVICE( face, - *aservice, - MULTI_MASTERS ); - - if ( *aservice ) - error = FT_Err_Ok; - } - - return error; - } - - - static FT_Error - ft_face_get_mvar_service( FT_Face face, - FT_Service_MetricsVariations *aservice ) - { - FT_Error error; - - - *aservice = NULL; - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - error = FT_ERR( Invalid_Argument ); - - if ( FT_HAS_MULTIPLE_MASTERS( face ) ) - { - FT_FACE_LOOKUP_SERVICE( face, - *aservice, - METRICS_VARIATIONS ); - - if ( *aservice ) - error = FT_Err_Ok; - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Multi_Master( FT_Face face, - FT_Multi_Master *amaster ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !amaster ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->get_mm ) - error = service->get_mm( face, amaster ); - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_MM_Var( FT_Face face, - FT_MM_Var* *amaster ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !amaster ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->get_mm_var ) - error = service->get_mm_var( face, amaster ); - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_MM_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Long* coords ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->set_mm_design ) - error = service->set_mm_design( face, num_coords, coords ); - } - - /* enforce recomputation of auto-hinting data */ - if ( !error && face->autohint.finalizer ) - { - face->autohint.finalizer( face->autohint.data ); - face->autohint.data = NULL; - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service_mm; - FT_Service_MetricsVariations service_mvar; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service_mm ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service_mm->set_var_design ) - error = service_mm->set_var_design( face, num_coords, coords ); - } - - error = ft_face_get_mvar_service( face, &service_mvar ); - if ( !error ) - { - if ( service_mvar->metrics_adjust ) - service_mvar->metrics_adjust( face ); - } - - /* enforce recomputation of auto-hinting data */ - if ( !error && face->autohint.finalizer ) - { - face->autohint.finalizer( face->autohint.data ); - face->autohint.data = NULL; - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->get_var_design ) - error = service->get_var_design( face, num_coords, coords ); - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service_mm; - FT_Service_MetricsVariations service_mvar; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service_mm ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service_mm->set_mm_blend ) - error = service_mm->set_mm_blend( face, num_coords, coords ); - } - - error = ft_face_get_mvar_service( face, &service_mvar ); - if ( !error ) - { - if ( service_mvar->metrics_adjust ) - service_mvar->metrics_adjust( face ); - } - - /* enforce recomputation of auto-hinting data */ - if ( !error && face->autohint.finalizer ) - { - face->autohint.finalizer( face->autohint.data ); - face->autohint.data = NULL; - } - - return error; - } - - - /* documentation is in ftmm.h */ - - /* This is exactly the same as the previous function. It exists for */ - /* orthogonality. */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service_mm; - FT_Service_MetricsVariations service_mvar; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service_mm ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service_mm->set_mm_blend ) - error = service_mm->set_mm_blend( face, num_coords, coords ); - } - - error = ft_face_get_mvar_service( face, &service_mvar ); - if ( !error ) - { - if ( service_mvar->metrics_adjust ) - service_mvar->metrics_adjust( face ); - } - - /* enforce recomputation of auto-hinting data */ - if ( !error && face->autohint.finalizer ) - { - face->autohint.finalizer( face->autohint.data ); - face->autohint.data = NULL; - } - - return error; - } - - - /* documentation is in ftmm.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->get_mm_blend ) - error = service->get_mm_blend( face, num_coords, coords ); - } - - return error; - } - - - /* documentation is in ftmm.h */ - - /* This is exactly the same as the previous function. It exists for */ - /* orthogonality. */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error; - FT_Service_MultiMasters service; - - - /* check of `face' delayed to `ft_face_get_mm_service' */ - - if ( !coords ) - return FT_THROW( Invalid_Argument ); - - error = ft_face_get_mm_service( face, &service ); - if ( !error ) - { - error = FT_ERR( Invalid_Argument ); - if ( service->get_mm_blend ) - error = service->get_mm_blend( face, num_coords, coords ); - } - - return error; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftobjs.c b/third_party/freetype/src/base/ftobjs.c deleted file mode 100644 index 59d65e2a69..0000000000 --- a/third_party/freetype/src/base/ftobjs.c +++ /dev/null @@ -1,5112 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftobjs.c */ -/* */ -/* The FreeType private base classes (body). */ -/* */ -/* Copyright 1996-2017 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 -#include FT_LIST_H -#include FT_OUTLINE_H -#include FT_INTERNAL_VALIDATE_H -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_RFORK_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_SFNT_H /* for SFNT_Load_Table_Func */ -#include FT_TRUETYPE_TABLES_H -#include FT_TRUETYPE_TAGS_H -#include FT_TRUETYPE_IDS_H - -#include FT_SERVICE_PROPERTIES_H -#include FT_SERVICE_SFNT_H -#include FT_SERVICE_POSTSCRIPT_NAME_H -#include FT_SERVICE_GLYPH_DICT_H -#include FT_SERVICE_TT_CMAP_H -#include FT_SERVICE_KERNING_H -#include FT_SERVICE_TRUETYPE_ENGINE_H - -#ifdef FT_CONFIG_OPTION_MAC_FONTS -#include "ftbase.h" -#endif - - -#ifdef FT_DEBUG_LEVEL_TRACE - -#include FT_BITMAP_H - -#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: `md5.c' is non-FreeType */ - /* code, and it gets used during development builds only. */ -#pragma warning( push ) -#pragma warning( disable : 4244 ) -#endif /* _MSC_VER */ - - /* It's easiest to include `md5.c' directly. However, since OpenSSL */ - /* also provides the same functions, there might be conflicts if */ - /* both FreeType and OpenSSL are built as static libraries. For */ - /* this reason, we put the MD5 stuff into the `FT_' namespace. */ -#define MD5_u32plus FT_MD5_u32plus -#define MD5_CTX FT_MD5_CTX -#define MD5_Init FT_MD5_Init -#define MD5_Update FT_MD5_Update -#define MD5_Final FT_MD5_Final - -#undef HAVE_OPENSSL - -#include "md5.c" - -#if defined( _MSC_VER ) -#pragma warning( pop ) -#endif - -#endif /* FT_DEBUG_LEVEL_TRACE */ - - -#define GRID_FIT_METRICS - - - /* forward declaration */ - static FT_Error - ft_open_face_internal( FT_Library library, - const FT_Open_Args* args, - FT_Long face_index, - FT_Face *aface, - FT_Bool test_mac_fonts ); - - - FT_BASE_DEF( FT_Pointer ) - ft_service_list_lookup( FT_ServiceDesc service_descriptors, - const char* service_id ) - { - FT_Pointer result = NULL; - FT_ServiceDesc desc = service_descriptors; - - - if ( desc && service_id ) - { - for ( ; desc->serv_id != NULL; desc++ ) - { - if ( ft_strcmp( desc->serv_id, service_id ) == 0 ) - { - result = (FT_Pointer)desc->serv_data; - break; - } - } - } - - return result; - } - - - FT_BASE_DEF( void ) - ft_validator_init( FT_Validator valid, - const FT_Byte* base, - const FT_Byte* limit, - FT_ValidationLevel level ) - { - valid->base = base; - valid->limit = limit; - valid->level = level; - valid->error = FT_Err_Ok; - } - - - FT_BASE_DEF( FT_Int ) - ft_validator_run( FT_Validator valid ) - { - /* This function doesn't work! None should call it. */ - FT_UNUSED( valid ); - - return -1; - } - - - FT_BASE_DEF( void ) - ft_validator_error( FT_Validator valid, - FT_Error error ) - { - /* since the cast below also disables the compiler's */ - /* type check, we introduce a dummy variable, which */ - /* will be optimized away */ - volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer; - - - valid->error = error; - - /* throw away volatileness; use `jump_buffer' or the */ - /* compiler may warn about an unused local variable */ - ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 ); - } - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** S T R E A M ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - /* create a new input stream from an FT_Open_Args structure */ - /* */ - FT_BASE_DEF( FT_Error ) - FT_Stream_New( FT_Library library, - const FT_Open_Args* args, - FT_Stream *astream ) - { - FT_Error error; - FT_Memory memory; - FT_Stream stream = NULL; - - - *astream = NULL; - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !args ) - return FT_THROW( Invalid_Argument ); - - memory = library->memory; - - if ( FT_NEW( stream ) ) - goto Exit; - - stream->memory = memory; - - if ( args->flags & FT_OPEN_MEMORY ) - { - /* create a memory-based stream */ - FT_Stream_OpenMemory( stream, - (const FT_Byte*)args->memory_base, - (FT_ULong)args->memory_size ); - } - -#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT - - else if ( args->flags & FT_OPEN_PATHNAME ) - { - /* create a normal system stream */ - error = FT_Stream_Open( stream, args->pathname ); - stream->pathname.pointer = args->pathname; - } - else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream ) - { - /* use an existing, user-provided stream */ - - /* in this case, we do not need to allocate a new stream object */ - /* since the caller is responsible for closing it himself */ - FT_FREE( stream ); - stream = args->stream; - } - -#endif - - else - error = FT_THROW( Invalid_Argument ); - - if ( error ) - FT_FREE( stream ); - else - stream->memory = memory; /* just to be certain */ - - *astream = stream; - - Exit: - return error; - } - - - FT_BASE_DEF( void ) - FT_Stream_Free( FT_Stream stream, - FT_Int external ) - { - if ( stream ) - { - FT_Memory memory = stream->memory; - - - FT_Stream_Close( stream ); - - if ( !external ) - FT_FREE( stream ); - } - } - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_objs - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - static FT_Error - ft_glyphslot_init( FT_GlyphSlot slot ) - { - FT_Driver driver = slot->face->driver; - FT_Driver_Class clazz = driver->clazz; - FT_Memory memory = driver->root.memory; - FT_Error error = FT_Err_Ok; - FT_Slot_Internal internal = NULL; - - - slot->library = driver->root.library; - - if ( FT_NEW( internal ) ) - goto Exit; - - slot->internal = internal; - - if ( FT_DRIVER_USES_OUTLINES( driver ) ) - error = FT_GlyphLoader_New( memory, &internal->loader ); - - if ( !error && clazz->init_slot ) - error = clazz->init_slot( slot ); - - Exit: - return error; - } - - - FT_BASE_DEF( void ) - ft_glyphslot_free_bitmap( FT_GlyphSlot slot ) - { - if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) - { - FT_Memory memory = FT_FACE_MEMORY( slot->face ); - - - FT_FREE( slot->bitmap.buffer ); - slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; - } - else - { - /* assume that the bitmap buffer was stolen or not */ - /* allocated from the heap */ - slot->bitmap.buffer = NULL; - } - } - - - FT_BASE_DEF( void ) - ft_glyphslot_set_bitmap( FT_GlyphSlot slot, - FT_Byte* buffer ) - { - ft_glyphslot_free_bitmap( slot ); - - slot->bitmap.buffer = buffer; - - FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 ); - } - - - FT_BASE_DEF( FT_Error ) - ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot, - FT_ULong size ) - { - FT_Memory memory = FT_FACE_MEMORY( slot->face ); - FT_Error error; - - - if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) - FT_FREE( slot->bitmap.buffer ); - else - slot->internal->flags |= FT_GLYPH_OWN_BITMAP; - - (void)FT_ALLOC( slot->bitmap.buffer, size ); - return error; - } - - - static void - ft_glyphslot_clear( FT_GlyphSlot slot ) - { - /* free bitmap if needed */ - ft_glyphslot_free_bitmap( slot ); - - /* clear all public fields in the glyph slot */ - FT_ZERO( &slot->metrics ); - FT_ZERO( &slot->outline ); - - slot->bitmap.width = 0; - slot->bitmap.rows = 0; - slot->bitmap.pitch = 0; - slot->bitmap.pixel_mode = 0; - /* `slot->bitmap.buffer' has been handled by ft_glyphslot_free_bitmap */ - - slot->bitmap_left = 0; - slot->bitmap_top = 0; - slot->num_subglyphs = 0; - slot->subglyphs = NULL; - slot->control_data = NULL; - slot->control_len = 0; - slot->other = NULL; - slot->format = FT_GLYPH_FORMAT_NONE; - - slot->linearHoriAdvance = 0; - slot->linearVertAdvance = 0; - slot->lsb_delta = 0; - slot->rsb_delta = 0; - } - - - static void - ft_glyphslot_done( FT_GlyphSlot slot ) - { - FT_Driver driver = slot->face->driver; - FT_Driver_Class clazz = driver->clazz; - FT_Memory memory = driver->root.memory; - - - if ( clazz->done_slot ) - clazz->done_slot( slot ); - - /* free bitmap buffer if needed */ - ft_glyphslot_free_bitmap( slot ); - - /* slot->internal might be NULL in out-of-memory situations */ - if ( slot->internal ) - { - /* free glyph loader */ - if ( FT_DRIVER_USES_OUTLINES( driver ) ) - { - FT_GlyphLoader_Done( slot->internal->loader ); - slot->internal->loader = NULL; - } - - FT_FREE( slot->internal ); - } - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_New_GlyphSlot( FT_Face face, - FT_GlyphSlot *aslot ) - { - FT_Error error; - FT_Driver driver; - FT_Driver_Class clazz; - FT_Memory memory; - FT_GlyphSlot slot = NULL; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !face->driver ) - return FT_THROW( Invalid_Argument ); - - driver = face->driver; - clazz = driver->clazz; - memory = driver->root.memory; - - FT_TRACE4(( "FT_New_GlyphSlot: Creating new slot object\n" )); - if ( !FT_ALLOC( slot, clazz->slot_object_size ) ) - { - slot->face = face; - - error = ft_glyphslot_init( slot ); - if ( error ) - { - ft_glyphslot_done( slot ); - FT_FREE( slot ); - goto Exit; - } - - slot->next = face->glyph; - face->glyph = slot; - - if ( aslot ) - *aslot = slot; - } - else if ( aslot ) - *aslot = NULL; - - - Exit: - FT_TRACE4(( "FT_New_GlyphSlot: Return 0x%x\n", error )); - - return error; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_GlyphSlot( FT_GlyphSlot slot ) - { - if ( slot ) - { - FT_Driver driver = slot->face->driver; - FT_Memory memory = driver->root.memory; - FT_GlyphSlot prev; - FT_GlyphSlot cur; - - - /* Remove slot from its parent face's list */ - prev = NULL; - cur = slot->face->glyph; - - while ( cur ) - { - if ( cur == slot ) - { - if ( !prev ) - slot->face->glyph = cur->next; - else - prev->next = cur->next; - - /* finalize client-specific data */ - if ( slot->generic.finalizer ) - slot->generic.finalizer( slot ); - - ft_glyphslot_done( slot ); - FT_FREE( slot ); - break; - } - prev = cur; - cur = cur->next; - } - } - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( void ) - FT_Set_Transform( FT_Face face, - FT_Matrix* matrix, - FT_Vector* delta ) - { - FT_Face_Internal internal; - - - if ( !face ) - return; - - internal = face->internal; - - internal->transform_flags = 0; - - if ( !matrix ) - { - internal->transform_matrix.xx = 0x10000L; - internal->transform_matrix.xy = 0; - internal->transform_matrix.yx = 0; - internal->transform_matrix.yy = 0x10000L; - - matrix = &internal->transform_matrix; - } - else - internal->transform_matrix = *matrix; - - /* set transform_flags bit flag 0 if `matrix' isn't the identity */ - if ( ( matrix->xy | matrix->yx ) || - matrix->xx != 0x10000L || - matrix->yy != 0x10000L ) - internal->transform_flags |= 1; - - if ( !delta ) - { - internal->transform_delta.x = 0; - internal->transform_delta.y = 0; - - delta = &internal->transform_delta; - } - else - internal->transform_delta = *delta; - - /* set transform_flags bit flag 1 if `delta' isn't the null vector */ - if ( delta->x | delta->y ) - internal->transform_flags |= 2; - } - - - static FT_Renderer - ft_lookup_glyph_renderer( FT_GlyphSlot slot ); - - -#ifdef GRID_FIT_METRICS - static void - ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot, - FT_Bool vertical ) - { - FT_Glyph_Metrics* metrics = &slot->metrics; - FT_Pos right, bottom; - - - if ( vertical ) - { - metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX ); - metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY ); - - right = FT_PIX_CEIL( metrics->vertBearingX + metrics->width ); - bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height ); - - metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX ); - metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY ); - - metrics->width = right - metrics->vertBearingX; - metrics->height = bottom - metrics->vertBearingY; - } - else - { - metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX ); - metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY ); - - right = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width ); - bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height ); - - metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX ); - metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY ); - - metrics->width = right - metrics->horiBearingX; - metrics->height = metrics->horiBearingY - bottom; - } - - metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance ); - metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance ); - } -#endif /* GRID_FIT_METRICS */ - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Load_Glyph( FT_Face face, - FT_UInt glyph_index, - FT_Int32 load_flags ) - { - FT_Error error; - FT_Driver driver; - FT_GlyphSlot slot; - FT_Library library; - FT_Bool autohint = FALSE; - FT_Module hinter; - TT_Face ttface = (TT_Face)face; - - - if ( !face || !face->size || !face->glyph ) - return FT_THROW( Invalid_Face_Handle ); - - /* The validity test for `glyph_index' is performed by the */ - /* font drivers. */ - - slot = face->glyph; - ft_glyphslot_clear( slot ); - - driver = face->driver; - library = driver->root.library; - hinter = library->auto_hinter; - - /* resolve load flags dependencies */ - - if ( load_flags & FT_LOAD_NO_RECURSE ) - load_flags |= FT_LOAD_NO_SCALE | - FT_LOAD_IGNORE_TRANSFORM; - - if ( load_flags & FT_LOAD_NO_SCALE ) - { - load_flags |= FT_LOAD_NO_HINTING | - FT_LOAD_NO_BITMAP; - - load_flags &= ~FT_LOAD_RENDER; - } - - if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) - load_flags &= ~FT_LOAD_RENDER; - - /* - * Determine whether we need to auto-hint or not. - * The general rules are: - * - * - Do only auto-hinting if we have a hinter module, a scalable font - * format dealing with outlines, and no transforms except simple - * slants and/or rotations by integer multiples of 90 degrees. - * - * - Then, auto-hint if FT_LOAD_FORCE_AUTOHINT is set or if we don't - * have a native font hinter. - * - * - Otherwise, auto-hint for LIGHT hinting mode or if there isn't - * any hinting bytecode in the TrueType/OpenType font. - * - * - Exception: The font is `tricky' and requires the native hinter to - * load properly. - */ - - if ( hinter && - !( load_flags & FT_LOAD_NO_HINTING ) && - !( load_flags & FT_LOAD_NO_AUTOHINT ) && - FT_DRIVER_IS_SCALABLE( driver ) && - FT_DRIVER_USES_OUTLINES( driver ) && - !FT_IS_TRICKY( face ) && - ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) || - ( face->internal->transform_matrix.yx == 0 && - face->internal->transform_matrix.xx != 0 ) || - ( face->internal->transform_matrix.xx == 0 && - face->internal->transform_matrix.yx != 0 ) ) ) - { - if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) || - !FT_DRIVER_HAS_HINTER( driver ) ) - autohint = TRUE; - else - { - FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags ); - - - /* the check for `num_locations' assures that we actually */ - /* test for instructions in a TTF and not in a CFF-based OTF */ - /* */ - /* since `maxSizeOfInstructions' might be unreliable, we */ - /* check the size of the `fpgm' and `prep' tables, too -- */ - /* the assumption is that there don't exist real TTFs where */ - /* both `fpgm' and `prep' tables are missing */ - if ( ( mode == FT_RENDER_MODE_LIGHT && - !FT_DRIVER_HINTS_LIGHTLY( driver ) ) || - ( FT_IS_SFNT( face ) && - ttface->num_locations && - ttface->max_profile.maxSizeOfInstructions == 0 && - ttface->font_program_size == 0 && - ttface->cvt_program_size == 0 ) ) - autohint = TRUE; - } - } - - if ( autohint ) - { - FT_AutoHinter_Interface hinting; - - - /* try to load embedded bitmaps first if available */ - /* */ - /* XXX: This is really a temporary hack that should disappear */ - /* promptly with FreeType 2.1! */ - /* */ - if ( FT_HAS_FIXED_SIZES( face ) && - ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) - { - error = driver->clazz->load_glyph( slot, face->size, - glyph_index, - load_flags | FT_LOAD_SBITS_ONLY ); - - if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP ) - goto Load_Ok; - } - - { - FT_Face_Internal internal = face->internal; - FT_Int transform_flags = internal->transform_flags; - - - /* since the auto-hinter calls FT_Load_Glyph by itself, */ - /* make sure that glyphs aren't transformed */ - internal->transform_flags = 0; - - /* load auto-hinted outline */ - hinting = (FT_AutoHinter_Interface)hinter->clazz->module_interface; - - error = hinting->load_glyph( (FT_AutoHinter)hinter, - slot, face->size, - glyph_index, load_flags ); - - internal->transform_flags = transform_flags; - } - } - else - { - error = driver->clazz->load_glyph( slot, - face->size, - glyph_index, - load_flags ); - if ( error ) - goto Exit; - - if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) - { - /* check that the loaded outline is correct */ - error = FT_Outline_Check( &slot->outline ); - if ( error ) - goto Exit; - -#ifdef GRID_FIT_METRICS - if ( !( load_flags & FT_LOAD_NO_HINTING ) ) - ft_glyphslot_grid_fit_metrics( slot, - FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) ); -#endif - } - } - - Load_Ok: - /* compute the advance */ - if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) - { - slot->advance.x = 0; - slot->advance.y = slot->metrics.vertAdvance; - } - else - { - slot->advance.x = slot->metrics.horiAdvance; - slot->advance.y = 0; - } - - /* compute the linear advance in 16.16 pixels */ - if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 && - ( FT_IS_SCALABLE( face ) ) ) - { - FT_Size_Metrics* metrics = &face->size->metrics; - - - /* it's tricky! */ - slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance, - metrics->x_scale, 64 ); - - slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance, - metrics->y_scale, 64 ); - } - - if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 ) - { - FT_Face_Internal internal = face->internal; - - - /* now, transform the glyph image if needed */ - if ( internal->transform_flags ) - { - /* get renderer */ - FT_Renderer renderer = ft_lookup_glyph_renderer( slot ); - - - if ( renderer ) - error = renderer->clazz->transform_glyph( - renderer, slot, - &internal->transform_matrix, - &internal->transform_delta ); - else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) - { - /* apply `standard' transformation if no renderer is available */ - if ( internal->transform_flags & 1 ) - FT_Outline_Transform( &slot->outline, - &internal->transform_matrix ); - - if ( internal->transform_flags & 2 ) - FT_Outline_Translate( &slot->outline, - internal->transform_delta.x, - internal->transform_delta.y ); - } - - /* transform advance */ - FT_Vector_Transform( &slot->advance, &internal->transform_matrix ); - } - } - - FT_TRACE5(( " x advance: %d\n" , slot->advance.x )); - FT_TRACE5(( " y advance: %d\n" , slot->advance.y )); - - FT_TRACE5(( " linear x advance: %d\n" , slot->linearHoriAdvance )); - FT_TRACE5(( " linear y advance: %d\n" , slot->linearVertAdvance )); - - /* do we need to render the image now? */ - if ( !error && - slot->format != FT_GLYPH_FORMAT_BITMAP && - slot->format != FT_GLYPH_FORMAT_COMPOSITE && - load_flags & FT_LOAD_RENDER ) - { - FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags ); - - - if ( mode == FT_RENDER_MODE_NORMAL && - (load_flags & FT_LOAD_MONOCHROME ) ) - mode = FT_RENDER_MODE_MONO; - - error = FT_Render_Glyph( slot, mode ); - } - - Exit: - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Load_Char( FT_Face face, - FT_ULong char_code, - FT_Int32 load_flags ) - { - FT_UInt glyph_index; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - glyph_index = (FT_UInt)char_code; - if ( face->charmap ) - glyph_index = FT_Get_Char_Index( face, char_code ); - - return FT_Load_Glyph( face, glyph_index, load_flags ); - } - - - /* destructor for sizes list */ - static void - destroy_size( FT_Memory memory, - FT_Size size, - FT_Driver driver ) - { - /* finalize client-specific data */ - if ( size->generic.finalizer ) - size->generic.finalizer( size ); - - /* finalize format-specific stuff */ - if ( driver->clazz->done_size ) - driver->clazz->done_size( size ); - - FT_FREE( size->internal ); - FT_FREE( size ); - } - - - static void - ft_cmap_done_internal( FT_CMap cmap ); - - - static void - destroy_charmaps( FT_Face face, - FT_Memory memory ) - { - FT_Int n; - - - if ( !face ) - return; - - for ( n = 0; n < face->num_charmaps; n++ ) - { - FT_CMap cmap = FT_CMAP( face->charmaps[n] ); - - - ft_cmap_done_internal( cmap ); - - face->charmaps[n] = NULL; - } - - FT_FREE( face->charmaps ); - face->num_charmaps = 0; - } - - - /* destructor for faces list */ - static void - destroy_face( FT_Memory memory, - FT_Face face, - FT_Driver driver ) - { - FT_Driver_Class clazz = driver->clazz; - - - /* discard auto-hinting data */ - if ( face->autohint.finalizer ) - face->autohint.finalizer( face->autohint.data ); - - /* Discard glyph slots for this face. */ - /* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */ - while ( face->glyph ) - FT_Done_GlyphSlot( face->glyph ); - - /* discard all sizes for this face */ - FT_List_Finalize( &face->sizes_list, - (FT_List_Destructor)destroy_size, - memory, - driver ); - face->size = NULL; - - /* now discard client data */ - if ( face->generic.finalizer ) - face->generic.finalizer( face ); - - /* discard charmaps */ - destroy_charmaps( face, memory ); - - /* finalize format-specific stuff */ - if ( clazz->done_face ) - clazz->done_face( face ); - - /* close the stream for this face if needed */ - FT_Stream_Free( - face->stream, - ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 ); - - face->stream = NULL; - - /* get rid of it */ - if ( face->internal ) - { - FT_FREE( face->internal ); - } - FT_FREE( face ); - } - - - static void - Destroy_Driver( FT_Driver driver ) - { - FT_List_Finalize( &driver->faces_list, - (FT_List_Destructor)destroy_face, - driver->root.memory, - driver ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* find_unicode_charmap */ - /* */ - /* */ - /* This function finds a Unicode charmap, if there is one. */ - /* And if there is more than one, it tries to favour the more */ - /* extensive one, i.e., one that supports UCS-4 against those which */ - /* are limited to the BMP (said UCS-2 encoding.) */ - /* */ - /* This function is called from open_face() (just below), and also */ - /* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */ - /* */ - static FT_Error - find_unicode_charmap( FT_Face face ) - { - FT_CharMap* first; - FT_CharMap* cur; - - - /* caller should have already checked that `face' is valid */ - FT_ASSERT( face ); - - first = face->charmaps; - - if ( !first ) - return FT_THROW( Invalid_CharMap_Handle ); - - /* - * The original TrueType specification(s) only specified charmap - * formats that are capable of mapping 8 or 16 bit character codes to - * glyph indices. - * - * However, recent updates to the Apple and OpenType specifications - * introduced new formats that are capable of mapping 32-bit character - * codes as well. And these are already used on some fonts, mainly to - * map non-BMP Asian ideographs as defined in Unicode. - * - * For compatibility purposes, these fonts generally come with - * *several* Unicode charmaps: - * - * - One of them in the "old" 16-bit format, that cannot access - * all glyphs in the font. - * - * - Another one in the "new" 32-bit format, that can access all - * the glyphs. - * - * This function has been written to always favor a 32-bit charmap - * when found. Otherwise, a 16-bit one is returned when found. - */ - - /* Since the `interesting' table, with IDs (3,10), is normally the */ - /* last one, we loop backwards. This loses with type1 fonts with */ - /* non-BMP characters (<.0001%), this wins with .ttf with non-BMP */ - /* chars (.01% ?), and this is the same about 99.99% of the time! */ - - cur = first + face->num_charmaps; /* points after the last one */ - - for ( ; --cur >= first; ) - { - if ( cur[0]->encoding == FT_ENCODING_UNICODE ) - { - /* XXX If some new encodings to represent UCS-4 are added, */ - /* they should be added here. */ - if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT && - cur[0]->encoding_id == TT_MS_ID_UCS_4 ) || - ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE && - cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) ) - { - face->charmap = cur[0]; - return FT_Err_Ok; - } - } - } - - /* We do not have any UCS-4 charmap. */ - /* Do the loop again and search for UCS-2 charmaps. */ - cur = first + face->num_charmaps; - - for ( ; --cur >= first; ) - { - if ( cur[0]->encoding == FT_ENCODING_UNICODE ) - { - face->charmap = cur[0]; - return FT_Err_Ok; - } - } - - return FT_THROW( Invalid_CharMap_Handle ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* find_variant_selector_charmap */ - /* */ - /* */ - /* This function finds the variant selector charmap, if there is one. */ - /* There can only be one (platform=0, specific=5, format=14). */ - /* */ - static FT_CharMap - find_variant_selector_charmap( FT_Face face ) - { - FT_CharMap* first; - FT_CharMap* end; - FT_CharMap* cur; - - - /* caller should have already checked that `face' is valid */ - FT_ASSERT( face ); - - first = face->charmaps; - - if ( !first ) - return NULL; - - end = first + face->num_charmaps; /* points after the last one */ - - for ( cur = first; cur < end; cur++ ) - { - if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE && - cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR && - FT_Get_CMap_Format( cur[0] ) == 14 ) - return cur[0]; - } - - return NULL; - } - - - /*************************************************************************/ - /* */ - /* */ - /* open_face */ - /* */ - /* */ - /* This function does some work for FT_Open_Face(). */ - /* */ - static FT_Error - open_face( FT_Driver driver, - FT_Stream *astream, - FT_Bool external_stream, - FT_Long face_index, - FT_Int num_params, - FT_Parameter* params, - FT_Face *aface ) - { - FT_Memory memory; - FT_Driver_Class clazz; - FT_Face face = NULL; - FT_Face_Internal internal = NULL; - - FT_Error error, error2; - - - clazz = driver->clazz; - memory = driver->root.memory; - - /* allocate the face object and perform basic initialization */ - if ( FT_ALLOC( face, clazz->face_object_size ) ) - goto Fail; - - face->driver = driver; - face->memory = memory; - face->stream = *astream; - - /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */ - if ( external_stream ) - face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM; - - if ( FT_NEW( internal ) ) - goto Fail; - - face->internal = internal; - -#ifdef FT_CONFIG_OPTION_INCREMENTAL - { - int i; - - - face->internal->incremental_interface = NULL; - for ( i = 0; i < num_params && !face->internal->incremental_interface; - i++ ) - if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL ) - face->internal->incremental_interface = - (FT_Incremental_Interface)params[i].data; - } -#endif - - if ( clazz->init_face ) - error = clazz->init_face( *astream, - face, - (FT_Int)face_index, - num_params, - params ); - *astream = face->stream; /* Stream may have been changed. */ - if ( error ) - goto Fail; - - /* select Unicode charmap by default */ - error2 = find_unicode_charmap( face ); - - /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */ - /* is returned. */ - - /* no error should happen, but we want to play safe */ - if ( error2 && FT_ERR_NEQ( error2, Invalid_CharMap_Handle ) ) - { - error = error2; - goto Fail; - } - - *aface = face; - - Fail: - if ( error ) - { - destroy_charmaps( face, memory ); - if ( clazz->done_face ) - clazz->done_face( face ); - FT_FREE( internal ); - FT_FREE( face ); - *aface = NULL; - } - - return error; - } - - - /* there's a Mac-specific extended implementation of FT_New_Face() */ - /* in src/base/ftmac.c */ - -#ifndef FT_MACINTOSH - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_New_Face( FT_Library library, - const char* pathname, - FT_Long face_index, - FT_Face *aface ) - { - FT_Open_Args args; - - - /* test for valid `library' and `aface' delayed to `FT_Open_Face' */ - if ( !pathname ) - return FT_THROW( Invalid_Argument ); - - args.flags = FT_OPEN_PATHNAME; - args.pathname = (char*)pathname; - args.stream = NULL; - - return ft_open_face_internal( library, &args, face_index, aface, 1 ); - } - -#endif - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_New_Memory_Face( FT_Library library, - const FT_Byte* file_base, - FT_Long file_size, - FT_Long face_index, - FT_Face *aface ) - { - FT_Open_Args args; - - - /* test for valid `library' and `face' delayed to `FT_Open_Face' */ - if ( !file_base ) - return FT_THROW( Invalid_Argument ); - - args.flags = FT_OPEN_MEMORY; - args.memory_base = file_base; - args.memory_size = file_size; - args.stream = NULL; - - return ft_open_face_internal( library, &args, face_index, aface, 1 ); - } - - -#ifdef FT_CONFIG_OPTION_MAC_FONTS - - /* The behavior here is very similar to that in base/ftmac.c, but it */ - /* is designed to work on non-mac systems, so no mac specific calls. */ - /* */ - /* We look at the file and determine if it is a mac dfont file or a mac */ - /* resource file, or a macbinary file containing a mac resource file. */ - /* */ - /* Unlike ftmac I'm not going to look at a `FOND'. I don't really see */ - /* the point, especially since there may be multiple `FOND' resources. */ - /* Instead I'll just look for `sfnt' and `POST' resources, ordered as */ - /* they occur in the file. */ - /* */ - /* Note that multiple `POST' resources do not mean multiple postscript */ - /* fonts; they all get jammed together to make what is essentially a */ - /* pfb file. */ - /* */ - /* We aren't interested in `NFNT' or `FONT' bitmap resources. */ - /* */ - /* As soon as we get an `sfnt' load it into memory and pass it off to */ - /* FT_Open_Face. */ - /* */ - /* If we have a (set of) `POST' resources, massage them into a (memory) */ - /* pfb file and pass that to FT_Open_Face. (As with ftmac.c I'm not */ - /* going to try to save the kerning info. After all that lives in the */ - /* `FOND' which isn't in the file containing the `POST' resources so */ - /* we don't really have access to it. */ - - - /* Finalizer for a memory stream; gets called by FT_Done_Face(). */ - /* It frees the memory it uses. */ - /* From `ftmac.c'. */ - static void - memory_stream_close( FT_Stream stream ) - { - FT_Memory memory = stream->memory; - - - FT_FREE( stream->base ); - - stream->size = 0; - stream->base = NULL; - stream->close = NULL; - } - - - /* Create a new memory stream from a buffer and a size. */ - /* From `ftmac.c'. */ - static FT_Error - new_memory_stream( FT_Library library, - FT_Byte* base, - FT_ULong size, - FT_Stream_CloseFunc close, - FT_Stream *astream ) - { - FT_Error error; - FT_Memory memory; - FT_Stream stream = NULL; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !base ) - return FT_THROW( Invalid_Argument ); - - *astream = NULL; - memory = library->memory; - if ( FT_NEW( stream ) ) - goto Exit; - - FT_Stream_OpenMemory( stream, base, size ); - - stream->close = close; - - *astream = stream; - - Exit: - return error; - } - - - /* Create a new FT_Face given a buffer and a driver name. */ - /* From `ftmac.c'. */ - FT_LOCAL_DEF( FT_Error ) - open_face_from_buffer( FT_Library library, - FT_Byte* base, - FT_ULong size, - FT_Long face_index, - const char* driver_name, - FT_Face *aface ) - { - FT_Open_Args args; - FT_Error error; - FT_Stream stream = NULL; - FT_Memory memory = library->memory; - - - error = new_memory_stream( library, - base, - size, - memory_stream_close, - &stream ); - if ( error ) - { - FT_FREE( base ); - return error; - } - - args.flags = FT_OPEN_STREAM; - args.stream = stream; - if ( driver_name ) - { - args.flags = args.flags | FT_OPEN_DRIVER; - args.driver = FT_Get_Module( library, driver_name ); - } - -#ifdef FT_MACINTOSH - /* At this point, the face index has served its purpose; */ - /* whoever calls this function has already used it to */ - /* locate the correct font data. We should not propagate */ - /* this index to FT_Open_Face() (unless it is negative). */ - - if ( face_index > 0 ) - face_index &= 0x7FFF0000L; /* retain GX data */ -#endif - - error = ft_open_face_internal( library, &args, face_index, aface, 0 ); - - if ( !error ) - (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; - else -#ifdef FT_MACINTOSH - FT_Stream_Free( stream, 0 ); -#else - { - FT_Stream_Close( stream ); - FT_FREE( stream ); - } -#endif - - return error; - } - - - /* Look up `TYP1' or `CID ' table from sfnt table directory. */ - /* `offset' and `length' must exclude the binary header in tables. */ - - /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */ - /* format too. Here, since we can't expect that the TrueType font */ - /* driver is loaded unconditionally, we must parse the font by */ - /* ourselves. We are only interested in the name of the table and */ - /* the offset. */ - - static FT_Error - ft_lookup_PS_in_sfnt_stream( FT_Stream stream, - FT_Long face_index, - FT_ULong* offset, - FT_ULong* length, - FT_Bool* is_sfnt_cid ) - { - FT_Error error; - FT_UShort numTables; - FT_Long pstable_index; - FT_ULong tag; - int i; - - - *offset = 0; - *length = 0; - *is_sfnt_cid = FALSE; - - /* TODO: support for sfnt-wrapped PS/CID in TTC format */ - - /* version check for 'typ1' (should be ignored?) */ - if ( FT_READ_ULONG( tag ) ) - return error; - if ( tag != TTAG_typ1 ) - return FT_THROW( Unknown_File_Format ); - - if ( FT_READ_USHORT( numTables ) ) - return error; - if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */ - return error; - - pstable_index = -1; - *is_sfnt_cid = FALSE; - - for ( i = 0; i < numTables; i++ ) - { - if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) || - FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) ) - return error; - - if ( tag == TTAG_CID ) - { - pstable_index++; - *offset += 22; - *length -= 22; - *is_sfnt_cid = TRUE; - if ( face_index < 0 ) - return FT_Err_Ok; - } - else if ( tag == TTAG_TYP1 ) - { - pstable_index++; - *offset += 24; - *length -= 24; - *is_sfnt_cid = FALSE; - if ( face_index < 0 ) - return FT_Err_Ok; - } - if ( face_index >= 0 && pstable_index == face_index ) - return FT_Err_Ok; - } - - return FT_THROW( Table_Missing ); - } - - - FT_LOCAL_DEF( FT_Error ) - open_face_PS_from_sfnt_stream( FT_Library library, - FT_Stream stream, - FT_Long face_index, - FT_Int num_params, - FT_Parameter *params, - FT_Face *aface ) - { - FT_Error error; - FT_Memory memory = library->memory; - FT_ULong offset, length; - FT_ULong pos; - FT_Bool is_sfnt_cid; - FT_Byte* sfnt_ps = NULL; - - FT_UNUSED( num_params ); - FT_UNUSED( params ); - - - /* ignore GX stuff */ - if ( face_index > 0 ) - face_index &= 0xFFFFL; - - pos = FT_STREAM_POS(); - - error = ft_lookup_PS_in_sfnt_stream( stream, - face_index, - &offset, - &length, - &is_sfnt_cid ); - if ( error ) - goto Exit; - - if ( offset > stream->size ) - { - FT_TRACE2(( "open_face_PS_from_sfnt_stream: invalid table offset\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - else if ( length > stream->size - offset ) - { - FT_TRACE2(( "open_face_PS_from_sfnt_stream: invalid table length\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - error = FT_Stream_Seek( stream, pos + offset ); - if ( error ) - goto Exit; - - if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) ) - goto Exit; - - error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length ); - if ( error ) - { - FT_FREE( sfnt_ps ); - goto Exit; - } - - error = open_face_from_buffer( library, - sfnt_ps, - length, - FT_MIN( face_index, 0 ), - is_sfnt_cid ? "cid" : "type1", - aface ); - Exit: - { - FT_Error error1; - - - if ( FT_ERR_EQ( error, Unknown_File_Format ) ) - { - error1 = FT_Stream_Seek( stream, pos ); - if ( error1 ) - return error1; - } - - return error; - } - } - - -#ifndef FT_MACINTOSH - - /* The resource header says we've got resource_cnt `POST' (type1) */ - /* resources in this file. They all need to be coalesced into */ - /* one lump which gets passed on to the type1 driver. */ - /* Here can be only one PostScript font in a file so face_index */ - /* must be 0 (or -1). */ - /* */ - static FT_Error - Mac_Read_POST_Resource( FT_Library library, - FT_Stream stream, - FT_Long *offsets, - FT_Long resource_cnt, - FT_Long face_index, - FT_Face *aface ) - { - FT_Error error = FT_ERR( Cannot_Open_Resource ); - FT_Memory memory = library->memory; - - FT_Byte* pfb_data = NULL; - int i, type, flags; - FT_ULong len; - FT_ULong pfb_len, pfb_pos, pfb_lenpos; - FT_ULong rlen, temp; - - - if ( face_index == -1 ) - face_index = 0; - if ( face_index != 0 ) - return error; - - /* Find the length of all the POST resources, concatenated. Assume */ - /* worst case (each resource in its own section). */ - pfb_len = 0; - for ( i = 0; i < resource_cnt; i++ ) - { - error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] ); - if ( error ) - goto Exit; - if ( FT_READ_ULONG( temp ) ) /* actually LONG */ - goto Exit; - - /* FT2 allocator takes signed long buffer length, - * too large value causing overflow should be checked - */ - FT_TRACE4(( " POST fragment #%d: length=0x%08x" - " total pfb_len=0x%08x\n", - i, temp, pfb_len + temp + 6 )); - - if ( FT_MAC_RFORK_MAX_LEN < temp || - FT_MAC_RFORK_MAX_LEN - temp < pfb_len + 6 ) - { - FT_TRACE2(( " MacOS resource length cannot exceed" - " 0x%08x\n", - FT_MAC_RFORK_MAX_LEN )); - - error = FT_THROW( Invalid_Offset ); - goto Exit; - } - - pfb_len += temp + 6; - } - - FT_TRACE2(( " total buffer size to concatenate" - " %d POST fragments: 0x%08x\n", - resource_cnt, pfb_len + 2 )); - - if ( pfb_len + 2 < 6 ) - { - FT_TRACE2(( " too long fragment length makes" - " pfb_len confused: pfb_len=0x%08x\n", - pfb_len )); - - error = FT_THROW( Array_Too_Large ); - goto Exit; - } - - if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) ) - goto Exit; - - pfb_data[0] = 0x80; - pfb_data[1] = 1; /* Ascii section */ - pfb_data[2] = 0; /* 4-byte length, fill in later */ - pfb_data[3] = 0; - pfb_data[4] = 0; - pfb_data[5] = 0; - pfb_pos = 6; - pfb_lenpos = 2; - - len = 0; - type = 1; - - for ( i = 0; i < resource_cnt; i++ ) - { - error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] ); - if ( error ) - goto Exit2; - if ( FT_READ_ULONG( rlen ) ) - goto Exit2; - - /* FT2 allocator takes signed long buffer length, - * too large fragment length causing overflow should be checked - */ - if ( 0x7FFFFFFFUL < rlen ) - { - error = FT_THROW( Invalid_Offset ); - goto Exit2; - } - - if ( FT_READ_USHORT( flags ) ) - goto Exit2; - - FT_TRACE3(( "POST fragment[%d]:" - " offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n", - i, offsets[i], rlen, flags )); - - error = FT_ERR( Array_Too_Large ); - - /* postpone the check of `rlen longer than buffer' */ - /* until `FT_Stream_Read' */ - - if ( ( flags >> 8 ) == 0 ) /* Comment, should not be loaded */ - { - FT_TRACE3(( " Skip POST fragment #%d because it is a comment\n", - i )); - continue; - } - - /* the flags are part of the resource, so rlen >= 2, */ - /* but some fonts declare rlen = 0 for empty fragment */ - if ( rlen > 2 ) - rlen -= 2; - else - rlen = 0; - - if ( ( flags >> 8 ) == type ) - len += rlen; - else - { - FT_TRACE3(( " Write POST fragment #%d header (4-byte) to buffer" - " %p + 0x%08x\n", - i, pfb_data, pfb_lenpos )); - - if ( pfb_lenpos + 3 > pfb_len + 2 ) - goto Exit2; - - pfb_data[pfb_lenpos ] = (FT_Byte)( len ); - pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 ); - pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 ); - pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 ); - - if ( ( flags >> 8 ) == 5 ) /* End of font mark */ - break; - - FT_TRACE3(( " Write POST fragment #%d header (6-byte) to buffer" - " %p + 0x%08x\n", - i, pfb_data, pfb_pos )); - - if ( pfb_pos + 6 > pfb_len + 2 ) - goto Exit2; - - pfb_data[pfb_pos++] = 0x80; - - type = flags >> 8; - len = rlen; - - pfb_data[pfb_pos++] = (FT_Byte)type; - pfb_lenpos = pfb_pos; - pfb_data[pfb_pos++] = 0; /* 4-byte length, fill in later */ - pfb_data[pfb_pos++] = 0; - pfb_data[pfb_pos++] = 0; - pfb_data[pfb_pos++] = 0; - } - - if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len ) - goto Exit2; - - FT_TRACE3(( " Load POST fragment #%d (%d byte) to buffer" - " %p + 0x%08x\n", - i, rlen, pfb_data, pfb_pos )); - - error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen ); - if ( error ) - goto Exit2; - - pfb_pos += rlen; - } - - error = FT_ERR( Array_Too_Large ); - - if ( pfb_pos + 2 > pfb_len + 2 ) - goto Exit2; - pfb_data[pfb_pos++] = 0x80; - pfb_data[pfb_pos++] = 3; - - if ( pfb_lenpos + 3 > pfb_len + 2 ) - goto Exit2; - pfb_data[pfb_lenpos ] = (FT_Byte)( len ); - pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 ); - pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 ); - pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 ); - - return open_face_from_buffer( library, - pfb_data, - pfb_pos, - face_index, - "type1", - aface ); - - Exit2: - if ( FT_ERR_EQ( error, Array_Too_Large ) ) - FT_TRACE2(( " Abort due to too-short buffer to store" - " all POST fragments\n" )); - else if ( FT_ERR_EQ( error, Invalid_Offset ) ) - FT_TRACE2(( " Abort due to invalid offset in a POST fragment\n" )); - - if ( error ) - error = FT_ERR( Cannot_Open_Resource ); - FT_FREE( pfb_data ); - - Exit: - return error; - } - - - /* The resource header says we've got resource_cnt `sfnt' */ - /* (TrueType/OpenType) resources in this file. Look through */ - /* them for the one indicated by face_index, load it into mem, */ - /* pass it on to the truetype driver, and return it. */ - /* */ - static FT_Error - Mac_Read_sfnt_Resource( FT_Library library, - FT_Stream stream, - FT_Long *offsets, - FT_Long resource_cnt, - FT_Long face_index, - FT_Face *aface ) - { - FT_Memory memory = library->memory; - FT_Byte* sfnt_data = NULL; - FT_Error error; - FT_ULong flag_offset; - FT_Long rlen; - int is_cff; - FT_Long face_index_in_resource = 0; - - - if ( face_index < 0 ) - face_index = -face_index - 1; - if ( face_index >= resource_cnt ) - return FT_THROW( Cannot_Open_Resource ); - - flag_offset = (FT_ULong)offsets[face_index]; - error = FT_Stream_Seek( stream, flag_offset ); - if ( error ) - goto Exit; - - if ( FT_READ_LONG( rlen ) ) - goto Exit; - if ( rlen < 1 ) - return FT_THROW( Cannot_Open_Resource ); - if ( (FT_ULong)rlen > FT_MAC_RFORK_MAX_LEN ) - return FT_THROW( Invalid_Offset ); - - error = open_face_PS_from_sfnt_stream( library, - stream, - face_index, - 0, NULL, - aface ); - if ( !error ) - goto Exit; - - /* rewind sfnt stream before open_face_PS_from_sfnt_stream() */ - error = FT_Stream_Seek( stream, flag_offset + 4 ); - if ( error ) - goto Exit; - - if ( FT_ALLOC( sfnt_data, rlen ) ) - return error; - error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, (FT_ULong)rlen ); - if ( error ) { - FT_FREE( sfnt_data ); - goto Exit; - } - - is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); - error = open_face_from_buffer( library, - sfnt_data, - (FT_ULong)rlen, - face_index_in_resource, - is_cff ? "cff" : "truetype", - aface ); - - Exit: - return error; - } - - - /* Check for a valid resource fork header, or a valid dfont */ - /* header. In a resource fork the first 16 bytes are repeated */ - /* at the location specified by bytes 4-7. In a dfont bytes */ - /* 4-7 point to 16 bytes of zeroes instead. */ - /* */ - static FT_Error - IsMacResource( FT_Library library, - FT_Stream stream, - FT_Long resource_offset, - FT_Long face_index, - FT_Face *aface ) - { - FT_Memory memory = library->memory; - FT_Error error; - FT_Long map_offset, rdata_pos; - FT_Long *data_offsets; - FT_Long count; - - - error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset, - &map_offset, &rdata_pos ); - if ( error ) - return error; - - /* POST resources must be sorted to concatenate properly */ - error = FT_Raccess_Get_DataOffsets( library, stream, - map_offset, rdata_pos, - TTAG_POST, TRUE, - &data_offsets, &count ); - if ( !error ) - { - error = Mac_Read_POST_Resource( library, stream, data_offsets, count, - face_index, aface ); - FT_FREE( data_offsets ); - /* POST exists in an LWFN providing a single face */ - if ( !error ) - (*aface)->num_faces = 1; - return error; - } - - /* sfnt resources should not be sorted to preserve the face order by - QuickDraw API */ - error = FT_Raccess_Get_DataOffsets( library, stream, - map_offset, rdata_pos, - TTAG_sfnt, FALSE, - &data_offsets, &count ); - if ( !error ) - { - FT_Long face_index_internal = face_index % count; - - - error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count, - face_index_internal, aface ); - FT_FREE( data_offsets ); - if ( !error ) - (*aface)->num_faces = count; - } - - return error; - } - - - /* Check for a valid macbinary header, and if we find one */ - /* check that the (flattened) resource fork in it is valid. */ - /* */ - static FT_Error - IsMacBinary( FT_Library library, - FT_Stream stream, - FT_Long face_index, - FT_Face *aface ) - { - unsigned char header[128]; - FT_Error error; - FT_Long dlen, offset; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Operation ); - - error = FT_Stream_Seek( stream, 0 ); - if ( error ) - goto Exit; - - error = FT_Stream_Read( stream, (FT_Byte*)header, 128 ); - if ( error ) - goto Exit; - - if ( header[ 0] != 0 || - header[74] != 0 || - header[82] != 0 || - header[ 1] == 0 || - header[ 1] > 33 || - header[63] != 0 || - header[2 + header[1]] != 0 || - header[0x53] > 0x7F ) - return FT_THROW( Unknown_File_Format ); - - dlen = ( header[0x53] << 24 ) | - ( header[0x54] << 16 ) | - ( header[0x55] << 8 ) | - header[0x56]; -#if 0 - rlen = ( header[0x57] << 24 ) | - ( header[0x58] << 16 ) | - ( header[0x59] << 8 ) | - header[0x5A]; -#endif /* 0 */ - offset = 128 + ( ( dlen + 127 ) & ~127 ); - - return IsMacResource( library, stream, offset, face_index, aface ); - - Exit: - return error; - } - - - static FT_Error - load_face_in_embedded_rfork( FT_Library library, - FT_Stream stream, - FT_Long face_index, - FT_Face *aface, - const FT_Open_Args *args ) - { - -#undef FT_COMPONENT -#define FT_COMPONENT trace_raccess - - FT_Memory memory = library->memory; - FT_Error error = FT_ERR( Unknown_File_Format ); - FT_UInt i; - - char * file_names[FT_RACCESS_N_RULES]; - FT_Long offsets[FT_RACCESS_N_RULES]; - FT_Error errors[FT_RACCESS_N_RULES]; - FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */ - - FT_Open_Args args2; - FT_Stream stream2 = NULL; - - - FT_Raccess_Guess( library, stream, - args->pathname, file_names, offsets, errors ); - - for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) - { - is_darwin_vfs = ft_raccess_rule_by_darwin_vfs( library, i ); - if ( is_darwin_vfs && vfs_rfork_has_no_font ) - { - FT_TRACE3(( "Skip rule %d: darwin vfs resource fork" - " is already checked and" - " no font is found\n", - i )); - continue; - } - - if ( errors[i] ) - { - FT_TRACE3(( "Error 0x%x has occurred in rule %d\n", - errors[i], i )); - continue; - } - - args2.flags = FT_OPEN_PATHNAME; - args2.pathname = file_names[i] ? file_names[i] : args->pathname; - - FT_TRACE3(( "Try rule %d: %s (offset=%d) ...", - i, args2.pathname, offsets[i] )); - - error = FT_Stream_New( library, &args2, &stream2 ); - if ( is_darwin_vfs && FT_ERR_EQ( error, Cannot_Open_Stream ) ) - vfs_rfork_has_no_font = TRUE; - - if ( error ) - { - FT_TRACE3(( "failed\n" )); - continue; - } - - error = IsMacResource( library, stream2, offsets[i], - face_index, aface ); - FT_Stream_Free( stream2, 0 ); - - FT_TRACE3(( "%s\n", error ? "failed": "successful" )); - - if ( !error ) - break; - else if ( is_darwin_vfs ) - vfs_rfork_has_no_font = TRUE; - } - - for (i = 0; i < FT_RACCESS_N_RULES; i++) - { - if ( file_names[i] ) - FT_FREE( file_names[i] ); - } - - /* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */ - if ( error ) - error = FT_ERR( Unknown_File_Format ); - - return error; - -#undef FT_COMPONENT -#define FT_COMPONENT trace_objs - - } - - - /* Check for some macintosh formats without Carbon framework. */ - /* Is this a macbinary file? If so look at the resource fork. */ - /* Is this a mac dfont file? */ - /* Is this an old style resource fork? (in data) */ - /* Else call load_face_in_embedded_rfork to try extra rules */ - /* (defined in `ftrfork.c'). */ - /* */ - static FT_Error - load_mac_face( FT_Library library, - FT_Stream stream, - FT_Long face_index, - FT_Face *aface, - const FT_Open_Args *args ) - { - FT_Error error; - FT_UNUSED( args ); - - - error = IsMacBinary( library, stream, face_index, aface ); - if ( FT_ERR_EQ( error, Unknown_File_Format ) ) - { - -#undef FT_COMPONENT -#define FT_COMPONENT trace_raccess - -#ifdef FT_DEBUG_LEVEL_TRACE - FT_TRACE3(( "Try as dfont: " )); - if ( !( args->flags & FT_OPEN_MEMORY ) ) - FT_TRACE3(( "%s ...", args->pathname )); -#endif - - error = IsMacResource( library, stream, 0, face_index, aface ); - - FT_TRACE3(( "%s\n", error ? "failed" : "successful" )); - -#undef FT_COMPONENT -#define FT_COMPONENT trace_objs - - } - - if ( ( FT_ERR_EQ( error, Unknown_File_Format ) || - FT_ERR_EQ( error, Invalid_Stream_Operation ) ) && - ( args->flags & FT_OPEN_PATHNAME ) ) - error = load_face_in_embedded_rfork( library, stream, - face_index, aface, args ); - return error; - } -#endif - -#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */ - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Open_Face( FT_Library library, - const FT_Open_Args* args, - FT_Long face_index, - FT_Face *aface ) - { - return ft_open_face_internal( library, args, face_index, aface, 1 ); - } - - - static FT_Error - ft_open_face_internal( FT_Library library, - const FT_Open_Args* args, - FT_Long face_index, - FT_Face *aface, - FT_Bool test_mac_fonts ) - { - FT_Error error; - FT_Driver driver = NULL; - FT_Memory memory = NULL; - FT_Stream stream = NULL; - FT_Face face = NULL; - FT_ListNode node = NULL; - FT_Bool external_stream; - FT_Module* cur; - FT_Module* limit; - -#ifndef FT_CONFIG_OPTION_MAC_FONTS - FT_UNUSED( test_mac_fonts ); -#endif - - -#ifdef FT_DEBUG_LEVEL_TRACE - FT_TRACE3(( "FT_Open_Face: " )); - if ( face_index < 0 ) - FT_TRACE3(( "Requesting number of faces and named instances\n")); - else - { - FT_TRACE3(( "Requesting face %ld", face_index & 0xFFFFL )); - if ( face_index & 0x7FFF0000L ) - FT_TRACE3(( ", named instance %ld", face_index >> 16 )); - FT_TRACE3(( "\n" )); - } -#endif - - /* test for valid `library' delayed to `FT_Stream_New' */ - - if ( ( !aface && face_index >= 0 ) || !args ) - return FT_THROW( Invalid_Argument ); - - external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) && - args->stream ); - - /* create input stream */ - error = FT_Stream_New( library, args, &stream ); - if ( error ) - goto Fail3; - - memory = library->memory; - - /* If the font driver is specified in the `args' structure, use */ - /* it. Otherwise, we scan the list of registered drivers. */ - if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver ) - { - driver = FT_DRIVER( args->driver ); - - /* not all modules are drivers, so check... */ - if ( FT_MODULE_IS_DRIVER( driver ) ) - { - FT_Int num_params = 0; - FT_Parameter* params = NULL; - - - if ( args->flags & FT_OPEN_PARAMS ) - { - num_params = args->num_params; - params = args->params; - } - - error = open_face( driver, &stream, external_stream, face_index, - num_params, params, &face ); - if ( !error ) - goto Success; - } - else - error = FT_THROW( Invalid_Handle ); - - FT_Stream_Free( stream, external_stream ); - goto Fail; - } - else - { - error = FT_ERR( Missing_Module ); - - /* check each font driver for an appropriate format */ - cur = library->modules; - limit = cur + library->num_modules; - - for ( ; cur < limit; cur++ ) - { - /* not all modules are font drivers, so check... */ - if ( FT_MODULE_IS_DRIVER( cur[0] ) ) - { - FT_Int num_params = 0; - FT_Parameter* params = NULL; - - - driver = FT_DRIVER( cur[0] ); - - if ( args->flags & FT_OPEN_PARAMS ) - { - num_params = args->num_params; - params = args->params; - } - - error = open_face( driver, &stream, external_stream, face_index, - num_params, params, &face ); - if ( !error ) - goto Success; - -#ifdef FT_CONFIG_OPTION_MAC_FONTS - if ( test_mac_fonts && - ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 && - FT_ERR_EQ( error, Table_Missing ) ) - { - /* TrueType but essential tables are missing */ - error = FT_Stream_Seek( stream, 0 ); - if ( error ) - break; - - error = open_face_PS_from_sfnt_stream( library, - stream, - face_index, - num_params, - params, - aface ); - if ( !error ) - { - FT_Stream_Free( stream, external_stream ); - return error; - } - } -#endif - - if ( FT_ERR_NEQ( error, Unknown_File_Format ) ) - goto Fail3; - } - } - - Fail3: - /* If we are on the mac, and we get an */ - /* FT_Err_Invalid_Stream_Operation it may be because we have an */ - /* empty data fork, so we need to check the resource fork. */ - if ( FT_ERR_NEQ( error, Cannot_Open_Stream ) && - FT_ERR_NEQ( error, Unknown_File_Format ) && - FT_ERR_NEQ( error, Invalid_Stream_Operation ) ) - goto Fail2; - -#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS ) - if ( test_mac_fonts ) - { - error = load_mac_face( library, stream, face_index, aface, args ); - if ( !error ) - { - /* We don't want to go to Success here. We've already done */ - /* that. On the other hand, if we succeeded we still need to */ - /* close this stream (we opened a different stream which */ - /* extracted the interesting information out of this stream */ - /* here. That stream will still be open and the face will */ - /* point to it). */ - FT_Stream_Free( stream, external_stream ); - return error; - } - } - - if ( FT_ERR_NEQ( error, Unknown_File_Format ) ) - goto Fail2; -#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */ - - /* no driver is able to handle this format */ - error = FT_THROW( Unknown_File_Format ); - - Fail2: - FT_Stream_Free( stream, external_stream ); - goto Fail; - } - - Success: - FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" )); - - /* add the face object to its driver's list */ - if ( FT_NEW( node ) ) - goto Fail; - - node->data = face; - /* don't assume driver is the same as face->driver, so use */ - /* face->driver instead. */ - FT_List_Add( &face->driver->faces_list, node ); - - /* now allocate a glyph slot object for the face */ - FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" )); - - if ( face_index >= 0 ) - { - error = FT_New_GlyphSlot( face, NULL ); - if ( error ) - goto Fail; - - /* finally, allocate a size object for the face */ - { - FT_Size size; - - - FT_TRACE4(( "FT_Open_Face: Creating size object\n" )); - - error = FT_New_Size( face, &size ); - if ( error ) - goto Fail; - - face->size = size; - } - } - - /* some checks */ - - if ( FT_IS_SCALABLE( face ) ) - { - if ( face->height < 0 ) - face->height = (FT_Short)-face->height; - - if ( !FT_HAS_VERTICAL( face ) ) - face->max_advance_height = (FT_Short)face->height; - } - - if ( FT_HAS_FIXED_SIZES( face ) ) - { - FT_Int i; - - - for ( i = 0; i < face->num_fixed_sizes; i++ ) - { - FT_Bitmap_Size* bsize = face->available_sizes + i; - - - if ( bsize->height < 0 ) - bsize->height = -bsize->height; - if ( bsize->x_ppem < 0 ) - bsize->x_ppem = -bsize->x_ppem; - if ( bsize->y_ppem < 0 ) - bsize->y_ppem = -bsize->y_ppem; - - /* check whether negation actually has worked */ - if ( bsize->height < 0 || bsize->x_ppem < 0 || bsize->y_ppem < 0 ) - { - FT_TRACE0(( "FT_Open_Face:" - " Invalid bitmap dimensions for stroke %d," - " now disabled\n", i )); - bsize->width = 0; - bsize->height = 0; - bsize->size = 0; - bsize->x_ppem = 0; - bsize->y_ppem = 0; - } - } - } - - /* initialize internal face data */ - { - FT_Face_Internal internal = face->internal; - - - internal->transform_matrix.xx = 0x10000L; - internal->transform_matrix.xy = 0; - internal->transform_matrix.yx = 0; - internal->transform_matrix.yy = 0x10000L; - - internal->transform_delta.x = 0; - internal->transform_delta.y = 0; - - internal->refcount = 1; - } - - if ( aface ) - *aface = face; - else - FT_Done_Face( face ); - - goto Exit; - - Fail: - if ( node ) - FT_Done_Face( face ); /* face must be in the driver's list */ - else if ( face ) - destroy_face( memory, face, driver ); - - Exit: -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !error && face_index < 0 ) - { - FT_TRACE3(( "FT_Open_Face: The font has %ld face%s\n" - " and %ld named instance%s for face %ld\n", - face->num_faces, - face->num_faces == 1 ? "" : "s", - face->style_flags >> 16, - ( face->style_flags >> 16 ) == 1 ? "" : "s", - -face_index - 1 )); - } -#endif - - FT_TRACE4(( "FT_Open_Face: Return 0x%x\n", error )); - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Attach_File( FT_Face face, - const char* filepathname ) - { - FT_Open_Args open; - - - /* test for valid `face' delayed to `FT_Attach_Stream' */ - - if ( !filepathname ) - return FT_THROW( Invalid_Argument ); - - open.stream = NULL; - open.flags = FT_OPEN_PATHNAME; - open.pathname = (char*)filepathname; - - return FT_Attach_Stream( face, &open ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Attach_Stream( FT_Face face, - FT_Open_Args* parameters ) - { - FT_Stream stream; - FT_Error error; - FT_Driver driver; - - FT_Driver_Class clazz; - - - /* test for valid `parameters' delayed to `FT_Stream_New' */ - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - driver = face->driver; - if ( !driver ) - return FT_THROW( Invalid_Driver_Handle ); - - error = FT_Stream_New( driver->root.library, parameters, &stream ); - if ( error ) - goto Exit; - - /* we implement FT_Attach_Stream in each driver through the */ - /* `attach_file' interface */ - - error = FT_ERR( Unimplemented_Feature ); - clazz = driver->clazz; - if ( clazz->attach_file ) - error = clazz->attach_file( face, stream ); - - /* close the attached stream */ - FT_Stream_Free( stream, - (FT_Bool)( parameters->stream && - ( parameters->flags & FT_OPEN_STREAM ) ) ); - - Exit: - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Reference_Face( FT_Face face ) - { - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - face->internal->refcount++; - - return FT_Err_Ok; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Done_Face( FT_Face face ) - { - FT_Error error; - FT_Driver driver; - FT_Memory memory; - FT_ListNode node; - - - error = FT_ERR( Invalid_Face_Handle ); - if ( face && face->driver ) - { - face->internal->refcount--; - if ( face->internal->refcount > 0 ) - error = FT_Err_Ok; - else - { - driver = face->driver; - memory = driver->root.memory; - - /* find face in driver's list */ - node = FT_List_Find( &driver->faces_list, face ); - if ( node ) - { - /* remove face object from the driver's list */ - FT_List_Remove( &driver->faces_list, node ); - FT_FREE( node ); - - /* now destroy the object proper */ - destroy_face( memory, face, driver ); - error = FT_Err_Ok; - } - } - } - - return error; - } - - - /* documentation is in ftobjs.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_New_Size( FT_Face face, - FT_Size *asize ) - { - FT_Error error; - FT_Memory memory; - FT_Driver driver; - FT_Driver_Class clazz; - - FT_Size size = NULL; - FT_ListNode node = NULL; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !asize ) - return FT_THROW( Invalid_Argument ); - - if ( !face->driver ) - return FT_THROW( Invalid_Driver_Handle ); - - *asize = NULL; - - driver = face->driver; - clazz = driver->clazz; - memory = face->memory; - - /* Allocate new size object and perform basic initialisation */ - if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) ) - goto Exit; - - size->face = face; - - /* for now, do not use any internal fields in size objects */ - size->internal = NULL; - - if ( clazz->init_size ) - error = clazz->init_size( size ); - - /* in case of success, add to the face's list */ - if ( !error ) - { - *asize = size; - node->data = size; - FT_List_Add( &face->sizes_list, node ); - } - - Exit: - if ( error ) - { - FT_FREE( node ); - FT_FREE( size ); - } - - return error; - } - - - /* documentation is in ftobjs.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Done_Size( FT_Size size ) - { - FT_Error error; - FT_Driver driver; - FT_Memory memory; - FT_Face face; - FT_ListNode node; - - - if ( !size ) - return FT_THROW( Invalid_Size_Handle ); - - face = size->face; - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - driver = face->driver; - if ( !driver ) - return FT_THROW( Invalid_Driver_Handle ); - - memory = driver->root.memory; - - error = FT_Err_Ok; - node = FT_List_Find( &face->sizes_list, size ); - if ( node ) - { - FT_List_Remove( &face->sizes_list, node ); - FT_FREE( node ); - - if ( face->size == size ) - { - face->size = NULL; - if ( face->sizes_list.head ) - face->size = (FT_Size)(face->sizes_list.head->data); - } - - destroy_size( memory, size, driver ); - } - else - error = FT_THROW( Invalid_Size_Handle ); - - return error; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_Match_Size( FT_Face face, - FT_Size_Request req, - FT_Bool ignore_width, - FT_ULong* size_index ) - { - FT_Int i; - FT_Long w, h; - - - if ( !FT_HAS_FIXED_SIZES( face ) ) - return FT_THROW( Invalid_Face_Handle ); - - /* FT_Bitmap_Size doesn't provide enough info... */ - if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL ) - return FT_THROW( Unimplemented_Feature ); - - w = FT_REQUEST_WIDTH ( req ); - h = FT_REQUEST_HEIGHT( req ); - - if ( req->width && !req->height ) - h = w; - else if ( !req->width && req->height ) - w = h; - - w = FT_PIX_ROUND( w ); - h = FT_PIX_ROUND( h ); - - if ( !w || !h ) - return FT_THROW( Invalid_Pixel_Size ); - - for ( i = 0; i < face->num_fixed_sizes; i++ ) - { - FT_Bitmap_Size* bsize = face->available_sizes + i; - - - if ( h != FT_PIX_ROUND( bsize->y_ppem ) ) - continue; - - if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width ) - { - FT_TRACE3(( "FT_Match_Size: bitmap strike %d matches\n", i )); - - if ( size_index ) - *size_index = (FT_ULong)i; - - return FT_Err_Ok; - } - } - - FT_TRACE3(( "FT_Match_Size: no matching bitmap strike\n" )); - - return FT_THROW( Invalid_Pixel_Size ); - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics, - FT_Pos advance ) - { - FT_Pos height = metrics->height; - - - /* compensate for glyph with bbox above/below the baseline */ - if ( metrics->horiBearingY < 0 ) - { - if ( height < metrics->horiBearingY ) - height = metrics->horiBearingY; - } - else if ( metrics->horiBearingY > 0 ) - height -= metrics->horiBearingY; - - /* the factor 1.2 is a heuristical value */ - if ( !advance ) - advance = height * 12 / 10; - - metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2; - metrics->vertBearingY = ( advance - height ) / 2; - metrics->vertAdvance = advance; - } - - - static void - ft_recompute_scaled_metrics( FT_Face face, - FT_Size_Metrics* metrics ) - { - /* Compute root ascender, descender, test height, and max_advance */ - -#ifdef GRID_FIT_METRICS - metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender, - metrics->y_scale ) ); - - metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender, - metrics->y_scale ) ); - - metrics->height = FT_PIX_ROUND( FT_MulFix( face->height, - metrics->y_scale ) ); - - metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width, - metrics->x_scale ) ); -#else /* !GRID_FIT_METRICS */ - metrics->ascender = FT_MulFix( face->ascender, - metrics->y_scale ); - - metrics->descender = FT_MulFix( face->descender, - metrics->y_scale ); - - metrics->height = FT_MulFix( face->height, - metrics->y_scale ); - - metrics->max_advance = FT_MulFix( face->max_advance_width, - metrics->x_scale ); -#endif /* !GRID_FIT_METRICS */ - } - - - FT_BASE_DEF( void ) - FT_Select_Metrics( FT_Face face, - FT_ULong strike_index ) - { - FT_Size_Metrics* metrics; - FT_Bitmap_Size* bsize; - - - metrics = &face->size->metrics; - bsize = face->available_sizes + strike_index; - - metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 ); - metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 ); - - if ( FT_IS_SCALABLE( face ) ) - { - metrics->x_scale = FT_DivFix( bsize->x_ppem, - face->units_per_EM ); - metrics->y_scale = FT_DivFix( bsize->y_ppem, - face->units_per_EM ); - - ft_recompute_scaled_metrics( face, metrics ); - } - else - { - metrics->x_scale = 1L << 16; - metrics->y_scale = 1L << 16; - metrics->ascender = bsize->y_ppem; - metrics->descender = 0; - metrics->height = bsize->height << 6; - metrics->max_advance = bsize->x_ppem; - } - - FT_TRACE5(( "FT_Select_Metrics:\n" )); - FT_TRACE5(( " x scale: %d (%f)\n", - metrics->x_scale, metrics->x_scale / 65536.0 )); - FT_TRACE5(( " y scale: %d (%f)\n", - metrics->y_scale, metrics->y_scale / 65536.0 )); - FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 )); - FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 )); - FT_TRACE5(( " height: %f\n", metrics->height / 64.0 )); - FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 )); - FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem )); - FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem )); - } - - - FT_BASE_DEF( void ) - FT_Request_Metrics( FT_Face face, - FT_Size_Request req ) - { - FT_Size_Metrics* metrics; - - - metrics = &face->size->metrics; - - if ( FT_IS_SCALABLE( face ) ) - { - FT_Long w = 0, h = 0, scaled_w = 0, scaled_h = 0; - - - switch ( req->type ) - { - case FT_SIZE_REQUEST_TYPE_NOMINAL: - w = h = face->units_per_EM; - break; - - case FT_SIZE_REQUEST_TYPE_REAL_DIM: - w = h = face->ascender - face->descender; - break; - - case FT_SIZE_REQUEST_TYPE_BBOX: - w = face->bbox.xMax - face->bbox.xMin; - h = face->bbox.yMax - face->bbox.yMin; - break; - - case FT_SIZE_REQUEST_TYPE_CELL: - w = face->max_advance_width; - h = face->ascender - face->descender; - break; - - case FT_SIZE_REQUEST_TYPE_SCALES: - metrics->x_scale = (FT_Fixed)req->width; - metrics->y_scale = (FT_Fixed)req->height; - if ( !metrics->x_scale ) - metrics->x_scale = metrics->y_scale; - else if ( !metrics->y_scale ) - metrics->y_scale = metrics->x_scale; - goto Calculate_Ppem; - - case FT_SIZE_REQUEST_TYPE_MAX: - break; - } - - /* to be on the safe side */ - if ( w < 0 ) - w = -w; - - if ( h < 0 ) - h = -h; - - scaled_w = FT_REQUEST_WIDTH ( req ); - scaled_h = FT_REQUEST_HEIGHT( req ); - - /* determine scales */ - if ( req->width ) - { - metrics->x_scale = FT_DivFix( scaled_w, w ); - - if ( req->height ) - { - metrics->y_scale = FT_DivFix( scaled_h, h ); - - if ( req->type == FT_SIZE_REQUEST_TYPE_CELL ) - { - if ( metrics->y_scale > metrics->x_scale ) - metrics->y_scale = metrics->x_scale; - else - metrics->x_scale = metrics->y_scale; - } - } - else - { - metrics->y_scale = metrics->x_scale; - scaled_h = FT_MulDiv( scaled_w, h, w ); - } - } - else - { - metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h ); - scaled_w = FT_MulDiv( scaled_h, w, h ); - } - - Calculate_Ppem: - /* calculate the ppems */ - if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL ) - { - scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale ); - scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale ); - } - - metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 ); - metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 ); - - ft_recompute_scaled_metrics( face, metrics ); - } - else - { - FT_ZERO( metrics ); - metrics->x_scale = 1L << 16; - metrics->y_scale = 1L << 16; - } - - FT_TRACE5(( "FT_Request_Metrics:\n" )); - FT_TRACE5(( " x scale: %d (%f)\n", - metrics->x_scale, metrics->x_scale / 65536.0 )); - FT_TRACE5(( " y scale: %d (%f)\n", - metrics->y_scale, metrics->y_scale / 65536.0 )); - FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 )); - FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 )); - FT_TRACE5(( " height: %f\n", metrics->height / 64.0 )); - FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 )); - FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem )); - FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem )); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Select_Size( FT_Face face, - FT_Int strike_index ) - { - FT_Driver_Class clazz; - - - if ( !face || !FT_HAS_FIXED_SIZES( face ) ) - return FT_THROW( Invalid_Face_Handle ); - - if ( strike_index < 0 || strike_index >= face->num_fixed_sizes ) - return FT_THROW( Invalid_Argument ); - - clazz = face->driver->clazz; - - if ( clazz->select_size ) - { - FT_Error error; - - - error = clazz->select_size( face->size, (FT_ULong)strike_index ); - -#ifdef FT_DEBUG_LEVEL_TRACE - { - FT_Size_Metrics* metrics = &face->size->metrics; - - - FT_TRACE5(( "FT_Select_Size (font driver's `select_size'):\n" )); - FT_TRACE5(( " x scale: %d (%f)\n", - metrics->x_scale, metrics->x_scale / 65536.0 )); - FT_TRACE5(( " y scale: %d (%f)\n", - metrics->y_scale, metrics->y_scale / 65536.0 )); - FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 )); - FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 )); - FT_TRACE5(( " height: %f\n", metrics->height / 64.0 )); - FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 )); - FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem )); - FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem )); - } -#endif - - return error; - } - - FT_Select_Metrics( face, (FT_ULong)strike_index ); - - return FT_Err_Ok; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Request_Size( FT_Face face, - FT_Size_Request req ) - { - FT_Driver_Class clazz; - FT_ULong strike_index; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !req || req->width < 0 || req->height < 0 || - req->type >= FT_SIZE_REQUEST_TYPE_MAX ) - return FT_THROW( Invalid_Argument ); - - clazz = face->driver->clazz; - - if ( clazz->request_size ) - { - FT_Error error; - - - error = clazz->request_size( face->size, req ); - -#ifdef FT_DEBUG_LEVEL_TRACE - { - FT_Size_Metrics* metrics = &face->size->metrics; - - - FT_TRACE5(( "FT_Request_Size (font driver's `request_size'):\n" )); - FT_TRACE5(( " x scale: %d (%f)\n", - metrics->x_scale, metrics->x_scale / 65536.0 )); - FT_TRACE5(( " y scale: %d (%f)\n", - metrics->y_scale, metrics->y_scale / 65536.0 )); - FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 )); - FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 )); - FT_TRACE5(( " height: %f\n", metrics->height / 64.0 )); - FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 )); - FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem )); - FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem )); - } -#endif - - return error; - } - - /* - * The reason that a driver doesn't have `request_size' defined is - * either that the scaling here suffices or that the supported formats - * are bitmap-only and size matching is not implemented. - * - * In the latter case, a simple size matching is done. - */ - if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) ) - { - FT_Error error; - - - error = FT_Match_Size( face, req, 0, &strike_index ); - if ( error ) - return error; - - return FT_Select_Size( face, (FT_Int)strike_index ); - } - - FT_Request_Metrics( face, req ); - - return FT_Err_Ok; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Char_Size( FT_Face face, - FT_F26Dot6 char_width, - FT_F26Dot6 char_height, - FT_UInt horz_resolution, - FT_UInt vert_resolution ) - { - FT_Size_RequestRec req; - - - /* check of `face' delayed to `FT_Request_Size' */ - - if ( !char_width ) - char_width = char_height; - else if ( !char_height ) - char_height = char_width; - - if ( !horz_resolution ) - horz_resolution = vert_resolution; - else if ( !vert_resolution ) - vert_resolution = horz_resolution; - - if ( char_width < 1 * 64 ) - char_width = 1 * 64; - if ( char_height < 1 * 64 ) - char_height = 1 * 64; - - if ( !horz_resolution ) - horz_resolution = vert_resolution = 72; - - req.type = FT_SIZE_REQUEST_TYPE_NOMINAL; - req.width = char_width; - req.height = char_height; - req.horiResolution = horz_resolution; - req.vertResolution = vert_resolution; - - return FT_Request_Size( face, &req ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Pixel_Sizes( FT_Face face, - FT_UInt pixel_width, - FT_UInt pixel_height ) - { - FT_Size_RequestRec req; - - - /* check of `face' delayed to `FT_Request_Size' */ - - if ( pixel_width == 0 ) - pixel_width = pixel_height; - else if ( pixel_height == 0 ) - pixel_height = pixel_width; - - if ( pixel_width < 1 ) - pixel_width = 1; - if ( pixel_height < 1 ) - pixel_height = 1; - - /* use `>=' to avoid potential compiler warning on 16bit platforms */ - if ( pixel_width >= 0xFFFFU ) - pixel_width = 0xFFFFU; - if ( pixel_height >= 0xFFFFU ) - pixel_height = 0xFFFFU; - - req.type = FT_SIZE_REQUEST_TYPE_NOMINAL; - req.width = (FT_Long)( pixel_width << 6 ); - req.height = (FT_Long)( pixel_height << 6 ); - req.horiResolution = 0; - req.vertResolution = 0; - - return FT_Request_Size( face, &req ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Kerning( FT_Face face, - FT_UInt left_glyph, - FT_UInt right_glyph, - FT_UInt kern_mode, - FT_Vector *akerning ) - { - FT_Error error = FT_Err_Ok; - FT_Driver driver; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !akerning ) - return FT_THROW( Invalid_Argument ); - - driver = face->driver; - - akerning->x = 0; - akerning->y = 0; - - if ( driver->clazz->get_kerning ) - { - error = driver->clazz->get_kerning( face, - left_glyph, - right_glyph, - akerning ); - if ( !error ) - { - if ( kern_mode != FT_KERNING_UNSCALED ) - { - akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale ); - akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale ); - - if ( kern_mode != FT_KERNING_UNFITTED ) - { - FT_Pos orig_x = akerning->x; - FT_Pos orig_y = akerning->y; - - - /* we scale down kerning values for small ppem values */ - /* to avoid that rounding makes them too big. */ - /* `25' has been determined heuristically. */ - if ( face->size->metrics.x_ppem < 25 ) - akerning->x = FT_MulDiv( orig_x, - face->size->metrics.x_ppem, 25 ); - if ( face->size->metrics.y_ppem < 25 ) - akerning->y = FT_MulDiv( orig_y, - face->size->metrics.y_ppem, 25 ); - - akerning->x = FT_PIX_ROUND( akerning->x ); - akerning->y = FT_PIX_ROUND( akerning->y ); - -#ifdef FT_DEBUG_LEVEL_TRACE - { - FT_Pos orig_x_rounded = FT_PIX_ROUND( orig_x ); - FT_Pos orig_y_rounded = FT_PIX_ROUND( orig_y ); - - - if ( akerning->x != orig_x_rounded || - akerning->y != orig_y_rounded ) - FT_TRACE5(( "FT_Get_Kerning: horizontal kerning" - " (%d, %d) scaled down to (%d, %d) pixels\n", - orig_x_rounded / 64, orig_y_rounded / 64, - akerning->x / 64, akerning->y / 64 )); - } -#endif - } - } - } - } - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Track_Kerning( FT_Face face, - FT_Fixed point_size, - FT_Int degree, - FT_Fixed* akerning ) - { - FT_Service_Kerning service; - FT_Error error = FT_Err_Ok; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !akerning ) - return FT_THROW( Invalid_Argument ); - - FT_FACE_FIND_SERVICE( face, service, KERNING ); - if ( !service ) - return FT_THROW( Unimplemented_Feature ); - - error = service->get_track( face, - point_size, - degree, - akerning ); - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Select_Charmap( FT_Face face, - FT_Encoding encoding ) - { - FT_CharMap* cur; - FT_CharMap* limit; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( encoding == FT_ENCODING_NONE ) - return FT_THROW( Invalid_Argument ); - - /* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */ - /* charmap available, i.e., one with UCS-4 characters, if possible. */ - /* */ - /* This is done by find_unicode_charmap() above, to share code. */ - if ( encoding == FT_ENCODING_UNICODE ) - return find_unicode_charmap( face ); - - cur = face->charmaps; - if ( !cur ) - return FT_THROW( Invalid_CharMap_Handle ); - - limit = cur + face->num_charmaps; - - for ( ; cur < limit; cur++ ) - { - if ( cur[0]->encoding == encoding ) - { - face->charmap = cur[0]; - return 0; - } - } - - return FT_THROW( Invalid_Argument ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Charmap( FT_Face face, - FT_CharMap charmap ) - { - FT_CharMap* cur; - FT_CharMap* limit; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - cur = face->charmaps; - if ( !cur || !charmap ) - return FT_THROW( Invalid_CharMap_Handle ); - - if ( FT_Get_CMap_Format( charmap ) == 14 ) - return FT_THROW( Invalid_Argument ); - - limit = cur + face->num_charmaps; - - for ( ; cur < limit; cur++ ) - { - if ( cur[0] == charmap ) - { - face->charmap = cur[0]; - return FT_Err_Ok; - } - } - - return FT_THROW( Invalid_Argument ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Int ) - FT_Get_Charmap_Index( FT_CharMap charmap ) - { - FT_Int i; - - - if ( !charmap || !charmap->face ) - return -1; - - for ( i = 0; i < charmap->face->num_charmaps; i++ ) - if ( charmap->face->charmaps[i] == charmap ) - break; - - FT_ASSERT( i < charmap->face->num_charmaps ); - - return i; - } - - - static void - ft_cmap_done_internal( FT_CMap cmap ) - { - FT_CMap_Class clazz = cmap->clazz; - FT_Face face = cmap->charmap.face; - FT_Memory memory = FT_FACE_MEMORY( face ); - - - if ( clazz->done ) - clazz->done( cmap ); - - FT_FREE( cmap ); - } - - - FT_BASE_DEF( void ) - FT_CMap_Done( FT_CMap cmap ) - { - if ( cmap ) - { - FT_Face face = cmap->charmap.face; - FT_Memory memory = FT_FACE_MEMORY( face ); - FT_Error error; - FT_Int i, j; - - - for ( i = 0; i < face->num_charmaps; i++ ) - { - if ( (FT_CMap)face->charmaps[i] == cmap ) - { - FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1]; - - - if ( FT_RENEW_ARRAY( face->charmaps, - face->num_charmaps, - face->num_charmaps - 1 ) ) - return; - - /* remove it from our list of charmaps */ - for ( j = i + 1; j < face->num_charmaps; j++ ) - { - if ( j == face->num_charmaps - 1 ) - face->charmaps[j - 1] = last_charmap; - else - face->charmaps[j - 1] = face->charmaps[j]; - } - - face->num_charmaps--; - - if ( (FT_CMap)face->charmap == cmap ) - face->charmap = NULL; - - ft_cmap_done_internal( cmap ); - - break; - } - } - } - } - - - FT_BASE_DEF( FT_Error ) - FT_CMap_New( FT_CMap_Class clazz, - FT_Pointer init_data, - FT_CharMap charmap, - FT_CMap *acmap ) - { - FT_Error error = FT_Err_Ok; - FT_Face face; - FT_Memory memory; - FT_CMap cmap = NULL; - - - if ( !clazz || !charmap || !charmap->face ) - return FT_THROW( Invalid_Argument ); - - face = charmap->face; - memory = FT_FACE_MEMORY( face ); - - if ( !FT_ALLOC( cmap, clazz->size ) ) - { - cmap->charmap = *charmap; - cmap->clazz = clazz; - - if ( clazz->init ) - { - error = clazz->init( cmap, init_data ); - if ( error ) - goto Fail; - } - - /* add it to our list of charmaps */ - if ( FT_RENEW_ARRAY( face->charmaps, - face->num_charmaps, - face->num_charmaps + 1 ) ) - goto Fail; - - face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap; - } - - Exit: - if ( acmap ) - *acmap = cmap; - - return error; - - Fail: - ft_cmap_done_internal( cmap ); - cmap = NULL; - goto Exit; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt ) - FT_Get_Char_Index( FT_Face face, - FT_ULong charcode ) - { - FT_UInt result = 0; - - - if ( face && face->charmap ) - { - FT_CMap cmap = FT_CMAP( face->charmap ); - - - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large charcode" )); - FT_TRACE1(( " 0x%x is truncated\n", charcode )); - } - - result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode ); - if ( result >= (FT_UInt)face->num_glyphs ) - result = 0; - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_ULong ) - FT_Get_First_Char( FT_Face face, - FT_UInt *agindex ) - { - FT_ULong result = 0; - FT_UInt gindex = 0; - - - /* only do something if we have a charmap, and we have glyphs at all */ - if ( face && face->charmap && face->num_glyphs ) - { - gindex = FT_Get_Char_Index( face, 0 ); - if ( gindex == 0 ) - result = FT_Get_Next_Char( face, 0, &gindex ); - } - - if ( agindex ) - *agindex = gindex; - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_ULong ) - FT_Get_Next_Char( FT_Face face, - FT_ULong charcode, - FT_UInt *agindex ) - { - FT_ULong result = 0; - FT_UInt gindex = 0; - - - if ( face && face->charmap && face->num_glyphs ) - { - FT_UInt32 code = (FT_UInt32)charcode; - FT_CMap cmap = FT_CMAP( face->charmap ); - - - do - { - gindex = cmap->clazz->char_next( cmap, &code ); - - } while ( gindex >= (FT_UInt)face->num_glyphs ); - - result = ( gindex == 0 ) ? 0 : code; - } - - if ( agindex ) - *agindex = gindex; - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt ) - FT_Face_GetCharVariantIndex( FT_Face face, - FT_ULong charcode, - FT_ULong variantSelector ) - { - FT_UInt result = 0; - - - if ( face && - face->charmap && - face->charmap->encoding == FT_ENCODING_UNICODE ) - { - FT_CharMap charmap = find_variant_selector_charmap( face ); - FT_CMap ucmap = FT_CMAP( face->charmap ); - - - if ( charmap ) - { - FT_CMap vcmap = FT_CMAP( charmap ); - - - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large charcode" )); - FT_TRACE1(( " 0x%x is truncated\n", charcode )); - } - if ( variantSelector > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" )); - FT_TRACE1(( " 0x%x is truncated\n", variantSelector )); - } - - result = vcmap->clazz->char_var_index( vcmap, ucmap, - (FT_UInt32)charcode, - (FT_UInt32)variantSelector ); - } - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Int ) - FT_Face_GetCharVariantIsDefault( FT_Face face, - FT_ULong charcode, - FT_ULong variantSelector ) - { - FT_Int result = -1; - - - if ( face ) - { - FT_CharMap charmap = find_variant_selector_charmap( face ); - - - if ( charmap ) - { - FT_CMap vcmap = FT_CMAP( charmap ); - - - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large charcode" )); - FT_TRACE1(( " 0x%x is truncated\n", charcode )); - } - if ( variantSelector > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" )); - FT_TRACE1(( " 0x%x is truncated\n", variantSelector )); - } - - result = vcmap->clazz->char_var_default( vcmap, - (FT_UInt32)charcode, - (FT_UInt32)variantSelector ); - } - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt32* ) - FT_Face_GetVariantSelectors( FT_Face face ) - { - FT_UInt32 *result = NULL; - - - if ( face ) - { - FT_CharMap charmap = find_variant_selector_charmap( face ); - - - if ( charmap ) - { - FT_CMap vcmap = FT_CMAP( charmap ); - FT_Memory memory = FT_FACE_MEMORY( face ); - - - result = vcmap->clazz->variant_list( vcmap, memory ); - } - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt32* ) - FT_Face_GetVariantsOfChar( FT_Face face, - FT_ULong charcode ) - { - FT_UInt32 *result = NULL; - - - if ( face ) - { - FT_CharMap charmap = find_variant_selector_charmap( face ); - - - if ( charmap ) - { - FT_CMap vcmap = FT_CMAP( charmap ); - FT_Memory memory = FT_FACE_MEMORY( face ); - - - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large charcode" )); - FT_TRACE1(( " 0x%x is truncated\n", charcode )); - } - - result = vcmap->clazz->charvariant_list( vcmap, memory, - (FT_UInt32)charcode ); - } - } - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt32* ) - FT_Face_GetCharsOfVariant( FT_Face face, - FT_ULong variantSelector ) - { - FT_UInt32 *result = NULL; - - - if ( face ) - { - FT_CharMap charmap = find_variant_selector_charmap( face ); - - - if ( charmap ) - { - FT_CMap vcmap = FT_CMAP( charmap ); - FT_Memory memory = FT_FACE_MEMORY( face ); - - - if ( variantSelector > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" )); - FT_TRACE1(( " 0x%x is truncated\n", variantSelector )); - } - - result = vcmap->clazz->variantchar_list( vcmap, memory, - (FT_UInt32)variantSelector ); - } - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_UInt ) - FT_Get_Name_Index( FT_Face face, - FT_String* glyph_name ) - { - FT_UInt result = 0; - - - if ( face && - FT_HAS_GLYPH_NAMES( face ) && - glyph_name ) - { - FT_Service_GlyphDict service; - - - FT_FACE_LOOKUP_SERVICE( face, - service, - GLYPH_DICT ); - - if ( service && service->name_index ) - result = service->name_index( face, glyph_name ); - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Glyph_Name( FT_Face face, - FT_UInt glyph_index, - FT_Pointer buffer, - FT_UInt buffer_max ) - { - FT_Error error; - FT_Service_GlyphDict service; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !buffer || buffer_max == 0 ) - return FT_THROW( Invalid_Argument ); - - /* clean up buffer */ - ((FT_Byte*)buffer)[0] = '\0'; - - if ( (FT_Long)glyph_index >= face->num_glyphs ) - return FT_THROW( Invalid_Glyph_Index ); - - if ( !FT_HAS_GLYPH_NAMES( face ) ) - return FT_THROW( Invalid_Argument ); - - FT_FACE_LOOKUP_SERVICE( face, service, GLYPH_DICT ); - if ( service && service->get_name ) - error = service->get_name( face, glyph_index, buffer, buffer_max ); - else - error = FT_THROW( Invalid_Argument ); - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( const char* ) - FT_Get_Postscript_Name( FT_Face face ) - { - const char* result = NULL; - - - if ( !face ) - goto Exit; - - if ( !result ) - { - FT_Service_PsFontName service; - - - FT_FACE_LOOKUP_SERVICE( face, - service, - POSTSCRIPT_FONT_NAME ); - - if ( service && service->get_ps_font_name ) - result = service->get_ps_font_name( face ); - } - - Exit: - return result; - } - - - /* documentation is in tttables.h */ - - FT_EXPORT_DEF( void* ) - FT_Get_Sfnt_Table( FT_Face face, - FT_Sfnt_Tag tag ) - { - void* table = NULL; - FT_Service_SFNT_Table service; - - - if ( face && FT_IS_SFNT( face ) ) - { - FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE ); - if ( service ) - table = service->get_table( face, tag ); - } - - return table; - } - - - /* documentation is in tttables.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Load_Sfnt_Table( FT_Face face, - FT_ULong tag, - FT_Long offset, - FT_Byte* buffer, - FT_ULong* length ) - { - FT_Service_SFNT_Table service; - - - if ( !face || !FT_IS_SFNT( face ) ) - return FT_THROW( Invalid_Face_Handle ); - - FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE ); - if ( !service ) - return FT_THROW( Unimplemented_Feature ); - - return service->load_table( face, tag, offset, buffer, length ); - } - - - /* documentation is in tttables.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Sfnt_Table_Info( FT_Face face, - FT_UInt table_index, - FT_ULong *tag, - FT_ULong *length ) - { - FT_Service_SFNT_Table service; - FT_ULong offset; - - - /* test for valid `length' delayed to `service->table_info' */ - - if ( !face || !FT_IS_SFNT( face ) ) - return FT_THROW( Invalid_Face_Handle ); - - FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE ); - if ( !service ) - return FT_THROW( Unimplemented_Feature ); - - return service->table_info( face, table_index, tag, &offset, length ); - } - - - /* documentation is in tttables.h */ - - FT_EXPORT_DEF( FT_ULong ) - FT_Get_CMap_Language_ID( FT_CharMap charmap ) - { - FT_Service_TTCMaps service; - FT_Face face; - TT_CMapInfo cmap_info; - - - if ( !charmap || !charmap->face ) - return 0; - - face = charmap->face; - FT_FACE_FIND_SERVICE( face, service, TT_CMAP ); - if ( !service ) - return 0; - if ( service->get_cmap_info( charmap, &cmap_info )) - return 0; - - return cmap_info.language; - } - - - /* documentation is in tttables.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_Get_CMap_Format( FT_CharMap charmap ) - { - FT_Service_TTCMaps service; - FT_Face face; - TT_CMapInfo cmap_info; - - - if ( !charmap || !charmap->face ) - return -1; - - face = charmap->face; - FT_FACE_FIND_SERVICE( face, service, TT_CMAP ); - if ( !service ) - return -1; - if ( service->get_cmap_info( charmap, &cmap_info )) - return -1; - - return cmap_info.format; - } - - - /* documentation is in ftsizes.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Activate_Size( FT_Size size ) - { - FT_Face face; - - - if ( !size ) - return FT_THROW( Invalid_Size_Handle ); - - face = size->face; - if ( !face || !face->driver ) - return FT_THROW( Invalid_Face_Handle ); - - /* we don't need anything more complex than that; all size objects */ - /* are already listed by the face */ - face->size = size; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** R E N D E R E R S ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - /* lookup a renderer by glyph format in the library's list */ - FT_BASE_DEF( FT_Renderer ) - FT_Lookup_Renderer( FT_Library library, - FT_Glyph_Format format, - FT_ListNode* node ) - { - FT_ListNode cur; - FT_Renderer result = NULL; - - - if ( !library ) - goto Exit; - - cur = library->renderers.head; - - if ( node ) - { - if ( *node ) - cur = (*node)->next; - *node = NULL; - } - - while ( cur ) - { - FT_Renderer renderer = FT_RENDERER( cur->data ); - - - if ( renderer->glyph_format == format ) - { - if ( node ) - *node = cur; - - result = renderer; - break; - } - cur = cur->next; - } - - Exit: - return result; - } - - - static FT_Renderer - ft_lookup_glyph_renderer( FT_GlyphSlot slot ) - { - FT_Face face = slot->face; - FT_Library library = FT_FACE_LIBRARY( face ); - FT_Renderer result = library->cur_renderer; - - - if ( !result || result->glyph_format != slot->format ) - result = FT_Lookup_Renderer( library, slot->format, 0 ); - - return result; - } - - - static void - ft_set_current_renderer( FT_Library library ) - { - FT_Renderer renderer; - - - renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 ); - library->cur_renderer = renderer; - } - - - static FT_Error - ft_add_renderer( FT_Module module ) - { - FT_Library library = module->library; - FT_Memory memory = library->memory; - FT_Error error; - FT_ListNode node = NULL; - - - if ( FT_NEW( node ) ) - goto Exit; - - { - FT_Renderer render = FT_RENDERER( module ); - FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz; - - - render->clazz = clazz; - render->glyph_format = clazz->glyph_format; - - /* allocate raster object if needed */ - if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE && - clazz->raster_class->raster_new ) - { - error = clazz->raster_class->raster_new( memory, &render->raster ); - if ( error ) - goto Fail; - - render->raster_render = clazz->raster_class->raster_render; - render->render = clazz->render_glyph; - } - - /* add to list */ - node->data = module; - FT_List_Add( &library->renderers, node ); - - ft_set_current_renderer( library ); - } - - Fail: - if ( error ) - FT_FREE( node ); - - Exit: - return error; - } - - - static void - ft_remove_renderer( FT_Module module ) - { - FT_Library library; - FT_Memory memory; - FT_ListNode node; - - - library = module->library; - if ( !library ) - return; - - memory = library->memory; - - node = FT_List_Find( &library->renderers, module ); - if ( node ) - { - FT_Renderer render = FT_RENDERER( module ); - - - /* release raster object, if any */ - if ( render->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE && - render->raster ) - render->clazz->raster_class->raster_done( render->raster ); - - /* remove from list */ - FT_List_Remove( &library->renderers, node ); - FT_FREE( node ); - - ft_set_current_renderer( library ); - } - } - - - /* documentation is in ftrender.h */ - - FT_EXPORT_DEF( FT_Renderer ) - FT_Get_Renderer( FT_Library library, - FT_Glyph_Format format ) - { - /* test for valid `library' delayed to `FT_Lookup_Renderer' */ - - return FT_Lookup_Renderer( library, format, 0 ); - } - - - /* documentation is in ftrender.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Set_Renderer( FT_Library library, - FT_Renderer renderer, - FT_UInt num_params, - FT_Parameter* parameters ) - { - FT_ListNode node; - FT_Error error = FT_Err_Ok; - - FT_Renderer_SetModeFunc set_mode; - - - if ( !library ) - { - error = FT_THROW( Invalid_Library_Handle ); - goto Exit; - } - - if ( !renderer ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( num_params > 0 && !parameters ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - node = FT_List_Find( &library->renderers, renderer ); - if ( !node ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - FT_List_Up( &library->renderers, node ); - - if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE ) - library->cur_renderer = renderer; - - set_mode = renderer->clazz->set_mode; - - for ( ; num_params > 0; num_params-- ) - { - error = set_mode( renderer, parameters->tag, parameters->data ); - if ( error ) - break; - parameters++; - } - - Exit: - return error; - } - - - FT_BASE_DEF( FT_Error ) - FT_Render_Glyph_Internal( FT_Library library, - FT_GlyphSlot slot, - FT_Render_Mode render_mode ) - { - FT_Error error = FT_Err_Ok; - FT_Renderer renderer; - - - /* if it is already a bitmap, no need to do anything */ - switch ( slot->format ) - { - case FT_GLYPH_FORMAT_BITMAP: /* already a bitmap, don't do anything */ - break; - - default: - { - FT_ListNode node = NULL; - - - /* small shortcut for the very common case */ - if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) - { - renderer = library->cur_renderer; - node = library->renderers.head; - } - else - renderer = FT_Lookup_Renderer( library, slot->format, &node ); - - error = FT_ERR( Unimplemented_Feature ); - while ( renderer ) - { - error = renderer->render( renderer, slot, render_mode, NULL ); - if ( !error || - FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) - break; - - /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ - /* is unsupported by the current renderer for this glyph image */ - /* format. */ - - /* now, look for another renderer that supports the same */ - /* format. */ - renderer = FT_Lookup_Renderer( library, slot->format, &node ); - } - } - } - -#ifdef FT_DEBUG_LEVEL_TRACE - -#undef FT_COMPONENT -#define FT_COMPONENT trace_bitmap - - /* - * Computing the MD5 checksum is expensive, unnecessarily distorting a - * possible profiling of FreeType if compiled with tracing support. For - * this reason, we execute the following code only if explicitly - * requested. - */ - - /* we use FT_TRACE3 in this block */ - if ( ft_trace_levels[trace_bitmap] >= 3 ) - { - /* we convert to a single bitmap format for computing the checksum */ - if ( !error && slot->bitmap.buffer ) - { - FT_Bitmap bitmap; - FT_Error err; - - - FT_Bitmap_Init( &bitmap ); - - /* this also converts the bitmap flow to `down' (i.e., pitch > 0) */ - err = FT_Bitmap_Convert( library, &slot->bitmap, &bitmap, 1 ); - if ( !err ) - { - MD5_CTX ctx; - unsigned char md5[16]; - int i; - unsigned int rows = bitmap.rows; - unsigned int pitch = (unsigned int)bitmap.pitch; - - - MD5_Init( &ctx ); - if ( bitmap.buffer ) - MD5_Update( &ctx, bitmap.buffer, rows * pitch ); - MD5_Final( md5, &ctx ); - - FT_TRACE3(( "MD5 checksum for %dx%d bitmap:\n" - " ", - rows, pitch )); - for ( i = 0; i < 16; i++ ) - FT_TRACE3(( "%02X", md5[i] )); - FT_TRACE3(( "\n" )); - } - - FT_Bitmap_Done( library, &bitmap ); - } - } - -#undef FT_COMPONENT -#define FT_COMPONENT trace_objs - -#endif /* FT_DEBUG_LEVEL_TRACE */ - - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Render_Glyph( FT_GlyphSlot slot, - FT_Render_Mode render_mode ) - { - FT_Library library; - - - if ( !slot || !slot->face ) - return FT_THROW( Invalid_Argument ); - - library = FT_FACE_LIBRARY( slot->face ); - - return FT_Render_Glyph_Internal( library, slot, render_mode ); - } - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** M O D U L E S ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* */ - /* Destroy_Module */ - /* */ - /* */ - /* Destroys a given module object. For drivers, this also destroys */ - /* all child faces. */ - /* */ - /* */ - /* module :: A handle to the target driver object. */ - /* */ - /* */ - /* The driver _must_ be LOCKED! */ - /* */ - static void - Destroy_Module( FT_Module module ) - { - FT_Memory memory = module->memory; - FT_Module_Class* clazz = module->clazz; - FT_Library library = module->library; - - - if ( library && library->auto_hinter == module ) - library->auto_hinter = NULL; - - /* if the module is a renderer */ - if ( FT_MODULE_IS_RENDERER( module ) ) - ft_remove_renderer( module ); - - /* if the module is a font driver, add some steps */ - if ( FT_MODULE_IS_DRIVER( module ) ) - Destroy_Driver( FT_DRIVER( module ) ); - - /* finalize the module object */ - if ( clazz->module_done ) - clazz->module_done( module ); - - /* discard it */ - FT_FREE( module ); - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Add_Module( FT_Library library, - const FT_Module_Class* clazz ) - { - FT_Error error; - FT_Memory memory; - FT_Module module = NULL; - FT_UInt nn; - - -#define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \ - FREETYPE_MINOR ) - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !clazz ) - return FT_THROW( Invalid_Argument ); - - /* check freetype version */ - if ( clazz->module_requires > FREETYPE_VER_FIXED ) - return FT_THROW( Invalid_Version ); - - /* look for a module with the same name in the library's table */ - for ( nn = 0; nn < library->num_modules; nn++ ) - { - module = library->modules[nn]; - if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 ) - { - /* this installed module has the same name, compare their versions */ - if ( clazz->module_version <= module->clazz->module_version ) - return FT_THROW( Lower_Module_Version ); - - /* remove the module from our list, then exit the loop to replace */ - /* it by our new version.. */ - FT_Remove_Module( library, module ); - break; - } - } - - memory = library->memory; - error = FT_Err_Ok; - - if ( library->num_modules >= FT_MAX_MODULES ) - { - error = FT_THROW( Too_Many_Drivers ); - goto Exit; - } - - /* allocate module object */ - if ( FT_ALLOC( module, clazz->module_size ) ) - goto Exit; - - /* base initialization */ - module->library = library; - module->memory = memory; - module->clazz = (FT_Module_Class*)clazz; - - /* check whether the module is a renderer - this must be performed */ - /* before the normal module initialization */ - if ( FT_MODULE_IS_RENDERER( module ) ) - { - /* add to the renderers list */ - error = ft_add_renderer( module ); - if ( error ) - goto Fail; - } - - /* is the module a auto-hinter? */ - if ( FT_MODULE_IS_HINTER( module ) ) - library->auto_hinter = module; - - /* if the module is a font driver */ - if ( FT_MODULE_IS_DRIVER( module ) ) - { - FT_Driver driver = FT_DRIVER( module ); - - - driver->clazz = (FT_Driver_Class)module->clazz; - } - - if ( clazz->module_init ) - { - error = clazz->module_init( module ); - if ( error ) - goto Fail; - } - - /* add module to the library's table */ - library->modules[library->num_modules++] = module; - - Exit: - return error; - - Fail: - if ( FT_MODULE_IS_RENDERER( module ) ) - { - FT_Renderer renderer = FT_RENDERER( module ); - - - if ( renderer->clazz && - renderer->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE && - renderer->raster ) - renderer->clazz->raster_class->raster_done( renderer->raster ); - } - - FT_FREE( module ); - goto Exit; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Module ) - FT_Get_Module( FT_Library library, - const char* module_name ) - { - FT_Module result = NULL; - FT_Module* cur; - FT_Module* limit; - - - if ( !library || !module_name ) - return result; - - cur = library->modules; - limit = cur + library->num_modules; - - for ( ; cur < limit; cur++ ) - if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 ) - { - result = cur[0]; - break; - } - - return result; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( const void* ) - FT_Get_Module_Interface( FT_Library library, - const char* mod_name ) - { - FT_Module module; - - - /* test for valid `library' delayed to FT_Get_Module() */ - - module = FT_Get_Module( library, mod_name ); - - return module ? module->clazz->module_interface : 0; - } - - - FT_BASE_DEF( FT_Pointer ) - ft_module_get_service( FT_Module module, - const char* service_id, - FT_Bool global ) - { - FT_Pointer result = NULL; - - - if ( module ) - { - FT_ASSERT( module->clazz && module->clazz->get_interface ); - - /* first, look for the service in the module */ - if ( module->clazz->get_interface ) - result = module->clazz->get_interface( module, service_id ); - - if ( global && !result ) - { - /* we didn't find it, look in all other modules then */ - FT_Library library = module->library; - FT_Module* cur = library->modules; - FT_Module* limit = cur + library->num_modules; - - - for ( ; cur < limit; cur++ ) - { - if ( cur[0] != module ) - { - FT_ASSERT( cur[0]->clazz ); - - if ( cur[0]->clazz->get_interface ) - { - result = cur[0]->clazz->get_interface( cur[0], service_id ); - if ( result ) - break; - } - } - } - } - } - - return result; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Remove_Module( FT_Library library, - FT_Module module ) - { - /* try to find the module from the table, then remove it from there */ - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( module ) - { - FT_Module* cur = library->modules; - FT_Module* limit = cur + library->num_modules; - - - for ( ; cur < limit; cur++ ) - { - if ( cur[0] == module ) - { - /* remove it from the table */ - library->num_modules--; - limit--; - while ( cur < limit ) - { - cur[0] = cur[1]; - cur++; - } - limit[0] = NULL; - - /* destroy the module */ - Destroy_Module( module ); - - return FT_Err_Ok; - } - } - } - return FT_THROW( Invalid_Driver_Handle ); - } - - - static FT_Error - ft_property_do( FT_Library library, - const FT_String* module_name, - const FT_String* property_name, - void* value, - FT_Bool set, - FT_Bool value_is_string ) - { - FT_Module* cur; - FT_Module* limit; - FT_Module_Interface interface; - - FT_Service_Properties service; - -#ifdef FT_DEBUG_LEVEL_ERROR - const FT_String* set_name = "FT_Property_Set"; - const FT_String* get_name = "FT_Property_Get"; - const FT_String* func_name = set ? set_name : get_name; -#endif - - FT_Bool missing_func; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !module_name || !property_name || !value ) - return FT_THROW( Invalid_Argument ); - - cur = library->modules; - limit = cur + library->num_modules; - - /* search module */ - for ( ; cur < limit; cur++ ) - if ( !ft_strcmp( cur[0]->clazz->module_name, module_name ) ) - break; - - if ( cur == limit ) - { - FT_ERROR(( "%s: can't find module `%s'\n", - func_name, module_name )); - return FT_THROW( Missing_Module ); - } - - /* check whether we have a service interface */ - if ( !cur[0]->clazz->get_interface ) - { - FT_ERROR(( "%s: module `%s' doesn't support properties\n", - func_name, module_name )); - return FT_THROW( Unimplemented_Feature ); - } - - /* search property service */ - interface = cur[0]->clazz->get_interface( cur[0], - FT_SERVICE_ID_PROPERTIES ); - if ( !interface ) - { - FT_ERROR(( "%s: module `%s' doesn't support properties\n", - func_name, module_name )); - return FT_THROW( Unimplemented_Feature ); - } - - service = (FT_Service_Properties)interface; - - if ( set ) - missing_func = (FT_Bool)( !service->set_property ); - else - missing_func = (FT_Bool)( !service->get_property ); - - if ( missing_func ) - { - FT_ERROR(( "%s: property service of module `%s' is broken\n", - func_name, module_name )); - return FT_THROW( Unimplemented_Feature ); - } - - return set ? service->set_property( cur[0], - property_name, - value, - value_is_string ) - : service->get_property( cur[0], - property_name, - value ); - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Property_Set( FT_Library library, - const FT_String* module_name, - const FT_String* property_name, - const void* value ) - { - return ft_property_do( library, - module_name, - property_name, - (void*)value, - TRUE, - FALSE ); - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Property_Get( FT_Library library, - const FT_String* module_name, - const FT_String* property_name, - void* value ) - { - return ft_property_do( library, - module_name, - property_name, - value, - FALSE, - FALSE ); - } - - -#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES - - /* this variant is used for handling the FREETYPE_PROPERTIES */ - /* environment variable */ - - FT_BASE_DEF( FT_Error ) - ft_property_string_set( FT_Library library, - const FT_String* module_name, - const FT_String* property_name, - FT_String* value ) - { - return ft_property_do( library, - module_name, - property_name, - (void*)value, - TRUE, - TRUE ); - } - -#endif - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** L I B R A R Y ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Reference_Library( FT_Library library ) - { - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - library->refcount++; - - return FT_Err_Ok; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_New_Library( FT_Memory memory, - FT_Library *alibrary ) - { - FT_Library library = NULL; - FT_Error error; - - - if ( !memory || !alibrary ) - return FT_THROW( Invalid_Argument ); - -#ifdef FT_DEBUG_LEVEL_ERROR - /* init debugging support */ - ft_debug_init(); -#endif - - /* first of all, allocate the library object */ - if ( FT_NEW( library ) ) - return error; - - library->memory = memory; - -#ifdef FT_CONFIG_OPTION_PIC - /* initialize position independent code containers */ - error = ft_pic_container_init( library ); - if ( error ) - goto Fail; -#endif - - /* we don't use raster_pool anymore. */ - library->raster_pool_size = 0; - library->raster_pool = NULL; - - library->version_major = FREETYPE_MAJOR; - library->version_minor = FREETYPE_MINOR; - library->version_patch = FREETYPE_PATCH; - - library->refcount = 1; - - /* That's ok now */ - *alibrary = library; - - return FT_Err_Ok; - -#ifdef FT_CONFIG_OPTION_PIC - Fail: - ft_pic_container_destroy( library ); -#endif - FT_FREE( library ); - return error; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( void ) - FT_Library_Version( FT_Library library, - FT_Int *amajor, - FT_Int *aminor, - FT_Int *apatch ) - { - FT_Int major = 0; - FT_Int minor = 0; - FT_Int patch = 0; - - - if ( library ) - { - major = library->version_major; - minor = library->version_minor; - patch = library->version_patch; - } - - if ( amajor ) - *amajor = major; - - if ( aminor ) - *aminor = minor; - - if ( apatch ) - *apatch = patch; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Done_Library( FT_Library library ) - { - FT_Memory memory; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - library->refcount--; - if ( library->refcount > 0 ) - goto Exit; - - memory = library->memory; - - /* - * Close all faces in the library. If we don't do this, we can have - * some subtle memory leaks. - * - * Example: - * - * - the cff font driver uses the pshinter module in cff_size_done - * - if the pshinter module is destroyed before the cff font driver, - * opened FT_Face objects managed by the driver are not properly - * destroyed, resulting in a memory leak - * - * Some faces are dependent on other faces, like Type42 faces that - * depend on TrueType faces synthesized internally. - * - * The order of drivers should be specified in driver_name[]. - */ - { - FT_UInt m, n; - const char* driver_name[] = { "type42", NULL }; - - - for ( m = 0; - m < sizeof ( driver_name ) / sizeof ( driver_name[0] ); - m++ ) - { - for ( n = 0; n < library->num_modules; n++ ) - { - FT_Module module = library->modules[n]; - const char* module_name = module->clazz->module_name; - FT_List faces; - - - if ( driver_name[m] && - ft_strcmp( module_name, driver_name[m] ) != 0 ) - continue; - - if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 ) - continue; - - FT_TRACE7(( "FT_Done_Library: close faces for %s\n", module_name )); - - faces = &FT_DRIVER( module )->faces_list; - while ( faces->head ) - { - FT_Done_Face( FT_FACE( faces->head->data ) ); - if ( faces->head ) - FT_TRACE0(( "FT_Done_Library: failed to free some faces\n" )); - } - } - } - } - - /* Close all other modules in the library */ -#if 1 - /* XXX Modules are removed in the reversed order so that */ - /* type42 module is removed before truetype module. This */ - /* avoids double free in some occasions. It is a hack. */ - while ( library->num_modules > 0 ) - FT_Remove_Module( library, - library->modules[library->num_modules - 1] ); -#else - { - FT_UInt n; - - - for ( n = 0; n < library->num_modules; n++ ) - { - FT_Module module = library->modules[n]; - - - if ( module ) - { - Destroy_Module( module ); - library->modules[n] = NULL; - } - } - } -#endif - -#ifdef FT_CONFIG_OPTION_PIC - /* Destroy pic container contents */ - ft_pic_container_destroy( library ); -#endif - - FT_FREE( library ); - - Exit: - return FT_Err_Ok; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( void ) - FT_Set_Debug_Hook( FT_Library library, - FT_UInt hook_index, - FT_DebugHook_Func debug_hook ) - { - if ( library && debug_hook && - hook_index < - ( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) ) - library->debug_hooks[hook_index] = debug_hook; - } - - - /* documentation is in ftmodapi.h */ - - FT_EXPORT_DEF( FT_TrueTypeEngineType ) - FT_Get_TrueType_Engine_Type( FT_Library library ) - { - FT_TrueTypeEngineType result = FT_TRUETYPE_ENGINE_TYPE_NONE; - - - if ( library ) - { - FT_Module module = FT_Get_Module( library, "truetype" ); - - - if ( module ) - { - FT_Service_TrueTypeEngine service; - - - service = (FT_Service_TrueTypeEngine) - ft_module_get_service( module, - FT_SERVICE_ID_TRUETYPE_ENGINE, - 0 ); - if ( service ) - result = service->engine_type; - } - } - - return result; - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_SubGlyph_Info( FT_GlyphSlot glyph, - FT_UInt sub_index, - FT_Int *p_index, - FT_UInt *p_flags, - FT_Int *p_arg1, - FT_Int *p_arg2, - FT_Matrix *p_transform ) - { - FT_Error error = FT_ERR( Invalid_Argument ); - - - if ( glyph && - glyph->subglyphs && - glyph->format == FT_GLYPH_FORMAT_COMPOSITE && - sub_index < glyph->num_subglyphs ) - { - FT_SubGlyph subg = glyph->subglyphs + sub_index; - - - *p_index = subg->index; - *p_flags = subg->flags; - *p_arg1 = subg->arg1; - *p_arg2 = subg->arg2; - *p_transform = subg->transform; - - error = FT_Err_Ok; - } - - return error; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftoutln.c b/third_party/freetype/src/base/ftoutln.c deleted file mode 100644 index 464a066dcc..0000000000 --- a/third_party/freetype/src/base/ftoutln.c +++ /dev/null @@ -1,1108 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftoutln.c */ -/* */ -/* FreeType outline management (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* All functions are declared in freetype.h. */ - /* */ - /*************************************************************************/ - - -#include -#include FT_OUTLINE_H -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_CALC_H -#include FT_INTERNAL_DEBUG_H -#include FT_TRIGONOMETRY_H - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_outline - - - static - const FT_Outline null_outline = { 0, 0, NULL, NULL, NULL, 0 }; - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Decompose( FT_Outline* outline, - const FT_Outline_Funcs* func_interface, - void* user ) - { -#undef SCALED -#define SCALED( x ) ( ( (x) < 0 ? -( -(x) << shift ) \ - : ( (x) << shift ) ) - delta ) - - FT_Vector v_last; - FT_Vector v_control; - FT_Vector v_start; - - FT_Vector* point; - FT_Vector* limit; - char* tags; - - FT_Error error; - - FT_Int n; /* index of contour in outline */ - FT_UInt first; /* index of first point in contour */ - FT_Int tag; /* current point's state */ - - FT_Int shift; - FT_Pos delta; - - - if ( !outline ) - return FT_THROW( Invalid_Outline ); - - if ( !func_interface ) - return FT_THROW( Invalid_Argument ); - - shift = func_interface->shift; - delta = func_interface->delta; - first = 0; - - for ( n = 0; n < outline->n_contours; n++ ) - { - FT_Int last; /* index of last point in contour */ - - - FT_TRACE5(( "FT_Outline_Decompose: Outline %d\n", n )); - - last = outline->contours[n]; - if ( last < 0 ) - goto Invalid_Outline; - limit = outline->points + last; - - v_start = outline->points[first]; - v_start.x = SCALED( v_start.x ); - v_start.y = SCALED( v_start.y ); - - v_last = outline->points[last]; - v_last.x = SCALED( v_last.x ); - v_last.y = SCALED( v_last.y ); - - v_control = v_start; - - point = outline->points + first; - tags = outline->tags + first; - tag = FT_CURVE_TAG( tags[0] ); - - /* A contour cannot start with a cubic control point! */ - if ( tag == FT_CURVE_TAG_CUBIC ) - goto Invalid_Outline; - - /* check first point to determine origin */ - if ( tag == FT_CURVE_TAG_CONIC ) - { - /* first point is conic control. Yes, this happens. */ - if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON ) - { - /* start at last point if it is on the curve */ - v_start = v_last; - limit--; - } - else - { - /* if both first and last points are conic, */ - /* start at their middle and record its position */ - /* for closure */ - v_start.x = ( v_start.x + v_last.x ) / 2; - v_start.y = ( v_start.y + v_last.y ) / 2; - - /* v_last = v_start; */ - } - point--; - tags--; - } - - FT_TRACE5(( " move to (%.2f, %.2f)\n", - v_start.x / 64.0, v_start.y / 64.0 )); - error = func_interface->move_to( &v_start, user ); - if ( error ) - goto Exit; - - while ( point < limit ) - { - point++; - tags++; - - tag = FT_CURVE_TAG( tags[0] ); - switch ( tag ) - { - case FT_CURVE_TAG_ON: /* emit a single line_to */ - { - FT_Vector vec; - - - vec.x = SCALED( point->x ); - vec.y = SCALED( point->y ); - - FT_TRACE5(( " line to (%.2f, %.2f)\n", - vec.x / 64.0, vec.y / 64.0 )); - error = func_interface->line_to( &vec, user ); - if ( error ) - goto Exit; - continue; - } - - case FT_CURVE_TAG_CONIC: /* consume conic arcs */ - v_control.x = SCALED( point->x ); - v_control.y = SCALED( point->y ); - - Do_Conic: - if ( point < limit ) - { - FT_Vector vec; - FT_Vector v_middle; - - - point++; - tags++; - tag = FT_CURVE_TAG( tags[0] ); - - vec.x = SCALED( point->x ); - vec.y = SCALED( point->y ); - - if ( tag == FT_CURVE_TAG_ON ) - { - FT_TRACE5(( " conic to (%.2f, %.2f)" - " with control (%.2f, %.2f)\n", - vec.x / 64.0, vec.y / 64.0, - v_control.x / 64.0, v_control.y / 64.0 )); - error = func_interface->conic_to( &v_control, &vec, user ); - if ( error ) - goto Exit; - continue; - } - - if ( tag != FT_CURVE_TAG_CONIC ) - goto Invalid_Outline; - - v_middle.x = ( v_control.x + vec.x ) / 2; - v_middle.y = ( v_control.y + vec.y ) / 2; - - FT_TRACE5(( " conic to (%.2f, %.2f)" - " with control (%.2f, %.2f)\n", - v_middle.x / 64.0, v_middle.y / 64.0, - v_control.x / 64.0, v_control.y / 64.0 )); - error = func_interface->conic_to( &v_control, &v_middle, user ); - if ( error ) - goto Exit; - - v_control = vec; - goto Do_Conic; - } - - FT_TRACE5(( " conic to (%.2f, %.2f)" - " with control (%.2f, %.2f)\n", - v_start.x / 64.0, v_start.y / 64.0, - v_control.x / 64.0, v_control.y / 64.0 )); - error = func_interface->conic_to( &v_control, &v_start, user ); - goto Close; - - default: /* FT_CURVE_TAG_CUBIC */ - { - FT_Vector vec1, vec2; - - - if ( point + 1 > limit || - FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC ) - goto Invalid_Outline; - - point += 2; - tags += 2; - - vec1.x = SCALED( point[-2].x ); - vec1.y = SCALED( point[-2].y ); - - vec2.x = SCALED( point[-1].x ); - vec2.y = SCALED( point[-1].y ); - - if ( point <= limit ) - { - FT_Vector vec; - - - vec.x = SCALED( point->x ); - vec.y = SCALED( point->y ); - - FT_TRACE5(( " cubic to (%.2f, %.2f)" - " with controls (%.2f, %.2f) and (%.2f, %.2f)\n", - vec.x / 64.0, vec.y / 64.0, - vec1.x / 64.0, vec1.y / 64.0, - vec2.x / 64.0, vec2.y / 64.0 )); - error = func_interface->cubic_to( &vec1, &vec2, &vec, user ); - if ( error ) - goto Exit; - continue; - } - - FT_TRACE5(( " cubic to (%.2f, %.2f)" - " with controls (%.2f, %.2f) and (%.2f, %.2f)\n", - v_start.x / 64.0, v_start.y / 64.0, - vec1.x / 64.0, vec1.y / 64.0, - vec2.x / 64.0, vec2.y / 64.0 )); - error = func_interface->cubic_to( &vec1, &vec2, &v_start, user ); - goto Close; - } - } - } - - /* close the contour with a line segment */ - FT_TRACE5(( " line to (%.2f, %.2f)\n", - v_start.x / 64.0, v_start.y / 64.0 )); - error = func_interface->line_to( &v_start, user ); - - Close: - if ( error ) - goto Exit; - - first = (FT_UInt)last + 1; - } - - FT_TRACE5(( "FT_Outline_Decompose: Done\n", n )); - return FT_Err_Ok; - - Exit: - FT_TRACE5(( "FT_Outline_Decompose: Error 0x%x\n", error )); - return error; - - Invalid_Outline: - return FT_THROW( Invalid_Outline ); - } - - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_New_Internal( FT_Memory memory, - FT_UInt numPoints, - FT_Int numContours, - FT_Outline *anoutline ) - { - FT_Error error; - - - if ( !anoutline || !memory ) - return FT_THROW( Invalid_Argument ); - - *anoutline = null_outline; - - if ( numContours < 0 || - (FT_UInt)numContours > numPoints ) - return FT_THROW( Invalid_Argument ); - - if ( numPoints > FT_OUTLINE_POINTS_MAX ) - return FT_THROW( Array_Too_Large ); - - if ( FT_NEW_ARRAY( anoutline->points, numPoints ) || - FT_NEW_ARRAY( anoutline->tags, numPoints ) || - FT_NEW_ARRAY( anoutline->contours, numContours ) ) - goto Fail; - - anoutline->n_points = (FT_Short)numPoints; - anoutline->n_contours = (FT_Short)numContours; - anoutline->flags |= FT_OUTLINE_OWNER; - - return FT_Err_Ok; - - Fail: - anoutline->flags |= FT_OUTLINE_OWNER; - FT_Outline_Done_Internal( memory, anoutline ); - - return error; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_New( FT_Library library, - FT_UInt numPoints, - FT_Int numContours, - FT_Outline *anoutline ) - { - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - return FT_Outline_New_Internal( library->memory, numPoints, - numContours, anoutline ); - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Check( FT_Outline* outline ) - { - if ( outline ) - { - FT_Int n_points = outline->n_points; - FT_Int n_contours = outline->n_contours; - FT_Int end0, end; - FT_Int n; - - - /* empty glyph? */ - if ( n_points == 0 && n_contours == 0 ) - return FT_Err_Ok; - - /* check point and contour counts */ - if ( n_points <= 0 || n_contours <= 0 ) - goto Bad; - - end0 = end = -1; - for ( n = 0; n < n_contours; n++ ) - { - end = outline->contours[n]; - - /* note that we don't accept empty contours */ - if ( end <= end0 || end >= n_points ) - goto Bad; - - end0 = end; - } - - if ( end != n_points - 1 ) - goto Bad; - - /* XXX: check the tags array */ - return FT_Err_Ok; - } - - Bad: - return FT_THROW( Invalid_Argument ); - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Copy( const FT_Outline* source, - FT_Outline *target ) - { - FT_Int is_owner; - - - if ( !source || !target ) - return FT_THROW( Invalid_Outline ); - - if ( source->n_points != target->n_points || - source->n_contours != target->n_contours ) - return FT_THROW( Invalid_Argument ); - - if ( source == target ) - return FT_Err_Ok; - - if ( source->n_points ) - { - FT_ARRAY_COPY( target->points, source->points, source->n_points ); - FT_ARRAY_COPY( target->tags, source->tags, source->n_points ); - } - - if ( source->n_contours ) - FT_ARRAY_COPY( target->contours, source->contours, source->n_contours ); - - /* copy all flags, except the `FT_OUTLINE_OWNER' one */ - is_owner = target->flags & FT_OUTLINE_OWNER; - target->flags = source->flags; - - target->flags &= ~FT_OUTLINE_OWNER; - target->flags |= is_owner; - - return FT_Err_Ok; - } - - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Done_Internal( FT_Memory memory, - FT_Outline* outline ) - { - if ( !outline ) - return FT_THROW( Invalid_Outline ); - - if ( !memory ) - return FT_THROW( Invalid_Argument ); - - if ( outline->flags & FT_OUTLINE_OWNER ) - { - FT_FREE( outline->points ); - FT_FREE( outline->tags ); - FT_FREE( outline->contours ); - } - *outline = null_outline; - - return FT_Err_Ok; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Done( FT_Library library, - FT_Outline* outline ) - { - /* check for valid `outline' in FT_Outline_Done_Internal() */ - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - return FT_Outline_Done_Internal( library->memory, outline ); - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( void ) - FT_Outline_Get_CBox( const FT_Outline* outline, - FT_BBox *acbox ) - { - FT_Pos xMin, yMin, xMax, yMax; - - - if ( outline && acbox ) - { - if ( outline->n_points == 0 ) - { - xMin = 0; - yMin = 0; - xMax = 0; - yMax = 0; - } - else - { - FT_Vector* vec = outline->points; - FT_Vector* limit = vec + outline->n_points; - - - xMin = xMax = vec->x; - yMin = yMax = vec->y; - vec++; - - for ( ; vec < limit; vec++ ) - { - FT_Pos x, y; - - - x = vec->x; - if ( x < xMin ) xMin = x; - if ( x > xMax ) xMax = x; - - y = vec->y; - if ( y < yMin ) yMin = y; - if ( y > yMax ) yMax = y; - } - } - acbox->xMin = xMin; - acbox->xMax = xMax; - acbox->yMin = yMin; - acbox->yMax = yMax; - } - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( void ) - FT_Outline_Translate( const FT_Outline* outline, - FT_Pos xOffset, - FT_Pos yOffset ) - { - FT_UShort n; - FT_Vector* vec; - - - if ( !outline ) - return; - - vec = outline->points; - - for ( n = 0; n < outline->n_points; n++ ) - { - vec->x += xOffset; - vec->y += yOffset; - vec++; - } - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( void ) - FT_Outline_Reverse( FT_Outline* outline ) - { - FT_UShort n; - FT_Int first, last; - - - if ( !outline ) - return; - - first = 0; - - for ( n = 0; n < outline->n_contours; n++ ) - { - last = outline->contours[n]; - - /* reverse point table */ - { - FT_Vector* p = outline->points + first; - FT_Vector* q = outline->points + last; - FT_Vector swap; - - - while ( p < q ) - { - swap = *p; - *p = *q; - *q = swap; - p++; - q--; - } - } - - /* reverse tags table */ - { - char* p = outline->tags + first; - char* q = outline->tags + last; - - - while ( p < q ) - { - char swap; - - - swap = *p; - *p = *q; - *q = swap; - p++; - q--; - } - } - - first = last + 1; - } - - outline->flags ^= FT_OUTLINE_REVERSE_FILL; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Render( FT_Library library, - FT_Outline* outline, - FT_Raster_Params* params ) - { - FT_Error error; - FT_Renderer renderer; - FT_ListNode node; - - - if ( !library ) - return FT_THROW( Invalid_Library_Handle ); - - if ( !outline ) - return FT_THROW( Invalid_Outline ); - - if ( !params ) - return FT_THROW( Invalid_Argument ); - - renderer = library->cur_renderer; - node = library->renderers.head; - - params->source = (void*)outline; - - error = FT_ERR( Cannot_Render_Glyph ); - while ( renderer ) - { - error = renderer->raster_render( renderer->raster, params ); - if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) - break; - - /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ - /* is unsupported by the current renderer for this glyph image */ - /* format */ - - /* now, look for another renderer that supports the same */ - /* format */ - renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, - &node ); - } - - return error; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Get_Bitmap( FT_Library library, - FT_Outline* outline, - const FT_Bitmap *abitmap ) - { - FT_Raster_Params params; - - - if ( !abitmap ) - return FT_THROW( Invalid_Argument ); - - /* other checks are delayed to `FT_Outline_Render' */ - - params.target = abitmap; - params.flags = 0; - - if ( abitmap->pixel_mode == FT_PIXEL_MODE_GRAY || - abitmap->pixel_mode == FT_PIXEL_MODE_LCD || - abitmap->pixel_mode == FT_PIXEL_MODE_LCD_V ) - params.flags |= FT_RASTER_FLAG_AA; - - return FT_Outline_Render( library, outline, ¶ms ); - } - - - /* documentation is in freetype.h */ - - FT_EXPORT_DEF( void ) - FT_Vector_Transform( FT_Vector* vector, - const FT_Matrix* matrix ) - { - FT_Pos xz, yz; - - - if ( !vector || !matrix ) - return; - - xz = FT_MulFix( vector->x, matrix->xx ) + - FT_MulFix( vector->y, matrix->xy ); - - yz = FT_MulFix( vector->x, matrix->yx ) + - FT_MulFix( vector->y, matrix->yy ); - - vector->x = xz; - vector->y = yz; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( void ) - FT_Outline_Transform( const FT_Outline* outline, - const FT_Matrix* matrix ) - { - FT_Vector* vec; - FT_Vector* limit; - - - if ( !outline || !matrix ) - return; - - vec = outline->points; - limit = vec + outline->n_points; - - for ( ; vec < limit; vec++ ) - FT_Vector_Transform( vec, matrix ); - } - - -#if 0 - -#define FT_OUTLINE_GET_CONTOUR( outline, c, first, last ) \ - do \ - { \ - (first) = ( c > 0 ) ? (outline)->points + \ - (outline)->contours[c - 1] + 1 \ - : (outline)->points; \ - (last) = (outline)->points + (outline)->contours[c]; \ - } while ( 0 ) - - - /* Is a point in some contour? */ - /* */ - /* We treat every point of the contour as if it */ - /* it were ON. That is, we allow false positives, */ - /* but disallow false negatives. (XXX really?) */ - static FT_Bool - ft_contour_has( FT_Outline* outline, - FT_Short c, - FT_Vector* point ) - { - FT_Vector* first; - FT_Vector* last; - FT_Vector* a; - FT_Vector* b; - FT_UInt n = 0; - - - FT_OUTLINE_GET_CONTOUR( outline, c, first, last ); - - for ( a = first; a <= last; a++ ) - { - FT_Pos x; - FT_Int intersect; - - - b = ( a == last ) ? first : a + 1; - - intersect = ( a->y - point->y ) ^ ( b->y - point->y ); - - /* a and b are on the same side */ - if ( intersect >= 0 ) - { - if ( intersect == 0 && a->y == point->y ) - { - if ( ( a->x <= point->x && b->x >= point->x ) || - ( a->x >= point->x && b->x <= point->x ) ) - return 1; - } - - continue; - } - - x = a->x + ( b->x - a->x ) * (point->y - a->y ) / ( b->y - a->y ); - - if ( x < point->x ) - n++; - else if ( x == point->x ) - return 1; - } - - return n & 1; - } - - - static FT_Bool - ft_contour_enclosed( FT_Outline* outline, - FT_UShort c ) - { - FT_Vector* first; - FT_Vector* last; - FT_Short i; - - - FT_OUTLINE_GET_CONTOUR( outline, c, first, last ); - - for ( i = 0; i < outline->n_contours; i++ ) - { - if ( i != c && ft_contour_has( outline, i, first ) ) - { - FT_Vector* pt; - - - for ( pt = first + 1; pt <= last; pt++ ) - if ( !ft_contour_has( outline, i, pt ) ) - return 0; - - return 1; - } - } - - return 0; - } - - - /* This version differs from the public one in that each */ - /* part (contour not enclosed in another contour) of the */ - /* outline is checked for orientation. This is */ - /* necessary for some buggy CJK fonts. */ - static FT_Orientation - ft_outline_get_orientation( FT_Outline* outline ) - { - FT_Short i; - FT_Vector* first; - FT_Vector* last; - FT_Orientation orient = FT_ORIENTATION_NONE; - - - first = outline->points; - for ( i = 0; i < outline->n_contours; i++, first = last + 1 ) - { - FT_Vector* point; - FT_Vector* xmin_point; - FT_Pos xmin; - - - last = outline->points + outline->contours[i]; - - /* skip degenerate contours */ - if ( last < first + 2 ) - continue; - - if ( ft_contour_enclosed( outline, i ) ) - continue; - - xmin = first->x; - xmin_point = first; - - for ( point = first + 1; point <= last; point++ ) - { - if ( point->x < xmin ) - { - xmin = point->x; - xmin_point = point; - } - } - - /* check the orientation of the contour */ - { - FT_Vector* prev; - FT_Vector* next; - FT_Orientation o; - - - prev = ( xmin_point == first ) ? last : xmin_point - 1; - next = ( xmin_point == last ) ? first : xmin_point + 1; - - if ( FT_Atan2( prev->x - xmin_point->x, prev->y - xmin_point->y ) > - FT_Atan2( next->x - xmin_point->x, next->y - xmin_point->y ) ) - o = FT_ORIENTATION_POSTSCRIPT; - else - o = FT_ORIENTATION_TRUETYPE; - - if ( orient == FT_ORIENTATION_NONE ) - orient = o; - else if ( orient != o ) - return FT_ORIENTATION_NONE; - } - } - - return orient; - } - -#endif /* 0 */ - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_Embolden( FT_Outline* outline, - FT_Pos strength ) - { - return FT_Outline_EmboldenXY( outline, strength, strength ); - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Outline_EmboldenXY( FT_Outline* outline, - FT_Pos xstrength, - FT_Pos ystrength ) - { - FT_Vector* points; - FT_Int c, first, last; - FT_Int orientation; - - - if ( !outline ) - return FT_THROW( Invalid_Outline ); - - xstrength /= 2; - ystrength /= 2; - if ( xstrength == 0 && ystrength == 0 ) - return FT_Err_Ok; - - orientation = FT_Outline_Get_Orientation( outline ); - if ( orientation == FT_ORIENTATION_NONE ) - { - if ( outline->n_contours ) - return FT_THROW( Invalid_Argument ); - else - return FT_Err_Ok; - } - - points = outline->points; - - first = 0; - for ( c = 0; c < outline->n_contours; c++ ) - { - FT_Vector in, out, anchor, shift; - FT_Fixed l_in, l_out, l_anchor = 0, l, q, d; - FT_Int i, j, k; - - - l_in = 0; - last = outline->contours[c]; - - /* pacify compiler */ - in.x = in.y = anchor.x = anchor.y = 0; - - /* Counter j cycles though the points; counter i advances only */ - /* when points are moved; anchor k marks the first moved point. */ - for ( i = last, j = first, k = -1; - j != i && i != k; - j = j < last ? j + 1 : first ) - { - if ( j != k ) - { - out.x = points[j].x - points[i].x; - out.y = points[j].y - points[i].y; - l_out = (FT_Fixed)FT_Vector_NormLen( &out ); - - if ( l_out == 0 ) - continue; - } - else - { - out = anchor; - l_out = l_anchor; - } - - if ( l_in != 0 ) - { - if ( k < 0 ) - { - k = i; - anchor = in; - l_anchor = l_in; - } - - d = FT_MulFix( in.x, out.x ) + FT_MulFix( in.y, out.y ); - - /* shift only if turn is less than ~160 degrees */ - if ( d > -0xF000L ) - { - d = d + 0x10000L; - - /* shift components along lateral bisector in proper orientation */ - shift.x = in.y + out.y; - shift.y = in.x + out.x; - - if ( orientation == FT_ORIENTATION_TRUETYPE ) - shift.x = -shift.x; - else - shift.y = -shift.y; - - /* restrict shift magnitude to better handle collapsing segments */ - q = FT_MulFix( out.x, in.y ) - FT_MulFix( out.y, in.x ); - if ( orientation == FT_ORIENTATION_TRUETYPE ) - q = -q; - - l = FT_MIN( l_in, l_out ); - - /* non-strict inequalities avoid divide-by-zero when q == l == 0 */ - if ( FT_MulFix( xstrength, q ) <= FT_MulFix( l, d ) ) - shift.x = FT_MulDiv( shift.x, xstrength, d ); - else - shift.x = FT_MulDiv( shift.x, l, q ); - - - if ( FT_MulFix( ystrength, q ) <= FT_MulFix( l, d ) ) - shift.y = FT_MulDiv( shift.y, ystrength, d ); - else - shift.y = FT_MulDiv( shift.y, l, q ); - } - else - shift.x = shift.y = 0; - - for ( ; - i != j; - i = i < last ? i + 1 : first ) - { - points[i].x += xstrength + shift.x; - points[i].y += ystrength + shift.y; - } - } - else - i = j; - - in = out; - l_in = l_out; - } - - first = last + 1; - } - - return FT_Err_Ok; - } - - - /* documentation is in ftoutln.h */ - - FT_EXPORT_DEF( FT_Orientation ) - FT_Outline_Get_Orientation( FT_Outline* outline ) - { - FT_BBox cbox; - FT_Int xshift, yshift; - FT_Vector* points; - FT_Vector v_prev, v_cur; - FT_Int c, n, first; - FT_Pos area = 0; - - - if ( !outline || outline->n_points <= 0 ) - return FT_ORIENTATION_TRUETYPE; - - /* We use the nonzero winding rule to find the orientation. */ - /* Since glyph outlines behave much more `regular' than arbitrary */ - /* cubic or quadratic curves, this test deals with the polygon */ - /* only that is spanned up by the control points. */ - - FT_Outline_Get_CBox( outline, &cbox ); - - /* Handle collapsed outlines to avoid undefined FT_MSB. */ - if ( cbox.xMin == cbox.xMax || cbox.yMin == cbox.yMax ) - return FT_ORIENTATION_NONE; - - xshift = FT_MSB( (FT_UInt32)( FT_ABS( cbox.xMax ) | - FT_ABS( cbox.xMin ) ) ) - 14; - xshift = FT_MAX( xshift, 0 ); - - yshift = FT_MSB( (FT_UInt32)( cbox.yMax - cbox.yMin ) ) - 14; - yshift = FT_MAX( yshift, 0 ); - - points = outline->points; - - first = 0; - for ( c = 0; c < outline->n_contours; c++ ) - { - FT_Int last = outline->contours[c]; - - - v_prev.x = points[last].x >> xshift; - v_prev.y = points[last].y >> yshift; - - for ( n = first; n <= last; n++ ) - { - v_cur.x = points[n].x >> xshift; - v_cur.y = points[n].y >> yshift; - - area += ( v_cur.y - v_prev.y ) * ( v_cur.x + v_prev.x ); - - v_prev = v_cur; - } - - first = last + 1; - } - - if ( area > 0 ) - return FT_ORIENTATION_POSTSCRIPT; - else if ( area < 0 ) - return FT_ORIENTATION_TRUETYPE; - else - return FT_ORIENTATION_NONE; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftpic.c b/third_party/freetype/src/base/ftpic.c deleted file mode 100644 index 0f84fddc98..0000000000 --- a/third_party/freetype/src/base/ftpic.c +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftpic.c */ -/* */ -/* The FreeType position independent code services (body). */ -/* */ -/* Copyright 2009-2017 by */ -/* Oran Agra and Mickey Gabel. */ -/* */ -/* 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 -#include FT_FREETYPE_H -#include FT_INTERNAL_OBJECTS_H -#include "basepic.h" - -#ifdef FT_CONFIG_OPTION_PIC - - /* documentation is in ftpic.h */ - - FT_BASE_DEF( FT_Error ) - ft_pic_container_init( FT_Library library ) - { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error; - - - FT_MEM_SET( pic_container, 0, sizeof ( *pic_container ) ); - - error = ft_base_pic_init( library ); - if ( error ) - return error; - - return FT_Err_Ok; - } - - - /* Destroy the contents of the container. */ - FT_BASE_DEF( void ) - ft_pic_container_destroy( FT_Library library ) - { - ft_base_pic_free( library ); - } - -#endif /* FT_CONFIG_OPTION_PIC */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftrfork.c b/third_party/freetype/src/base/ftrfork.c deleted file mode 100644 index f7b81375dd..0000000000 --- a/third_party/freetype/src/base/ftrfork.c +++ /dev/null @@ -1,937 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftrfork.c */ -/* */ -/* Embedded resource forks accessor (body). */ -/* */ -/* Copyright 2004-2017 by */ -/* Masatake YAMATO and Redhat K.K. */ -/* */ -/* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ -/* derived from ftobjs.c. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - -/***************************************************************************/ -/* Development of the code in this file is support of */ -/* Information-technology Promotion Agency, Japan. */ -/***************************************************************************/ - - -#include -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_RFORK_H -#include "basepic.h" -#include "ftbase.h" - -#undef FT_COMPONENT -#define FT_COMPONENT trace_raccess - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** Resource fork directory access ****/ - /**** ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - FT_BASE_DEF( FT_Error ) - FT_Raccess_Get_HeaderInfo( FT_Library library, - FT_Stream stream, - FT_Long rfork_offset, - FT_Long *map_offset, - FT_Long *rdata_pos ) - { - FT_Error error; - unsigned char head[16], head2[16]; - FT_Long map_pos, map_len, rdata_len; - int allzeros, allmatch, i; - FT_Long type_list; - - FT_UNUSED( library ); - - - error = FT_Stream_Seek( stream, (FT_ULong)rfork_offset ); - if ( error ) - return error; - - error = FT_Stream_Read( stream, (FT_Byte*)head, 16 ); - if ( error ) - return error; - - /* ensure positive values */ - if ( head[0] >= 0x80 || - head[4] >= 0x80 || - head[8] >= 0x80 || - head[12] >= 0x80 ) - return FT_THROW( Unknown_File_Format ); - - *rdata_pos = ( head[ 0] << 24 ) | - ( head[ 1] << 16 ) | - ( head[ 2] << 8 ) | - head[ 3]; - map_pos = ( head[ 4] << 24 ) | - ( head[ 5] << 16 ) | - ( head[ 6] << 8 ) | - head[ 7]; - rdata_len = ( head[ 8] << 24 ) | - ( head[ 9] << 16 ) | - ( head[10] << 8 ) | - head[11]; - map_len = ( head[12] << 24 ) | - ( head[13] << 16 ) | - ( head[14] << 8 ) | - head[15]; - - /* the map must not be empty */ - if ( !map_pos ) - return FT_THROW( Unknown_File_Format ); - - /* check whether rdata and map overlap */ - if ( *rdata_pos < map_pos ) - { - if ( *rdata_pos > map_pos - rdata_len ) - return FT_THROW( Unknown_File_Format ); - } - else - { - if ( map_pos > *rdata_pos - map_len ) - return FT_THROW( Unknown_File_Format ); - } - - /* check whether end of rdata or map exceeds stream size */ - if ( FT_LONG_MAX - rdata_len < *rdata_pos || - FT_LONG_MAX - map_len < map_pos || - - FT_LONG_MAX - ( *rdata_pos + rdata_len ) < rfork_offset || - FT_LONG_MAX - ( map_pos + map_len ) < rfork_offset || - - (FT_ULong)( rfork_offset + *rdata_pos + rdata_len ) > stream->size || - (FT_ULong)( rfork_offset + map_pos + map_len ) > stream->size ) - return FT_THROW( Unknown_File_Format ); - - *rdata_pos += rfork_offset; - map_pos += rfork_offset; - - error = FT_Stream_Seek( stream, (FT_ULong)map_pos ); - if ( error ) - return error; - - head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */ - - error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 ); - if ( error ) - return error; - - allzeros = 1; - allmatch = 1; - for ( i = 0; i < 16; i++ ) - { - if ( head2[i] != 0 ) - allzeros = 0; - if ( head2[i] != head[i] ) - allmatch = 0; - } - if ( !allzeros && !allmatch ) - return FT_THROW( Unknown_File_Format ); - - /* If we have reached this point then it is probably a mac resource */ - /* file. Now, does it contain any interesting resources? */ - - (void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */ - + 2 /* skip file resource number */ - + 2 ); /* skip attributes */ - - if ( FT_READ_SHORT( type_list ) ) - return error; - if ( type_list < 0 ) - return FT_THROW( Unknown_File_Format ); - - error = FT_Stream_Seek( stream, (FT_ULong)( map_pos + type_list ) ); - if ( error ) - return error; - - *map_offset = map_pos + type_list; - return FT_Err_Ok; - } - - - static int - ft_raccess_sort_ref_by_id( FT_RFork_Ref* a, - FT_RFork_Ref* b ) - { - if ( a->res_id < b->res_id ) - return -1; - else if ( a->res_id > b->res_id ) - return 1; - else - return 0; - } - - - FT_BASE_DEF( FT_Error ) - FT_Raccess_Get_DataOffsets( FT_Library library, - FT_Stream stream, - FT_Long map_offset, - FT_Long rdata_pos, - FT_Long tag, - FT_Bool sort_by_res_id, - FT_Long **offsets, - FT_Long *count ) - { - FT_Error error; - int i, j, cnt, subcnt; - FT_Long tag_internal, rpos; - FT_Memory memory = library->memory; - FT_Long temp; - FT_Long *offsets_internal = NULL; - FT_RFork_Ref *ref = NULL; - - - FT_TRACE3(( "\n" )); - error = FT_Stream_Seek( stream, (FT_ULong)map_offset ); - if ( error ) - return error; - - if ( FT_READ_SHORT( cnt ) ) - return error; - cnt++; - - /* `rpos' is a signed 16bit integer offset to resource records; the */ - /* size of a resource record is 12 bytes. The map header is 28 bytes, */ - /* and a type list needs 10 bytes or more. If we assume that the name */ - /* list is empty and we have only a single entry in the type list, */ - /* there can be at most */ - /* */ - /* (32768 - 28 - 10) / 12 = 2727 */ - /* */ - /* resources. */ - /* */ - /* A type list starts with a two-byte counter, followed by 10-byte */ - /* type records. Assuming that there are no resources, the number of */ - /* type records can be at most */ - /* */ - /* (32768 - 28 - 2) / 8 = 4079 */ - /* */ - if ( cnt > 4079 ) - return FT_THROW( Invalid_Table ); - - for ( i = 0; i < cnt; i++ ) - { - if ( FT_READ_LONG( tag_internal ) || - FT_READ_SHORT( subcnt ) || - FT_READ_SHORT( rpos ) ) - return error; - - FT_TRACE2(( "Resource tags: %c%c%c%c\n", - (char)( 0xFF & ( tag_internal >> 24 ) ), - (char)( 0xFF & ( tag_internal >> 16 ) ), - (char)( 0xFF & ( tag_internal >> 8 ) ), - (char)( 0xFF & ( tag_internal >> 0 ) ) )); - FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n", - subcnt, rpos )); - - if ( tag_internal == tag ) - { - *count = subcnt + 1; - rpos += map_offset; - - /* a zero count might be valid in the resource specification, */ - /* however, it is completely useless to us */ - if ( *count < 1 || *count > 2727 ) - return FT_THROW( Invalid_Table ); - - error = FT_Stream_Seek( stream, (FT_ULong)rpos ); - if ( error ) - return error; - - if ( FT_NEW_ARRAY( ref, *count ) ) - return error; - - for ( j = 0; j < *count; j++ ) - { - if ( FT_READ_SHORT( ref[j].res_id ) ) - goto Exit; - if ( FT_STREAM_SKIP( 2 ) ) /* resource name offset */ - goto Exit; - if ( FT_READ_LONG( temp ) ) /* attributes (8bit), offset (24bit) */ - goto Exit; - if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ - goto Exit; - - if ( ref[j].res_id < 0 || temp < 0 ) - { - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - ref[j].offset = temp & 0xFFFFFFL; - - FT_TRACE3(( " [%d]:" - " resource_id=0x%04x, offset=0x%08x\n", - j, ref[j].res_id, ref[j].offset )); - } - - if ( sort_by_res_id ) - { - ft_qsort( ref, - (size_t)*count, - sizeof ( FT_RFork_Ref ), - ( int(*)(const void*, - const void*) )ft_raccess_sort_ref_by_id ); - - FT_TRACE3(( " -- sort resources by their ids --\n" )); - - for ( j = 0; j < *count; j++ ) - FT_TRACE3(( " [%d]:" - " resource_id=0x%04x, offset=0x%08x\n", - j, ref[j].res_id, ref[j].offset )); - } - - if ( FT_NEW_ARRAY( offsets_internal, *count ) ) - goto Exit; - - /* XXX: duplicated reference ID, - * gap between reference IDs are acceptable? - * further investigation on Apple implementation is needed. - */ - for ( j = 0; j < *count; j++ ) - offsets_internal[j] = rdata_pos + ref[j].offset; - - *offsets = offsets_internal; - error = FT_Err_Ok; - - Exit: - FT_FREE( ref ); - return error; - } - } - - return FT_THROW( Cannot_Open_Resource ); - } - - -#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** ****/ - /**** Guessing functions ****/ - /**** ****/ - /**** When you add a new guessing function, ****/ - /**** update FT_RACCESS_N_RULES in ftrfork.h. ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - static FT_Error - raccess_guess_apple_double( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_apple_single( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_darwin_ufs_export( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_darwin_newvfs( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_darwin_hfsplus( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_vfat( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_linux_cap( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_linux_double( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_linux_netatalk( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ); - - - CONST_FT_RFORK_RULE_ARRAY_BEGIN(ft_raccess_guess_table, - ft_raccess_guess_rec) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_double, apple_double) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_single, apple_single) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_ufs_export, darwin_ufs_export) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_newvfs, darwin_newvfs) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_hfsplus, darwin_hfsplus) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(vfat, vfat) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_cap, linux_cap) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_double, linux_double) - CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_netatalk, linux_netatalk) - CONST_FT_RFORK_RULE_ARRAY_END - - - /*************************************************************************/ - /**** ****/ - /**** Helper functions ****/ - /**** ****/ - /*************************************************************************/ - - static FT_Error - raccess_guess_apple_generic( FT_Library library, - FT_Stream stream, - char *base_file_name, - FT_Int32 magic, - FT_Long *result_offset ); - - static FT_Error - raccess_guess_linux_double_from_file_name( FT_Library library, - char * file_name, - FT_Long *result_offset ); - - static char * - raccess_make_file_name( FT_Memory memory, - const char *original_name, - const char *insertion ); - - FT_BASE_DEF( void ) - FT_Raccess_Guess( FT_Library library, - FT_Stream stream, - char* base_name, - char **new_names, - FT_Long *offsets, - FT_Error *errors ) - { - FT_Int i; - - - for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) - { - new_names[i] = NULL; - if ( NULL != stream ) - errors[i] = FT_Stream_Seek( stream, 0 ); - else - errors[i] = FT_Err_Ok; - - if ( errors[i] ) - continue; - - errors[i] = (FT_RACCESS_GUESS_TABLE_GET[i].func)( library, - stream, base_name, - &(new_names[i]), - &(offsets[i]) ); - } - - return; - } - - -#ifndef FT_MACINTOSH - static FT_RFork_Rule - raccess_get_rule_type_from_rule_index( FT_Library library, - FT_UInt rule_index ) - { - FT_UNUSED( library ); - - if ( rule_index >= FT_RACCESS_N_RULES ) - return FT_RFork_Rule_invalid; - - return FT_RACCESS_GUESS_TABLE_GET[rule_index].type; - } - - - /* - * For this function, refer ftbase.h. - */ - FT_LOCAL_DEF( FT_Bool ) - ft_raccess_rule_by_darwin_vfs( FT_Library library, - FT_UInt rule_index ) - { - switch( raccess_get_rule_type_from_rule_index( library, rule_index ) ) - { - case FT_RFork_Rule_darwin_newvfs: - case FT_RFork_Rule_darwin_hfsplus: - return TRUE; - - default: - return FALSE; - } - } -#endif - - - static FT_Error - raccess_guess_apple_double( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - FT_Int32 magic = ( 0x00 << 24 ) | - ( 0x05 << 16 ) | - ( 0x16 << 8 ) | - 0x07; - - - *result_file_name = NULL; - if ( NULL == stream ) - return FT_THROW( Cannot_Open_Stream ); - - return raccess_guess_apple_generic( library, stream, base_file_name, - magic, result_offset ); - } - - - static FT_Error - raccess_guess_apple_single( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - FT_Int32 magic = ( 0x00 << 24 ) | - ( 0x05 << 16 ) | - ( 0x16 << 8 ) | - 0x00; - - - *result_file_name = NULL; - if ( NULL == stream ) - return FT_THROW( Cannot_Open_Stream ); - - return raccess_guess_apple_generic( library, stream, base_file_name, - magic, result_offset ); - } - - - static FT_Error - raccess_guess_darwin_ufs_export( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - char* newpath; - FT_Error error; - FT_Memory memory; - - FT_UNUSED( stream ); - - - memory = library->memory; - newpath = raccess_make_file_name( memory, base_file_name, "._" ); - if ( !newpath ) - return FT_THROW( Out_Of_Memory ); - - error = raccess_guess_linux_double_from_file_name( library, newpath, - result_offset ); - if ( !error ) - *result_file_name = newpath; - else - FT_FREE( newpath ); - - return error; - } - - - static FT_Error - raccess_guess_darwin_hfsplus( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - /* - Only meaningful on systems with hfs+ drivers (or Macs). - */ - FT_Error error; - char* newpath = NULL; - FT_Memory memory; - FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name ); - - FT_UNUSED( stream ); - - - memory = library->memory; - - if ( base_file_len + 6 > FT_INT_MAX ) - return FT_THROW( Array_Too_Large ); - - if ( FT_ALLOC( newpath, base_file_len + 6 ) ) - return error; - - FT_MEM_COPY( newpath, base_file_name, base_file_len ); - FT_MEM_COPY( newpath + base_file_len, "/rsrc", 6 ); - - *result_file_name = newpath; - *result_offset = 0; - - return FT_Err_Ok; - } - - - static FT_Error - raccess_guess_darwin_newvfs( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - /* - Only meaningful on systems with Mac OS X (> 10.1). - */ - FT_Error error; - char* newpath = NULL; - FT_Memory memory; - FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name ); - - FT_UNUSED( stream ); - - - memory = library->memory; - - if ( base_file_len + 18 > FT_INT_MAX ) - return FT_THROW( Array_Too_Large ); - - if ( FT_ALLOC( newpath, base_file_len + 18 ) ) - return error; - - FT_MEM_COPY( newpath, base_file_name, base_file_len ); - FT_MEM_COPY( newpath + base_file_len, "/..namedfork/rsrc", 18 ); - - *result_file_name = newpath; - *result_offset = 0; - - return FT_Err_Ok; - } - - - static FT_Error - raccess_guess_vfat( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - char* newpath; - FT_Memory memory; - - FT_UNUSED( stream ); - - - memory = library->memory; - - newpath = raccess_make_file_name( memory, base_file_name, - "resource.frk/" ); - if ( !newpath ) - return FT_THROW( Out_Of_Memory ); - - *result_file_name = newpath; - *result_offset = 0; - - return FT_Err_Ok; - } - - - static FT_Error - raccess_guess_linux_cap( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - char* newpath; - FT_Memory memory; - - FT_UNUSED( stream ); - - - memory = library->memory; - - newpath = raccess_make_file_name( memory, base_file_name, ".resource/" ); - if ( !newpath ) - return FT_THROW( Out_Of_Memory ); - - *result_file_name = newpath; - *result_offset = 0; - - return FT_Err_Ok; - } - - - static FT_Error - raccess_guess_linux_double( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - char* newpath; - FT_Error error; - FT_Memory memory; - - FT_UNUSED( stream ); - - - memory = library->memory; - - newpath = raccess_make_file_name( memory, base_file_name, "%" ); - if ( !newpath ) - return FT_THROW( Out_Of_Memory ); - - error = raccess_guess_linux_double_from_file_name( library, newpath, - result_offset ); - if ( !error ) - *result_file_name = newpath; - else - FT_FREE( newpath ); - - return error; - } - - - static FT_Error - raccess_guess_linux_netatalk( FT_Library library, - FT_Stream stream, - char *base_file_name, - char **result_file_name, - FT_Long *result_offset ) - { - char* newpath; - FT_Error error; - FT_Memory memory; - - FT_UNUSED( stream ); - - - memory = library->memory; - - newpath = raccess_make_file_name( memory, base_file_name, - ".AppleDouble/" ); - if ( !newpath ) - return FT_THROW( Out_Of_Memory ); - - error = raccess_guess_linux_double_from_file_name( library, newpath, - result_offset ); - if ( !error ) - *result_file_name = newpath; - else - FT_FREE( newpath ); - - return error; - } - - - static FT_Error - raccess_guess_apple_generic( FT_Library library, - FT_Stream stream, - char *base_file_name, - FT_Int32 magic, - FT_Long *result_offset ) - { - FT_Int32 magic_from_stream; - FT_Error error; - FT_Int32 version_number = 0; - FT_UShort n_of_entries; - - int i; - FT_Int32 entry_id, entry_offset, entry_length = 0; - - const FT_Int32 resource_fork_entry_id = 0x2; - - FT_UNUSED( library ); - FT_UNUSED( base_file_name ); - FT_UNUSED( version_number ); - FT_UNUSED( entry_length ); - - - if ( FT_READ_LONG( magic_from_stream ) ) - return error; - if ( magic_from_stream != magic ) - return FT_THROW( Unknown_File_Format ); - - if ( FT_READ_LONG( version_number ) ) - return error; - - /* filler */ - error = FT_Stream_Skip( stream, 16 ); - if ( error ) - return error; - - if ( FT_READ_USHORT( n_of_entries ) ) - return error; - if ( n_of_entries == 0 ) - return FT_THROW( Unknown_File_Format ); - - for ( i = 0; i < n_of_entries; i++ ) - { - if ( FT_READ_LONG( entry_id ) ) - return error; - if ( entry_id == resource_fork_entry_id ) - { - if ( FT_READ_LONG( entry_offset ) || - FT_READ_LONG( entry_length ) ) - continue; - *result_offset = entry_offset; - - return FT_Err_Ok; - } - else - { - error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */ - if ( error ) - return error; - } - } - - return FT_THROW( Unknown_File_Format ); - } - - - static FT_Error - raccess_guess_linux_double_from_file_name( FT_Library library, - char *file_name, - FT_Long *result_offset ) - { - FT_Open_Args args2; - FT_Stream stream2; - char * nouse = NULL; - FT_Error error; - - - args2.flags = FT_OPEN_PATHNAME; - args2.pathname = file_name; - error = FT_Stream_New( library, &args2, &stream2 ); - if ( error ) - return error; - - error = raccess_guess_apple_double( library, stream2, file_name, - &nouse, result_offset ); - - FT_Stream_Free( stream2, 0 ); - - return error; - } - - - static char* - raccess_make_file_name( FT_Memory memory, - const char *original_name, - const char *insertion ) - { - char* new_name = NULL; - const char* tmp; - const char* slash; - size_t new_length; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( error ); - - - new_length = ft_strlen( original_name ) + ft_strlen( insertion ); - if ( FT_ALLOC( new_name, new_length + 1 ) ) - return NULL; - - tmp = ft_strrchr( original_name, '/' ); - if ( tmp ) - { - ft_strncpy( new_name, - original_name, - (size_t)( tmp - original_name + 1 ) ); - new_name[tmp - original_name + 1] = '\0'; - slash = tmp + 1; - } - else - { - slash = original_name; - new_name[0] = '\0'; - } - - ft_strcat( new_name, insertion ); - ft_strcat( new_name, slash ); - - return new_name; - } - - -#else /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ - - - /*************************************************************************/ - /* Dummy function; just sets errors */ - /*************************************************************************/ - - FT_BASE_DEF( void ) - FT_Raccess_Guess( FT_Library library, - FT_Stream stream, - char *base_name, - char **new_names, - FT_Long *offsets, - FT_Error *errors ) - { - FT_Int i; - - FT_UNUSED( library ); - FT_UNUSED( stream ); - FT_UNUSED( base_name ); - - - for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) - { - new_names[i] = NULL; - offsets[i] = 0; - errors[i] = FT_ERR( Unimplemented_Feature ); - } - } - - -#endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftsnames.c b/third_party/freetype/src/base/ftsnames.c deleted file mode 100644 index a5b41eb884..0000000000 --- a/third_party/freetype/src/base/ftsnames.c +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftsnames.c */ -/* */ -/* Simple interface to access SFNT name tables (which are used */ -/* to hold font names, copyright info, notices, etc.) (body). */ -/* */ -/* This is _not_ used to retrieve glyph names! */ -/* */ -/* Copyright 1996-2017 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 -#include FT_SFNT_NAMES_H -#include FT_INTERNAL_TRUETYPE_TYPES_H -#include FT_INTERNAL_STREAM_H - - -#ifdef TT_CONFIG_OPTION_SFNT_NAMES - - - /* documentation is in ftsnames.h */ - - FT_EXPORT_DEF( FT_UInt ) - FT_Get_Sfnt_Name_Count( FT_Face face ) - { - return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0; - } - - - /* documentation is in ftsnames.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_Sfnt_Name( FT_Face face, - FT_UInt idx, - FT_SfntName *aname ) - { - FT_Error error = FT_ERR( Invalid_Argument ); - - - if ( aname && face && FT_IS_SFNT( face ) ) - { - TT_Face ttface = (TT_Face)face; - - - if ( idx < (FT_UInt)ttface->num_names ) - { - TT_NameEntryRec* entry = ttface->name_table.names + idx; - - - /* load name on demand */ - if ( entry->stringLength > 0 && !entry->string ) - { - FT_Memory memory = face->memory; - FT_Stream stream = face->stream; - - - if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) || - FT_STREAM_SEEK( entry->stringOffset ) || - FT_STREAM_READ( entry->string, entry->stringLength ) ) - { - FT_FREE( entry->string ); - entry->stringLength = 0; - } - } - - aname->platform_id = entry->platformID; - aname->encoding_id = entry->encodingID; - aname->language_id = entry->languageID; - aname->name_id = entry->nameID; - aname->string = (FT_Byte*)entry->string; - aname->string_len = entry->stringLength; - - error = FT_Err_Ok; - } - } - - return error; - } - - -#endif /* TT_CONFIG_OPTION_SFNT_NAMES */ - - -/* END */ diff --git a/third_party/freetype/src/base/ftstream.c b/third_party/freetype/src/base/ftstream.c deleted file mode 100644 index a3f8c8b3c9..0000000000 --- a/third_party/freetype/src/base/ftstream.c +++ /dev/null @@ -1,860 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftstream.c */ -/* */ -/* I/O stream support (body). */ -/* */ -/* Copyright 2000-2017 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 -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_DEBUG_H - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_stream - - - FT_BASE_DEF( void ) - FT_Stream_OpenMemory( FT_Stream stream, - const FT_Byte* base, - FT_ULong size ) - { - stream->base = (FT_Byte*) base; - stream->size = size; - stream->pos = 0; - stream->cursor = NULL; - stream->read = NULL; - stream->close = NULL; - } - - - FT_BASE_DEF( void ) - FT_Stream_Close( FT_Stream stream ) - { - if ( stream && stream->close ) - stream->close( stream ); - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_Seek( FT_Stream stream, - FT_ULong pos ) - { - FT_Error error = FT_Err_Ok; - - - if ( stream->read ) - { - if ( stream->read( stream, pos, 0, 0 ) ) - { - FT_ERROR(( "FT_Stream_Seek:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - pos, stream->size )); - - error = FT_THROW( Invalid_Stream_Operation ); - } - } - /* note that seeking to the first position after the file is valid */ - else if ( pos > stream->size ) - { - FT_ERROR(( "FT_Stream_Seek:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - pos, stream->size )); - - error = FT_THROW( Invalid_Stream_Operation ); - } - - if ( !error ) - stream->pos = pos; - - return error; - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_Skip( FT_Stream stream, - FT_Long distance ) - { - if ( distance < 0 ) - return FT_THROW( Invalid_Stream_Operation ); - - return FT_Stream_Seek( stream, stream->pos + (FT_ULong)distance ); - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_Pos( FT_Stream stream ) - { - return stream->pos; - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_Read( FT_Stream stream, - FT_Byte* buffer, - FT_ULong count ) - { - return FT_Stream_ReadAt( stream, stream->pos, buffer, count ); - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_ReadAt( FT_Stream stream, - FT_ULong pos, - FT_Byte* buffer, - FT_ULong count ) - { - FT_Error error = FT_Err_Ok; - FT_ULong read_bytes; - - - if ( pos >= stream->size ) - { - FT_ERROR(( "FT_Stream_ReadAt:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - pos, stream->size )); - - return FT_THROW( Invalid_Stream_Operation ); - } - - if ( stream->read ) - read_bytes = stream->read( stream, pos, buffer, count ); - else - { - read_bytes = stream->size - pos; - if ( read_bytes > count ) - read_bytes = count; - - FT_MEM_COPY( buffer, stream->base + pos, read_bytes ); - } - - stream->pos = pos + read_bytes; - - if ( read_bytes < count ) - { - FT_ERROR(( "FT_Stream_ReadAt:" - " invalid read; expected %lu bytes, got %lu\n", - count, read_bytes )); - - error = FT_THROW( Invalid_Stream_Operation ); - } - - return error; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_TryRead( FT_Stream stream, - FT_Byte* buffer, - FT_ULong count ) - { - FT_ULong read_bytes = 0; - - - if ( stream->pos >= stream->size ) - goto Exit; - - if ( stream->read ) - read_bytes = stream->read( stream, stream->pos, buffer, count ); - else - { - read_bytes = stream->size - stream->pos; - if ( read_bytes > count ) - read_bytes = count; - - FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes ); - } - - stream->pos += read_bytes; - - Exit: - return read_bytes; - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_ExtractFrame( FT_Stream stream, - FT_ULong count, - FT_Byte** pbytes ) - { - FT_Error error; - - - error = FT_Stream_EnterFrame( stream, count ); - if ( !error ) - { - *pbytes = (FT_Byte*)stream->cursor; - - /* equivalent to FT_Stream_ExitFrame(), with no memory block release */ - stream->cursor = NULL; - stream->limit = NULL; - } - - return error; - } - - - FT_BASE_DEF( void ) - FT_Stream_ReleaseFrame( FT_Stream stream, - FT_Byte** pbytes ) - { - if ( stream && stream->read ) - { - FT_Memory memory = stream->memory; - -#ifdef FT_DEBUG_MEMORY - ft_mem_free( memory, *pbytes ); - *pbytes = NULL; -#else - FT_FREE( *pbytes ); -#endif - } - *pbytes = NULL; - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_EnterFrame( FT_Stream stream, - FT_ULong count ) - { - FT_Error error = FT_Err_Ok; - FT_ULong read_bytes; - - - /* check for nested frame access */ - FT_ASSERT( stream && stream->cursor == 0 ); - - if ( stream->read ) - { - /* allocate the frame in memory */ - FT_Memory memory = stream->memory; - - - /* simple sanity check */ - if ( count > stream->size ) - { - FT_ERROR(( "FT_Stream_EnterFrame:" - " frame size (%lu) larger than stream size (%lu)\n", - count, stream->size )); - - error = FT_THROW( Invalid_Stream_Operation ); - goto Exit; - } - -#ifdef FT_DEBUG_MEMORY - /* assume _ft_debug_file and _ft_debug_lineno are already set */ - stream->base = (unsigned char*)ft_mem_qalloc( memory, - (FT_Long)count, - &error ); - if ( error ) - goto Exit; -#else - if ( FT_QALLOC( stream->base, count ) ) - goto Exit; -#endif - /* read it */ - read_bytes = stream->read( stream, stream->pos, - stream->base, count ); - if ( read_bytes < count ) - { - FT_ERROR(( "FT_Stream_EnterFrame:" - " invalid read; expected %lu bytes, got %lu\n", - count, read_bytes )); - - FT_FREE( stream->base ); - error = FT_THROW( Invalid_Stream_Operation ); - } - stream->cursor = stream->base; - stream->limit = stream->cursor + count; - stream->pos += read_bytes; - } - else - { - /* check current and new position */ - if ( stream->pos >= stream->size || - stream->size - stream->pos < count ) - { - FT_ERROR(( "FT_Stream_EnterFrame:" - " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", - stream->pos, count, stream->size )); - - error = FT_THROW( Invalid_Stream_Operation ); - goto Exit; - } - - /* set cursor */ - stream->cursor = stream->base + stream->pos; - stream->limit = stream->cursor + count; - stream->pos += count; - } - - Exit: - return error; - } - - - FT_BASE_DEF( void ) - FT_Stream_ExitFrame( FT_Stream stream ) - { - /* IMPORTANT: The assertion stream->cursor != 0 was removed, given */ - /* that it is possible to access a frame of length 0 in */ - /* some weird fonts (usually, when accessing an array of */ - /* 0 records, like in some strange kern tables). */ - /* */ - /* In this case, the loader code handles the 0-length table */ - /* gracefully; however, stream.cursor is really set to 0 by the */ - /* FT_Stream_EnterFrame() call, and this is not an error. */ - /* */ - FT_ASSERT( stream ); - - if ( stream->read ) - { - FT_Memory memory = stream->memory; - -#ifdef FT_DEBUG_MEMORY - ft_mem_free( memory, stream->base ); - stream->base = NULL; -#else - FT_FREE( stream->base ); -#endif - } - stream->cursor = NULL; - stream->limit = NULL; - } - - - FT_BASE_DEF( FT_Char ) - FT_Stream_GetChar( FT_Stream stream ) - { - FT_Char result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - if ( stream->cursor < stream->limit ) - result = (FT_Char)*stream->cursor++; - - return result; - } - - - FT_BASE_DEF( FT_UShort ) - FT_Stream_GetUShort( FT_Stream stream ) - { - FT_Byte* p; - FT_UShort result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - p = stream->cursor; - if ( p + 1 < stream->limit ) - result = FT_NEXT_USHORT( p ); - stream->cursor = p; - - return result; - } - - - FT_BASE_DEF( FT_UShort ) - FT_Stream_GetUShortLE( FT_Stream stream ) - { - FT_Byte* p; - FT_UShort result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - p = stream->cursor; - if ( p + 1 < stream->limit ) - result = FT_NEXT_USHORT_LE( p ); - stream->cursor = p; - - return result; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_GetUOffset( FT_Stream stream ) - { - FT_Byte* p; - FT_ULong result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - p = stream->cursor; - if ( p + 2 < stream->limit ) - result = FT_NEXT_UOFF3( p ); - stream->cursor = p; - return result; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_GetULong( FT_Stream stream ) - { - FT_Byte* p; - FT_ULong result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - p = stream->cursor; - if ( p + 3 < stream->limit ) - result = FT_NEXT_ULONG( p ); - stream->cursor = p; - return result; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_GetULongLE( FT_Stream stream ) - { - FT_Byte* p; - FT_ULong result; - - - FT_ASSERT( stream && stream->cursor ); - - result = 0; - p = stream->cursor; - if ( p + 3 < stream->limit ) - result = FT_NEXT_ULONG_LE( p ); - stream->cursor = p; - return result; - } - - - FT_BASE_DEF( FT_Char ) - FT_Stream_ReadChar( FT_Stream stream, - FT_Error* error ) - { - FT_Byte result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->read ) - { - if ( stream->read( stream, stream->pos, &result, 1L ) != 1L ) - goto Fail; - } - else - { - if ( stream->pos < stream->size ) - result = stream->base[stream->pos]; - else - goto Fail; - } - stream->pos++; - - return (FT_Char)result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadChar:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_UShort ) - FT_Stream_ReadUShort( FT_Stream stream, - FT_Error* error ) - { - FT_Byte reads[2]; - FT_Byte* p = 0; - FT_UShort result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->pos + 1 < stream->size ) - { - if ( stream->read ) - { - if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) - goto Fail; - - p = reads; - } - else - p = stream->base + stream->pos; - - if ( p ) - result = FT_NEXT_USHORT( p ); - } - else - goto Fail; - - stream->pos += 2; - - return result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadUShort:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_UShort ) - FT_Stream_ReadUShortLE( FT_Stream stream, - FT_Error* error ) - { - FT_Byte reads[2]; - FT_Byte* p = 0; - FT_UShort result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->pos + 1 < stream->size ) - { - if ( stream->read ) - { - if ( stream->read( stream, stream->pos, reads, 2L ) != 2L ) - goto Fail; - - p = reads; - } - else - p = stream->base + stream->pos; - - if ( p ) - result = FT_NEXT_USHORT_LE( p ); - } - else - goto Fail; - - stream->pos += 2; - - return result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadUShortLE:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_ReadUOffset( FT_Stream stream, - FT_Error* error ) - { - FT_Byte reads[3]; - FT_Byte* p = 0; - FT_ULong result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->pos + 2 < stream->size ) - { - if ( stream->read ) - { - if (stream->read( stream, stream->pos, reads, 3L ) != 3L ) - goto Fail; - - p = reads; - } - else - p = stream->base + stream->pos; - - if ( p ) - result = FT_NEXT_UOFF3( p ); - } - else - goto Fail; - - stream->pos += 3; - - return result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadUOffset:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_ReadULong( FT_Stream stream, - FT_Error* error ) - { - FT_Byte reads[4]; - FT_Byte* p = 0; - FT_ULong result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->pos + 3 < stream->size ) - { - if ( stream->read ) - { - if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) - goto Fail; - - p = reads; - } - else - p = stream->base + stream->pos; - - if ( p ) - result = FT_NEXT_ULONG( p ); - } - else - goto Fail; - - stream->pos += 4; - - return result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadULong:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_ULong ) - FT_Stream_ReadULongLE( FT_Stream stream, - FT_Error* error ) - { - FT_Byte reads[4]; - FT_Byte* p = 0; - FT_ULong result = 0; - - - FT_ASSERT( stream ); - - *error = FT_Err_Ok; - - if ( stream->pos + 3 < stream->size ) - { - if ( stream->read ) - { - if ( stream->read( stream, stream->pos, reads, 4L ) != 4L ) - goto Fail; - - p = reads; - } - else - p = stream->base + stream->pos; - - if ( p ) - result = FT_NEXT_ULONG_LE( p ); - } - else - goto Fail; - - stream->pos += 4; - - return result; - - Fail: - *error = FT_THROW( Invalid_Stream_Operation ); - FT_ERROR(( "FT_Stream_ReadULongLE:" - " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); - - return 0; - } - - - FT_BASE_DEF( FT_Error ) - FT_Stream_ReadFields( FT_Stream stream, - const FT_Frame_Field* fields, - void* structure ) - { - FT_Error error; - FT_Bool frame_accessed = 0; - FT_Byte* cursor; - - - if ( !fields ) - return FT_THROW( Invalid_Argument ); - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - - cursor = stream->cursor; - - error = FT_Err_Ok; - do - { - FT_ULong value; - FT_Int sign_shift; - FT_Byte* p; - - - switch ( fields->value ) - { - case ft_frame_start: /* access a new frame */ - error = FT_Stream_EnterFrame( stream, fields->offset ); - if ( error ) - goto Exit; - - frame_accessed = 1; - cursor = stream->cursor; - fields++; - continue; /* loop! */ - - case ft_frame_bytes: /* read a byte sequence */ - case ft_frame_skip: /* skip some bytes */ - { - FT_UInt len = fields->size; - - - if ( cursor + len > stream->limit ) - { - error = FT_THROW( Invalid_Stream_Operation ); - goto Exit; - } - - if ( fields->value == ft_frame_bytes ) - { - p = (FT_Byte*)structure + fields->offset; - FT_MEM_COPY( p, cursor, len ); - } - cursor += len; - fields++; - continue; - } - - case ft_frame_byte: - case ft_frame_schar: /* read a single byte */ - value = FT_NEXT_BYTE( cursor ); - sign_shift = 24; - break; - - case ft_frame_short_be: - case ft_frame_ushort_be: /* read a 2-byte big-endian short */ - value = FT_NEXT_USHORT( cursor ); - sign_shift = 16; - break; - - case ft_frame_short_le: - case ft_frame_ushort_le: /* read a 2-byte little-endian short */ - value = FT_NEXT_USHORT_LE( cursor ); - sign_shift = 16; - break; - - case ft_frame_long_be: - case ft_frame_ulong_be: /* read a 4-byte big-endian long */ - value = FT_NEXT_ULONG( cursor ); - sign_shift = 0; - break; - - case ft_frame_long_le: - case ft_frame_ulong_le: /* read a 4-byte little-endian long */ - value = FT_NEXT_ULONG_LE( cursor ); - sign_shift = 0; - break; - - case ft_frame_off3_be: - case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ - value = FT_NEXT_UOFF3( cursor ); - sign_shift = 8; - break; - - case ft_frame_off3_le: - case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ - value = FT_NEXT_UOFF3_LE( cursor ); - sign_shift = 8; - break; - - default: - /* otherwise, exit the loop */ - stream->cursor = cursor; - goto Exit; - } - - /* now, compute the signed value is necessary */ - if ( fields->value & FT_FRAME_OP_SIGNED ) - value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift ); - - /* finally, store the value in the object */ - - p = (FT_Byte*)structure + fields->offset; - switch ( fields->size ) - { - case ( 8 / FT_CHAR_BIT ): - *(FT_Byte*)p = (FT_Byte)value; - break; - - case ( 16 / FT_CHAR_BIT ): - *(FT_UShort*)p = (FT_UShort)value; - break; - - case ( 32 / FT_CHAR_BIT ): - *(FT_UInt32*)p = (FT_UInt32)value; - break; - - default: /* for 64-bit systems */ - *(FT_ULong*)p = (FT_ULong)value; - } - - /* go to next field */ - fields++; - } - while ( 1 ); - - Exit: - /* close the frame if it was opened by this read */ - if ( frame_accessed ) - FT_Stream_ExitFrame( stream ); - - return error; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftsystem.c b/third_party/freetype/src/base/ftsystem.c deleted file mode 100644 index 324f949a49..0000000000 --- a/third_party/freetype/src/base/ftsystem.c +++ /dev/null @@ -1,320 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftsystem.c */ -/* */ -/* ANSI-specific FreeType low-level system interface (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* This file contains the default interface used by FreeType to access */ - /* low-level, i.e. memory management, i/o access as well as thread */ - /* synchronisation. It can be replaced by user-specific routines if */ - /* necessary. */ - /* */ - /*************************************************************************/ - - -#include -#include FT_CONFIG_CONFIG_H -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_SYSTEM_H -#include FT_ERRORS_H -#include FT_TYPES_H - - - /*************************************************************************/ - /* */ - /* MEMORY MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /* It is not necessary to do any error checking for the */ - /* allocation-related functions. This will be done by the higher level */ - /* routines like ft_mem_alloc() or ft_mem_realloc(). */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* */ - /* ft_alloc */ - /* */ - /* */ - /* The memory allocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* size :: The requested size in bytes. */ - /* */ - /* */ - /* The address of newly allocated block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_alloc( FT_Memory memory, - long size ) - { - FT_UNUSED( memory ); - - return ft_smalloc( (size_t)size ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_realloc */ - /* */ - /* */ - /* The memory reallocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* cur_size :: The current size of the allocated memory block. */ - /* */ - /* new_size :: The newly requested size in bytes. */ - /* */ - /* block :: The current address of the block in memory. */ - /* */ - /* */ - /* The address of the reallocated memory block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) - { - FT_UNUSED( memory ); - FT_UNUSED( cur_size ); - - return ft_srealloc( block, (size_t)new_size ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_free */ - /* */ - /* */ - /* The memory release function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* block :: The address of block in memory to be freed. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_free( FT_Memory memory, - void* block ) - { - FT_UNUSED( memory ); - - ft_sfree( block ); - } - - - /*************************************************************************/ - /* */ - /* RESOURCE MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - -#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_io - - /* We use the macro STREAM_FILE for convenience to extract the */ - /* system-specific stream handle from a given FreeType stream object */ -#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer ) - - - /*************************************************************************/ - /* */ - /* */ - /* ft_ansi_stream_close */ - /* */ - /* */ - /* The function to close a stream. */ - /* */ - /* */ - /* stream :: A pointer to the stream object. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_ansi_stream_close( FT_Stream stream ) - { - ft_fclose( STREAM_FILE( stream ) ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_ansi_stream_io */ - /* */ - /* */ - /* The function to open a stream. */ - /* */ - /* */ - /* stream :: A pointer to the stream object. */ - /* */ - /* offset :: The position in the data stream to start reading. */ - /* */ - /* buffer :: The address of buffer to store the read data. */ - /* */ - /* count :: The number of bytes to read from the stream. */ - /* */ - /* */ - /* The number of bytes actually read. If `count' is zero (this is, */ - /* the function is used for seeking), a non-zero return value */ - /* indicates an error. */ - /* */ - FT_CALLBACK_DEF( unsigned long ) - ft_ansi_stream_io( FT_Stream stream, - unsigned long offset, - unsigned char* buffer, - unsigned long count ) - { - FT_FILE* file; - - - if ( !count && offset > stream->size ) - return 1; - - file = STREAM_FILE( stream ); - - if ( stream->pos != offset ) - ft_fseek( file, (long)offset, SEEK_SET ); - - return (unsigned long)ft_fread( buffer, 1, count, file ); - } - - - /* documentation is in ftstream.h */ - - FT_BASE_DEF( FT_Error ) - FT_Stream_Open( FT_Stream stream, - const char* filepathname ) - { - FT_FILE* file; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - - stream->descriptor.pointer = NULL; - stream->pathname.pointer = (char*)filepathname; - stream->base = NULL; - stream->pos = 0; - stream->read = NULL; - stream->close = NULL; - - file = ft_fopen( filepathname, "rb" ); - if ( !file ) - { - FT_ERROR(( "FT_Stream_Open:" - " could not open `%s'\n", filepathname )); - - return FT_THROW( Cannot_Open_Resource ); - } - - ft_fseek( file, 0, SEEK_END ); - stream->size = (unsigned long)ft_ftell( file ); - if ( !stream->size ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); - ft_fclose( file ); - return FT_THROW( Cannot_Open_Stream ); - } - ft_fseek( file, 0, SEEK_SET ); - - stream->descriptor.pointer = file; - stream->read = ft_ansi_stream_io; - stream->close = ft_ansi_stream_close; - - FT_TRACE1(( "FT_Stream_Open:" )); - FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", - filepathname, stream->size )); - - return FT_Err_Ok; - } - -#endif /* !FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT */ - -#ifdef FT_DEBUG_MEMORY - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ); - - extern void - ft_mem_debug_done( FT_Memory memory ); - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Memory ) - FT_New_Memory( void ) - { - FT_Memory memory; - - - memory = (FT_Memory)ft_smalloc( sizeof ( *memory ) ); - if ( memory ) - { - memory->user = NULL; - memory->alloc = ft_alloc; - memory->realloc = ft_realloc; - memory->free = ft_free; -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_init( memory ); -#endif - } - - return memory; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_Memory( FT_Memory memory ) - { -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_done( memory ); -#endif - ft_sfree( memory ); - } - - -/* END */ diff --git a/third_party/freetype/src/base/fttrigon.c b/third_party/freetype/src/base/fttrigon.c deleted file mode 100644 index 7a4d17c829..0000000000 --- a/third_party/freetype/src/base/fttrigon.c +++ /dev/null @@ -1,526 +0,0 @@ -/***************************************************************************/ -/* */ -/* fttrigon.c */ -/* */ -/* FreeType trigonometric functions (body). */ -/* */ -/* Copyright 2001-2017 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. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* This is a fixed-point CORDIC implementation of trigonometric */ - /* functions as well as transformations between Cartesian and polar */ - /* coordinates. The angles are represented as 16.16 fixed-point values */ - /* in degrees, i.e., the angular resolution is 2^-16 degrees. Note that */ - /* only vectors longer than 2^16*180/pi (or at least 22 bits) on a */ - /* discrete Cartesian grid can have the same or better angular */ - /* resolution. Therefore, to maintain this precision, some functions */ - /* require an interim upscaling of the vectors, whereas others operate */ - /* with 24-bit long vectors directly. */ - /* */ - /*************************************************************************/ - -#include -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_CALC_H -#include FT_TRIGONOMETRY_H - - - /* the Cordic shrink factor 0.858785336480436 * 2^32 */ -#define FT_TRIG_SCALE 0xDBD95B16UL - - /* the highest bit in overflow-safe vector components, */ - /* MSB of 0.858785336480436 * sqrt(0.5) * 2^30 */ -#define FT_TRIG_SAFE_MSB 29 - - /* this table was generated for FT_PI = 180L << 16, i.e. degrees */ -#define FT_TRIG_MAX_ITERS 23 - - static const FT_Angle - ft_trig_arctan_table[] = - { - 1740967L, 919879L, 466945L, 234379L, 117304L, 58666L, 29335L, - 14668L, 7334L, 3667L, 1833L, 917L, 458L, 229L, 115L, - 57L, 29L, 14L, 7L, 4L, 2L, 1L - }; - - -#ifdef FT_LONG64 - - /* multiply a given value by the CORDIC shrink factor */ - static FT_Fixed - ft_trig_downscale( FT_Fixed val ) - { - FT_Int s = 1; - - - if ( val < 0 ) - { - val = -val; - s = -1; - } - - /* 0x40000000 comes from regression analysis between true */ - /* and CORDIC hypotenuse, so it minimizes the error */ - val = (FT_Fixed)( - ( (FT_UInt64)val * FT_TRIG_SCALE + 0x40000000UL ) >> 32 ); - - return s < 0 ? -val : val; - } - -#else /* !FT_LONG64 */ - - /* multiply a given value by the CORDIC shrink factor */ - static FT_Fixed - ft_trig_downscale( FT_Fixed val ) - { - FT_Int s = 1; - FT_UInt32 lo1, hi1, lo2, hi2, lo, hi, i1, i2; - - - if ( val < 0 ) - { - val = -val; - s = -1; - } - - lo1 = (FT_UInt32)val & 0x0000FFFFU; - hi1 = (FT_UInt32)val >> 16; - lo2 = FT_TRIG_SCALE & 0x0000FFFFU; - hi2 = FT_TRIG_SCALE >> 16; - - lo = lo1 * lo2; - i1 = lo1 * hi2; - i2 = lo2 * hi1; - hi = hi1 * hi2; - - /* Check carry overflow of i1 + i2 */ - i1 += i2; - hi += (FT_UInt32)( i1 < i2 ) << 16; - - hi += i1 >> 16; - i1 = i1 << 16; - - /* Check carry overflow of i1 + lo */ - lo += i1; - hi += ( lo < i1 ); - - /* 0x40000000 comes from regression analysis between true */ - /* and CORDIC hypotenuse, so it minimizes the error */ - - /* Check carry overflow of lo + 0x40000000 */ - lo += 0x40000000UL; - hi += ( lo < 0x40000000UL ); - - val = (FT_Fixed)hi; - - return s < 0 ? -val : val; - } - -#endif /* !FT_LONG64 */ - - - /* undefined and never called for zero vector */ - static FT_Int - ft_trig_prenorm( FT_Vector* vec ) - { - FT_Pos x, y; - FT_Int shift; - - - x = vec->x; - y = vec->y; - - shift = FT_MSB( (FT_UInt32)( FT_ABS( x ) | FT_ABS( y ) ) ); - - if ( shift <= FT_TRIG_SAFE_MSB ) - { - shift = FT_TRIG_SAFE_MSB - shift; - vec->x = (FT_Pos)( (FT_ULong)x << shift ); - vec->y = (FT_Pos)( (FT_ULong)y << shift ); - } - else - { - shift -= FT_TRIG_SAFE_MSB; - vec->x = x >> shift; - vec->y = y >> shift; - shift = -shift; - } - - return shift; - } - - - static void - ft_trig_pseudo_rotate( FT_Vector* vec, - FT_Angle theta ) - { - FT_Int i; - FT_Fixed x, y, xtemp, b; - const FT_Angle *arctanptr; - - - x = vec->x; - y = vec->y; - - /* Rotate inside [-PI/4,PI/4] sector */ - while ( theta < -FT_ANGLE_PI4 ) - { - xtemp = y; - y = -x; - x = xtemp; - theta += FT_ANGLE_PI2; - } - - while ( theta > FT_ANGLE_PI4 ) - { - xtemp = -y; - y = x; - x = xtemp; - theta -= FT_ANGLE_PI2; - } - - arctanptr = ft_trig_arctan_table; - - /* Pseudorotations, with right shifts */ - for ( i = 1, b = 1; i < FT_TRIG_MAX_ITERS; b <<= 1, i++ ) - { - if ( theta < 0 ) - { - xtemp = x + ( ( y + b ) >> i ); - y = y - ( ( x + b ) >> i ); - x = xtemp; - theta += *arctanptr++; - } - else - { - xtemp = x - ( ( y + b ) >> i ); - y = y + ( ( x + b ) >> i ); - x = xtemp; - theta -= *arctanptr++; - } - } - - vec->x = x; - vec->y = y; - } - - - static void - ft_trig_pseudo_polarize( FT_Vector* vec ) - { - FT_Angle theta; - FT_Int i; - FT_Fixed x, y, xtemp, b; - const FT_Angle *arctanptr; - - - x = vec->x; - y = vec->y; - - /* Get the vector into [-PI/4,PI/4] sector */ - if ( y > x ) - { - if ( y > -x ) - { - theta = FT_ANGLE_PI2; - xtemp = y; - y = -x; - x = xtemp; - } - else - { - theta = y > 0 ? FT_ANGLE_PI : -FT_ANGLE_PI; - x = -x; - y = -y; - } - } - else - { - if ( y < -x ) - { - theta = -FT_ANGLE_PI2; - xtemp = -y; - y = x; - x = xtemp; - } - else - { - theta = 0; - } - } - - arctanptr = ft_trig_arctan_table; - - /* Pseudorotations, with right shifts */ - for ( i = 1, b = 1; i < FT_TRIG_MAX_ITERS; b <<= 1, i++ ) - { - if ( y > 0 ) - { - xtemp = x + ( ( y + b ) >> i ); - y = y - ( ( x + b ) >> i ); - x = xtemp; - theta += *arctanptr++; - } - else - { - xtemp = x - ( ( y + b ) >> i ); - y = y + ( ( x + b ) >> i ); - x = xtemp; - theta -= *arctanptr++; - } - } - - /* round theta to acknowledge its error that mostly comes */ - /* from accumulated rounding errors in the arctan table */ - if ( theta >= 0 ) - theta = FT_PAD_ROUND( theta, 16 ); - else - theta = -FT_PAD_ROUND( -theta, 16 ); - - vec->x = x; - vec->y = theta; - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_Cos( FT_Angle angle ) - { - FT_Vector v; - - - FT_Vector_Unit( &v, angle ); - - return v.x; - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_Sin( FT_Angle angle ) - { - FT_Vector v; - - - FT_Vector_Unit( &v, angle ); - - return v.y; - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_Tan( FT_Angle angle ) - { - FT_Vector v; - - - FT_Vector_Unit( &v, angle ); - - return FT_DivFix( v.y, v.x ); - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Angle ) - FT_Atan2( FT_Fixed dx, - FT_Fixed dy ) - { - FT_Vector v; - - - if ( dx == 0 && dy == 0 ) - return 0; - - v.x = dx; - v.y = dy; - ft_trig_prenorm( &v ); - ft_trig_pseudo_polarize( &v ); - - return v.y; - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( void ) - FT_Vector_Unit( FT_Vector* vec, - FT_Angle angle ) - { - if ( !vec ) - return; - - vec->x = FT_TRIG_SCALE >> 8; - vec->y = 0; - ft_trig_pseudo_rotate( vec, angle ); - vec->x = ( vec->x + 0x80L ) >> 8; - vec->y = ( vec->y + 0x80L ) >> 8; - } - - - /* these macros return 0 for positive numbers, - and -1 for negative ones */ -#define FT_SIGN_LONG( x ) ( (x) >> ( FT_SIZEOF_LONG * 8 - 1 ) ) -#define FT_SIGN_INT( x ) ( (x) >> ( FT_SIZEOF_INT * 8 - 1 ) ) -#define FT_SIGN_INT32( x ) ( (x) >> 31 ) -#define FT_SIGN_INT16( x ) ( (x) >> 15 ) - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( void ) - FT_Vector_Rotate( FT_Vector* vec, - FT_Angle angle ) - { - FT_Int shift; - FT_Vector v; - - - if ( !vec || !angle ) - return; - - v = *vec; - - if ( v.x == 0 && v.y == 0 ) - return; - - shift = ft_trig_prenorm( &v ); - ft_trig_pseudo_rotate( &v, angle ); - v.x = ft_trig_downscale( v.x ); - v.y = ft_trig_downscale( v.y ); - - if ( shift > 0 ) - { - FT_Int32 half = (FT_Int32)1L << ( shift - 1 ); - - - vec->x = ( v.x + half + FT_SIGN_LONG( v.x ) ) >> shift; - vec->y = ( v.y + half + FT_SIGN_LONG( v.y ) ) >> shift; - } - else - { - shift = -shift; - vec->x = (FT_Pos)( (FT_ULong)v.x << shift ); - vec->y = (FT_Pos)( (FT_ULong)v.y << shift ); - } - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Fixed ) - FT_Vector_Length( FT_Vector* vec ) - { - FT_Int shift; - FT_Vector v; - - - if ( !vec ) - return 0; - - v = *vec; - - /* handle trivial cases */ - if ( v.x == 0 ) - { - return FT_ABS( v.y ); - } - else if ( v.y == 0 ) - { - return FT_ABS( v.x ); - } - - /* general case */ - shift = ft_trig_prenorm( &v ); - ft_trig_pseudo_polarize( &v ); - - v.x = ft_trig_downscale( v.x ); - - if ( shift > 0 ) - return ( v.x + ( 1L << ( shift - 1 ) ) ) >> shift; - - return (FT_Fixed)( (FT_UInt32)v.x << -shift ); - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( void ) - FT_Vector_Polarize( FT_Vector* vec, - FT_Fixed *length, - FT_Angle *angle ) - { - FT_Int shift; - FT_Vector v; - - - if ( !vec || !length || !angle ) - return; - - v = *vec; - - if ( v.x == 0 && v.y == 0 ) - return; - - shift = ft_trig_prenorm( &v ); - ft_trig_pseudo_polarize( &v ); - - v.x = ft_trig_downscale( v.x ); - - *length = shift >= 0 ? ( v.x >> shift ) - : (FT_Fixed)( (FT_UInt32)v.x << -shift ); - *angle = v.y; - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( void ) - FT_Vector_From_Polar( FT_Vector* vec, - FT_Fixed length, - FT_Angle angle ) - { - if ( !vec ) - return; - - vec->x = length; - vec->y = 0; - - FT_Vector_Rotate( vec, angle ); - } - - - /* documentation is in fttrigon.h */ - - FT_EXPORT_DEF( FT_Angle ) - FT_Angle_Diff( FT_Angle angle1, - FT_Angle angle2 ) - { - FT_Angle delta = angle2 - angle1; - - - while ( delta <= -FT_ANGLE_PI ) - delta += FT_ANGLE_2PI; - - while ( delta > FT_ANGLE_PI ) - delta -= FT_ANGLE_2PI; - - return delta; - } - - -/* END */ diff --git a/third_party/freetype/src/base/fttype1.c b/third_party/freetype/src/base/fttype1.c deleted file mode 100644 index 4d16a6371a..0000000000 --- a/third_party/freetype/src/base/fttype1.c +++ /dev/null @@ -1,127 +0,0 @@ -/***************************************************************************/ -/* */ -/* fttype1.c */ -/* */ -/* FreeType utility file for PS names support (body). */ -/* */ -/* Copyright 2002-2017 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 -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_SERVICE_H -#include FT_SERVICE_POSTSCRIPT_INFO_H - - - /* documentation is in t1tables.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_PS_Font_Info( FT_Face face, - PS_FontInfoRec* afont_info ) - { - FT_Error error; - FT_Service_PsInfo service; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !afont_info ) - return FT_THROW( Invalid_Argument ); - - FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); - - if ( service && service->ps_get_font_info ) - error = service->ps_get_font_info( face, afont_info ); - else - error = FT_THROW( Invalid_Argument ); - - return error; - } - - - /* documentation is in t1tables.h */ - - FT_EXPORT_DEF( FT_Int ) - FT_Has_PS_Glyph_Names( FT_Face face ) - { - FT_Int result = 0; - FT_Service_PsInfo service; - - - if ( face ) - { - FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); - - if ( service && service->ps_has_glyph_names ) - result = service->ps_has_glyph_names( face ); - } - - return result; - } - - - /* documentation is in t1tables.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_Get_PS_Font_Private( FT_Face face, - PS_PrivateRec* afont_private ) - { - FT_Error error; - FT_Service_PsInfo service; - - - if ( !face ) - return FT_THROW( Invalid_Face_Handle ); - - if ( !afont_private ) - return FT_THROW( Invalid_Argument ); - - FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); - - if ( service && service->ps_get_font_private ) - error = service->ps_get_font_private( face, afont_private ); - else - error = FT_THROW( Invalid_Argument ); - - return error; - } - - - /* documentation is in t1tables.h */ - - FT_EXPORT_DEF( FT_Long ) - FT_Get_PS_Font_Value( FT_Face face, - PS_Dict_Keys key, - FT_UInt idx, - void *value, - FT_Long value_len ) - { - FT_Int result = 0; - FT_Service_PsInfo service = NULL; - - - if ( face ) - { - FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO ); - - if ( service && service->ps_get_font_value ) - result = service->ps_get_font_value( face, key, idx, - value, value_len ); - } - - return result; - } - - -/* END */ diff --git a/third_party/freetype/src/base/ftutil.c b/third_party/freetype/src/base/ftutil.c deleted file mode 100644 index dccc209f4d..0000000000 --- a/third_party/freetype/src/base/ftutil.c +++ /dev/null @@ -1,441 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftutil.c */ -/* */ -/* FreeType utility file for memory and list management (body). */ -/* */ -/* Copyright 2002-2017 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 -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_MEMORY_H -#include FT_INTERNAL_OBJECTS_H -#include FT_LIST_H - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_memory - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** *****/ - /***** M E M O R Y M A N A G E M E N T *****/ - /***** *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_alloc( FT_Memory memory, - FT_Long size, - FT_Error *p_error ) - { - FT_Error error; - FT_Pointer block = ft_mem_qalloc( memory, size, &error ); - - if ( !error && size > 0 ) - FT_MEM_ZERO( block, size ); - - *p_error = error; - return block; - } - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_qalloc( FT_Memory memory, - FT_Long size, - FT_Error *p_error ) - { - FT_Error error = FT_Err_Ok; - FT_Pointer block = NULL; - - - if ( size > 0 ) - { - block = memory->alloc( memory, size ); - if ( !block ) - error = FT_THROW( Out_Of_Memory ); - } - else if ( size < 0 ) - { - /* may help catch/prevent security issues */ - error = FT_THROW( Invalid_Argument ); - } - - *p_error = error; - return block; - } - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_realloc( FT_Memory memory, - FT_Long item_size, - FT_Long cur_count, - FT_Long new_count, - void* block, - FT_Error *p_error ) - { - FT_Error error = FT_Err_Ok; - - - block = ft_mem_qrealloc( memory, item_size, - cur_count, new_count, block, &error ); - if ( !error && new_count > cur_count ) - FT_MEM_ZERO( (char*)block + cur_count * item_size, - ( new_count - cur_count ) * item_size ); - - *p_error = error; - return block; - } - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_qrealloc( FT_Memory memory, - FT_Long item_size, - FT_Long cur_count, - FT_Long new_count, - void* block, - FT_Error *p_error ) - { - FT_Error error = FT_Err_Ok; - - - /* Note that we now accept `item_size == 0' as a valid parameter, in - * order to cover very weird cases where an ALLOC_MULT macro would be - * called. - */ - if ( cur_count < 0 || new_count < 0 || item_size < 0 ) - { - /* may help catch/prevent nasty security issues */ - error = FT_THROW( Invalid_Argument ); - } - else if ( new_count == 0 || item_size == 0 ) - { - ft_mem_free( memory, block ); - block = NULL; - } - else if ( new_count > FT_INT_MAX/item_size ) - { - error = FT_THROW( Array_Too_Large ); - } - else if ( cur_count == 0 ) - { - FT_ASSERT( !block ); - - block = ft_mem_alloc( memory, new_count*item_size, &error ); - } - else - { - FT_Pointer block2; - FT_Long cur_size = cur_count*item_size; - FT_Long new_size = new_count*item_size; - - - block2 = memory->realloc( memory, cur_size, new_size, block ); - if ( !block2 ) - error = FT_THROW( Out_Of_Memory ); - else - block = block2; - } - - *p_error = error; - return block; - } - - - FT_BASE_DEF( void ) - ft_mem_free( FT_Memory memory, - const void *P ) - { - if ( P ) - memory->free( memory, (void*)P ); - } - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_dup( FT_Memory memory, - const void* address, - FT_ULong size, - FT_Error *p_error ) - { - FT_Error error; - FT_Pointer p = ft_mem_qalloc( memory, (FT_Long)size, &error ); - - - if ( !error && address ) - ft_memcpy( p, address, size ); - - *p_error = error; - return p; - } - - - FT_BASE_DEF( FT_Pointer ) - ft_mem_strdup( FT_Memory memory, - const char* str, - FT_Error *p_error ) - { - FT_ULong len = str ? (FT_ULong)ft_strlen( str ) + 1 - : 0; - - - return ft_mem_dup( memory, str, len, p_error ); - } - - - FT_BASE_DEF( FT_Int ) - ft_mem_strcpyn( char* dst, - const char* src, - FT_ULong size ) - { - while ( size > 1 && *src != 0 ) - { - *dst++ = *src++; - size--; - } - - *dst = 0; /* always zero-terminate */ - - return *src != 0; - } - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** *****/ - /***** D O U B L Y L I N K E D L I S T S *****/ - /***** *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - -#undef FT_COMPONENT -#define FT_COMPONENT trace_list - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( FT_ListNode ) - FT_List_Find( FT_List list, - void* data ) - { - FT_ListNode cur; - - - if ( !list ) - return NULL; - - cur = list->head; - while ( cur ) - { - if ( cur->data == data ) - return cur; - - cur = cur->next; - } - - return NULL; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( void ) - FT_List_Add( FT_List list, - FT_ListNode node ) - { - FT_ListNode before; - - - if ( !list || !node ) - return; - - before = list->tail; - - node->next = NULL; - node->prev = before; - - if ( before ) - before->next = node; - else - list->head = node; - - list->tail = node; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( void ) - FT_List_Insert( FT_List list, - FT_ListNode node ) - { - FT_ListNode after; - - - if ( !list || !node ) - return; - - after = list->head; - - node->next = after; - node->prev = NULL; - - if ( !after ) - list->tail = node; - else - after->prev = node; - - list->head = node; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( void ) - FT_List_Remove( FT_List list, - FT_ListNode node ) - { - FT_ListNode before, after; - - - if ( !list || !node ) - return; - - before = node->prev; - after = node->next; - - if ( before ) - before->next = after; - else - list->head = after; - - if ( after ) - after->prev = before; - else - list->tail = before; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( void ) - FT_List_Up( FT_List list, - FT_ListNode node ) - { - FT_ListNode before, after; - - - if ( !list || !node ) - return; - - before = node->prev; - after = node->next; - - /* check whether we are already on top of the list */ - if ( !before ) - return; - - before->next = after; - - if ( after ) - after->prev = before; - else - list->tail = before; - - node->prev = NULL; - node->next = list->head; - list->head->prev = node; - list->head = node; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_List_Iterate( FT_List list, - FT_List_Iterator iterator, - void* user ) - { - FT_ListNode cur; - FT_Error error = FT_Err_Ok; - - - if ( !list || !iterator ) - return FT_THROW( Invalid_Argument ); - - cur = list->head; - - while ( cur ) - { - FT_ListNode next = cur->next; - - - error = iterator( cur, user ); - if ( error ) - break; - - cur = next; - } - - return error; - } - - - /* documentation is in ftlist.h */ - - FT_EXPORT_DEF( void ) - FT_List_Finalize( FT_List list, - FT_List_Destructor destroy, - FT_Memory memory, - void* user ) - { - FT_ListNode cur; - - - if ( !list || !memory ) - return; - - cur = list->head; - while ( cur ) - { - FT_ListNode next = cur->next; - void* data = cur->data; - - - if ( destroy ) - destroy( memory, data, user ); - - FT_FREE( cur ); - cur = next; - } - - list->head = NULL; - list->tail = NULL; - } - - -/* END */ -- cgit v1.2.3