From 27a4f9c4ac45ff65f941964f7351b64b1e6a9f35 Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 20 Oct 2009 17:20:18 +0000 Subject: *** empty log message *** --- src/freetype2/base/basepic.c | 83 +++++ src/freetype2/base/basepic.h | 62 ++++ src/freetype2/base/ftadvanc.c | 163 ++++++++++ src/freetype2/base/ftbase.c | 11 +- src/freetype2/base/ftbase.h | 57 ++++ src/freetype2/base/ftbbox.c | 21 +- src/freetype2/base/ftbitmap.c | 43 ++- src/freetype2/base/ftcalc.c | 217 +++++++++++--- src/freetype2/base/ftcid.c | 117 ++++++++ src/freetype2/base/ftdbgmem.c | 9 +- src/freetype2/base/ftdebug.c | 8 +- src/freetype2/base/ftfstype.c | 62 ++++ src/freetype2/base/ftgloadr.c | 7 + src/freetype2/base/ftglyph.c | 95 ++---- src/freetype2/base/ftinit.c | 119 +++++++- src/freetype2/base/ftlcdfil.c | 16 +- src/freetype2/base/ftmac.c | 297 ++++++++---------- src/freetype2/base/ftmm.c | 4 +- src/freetype2/base/ftnames.c | 94 ------ src/freetype2/base/ftobjs.c | 681 ++++++++++++++++++++++++++++++++++++------ src/freetype2/base/ftotval.c | 3 +- src/freetype2/base/ftoutln.c | 70 ++++- src/freetype2/base/ftpatent.c | 18 +- src/freetype2/base/ftpfr.c | 33 +- src/freetype2/base/ftpic.c | 54 ++++ src/freetype2/base/ftrfork.c | 187 +++++++++--- src/freetype2/base/ftsnames.c | 94 ++++++ src/freetype2/base/ftstream.c | 64 ++-- src/freetype2/base/ftstroke.c | 189 +++++++----- src/freetype2/base/ftsynth.c | 57 ++-- src/freetype2/base/ftsystem.c | 11 +- src/freetype2/base/fttrigon.c | 10 +- 32 files changed, 2201 insertions(+), 755 deletions(-) create mode 100644 src/freetype2/base/basepic.c create mode 100644 src/freetype2/base/basepic.h create mode 100644 src/freetype2/base/ftadvanc.c create mode 100644 src/freetype2/base/ftbase.h create mode 100644 src/freetype2/base/ftcid.c create mode 100644 src/freetype2/base/ftfstype.c delete mode 100644 src/freetype2/base/ftnames.c create mode 100644 src/freetype2/base/ftpic.c create mode 100644 src/freetype2/base/ftsnames.c (limited to 'src/freetype2/base') diff --git a/src/freetype2/base/basepic.c b/src/freetype2/base/basepic.c new file mode 100644 index 0000000..c0bccb6 --- /dev/null +++ b/src/freetype2/base/basepic.c @@ -0,0 +1,83 @@ +/***************************************************************************/ +/* */ +/* basepic.c */ +/* */ +/* The FreeType position independent code services for base. */ +/* */ +/* Copyright 2009 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*); + void FT_Init_Class_ft_bitmap_glyph_class(FT_Glyph_Class*); + + /* forward declaration of PIC init functions from ftinit.c */ + FT_Error ft_create_default_module_classes(FT_Library); + void ft_destroy_default_module_classes(FT_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; + 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); + +Exit: + if(error) + ft_base_pic_free(library); + return error; + } + + +#endif /* FT_CONFIG_OPTION_PIC */ + + +/* END */ diff --git a/src/freetype2/base/basepic.h b/src/freetype2/base/basepic.h new file mode 100644 index 0000000..bb17745 --- /dev/null +++ b/src/freetype2/base/basepic.h @@ -0,0 +1,62 @@ +/***************************************************************************/ +/* */ +/* basepic.h */ +/* */ +/* The FreeType position independent code services for base. */ +/* */ +/* Copyright 2009 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__ + + +FT_BEGIN_HEADER + +#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 + +#else /* FT_CONFIG_OPTION_PIC */ + +#include FT_GLYPH_H + + typedef struct BasePIC_ + { + FT_Module_Class** default_module_classes; + FT_Glyph_Class ft_outline_glyph_class; + FT_Glyph_Class ft_bitmap_glyph_class; + } 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) + + void + ft_base_pic_free( FT_Library library ); + + FT_Error + ft_base_pic_init( FT_Library library ); + +#endif /* FT_CONFIG_OPTION_PIC */ + /* */ + +FT_END_HEADER + +#endif /* __BASEPIC_H__ */ + + +/* END */ diff --git a/src/freetype2/base/ftadvanc.c b/src/freetype2/base/ftadvanc.c new file mode 100644 index 0000000..8ab7fcb --- /dev/null +++ b/src/freetype2/base/ftadvanc.c @@ -0,0 +1,163 @@ +/***************************************************************************/ +/* */ +/* ftadvanc.c */ +/* */ +/* Quick computation of advance widths (body). */ +/* */ +/* Copyright 2008, 2009 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_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 == NULL ) + return FT_Err_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 */ + +#define LOAD_ADVANCE_FAST_CHECK( 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_Err_Invalid_Face_Handle; + + if ( gindex >= (FT_UInt)face->num_glyphs ) + return FT_Err_Invalid_Glyph_Index; + + func = face->driver->clazz->get_advances; + if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) + { + FT_Error error; + + + error = func( face, gindex, 1, flags, padvance ); + if ( !error ) + return _ft_face_scale_advances( face, padvance, 1, flags ); + + if ( error != FT_ERROR_BASE( FT_Err_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_Err_Invalid_Face_Handle; + + num = (FT_UInt)face->num_glyphs; + end = start + count; + if ( start >= num || end < start || end > num ) + return FT_Err_Invalid_Glyph_Index; + + if ( count == 0 ) + return FT_Err_Ok; + + func = face->driver->clazz->get_advances; + if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) + { + error = func( face, start, count, flags, padvances ); + if ( !error ) + goto Exit; + + if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) + return error; + } + + error = FT_Err_Ok; + + if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) + return FT_Err_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; + + padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) + ? face->glyph->advance.y + : face->glyph->advance.x; + } + + if ( error ) + return error; + + Exit: + return _ft_face_scale_advances( face, padvances, count, flags ); + } + + +/* END */ diff --git a/src/freetype2/base/ftbase.c b/src/freetype2/base/ftbase.c index d176b81..6a27ea9 100644 --- a/src/freetype2/base/ftbase.c +++ b/src/freetype2/base/ftbase.c @@ -4,7 +4,7 @@ /* */ /* Single object library component (body only). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -20,19 +20,22 @@ #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 "ftnames.c" #include "ftobjs.c" #include "ftoutln.c" #include "ftrfork.c" +#include "ftsnames.c" #include "ftstream.c" #include "fttrigon.c" #include "ftutil.c" -#if defined( __APPLE__ ) && !defined ( DARWIN_NO_CARBON ) -#include +#if defined( FT_MACINTOSH ) && !defined ( DARWIN_NO_CARBON ) +#include "ftmac.c" #endif /* END */ diff --git a/src/freetype2/base/ftbase.h b/src/freetype2/base/ftbase.h new file mode 100644 index 0000000..9cae85d --- /dev/null +++ b/src/freetype2/base/ftbase.h @@ -0,0 +1,57 @@ +/***************************************************************************/ +/* */ +/* ftbase.h */ +/* */ +/* The FreeType private functions used in base module (specification). */ +/* */ +/* Copyright 2008 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 + + + /* 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_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 ); + + + /* 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_END_HEADER + +#endif /* __FTBASE_H__ */ + + +/* END */ diff --git a/src/freetype2/base/ftbbox.c b/src/freetype2/base/ftbbox.c index 532ab13..8136ccc 100644 --- a/src/freetype2/base/ftbbox.c +++ b/src/freetype2/base/ftbbox.c @@ -29,6 +29,7 @@ #include FT_IMAGE_H #include FT_OUTLINE_H #include FT_INTERNAL_CALC_H +#include FT_INTERNAL_OBJECTS_H typedef struct TBBox_Rec_ @@ -559,6 +560,13 @@ return 0; } +FT_DEFINE_OUTLINE_FUNCS(bbox_interface, + (FT_Outline_MoveTo_Func) BBox_Move_To, + (FT_Outline_LineTo_Func) BBox_Move_To, + (FT_Outline_ConicTo_Func)BBox_Conic_To, + (FT_Outline_CubicTo_Func)BBox_Cubic_To, + 0, 0 + ) /* documentation is in ftbbox.h */ @@ -628,18 +636,13 @@ /* the two boxes are different, now walk over the outline to */ /* get the Bezier arc extrema. */ - static const FT_Outline_Funcs bbox_interface = - { - (FT_Outline_MoveTo_Func) BBox_Move_To, - (FT_Outline_LineTo_Func) BBox_Move_To, - (FT_Outline_ConicTo_Func)BBox_Conic_To, - (FT_Outline_CubicTo_Func)BBox_Cubic_To, - 0, 0 - }; - FT_Error error; TBBox_Rec user; +#ifdef FT_CONFIG_OPTION_PIC + FT_Outline_Funcs bbox_interface; + Init_Class_bbox_interface(&bbox_interface); +#endif user.bbox = bbox; diff --git a/src/freetype2/base/ftbitmap.c b/src/freetype2/base/ftbitmap.c index 4c1cdf2..46fcce6 100644 --- a/src/freetype2/base/ftbitmap.c +++ b/src/freetype2/base/ftbitmap.c @@ -2,10 +2,9 @@ /* */ /* ftbitmap.c */ /* */ -/* FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */ -/* bitmaps into 8bpp format (body). */ +/* FreeType utility functions for bitmaps (body). */ /* */ -/* Copyright 2004, 2005, 2006, 2007 by */ +/* Copyright 2004, 2005, 2006, 2007, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -19,6 +18,7 @@ #include #include FT_BITMAP_H +#include FT_IMAGE_H #include FT_INTERNAL_OBJECTS_H @@ -228,8 +228,12 @@ if ( !bitmap || !bitmap->buffer ) return FT_Err_Invalid_Argument; - xstr = FT_PIX_ROUND( xStrength ) >> 6; - ystr = FT_PIX_ROUND( yStrength ) >> 6; + if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) || + ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) ) + return FT_Err_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; @@ -388,6 +392,8 @@ 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: { FT_Int pad; FT_Long old_size; @@ -482,6 +488,8 @@ case FT_PIXEL_MODE_GRAY: + case FT_PIXEL_MODE_LCD: + case FT_PIXEL_MODE_LCD_V: { FT_Int width = source->width; FT_Byte* s = source->buffer; @@ -603,6 +611,31 @@ } + /* 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_New( &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 ) diff --git a/src/freetype2/base/ftcalc.c b/src/freetype2/base/ftcalc.c index 63aed95..3892fab 100644 --- a/src/freetype2/base/ftcalc.c +++ b/src/freetype2/base/ftcalc.c @@ -4,7 +4,7 @@ /* */ /* Arithmetic computations (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -33,10 +33,14 @@ #include +#include FT_GLYPH_H #include FT_INTERNAL_CALC_H #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_OBJECTS_H +#ifdef FT_MULFIX_INLINED +#undef FT_MulFix +#endif /* we need to define a 64-bits data type here */ @@ -106,12 +110,12 @@ FT_EXPORT_DEF( FT_Int32 ) FT_Sqrt32( FT_Int32 x ) { - FT_ULong val, root, newroot, mask; + FT_UInt32 val, root, newroot, mask; root = 0; - mask = 0x40000000L; - val = (FT_ULong)x; + mask = (FT_UInt32)0x40000000UL; + val = (FT_UInt32)x; do { @@ -192,15 +196,33 @@ FT_MulFix( FT_Long a, FT_Long b ) { +#ifdef FT_MULFIX_ASSEMBLER + + return FT_MULFIX_ASSEMBLER( a, b ); + +#else + FT_Int s = 1; FT_Long c; - if ( a < 0 ) { a = -a; s = -1; } - if ( b < 0 ) { b = -b; s = -s; } + if ( a < 0 ) + { + a = -a; + s = -1; + } + + if ( b < 0 ) + { + b = -b; + s = -s; + } c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 ); - return ( s > 0 ) ? c : -c ; + + return ( s > 0 ) ? c : -c; + +#endif /* FT_MULFIX_ASSEMBLER */ } @@ -340,6 +362,7 @@ long s; + /* XXX: this function does not allow 64-bit arguments */ if ( a == 0 || b == c ) return a; @@ -355,12 +378,12 @@ FT_Int64 temp, temp2; - ft_multo64( a, b, &temp ); + ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp ); temp2.hi = 0; temp2.lo = (FT_UInt32)(c >> 1); FT_Add64( &temp, &temp2, &temp ); - a = ft_div64by32( temp.hi, temp.lo, c ); + a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); } else a = 0x7FFFFFFFL; @@ -394,8 +417,8 @@ FT_Int64 temp; - ft_multo64( a, b, &temp ); - a = ft_div64by32( temp.hi, temp.lo, c ); + ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp ); + a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); } else a = 0x7FFFFFFFL; @@ -412,31 +435,18 @@ FT_MulFix( FT_Long a, FT_Long b ) { - /* use inline assembly to speed up things a bit */ - -#if defined( __GNUC__ ) && defined( i386 ) - - FT_Long result; +#ifdef FT_MULFIX_ASSEMBLER + return FT_MULFIX_ASSEMBLER( a, b ); - __asm__ __volatile__ ( - "imul %%edx\n" - "movl %%edx, %%ecx\n" - "sarl $31, %%ecx\n" - "addl $0x8000, %%ecx\n" - "addl %%ecx, %%eax\n" - "adcl $0, %%edx\n" - "shrl $16, %%eax\n" - "shll $16, %%edx\n" - "addl %%edx, %%eax\n" - "mov %%eax, %0\n" - : "=r"(result) - : "a"(a), "d"(b) - : "%ecx" - ); - return result; +#elif 0 -#elif 1 + /* + * 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_ULong ua, ub; @@ -445,6 +455,24 @@ if ( a == 0 || b == 0x10000L ) return a; + /* + * 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 ) ); @@ -512,13 +540,14 @@ FT_UInt32 q; - s = a; a = FT_ABS(a); - s ^= b; b = FT_ABS(b); + /* XXX: this function does not allow 64-bit arguments */ + s = (FT_Int32)a; a = FT_ABS( a ); + s ^= (FT_Int32)b; b = FT_ABS( b ); if ( b == 0 ) { /* check for division by 0 */ - q = 0x7FFFFFFFL; + q = (FT_UInt32)0x7FFFFFFFL; } else if ( ( a >> 16 ) == 0 ) { @@ -535,7 +564,7 @@ temp2.hi = 0; temp2.lo = (FT_UInt32)( b >> 1 ); FT_Add64( &temp, &temp2, &temp ); - q = ft_div64by32( temp.hi, temp.lo, b ); + q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b ); } return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q ); @@ -666,6 +695,110 @@ #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_Err_Invalid_Argument; + + /* compute discriminant */ + delta = FT_MulFix( matrix->xx, matrix->yy ) - + FT_MulFix( matrix->xy, matrix->yx ); + + if ( !delta ) + return FT_Err_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_Int32 ) @@ -709,7 +842,7 @@ FT_Pos out_x, FT_Pos out_y ) { - FT_Int result; + FT_Long result; /* avoid overflow on 16-bit system */ /* deal with the trivial cases quickly */ @@ -758,8 +891,9 @@ FT_Int64 z1, z2; - ft_multo64( in_x, out_y, &z1 ); - ft_multo64( in_y, out_x, &z2 ); + /* XXX: this function does not allow 64-bit arguments */ + ft_multo64( (FT_Int32)in_x, (FT_Int32)out_y, &z1 ); + ft_multo64( (FT_Int32)in_y, (FT_Int32)out_x, &z2 ); if ( z1.hi > z2.hi ) result = +1; @@ -775,7 +909,8 @@ #endif } - return result; + /* XXX: only the sign of return value, +1/0/-1 must be used */ + return (FT_Int)result; } diff --git a/src/freetype2/base/ftcid.c b/src/freetype2/base/ftcid.c new file mode 100644 index 0000000..733aae1 --- /dev/null +++ b/src/freetype2/base/ftcid.c @@ -0,0 +1,117 @@ +/***************************************************************************/ +/* */ +/* ftcid.c */ +/* */ +/* FreeType API for accessing CID font information. */ +/* */ +/* Copyright 2007, 2009 by Derek Clegg, Michael Toftdal. */ +/* */ +/* 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_CID_H +#include FT_INTERNAL_OBJECTS_H +#include FT_SERVICE_CID_H + + + /* documentation is in ftcid.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Get_CID_Registry_Ordering_Supplement( FT_Face face, + const char* *registry, + const char* *ordering, + FT_Int *supplement) + { + FT_Error error; + const char* r = NULL; + const char* o = NULL; + FT_Int s = 0; + + + error = FT_Err_Invalid_Argument; + + if ( face ) + { + FT_Service_CID service; + + + FT_FACE_FIND_SERVICE( face, service, CID ); + + if ( service && service->get_ros ) + error = service->get_ros( face, &r, &o, &s ); + } + + if ( registry ) + *registry = r; + + if ( ordering ) + *ordering = o; + + if ( supplement ) + *supplement = s; + + return error; + } + + + FT_EXPORT_DEF( FT_Error ) + FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, + FT_Bool *is_cid ) + { + FT_Error error = FT_Err_Invalid_Argument; + FT_Bool ic = 0; + + + if ( face ) + { + FT_Service_CID service; + + + FT_FACE_FIND_SERVICE( face, service, CID ); + + if ( service && service->get_is_cid ) + error = service->get_is_cid( face, &ic); + } + + if ( is_cid ) + *is_cid = ic; + + return error; + } + + + FT_EXPORT_DEF( FT_Error ) + FT_Get_CID_From_Glyph_Index( FT_Face face, + FT_UInt glyph_index, + FT_UInt *cid ) + { + FT_Error error = FT_Err_Invalid_Argument; + FT_UInt c = 0; + + + if ( face ) + { + FT_Service_CID service; + + + FT_FACE_FIND_SERVICE( face, service, CID ); + + if ( service && service->get_cid_from_glyph_index ) + error = service->get_cid_from_glyph_index( face, glyph_index, &c); + } + + if ( cid ) + *cid = c; + + return error; + } + + +/* END */ diff --git a/src/freetype2/base/ftdbgmem.c b/src/freetype2/base/ftdbgmem.c index 52a5c20..677f242 100644 --- a/src/freetype2/base/ftdbgmem.c +++ b/src/freetype2/base/ftdbgmem.c @@ -4,7 +4,7 @@ /* */ /* Memory debugger (body). */ /* */ -/* Copyright 2001, 2002, 2003, 2004, 2005, 2006 by */ +/* Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -33,8 +33,7 @@ * memory, however. */ -#include -#include +#include FT_CONFIG_STANDARD_LIBRARY_H FT_BASE_DEF( const char* ) _ft_debug_file = 0; FT_BASE_DEF( long ) _ft_debug_lineno = 0; @@ -422,7 +421,7 @@ "FreeType: %ld bytes of memory leaked in %ld blocks\n", leaks, leak_count ); - printf( "FreeType: No memory leaks detected!\n" ); + printf( "FreeType: no memory leaks detected\n" ); } } @@ -990,7 +989,7 @@ #else /* !FT_DEBUG_MEMORY */ /* ANSI C doesn't like empty source files */ - const FT_Byte _debug_mem_dummy = 0; + static const FT_Byte _debug_mem_dummy = 0; #endif /* !FT_DEBUG_MEMORY */ diff --git a/src/freetype2/base/ftdebug.c b/src/freetype2/base/ftdebug.c index c55d3c8..2adbeab 100644 --- a/src/freetype2/base/ftdebug.c +++ b/src/freetype2/base/ftdebug.c @@ -4,7 +4,7 @@ /* */ /* Debugging and logging component (body). */ /* */ -/* Copyright 1996-2001, 2002, 2004 by */ +/* Copyright 1996-2001, 2002, 2004, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -46,7 +46,7 @@ #include FT_INTERNAL_DEBUG_H -#if defined( FT_DEBUG_LEVEL_ERROR ) +#ifdef FT_DEBUG_LEVEL_ERROR /* documentation is in ftdebug.h */ @@ -57,7 +57,7 @@ va_start( ap, fmt ); - vprintf( fmt, ap ); + vfprintf( stderr, fmt, ap ); va_end( ap ); } @@ -71,7 +71,7 @@ va_start( ap, fmt ); - vprintf( fmt, ap ); + vfprintf( stderr, fmt, ap ); va_end( ap ); exit( EXIT_FAILURE ); diff --git a/src/freetype2/base/ftfstype.c b/src/freetype2/base/ftfstype.c new file mode 100644 index 0000000..d0ef7b7 --- /dev/null +++ b/src/freetype2/base/ftfstype.c @@ -0,0 +1,62 @@ +/***************************************************************************/ +/* */ +/* ftfstype.c */ +/* */ +/* FreeType utility file to access FSType data (body). */ +/* */ +/* Copyright 2008, 2009 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/src/freetype2/base/ftgloadr.c b/src/freetype2/base/ftgloadr.c index ab52621..ac0010d 100644 --- a/src/freetype2/base/ftgloadr.c +++ b/src/freetype2/base/ftgloadr.c @@ -218,6 +218,9 @@ { new_max = FT_PAD_CEIL( new_max, 8 ); + if ( new_max > FT_OUTLINE_POINTS_MAX ) + return FT_Err_Array_Too_Large; + if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) || FT_RENEW_ARRAY( base->tags, old_max, new_max ) ) goto Exit; @@ -246,6 +249,10 @@ if ( new_max > old_max ) { new_max = FT_PAD_CEIL( new_max, 4 ); + + if ( new_max > FT_OUTLINE_CONTOURS_MAX ) + return FT_Err_Array_Too_Large; + if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) ) goto Exit; diff --git a/src/freetype2/base/ftglyph.c b/src/freetype2/base/ftglyph.c index 969c5db..ef61d45 100644 --- a/src/freetype2/base/ftglyph.c +++ b/src/freetype2/base/ftglyph.c @@ -4,7 +4,7 @@ /* */ /* FreeType convenience functions to handle glyphs (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2007, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -34,6 +34,7 @@ #include FT_BITMAP_H #include FT_INTERNAL_OBJECTS_H +#include "basepic.h" /*************************************************************************/ /* */ @@ -45,68 +46,6 @@ #define FT_COMPONENT trace_glyph - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** Convenience functions ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /* 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_Err_Invalid_Argument; - - /* compute discriminant */ - delta = FT_MulFix( matrix->xx, matrix->yy ) - - FT_MulFix( matrix->xy, matrix->yx ); - - if ( !delta ) - return FT_Err_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; - } - - /*************************************************************************/ /*************************************************************************/ /**** ****/ @@ -191,9 +130,7 @@ } - FT_CALLBACK_TABLE_DEF - const FT_Glyph_Class ft_bitmap_glyph_class = - { + FT_DEFINE_GLYPH(ft_bitmap_glyph_class, sizeof ( FT_BitmapGlyphRec ), FT_GLYPH_FORMAT_BITMAP, @@ -203,7 +140,7 @@ 0, /* FT_Glyph_TransformFunc */ ft_bitmap_glyph_bbox, 0 /* FT_Glyph_PrepareFunc */ - }; + ) /*************************************************************************/ @@ -317,9 +254,7 @@ } - FT_CALLBACK_TABLE_DEF - const FT_Glyph_Class ft_outline_glyph_class = - { + FT_DEFINE_GLYPH( ft_outline_glyph_class, sizeof ( FT_OutlineGlyphRec ), FT_GLYPH_FORMAT_OUTLINE, @@ -329,7 +264,7 @@ ft_outline_glyph_transform, ft_outline_glyph_bbox, ft_outline_glyph_prepare - }; + ) /*************************************************************************/ @@ -376,10 +311,16 @@ const FT_Glyph_Class* clazz; + /* check arguments */ + if ( !target ) + { + error = FT_Err_Invalid_Argument; + goto Exit; + } + *target = 0; - /* check arguments */ - if ( !target || !source || !source->clazz ) + if ( !source || !source->clazz ) { error = FT_Err_Invalid_Argument; goto Exit; @@ -429,11 +370,11 @@ /* if it is a bitmap, that's easy :-) */ if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) - clazz = &ft_bitmap_glyph_class; + clazz = FT_BITMAP_GLYPH_CLASS_GET; /* it it is an outline too */ else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) - clazz = &ft_outline_glyph_class; + clazz = FT_OUTLINE_GLYPH_CLASS_GET; else { @@ -589,7 +530,7 @@ clazz = glyph->clazz; /* when called with a bitmap glyph, do nothing and return successfully */ - if ( clazz == &ft_bitmap_glyph_class ) + if ( clazz == FT_BITMAP_GLYPH_CLASS_GET ) goto Exit; if ( !clazz || !clazz->glyph_prepare ) @@ -602,7 +543,7 @@ dummy.format = clazz->glyph_format; /* create result bitmap glyph */ - error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class, + error = ft_new_glyph( glyph->library, FT_BITMAP_GLYPH_CLASS_GET, (FT_Glyph*)(void*)&bitmap ); if ( error ) goto Exit; diff --git a/src/freetype2/base/ftinit.c b/src/freetype2/base/ftinit.c index 7af19c3..ef13503 100644 --- a/src/freetype2/base/ftinit.c +++ b/src/freetype2/base/ftinit.c @@ -4,7 +4,7 @@ /* */ /* FreeType initialization layer (body). */ /* */ -/* Copyright 1996-2001, 2002, 2005, 2007 by */ +/* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -42,6 +42,7 @@ #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_DEBUG_H #include FT_MODULE_H +#include "basepic.h" /*************************************************************************/ @@ -53,11 +54,13 @@ #undef FT_COMPONENT #define FT_COMPONENT trace_init +#ifndef FT_CONFIG_OPTION_PIC + #undef FT_USE_MODULE #ifdef __cplusplus -#define FT_USE_MODULE( x ) extern "C" const FT_Module_Class x; +#define FT_USE_MODULE( type, x ) extern "C" const type x; #else -#define FT_USE_MODULE( x ) extern const FT_Module_Class x; +#define FT_USE_MODULE( type, x ) extern const type x; #endif @@ -65,7 +68,7 @@ #undef FT_USE_MODULE -#define FT_USE_MODULE( x ) (const FT_Module_Class*)&(x), +#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), static const FT_Module_Class* const ft_default_modules[] = @@ -74,6 +77,99 @@ 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 = 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 = 0; + } + + /* 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; + FT_Module_Class* clazz; + FT_UInt i; + BasePIC* pic_container = library->pic_container.base; + + memory = library->memory; + pic_container->default_module_classes = 0; + + 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] = 0; + classes[FT_NUM_MODULE_CLASSES] = 0; + + 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 */ @@ -86,16 +182,15 @@ /* test for valid `library' delayed to FT_Add_Module() */ - cur = ft_default_modules; + cur = FT_DEFAULT_MODULES_GET; while ( *cur ) { error = FT_Add_Module( library, *cur ); /* notify errors, but don't stop */ if ( error ) - { - FT_ERROR(( "FT_Add_Default_Module: Cannot install `%s', error = 0x%x\n", - (*cur)->module_name, error )); - } + FT_TRACE0(( "FT_Add_Default_Module:" + " Cannot install `%s', error = 0x%x\n", + (*cur)->module_name, error )); cur++; } } @@ -127,13 +222,7 @@ if ( error ) FT_Done_Memory( memory ); else - { - (*alibrary)->version_major = FREETYPE_MAJOR; - (*alibrary)->version_minor = FREETYPE_MINOR; - (*alibrary)->version_patch = FREETYPE_PATCH; - FT_Add_Default_Modules( *alibrary ); - } return error; } diff --git a/src/freetype2/base/ftlcdfil.c b/src/freetype2/base/ftlcdfil.c index f40bbea..8064011 100644 --- a/src/freetype2/base/ftlcdfil.c +++ b/src/freetype2/base/ftlcdfil.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for color filtering of subpixel bitmap glyphs (body). */ /* */ -/* Copyright 2006 by */ +/* Copyright 2006, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -161,7 +161,7 @@ #ifdef USE_LEGACY - /* FIR filter used by the default and light filters */ + /* intra-pixel filter used by the legacy filter */ static void _ft_lcd_filter_legacy( FT_Bitmap* bitmap, FT_Render_Mode mode, @@ -181,7 +181,7 @@ FT_UNUSED( library ); - /* horizontal in-place FIR filter */ + /* horizontal in-place intra-pixel filter */ if ( mode == FT_RENDER_MODE_LCD && width >= 3 ) { FT_Byte* line = bitmap->buffer; @@ -266,7 +266,7 @@ #endif /* USE_LEGACY */ - FT_EXPORT( FT_Error ) + FT_EXPORT_DEF( FT_Error ) FT_Library_SetLcdFilter( FT_Library library, FT_LcdFilter filter ) { @@ -296,13 +296,13 @@ #elif defined( FT_FORCE_LIGHT_LCD_FILTER ) - memcpy( library->lcd_weights, light_filter, 5 ); + ft_memcpy( library->lcd_weights, light_filter, 5 ); library->lcd_filter_func = _ft_lcd_filter_fir; library->lcd_extra = 2; #else - memcpy( library->lcd_weights, default_filter, 5 ); + ft_memcpy( library->lcd_weights, default_filter, 5 ); library->lcd_filter_func = _ft_lcd_filter_fir; library->lcd_extra = 2; @@ -311,7 +311,7 @@ break; case FT_LCD_FILTER_LIGHT: - memcpy( library->lcd_weights, light_filter, 5 ); + ft_memcpy( library->lcd_weights, light_filter, 5 ); library->lcd_filter_func = _ft_lcd_filter_fir; library->lcd_extra = 2; break; @@ -335,7 +335,7 @@ #else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - FT_EXPORT( FT_Error ) + FT_EXPORT_DEF( FT_Error ) FT_Library_SetLcdFilter( FT_Library library, FT_LcdFilter filter ) { diff --git a/src/freetype2/base/ftmac.c b/src/freetype2/base/ftmac.c index fd6201a..63f927d 100644 --- a/src/freetype2/base/ftmac.c +++ b/src/freetype2/base/ftmac.c @@ -8,7 +8,8 @@ /* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */ /* classic platforms built by MPW. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, */ +/* 2009 by */ /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -67,7 +68,9 @@ #include #include FT_FREETYPE_H +#include FT_TRUETYPE_TAGS_H #include FT_INTERNAL_STREAM_H +#include "ftbase.h" /* This is for Mac OS X. Without redefinition, OS_INLINE */ /* expands to `static inline' which doesn't survive the */ @@ -76,20 +79,36 @@ #undef OS_INLINE #define OS_INLINE static __inline__ #endif -#include -#ifndef HFS_MAXPATHLEN -#define HFS_MAXPATHLEN 1024 + /* `configure' checks the availability of `ResourceIndex' strictly */ + /* and sets HAVE_TYPE_RESOURCE_INDEX 1 or 0 always. If it is */ + /* not set (e.g., a build without `configure'), the availability */ + /* is guessed from the SDK version. */ +#ifndef HAVE_TYPE_RESOURCE_INDEX +#if !defined( MAC_OS_X_VERSION_10_5 ) || \ + ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 ) +#define HAVE_TYPE_RESOURCE_INDEX 0 +#else +#define HAVE_TYPE_RESOURCE_INDEX 1 +#endif +#endif /* !HAVE_TYPE_RESOURCE_INDEX */ + +#if ( HAVE_TYPE_RESOURCE_INDEX == 0 ) + typedef short ResourceIndex; #endif +#include +#include +#include /* PATH_MAX */ + + /* Don't want warnings about our own use of deprecated functions. */ #define FT_DEPRECATED_ATTRIBUTE #include FT_MAC_H - /* undefine blocking-macros in ftmac.h */ -#undef FT_GetFile_From_Mac_Name( a, b, c ) -#undef FT_GetFile_From_Mac_ATS_Name( a, b, c ) -#undef FT_New_Face_From_FSSpec( a, b, c, d ) +#ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */ +#define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault +#endif /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over @@ -100,6 +119,7 @@ #endif + /* This function is deprecated because FSSpec is deprecated in Mac OS X */ FT_EXPORT_DEF( FT_Error ) FT_GetFile_From_Mac_Name( const char* fontName, FSSpec* pathSpec, @@ -115,19 +135,28 @@ /* Private function. */ /* The FSSpec type has been discouraged for a long time, */ - /* but for some reason, there is no FSRef version of */ - /* ATSFontGetFileSpecification(), so we made our own. */ - /* Apple will provide one eventually. */ + /* unfortunately an FSRef replacement API for */ + /* ATSFontGetFileSpecification() is only available in */ + /* Mac OS X 10.5 and later. */ static OSStatus FT_ATSFontGetFileReference( ATSFontRef ats_font_id, FSRef* ats_font_ref ) { -#if __LP64__ +#if defined( MAC_OS_X_VERSION_10_5 ) && \ + ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) + + OSStatus err; + + err = ATSFontGetFileReference( ats_font_id, ats_font_ref ); + + return err; +#elif __LP64__ /* No 64bit Carbon API on legacy platforms */ FT_UNUSED( ats_font_id ); FT_UNUSED( ats_font_ref ); + return fnfErr; -#else +#else /* 32bit Carbon API on legacy platforms */ OSStatus err; FSSpec spec; @@ -214,7 +243,8 @@ FSSpec* pathSpec, FT_Long* face_index ) { -#if __LP64__ +#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ + ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) FT_UNUSED( fontName ); FT_UNUSED( pathSpec ); FT_UNUSED( face_index ); @@ -239,8 +269,8 @@ static OSErr - FT_FSPathMakeRes( const UInt8* pathname, - short* res ) + FT_FSPathMakeRes( const UInt8* pathname, + ResFileRefNum* res ) { OSErr err; FSRef ref; @@ -357,7 +387,7 @@ static void parse_fond( char* fond_data, short* have_sfnt, - short* sfnt_id, + ResID* sfnt_id, Str255 lwfn_file_name, short face_index ) { @@ -374,6 +404,10 @@ assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); base_assoc = assoc; + /* the maximum faces in a FOND is 48, size of StyleTable.indexes[] */ + if ( 47 < face_index ) + return; + /* Let's do a little range checking before we get too excited here */ if ( face_index < count_faces_sfnt( fond_data ) ) { @@ -425,9 +459,10 @@ ft_memcpy(ps_name, names[0] + 1, ps_name_len); ps_name[ps_name_len] = 0; } - if ( style->indexes[0] > 1 ) + if ( style->indexes[face_index] > 1 && + style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) { - unsigned char* suffixes = names[style->indexes[0] - 1]; + unsigned char* suffixes = names[style->indexes[face_index] - 1]; for ( i = 1; i <= suffixes[0]; i++ ) @@ -463,8 +498,8 @@ UInt8* path_lwfn, size_t path_size ) { - FSRef ref, par_ref; - int dirname_len; + FSRef ref, par_ref; + size_t dirname_len; /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */ @@ -504,10 +539,10 @@ count_faces( Handle fond, const UInt8* pathname ) { - short sfnt_id; + ResID sfnt_id; short have_sfnt, have_lwfn; Str255 lwfn_file_name; - UInt8 buff[HFS_MAXPATHLEN]; + UInt8 buff[PATH_MAX]; FT_Error err; short num_faces; @@ -539,13 +574,13 @@ chunks are often not organized that way, so we glue chunks of the same type together. */ static FT_Error - read_lwfn( FT_Memory memory, - short res, - FT_Byte** pfb_data, - FT_ULong* size ) + read_lwfn( FT_Memory memory, + ResFileRefNum res, + FT_Byte** pfb_data, + FT_ULong* size ) { FT_Error error = FT_Err_Ok; - short res_id; + ResID res_id; unsigned char *buffer, *p, *size_p = NULL; FT_ULong total_size = 0; FT_ULong old_total_size = 0; @@ -563,7 +598,7 @@ for (;;) { - post_data = Get1Resource( 'POST', res_id++ ); + post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ @@ -602,7 +637,7 @@ for (;;) { - post_data = Get1Resource( 'POST', res_id++ ); + post_data = Get1Resource( TTAG_POST, res_id++ ); if ( post_data == NULL ) break; /* we are done */ @@ -654,120 +689,17 @@ } - /* Finalizer for a memory stream; gets called by FT_Done_Face(). - It frees the memory it uses. */ - static void - memory_stream_close( FT_Stream stream ) - { - FT_Memory memory = stream->memory; - - - FT_FREE( stream->base ); - - stream->size = 0; - stream->base = 0; - stream->close = 0; - } - - - /* Create a new memory stream from a buffer and a size. */ - 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; - - - if ( !library ) - return FT_Err_Invalid_Library_Handle; - - if ( !base ) - return FT_Err_Invalid_Argument; - - *astream = 0; - 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. */ - static FT_Error - open_face_from_buffer( FT_Library library, - FT_Byte* base, - FT_ULong size, - FT_Long face_index, - char* driver_name, - FT_Face* aface ) - { - FT_Open_Args args; - FT_Error error; - FT_Stream stream; - 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 ); - } - - /* At this point, 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 = 0; - - error = FT_Open_Face( library, &args, face_index, aface ); - if ( error == FT_Err_Ok ) - (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; - else - FT_Stream_Free( stream, 0 ); - - return error; - } - - - /* Create a new FT_Face from a file spec to an LWFN file. */ + /* Create a new FT_Face from a file path to an LWFN file. */ static FT_Error FT_New_Face_From_LWFN( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { - FT_Byte* pfb_data; - FT_ULong pfb_size; - FT_Error error; - short res; + FT_Byte* pfb_data; + FT_ULong pfb_size; + FT_Error error; + ResFileRefNum res; if ( noErr != FT_FSPathMakeRes( pathname, &res ) ) @@ -792,7 +724,7 @@ /* Create a new FT_Face from an SFNT resource, specified by res ID. */ static FT_Error FT_New_Face_From_SFNT( FT_Library library, - short sfnt_id, + ResID sfnt_id, FT_Long face_index, FT_Face* aface ) { @@ -801,11 +733,11 @@ size_t sfnt_size; FT_Error error = FT_Err_Ok; FT_Memory memory = library->memory; - int is_cff; + int is_cff, is_sfnt_ps; - sfnt = GetResource( 'sfnt', sfnt_id ); - if ( ResError() ) + sfnt = GetResource( TTAG_sfnt, sfnt_id ); + if ( sfnt == NULL ) return FT_Err_Invalid_Handle; sfnt_size = (FT_ULong)GetHandleSize( sfnt ); @@ -818,31 +750,56 @@ ft_memcpy( sfnt_data, *sfnt, sfnt_size ); ReleaseResource( sfnt ); - is_cff = sfnt_size > 4 && sfnt_data[0] == 'O' && - sfnt_data[1] == 'T' && - sfnt_data[2] == 'T' && - sfnt_data[3] == 'O'; + is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); + is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 ); - return open_face_from_buffer( library, - sfnt_data, - sfnt_size, - face_index, - is_cff ? "cff" : "truetype", - aface ); + if ( is_sfnt_ps ) + { + FT_Stream stream; + + + if ( FT_NEW( stream ) ) + goto Try_OpenType; + + FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size ); + if ( !open_face_PS_from_sfnt_stream( library, + stream, + face_index, + 0, NULL, + aface ) ) + { + FT_Stream_Close( stream ); + FT_FREE( stream ); + FT_FREE( sfnt_data ); + goto Exit; + } + + FT_FREE( stream ); + } + Try_OpenType: + error = open_face_from_buffer( library, + sfnt_data, + sfnt_size, + face_index, + is_cff ? "cff" : "truetype", + aface ); + Exit: + return error; } - /* Create a new FT_Face from a file spec to a suitcase file. */ + /* Create a new FT_Face from a file path to a suitcase file. */ static FT_Error FT_New_Face_From_Suitcase( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { - FT_Error error = FT_Err_Cannot_Open_Resource; - short res_ref, res_index; - Handle fond; - short num_faces_in_res, num_faces_in_fond; + FT_Error error = FT_Err_Cannot_Open_Resource; + ResFileRefNum res_ref; + ResourceIndex res_index; + Handle fond; + short num_faces_in_res, num_faces_in_fond; if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) ) @@ -855,7 +812,7 @@ num_faces_in_res = 0; for ( res_index = 1; ; ++res_index ) { - fond = Get1IndResource( 'FOND', res_index ); + fond = Get1IndResource( TTAG_FOND, res_index ); if ( ResError() ) break; @@ -869,7 +826,7 @@ } CloseResFile( res_ref ); - if ( FT_Err_Ok == error && NULL != aface ) + if ( FT_Err_Ok == error && NULL != aface && NULL != *aface ) (*aface)->num_faces = num_faces_in_res; return error; } @@ -883,25 +840,25 @@ FT_Long face_index, FT_Face* aface ) { - short sfnt_id, have_sfnt, have_lwfn = 0; - short fond_id; + short have_sfnt, have_lwfn = 0; + ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; - UInt8 path_lwfn[HFS_MAXPATHLEN]; + UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; GetResInfo( fond, &fond_id, &fond_type, fond_name ); - if ( ResError() != noErr || fond_type != 'FOND' ) + if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_Err_Invalid_File_Format; parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); if ( lwfn_file_name[0] ) { - short res; + ResFileRefNum res; res = HomeResFile( fond ); @@ -909,7 +866,7 @@ goto found_no_lwfn_file; { - UInt8 path_fond[HFS_MAXPATHLEN]; + UInt8 path_fond[PATH_MAX]; FSRef ref; @@ -961,7 +918,7 @@ /* LWFN is a (very) specific file format, check for it explicitly */ file_type = get_file_type_from_path( pathname ); - if ( file_type == 'LWFN' ) + if ( file_type == TTAG_LWFN ) return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); /* Otherwise the file type doesn't matter (there are more than */ @@ -1029,6 +986,8 @@ /* FT_New_Face_From_FSRef is identical to FT_New_Face except it */ /* accepts an FSRef instead of a path. */ /* */ + /* This function is deprecated because Carbon data types (FSRef) */ + /* are not cross-platform, and thus not suitable for the freetype API. */ FT_EXPORT_DEF( FT_Error ) FT_New_Face_From_FSRef( FT_Library library, const FSRef* ref, @@ -1038,7 +997,7 @@ FT_Error error; FT_Open_Args args; OSErr err; - UInt8 pathname[HFS_MAXPATHLEN]; + UInt8 pathname[PATH_MAX]; if ( !ref ) @@ -1068,13 +1027,15 @@ /* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */ /* accepts an FSSpec instead of a path. */ /* */ + /* This function is deprecated because FSSpec is deprecated in Mac OS X */ FT_EXPORT_DEF( FT_Error ) FT_New_Face_From_FSSpec( FT_Library library, const FSSpec* spec, FT_Long face_index, FT_Face* aface ) { -#if __LP64__ +#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ + ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) FT_UNUSED( library ); FT_UNUSED( spec ); FT_UNUSED( face_index ); diff --git a/src/freetype2/base/ftmm.c b/src/freetype2/base/ftmm.c index 586d5e8..0307729 100644 --- a/src/freetype2/base/ftmm.c +++ b/src/freetype2/base/ftmm.c @@ -4,7 +4,7 @@ /* */ /* Multiple Master font support (body). */ /* */ -/* Copyright 1996-2001, 2003, 2004 by */ +/* Copyright 1996-2001, 2003, 2004, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -52,7 +52,7 @@ *aservice, MULTI_MASTERS ); - if ( aservice ) + if ( *aservice ) error = FT_Err_Ok; } diff --git a/src/freetype2/base/ftnames.c b/src/freetype2/base/ftnames.c deleted file mode 100644 index 7fde5c4..0000000 --- a/src/freetype2/base/ftnames.c +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftnames.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-2001, 2002 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 ftnames.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 ftnames.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 == NULL ) - { - 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/src/freetype2/base/ftobjs.c b/src/freetype2/base/ftobjs.c index fa08094..421540c 100644 --- a/src/freetype2/base/ftobjs.c +++ b/src/freetype2/base/ftobjs.c @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -26,6 +26,7 @@ #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_OUTLINE_H @@ -36,8 +37,11 @@ #include FT_SERVICE_KERNING_H #include FT_SERVICE_TRUETYPE_ENGINE_H +#include "ftbase.h" + #define GRID_FIT_METRICS + FT_BASE_DEF( FT_Pointer ) ft_service_list_lookup( FT_ServiceDesc service_descriptors, const char* service_id ) @@ -128,13 +132,14 @@ FT_Stream stream; + *astream = 0; + if ( !library ) return FT_Err_Invalid_Library_Handle; if ( !args ) return FT_Err_Invalid_Argument; - *astream = 0; memory = library->memory; if ( FT_NEW( stream ) ) @@ -196,6 +201,12 @@ } + /*************************************************************************/ + /* */ + /* 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 @@ -244,7 +255,7 @@ FT_BASE_DEF( void ) ft_glyphslot_free_bitmap( FT_GlyphSlot slot ) { - if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) + if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) { FT_Memory memory = FT_FACE_MEMORY( slot->face ); @@ -337,14 +348,18 @@ /* free bitmap buffer if needed */ ft_glyphslot_free_bitmap( slot ); - /* free glyph loader */ - if ( FT_DRIVER_USES_OUTLINES( driver ) ) + /* slot->internal might be NULL in out-of-memory situations */ + if ( slot->internal ) { - FT_GlyphLoader_Done( slot->internal->loader ); - slot->internal->loader = 0; - } + /* free glyph loader */ + if ( FT_DRIVER_USES_OUTLINES( driver ) ) + { + FT_GlyphLoader_Done( slot->internal->loader ); + slot->internal->loader = 0; + } - FT_FREE( slot->internal ); + FT_FREE( slot->internal ); + } } @@ -542,7 +557,7 @@ FT_Driver driver; FT_GlyphSlot slot; FT_Library library; - FT_Bool autohint = 0; + FT_Bool autohint = FALSE; FT_Module hinter; @@ -577,31 +592,33 @@ * 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. + * - 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, autohint if FT_LOAD_FORCE_AUTOHINT is set - * or if we don't have a native font hinter. + * - 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. * - * - Exception: The font requires the unpatented - * bytecode interpreter to load properly. + * - Exception: The font is `tricky' and requires the native hinter to + * load properly. */ - autohint = 0; - if ( hinter && - ( load_flags & FT_LOAD_NO_HINTING ) == 0 && - ( load_flags & FT_LOAD_NO_AUTOHINT ) == 0 && - FT_DRIVER_IS_SCALABLE( driver ) && - FT_DRIVER_USES_OUTLINES( driver ) && - face->internal->transform_matrix.yy > 0 && - face->internal->transform_matrix.yx == 0 ) - { - if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) != 0 || - !FT_DRIVER_HAS_HINTER( driver ) ) - autohint = 1; + 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 ) && + ( ( 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 ); @@ -609,7 +626,7 @@ if ( mode == FT_RENDER_MODE_LIGHT || face->internal->ignore_unpatented_hinter ) - autohint = 1; + autohint = TRUE; } } @@ -634,12 +651,24 @@ goto Load_Ok; } - /* load auto-hinted outline */ - hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface; + { + FT_Face_Internal internal = face->internal; + FT_Int transform_flags = internal->transform_flags; + - error = hinting->load_glyph( (FT_AutoHinter)hinter, - slot, face->size, - glyph_index, load_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_Service)hinter->clazz->module_interface; + + error = hinting->load_glyph( (FT_AutoHinter)hinter, + slot, face->size, + glyph_index, load_flags ); + + internal->transform_flags = transform_flags; + } } else { @@ -680,7 +709,7 @@ /* compute the linear advance in 16.16 pixels */ if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 && - ( face->face_flags & FT_FACE_FLAG_SCALABLE ) ) + ( FT_IS_SCALABLE( face ) ) ) { FT_Size_Metrics* metrics = &face->size->metrics; @@ -883,14 +912,13 @@ /* 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). */ + /* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */ /* */ static FT_Error find_unicode_charmap( FT_Face face ) { FT_CharMap* first; FT_CharMap* cur; - FT_CharMap* unicmap = NULL; /* some UCS-2 map, if we found it */ /* caller should have already checked that `face' is valid */ @@ -935,36 +963,75 @@ { if ( cur[0]->encoding == FT_ENCODING_UNICODE ) { - unicmap = cur; /* record we found a Unicode charmap */ - - /* XXX If some new encodings to represent UCS-4 are added, */ - /* they should be added here. */ + /* 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]->encoding_id == TT_MS_ID_UCS_4 ) || ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE && - cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) ) - - /* Hurray! We found a UCS-4 charmap. We can stop the scan! */ + cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) ) { face->charmap = cur[0]; - return 0; + return FT_Err_Ok; } } } - /* We do not have any UCS-4 charmap. Sigh. */ - /* Let's see if we have some other kind of Unicode charmap, though. */ - if ( unicmap != NULL ) + /* 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; ) { - face->charmap = unicmap[0]; - return 0; + if ( cur[0]->encoding == FT_ENCODING_UNICODE ) + { + face->charmap = cur[0]; + return FT_Err_Ok; + } } - /* Chou blanc! */ return FT_Err_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; + } + + /*************************************************************************/ /* */ /* */ @@ -1013,15 +1080,17 @@ for ( i = 0; i < num_params && !face->internal->incremental_interface; i++ ) if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL ) - face->internal->incremental_interface = params[i].data; + face->internal->incremental_interface = + (FT_Incremental_Interface)params[i].data; } #endif - error = clazz->init_face( stream, - face, - (FT_Int)face_index, - num_params, - params ); + if ( clazz->init_face ) + error = clazz->init_face( stream, + face, + (FT_Int)face_index, + num_params, + params ); if ( error ) goto Fail; @@ -1044,7 +1113,8 @@ if ( error ) { destroy_charmaps( face, memory ); - clazz->done_face( face ); + if ( clazz->done_face ) + clazz->done_face( face ); FT_FREE( internal ); FT_FREE( face ); *aface = 0; @@ -1057,7 +1127,7 @@ /* there's a Mac-specific extended implementation of FT_New_Face() */ /* in src/base/ftmac.c */ -#ifndef FT_MACINTOSH +#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON ) /* documentation is in freetype.h */ @@ -1076,11 +1146,12 @@ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; + args.stream = NULL; return FT_Open_Face( library, &args, face_index, aface ); } -#endif /* !FT_MACINTOSH */ +#endif /* defined( FT_MACINTOSH ) && !defined( DARWIN_NO_CARBON ) */ /* documentation is in freetype.h */ @@ -1102,12 +1173,13 @@ args.flags = FT_OPEN_MEMORY; args.memory_base = file_base; args.memory_size = file_size; + args.stream = NULL; return FT_Open_Face( library, &args, face_index, aface ); } -#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS ) +#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. */ @@ -1136,9 +1208,9 @@ /* 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 */ + /* 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 ) { @@ -1154,7 +1226,7 @@ /* Create a new memory stream from a buffer and a size. */ - /* from ftmac.c */ + /* From ftmac.c. */ static FT_Error new_memory_stream( FT_Library library, FT_Byte* base, @@ -1191,7 +1263,7 @@ /* Create a new FT_Face given a buffer and a driver name. */ /* from ftmac.c */ - static FT_Error + FT_LOCAL_DEF( FT_Error ) open_face_from_buffer( FT_Library library, FT_Byte* base, FT_ULong size, @@ -1224,20 +1296,172 @@ args.driver = FT_Get_Module( library, driver_name ); } +#ifdef FT_MACINTOSH + /* At this point, 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 = 0; +#endif + error = FT_Open_Face( library, &args, face_index, aface ); if ( error == FT_Err_Ok ) (*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 unconditially, 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_Err_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_Err_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_Long pos; + FT_Bool is_sfnt_cid; + FT_Byte* sfnt_ps; + + FT_UNUSED( num_params ); + FT_UNUSED( params ); + + + pos = FT_Stream_Pos( stream ); + + error = ft_lookup_PS_in_sfnt_stream( stream, + face_index, + &offset, + &length, + &is_sfnt_cid ); + if ( error ) + goto Exit; + + if ( FT_Stream_Seek( stream, pos + offset ) ) + goto Exit; + + if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) ) + goto Exit; + + error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length ); + if ( error ) + goto Exit; + + error = open_face_from_buffer( library, + sfnt_ps, + length, + face_index < 0 ? face_index : 0, + is_sfnt_cid ? "cid" : "type1", + aface ); + Exit: + { + FT_Error error1; + + + if ( error == FT_Err_Unknown_File_Format ) + { + error1 = FT_Stream_Seek( stream, pos ); + if ( error1 ) + return error1; + } + + return error; + } + } + + +#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON ) + /* 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. */ @@ -1392,17 +1616,25 @@ if ( rlen == -1 ) return FT_Err_Cannot_Open_Resource; + 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() */ + if ( FT_Stream_Seek( stream, flag_offset + 4 ) ) + goto Exit; + if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) ) return error; error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen ); if ( error ) goto Exit; - is_cff = rlen > 4 && sfnt_data[0] == 'O' && - sfnt_data[1] == 'T' && - sfnt_data[2] == 'T' && - sfnt_data[3] == 'O'; - + is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); error = open_face_from_buffer( library, sfnt_data, rlen, @@ -1441,7 +1673,7 @@ error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, - FT_MAKE_TAG( 'P', 'O', 'S', 'T' ), + TTAG_POST, &data_offsets, &count ); if ( !error ) { @@ -1456,7 +1688,7 @@ error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, - FT_MAKE_TAG( 's', 'f', 'n', 't' ), + TTAG_sfnt, &data_offsets, &count ); if ( !error ) { @@ -1488,6 +1720,9 @@ FT_Long dlen, offset; + if ( NULL == stream ) + return FT_Err_Invalid_Stream_Operation; + error = FT_Stream_Seek( stream, 0 ); if ( error ) goto Exit; @@ -1544,7 +1779,7 @@ FT_Error errors[FT_RACCESS_N_RULES]; FT_Open_Args args2; - FT_Stream stream2; + FT_Stream stream2 = 0; FT_Raccess_Guess( library, stream, @@ -1599,7 +1834,7 @@ } - /* Check for some macintosh formats. */ + /* 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) */ @@ -1642,6 +1877,7 @@ face_index, aface, args ); return error; } +#endif #endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */ @@ -1657,10 +1893,12 @@ FT_Error error; FT_Driver driver; FT_Memory memory; - FT_Stream stream; + FT_Stream stream = 0; FT_Face face = 0; FT_ListNode node = 0; FT_Bool external_stream; + FT_Module* cur; + FT_Module* limit; /* test for valid `library' delayed to */ @@ -1675,7 +1913,7 @@ /* create input stream */ error = FT_Stream_New( library, args, &stream ); if ( error ) - goto Exit; + goto Fail3; memory = library->memory; @@ -1712,8 +1950,8 @@ else { /* check each font driver for an appropriate format */ - FT_Module* cur = library->modules; - FT_Module* limit = cur + library->num_modules; + cur = library->modules; + limit = cur + library->num_modules; for ( ; cur < limit; cur++ ) @@ -1738,6 +1976,28 @@ if ( !error ) goto Success; +#ifdef FT_CONFIG_OPTION_MAC_FONTS + if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 && + FT_ERROR_BASE( error ) == FT_Err_Table_Missing ) + { + /* TrueType but essential tables are missing */ + if ( FT_Stream_Seek( stream, 0 ) ) + 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_ERROR_BASE( error ) != FT_Err_Unknown_File_Format ) goto Fail3; } @@ -1747,7 +2007,8 @@ /* 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_ERROR_BASE( error ) != FT_Err_Unknown_File_Format && + if ( FT_ERROR_BASE( error ) != FT_Err_Cannot_Open_Stream && + FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format && FT_ERROR_BASE( error ) != FT_Err_Invalid_Stream_Operation ) goto Fail2; @@ -2143,12 +2404,24 @@ 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 = metrics->height * 12 / 10; + advance = height * 12 / 10; - metrics->vertBearingX = -( metrics->width / 2 ); - metrics->vertBearingY = ( advance - metrics->height ) / 2; + metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2; + metrics->vertBearingY = ( advance - height ) / 2; metrics->vertAdvance = advance; } @@ -2212,8 +2485,8 @@ } else { - metrics->x_scale = 1L << 22; - metrics->y_scale = 1L << 22; + metrics->x_scale = 1L << 16; + metrics->y_scale = 1L << 16; metrics->ascender = bsize->y_ppem; metrics->descender = 0; metrics->height = bsize->height << 6; @@ -2324,8 +2597,8 @@ else { FT_ZERO( metrics ); - metrics->x_scale = 1L << 22; - metrics->y_scale = 1L << 22; + metrics->x_scale = 1L << 16; + metrics->y_scale = 1L << 16; } } @@ -2631,6 +2904,8 @@ cur = face->charmaps; if ( !cur ) return FT_Err_Invalid_CharMap_Handle; + if ( FT_Get_CMap_Format( charmap ) == 14 ) + return FT_Err_Invalid_Argument; limit = cur + face->num_charmaps; @@ -2791,7 +3066,12 @@ FT_CMap cmap = FT_CMAP( face->charmap ); - result = cmap->clazz->char_index( cmap, charcode ); + 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 ); } return result; } @@ -2849,6 +3129,186 @@ } + /* 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 != NULL ) + { + 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 != NULL ) + { + 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 != NULL ) + { + 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 != NULL ) + { + 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 != NULL ) + { + 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 ) @@ -2891,7 +3351,7 @@ ((FT_Byte*)buffer)[0] = 0; if ( face && - glyph_index <= (FT_UInt)face->num_glyphs && + (FT_Long)glyph_index <= face->num_glyphs && FT_HAS_GLYPH_NAMES( face ) ) { FT_Service_GlyphDict service; @@ -2991,6 +3451,7 @@ FT_ULong *length ) { FT_Service_SFNT_Table service; + FT_ULong offset; if ( !face || !FT_IS_SFNT( face ) ) @@ -3000,7 +3461,7 @@ if ( service == NULL ) return FT_Err_Unimplemented_Feature; - return service->table_info( face, table_index, tag, length ); + return service->table_info( face, table_index, tag, &offset, length ); } @@ -3061,11 +3522,11 @@ if ( size == NULL ) - return FT_Err_Bad_Argument; + return FT_Err_Invalid_Argument; face = size->face; if ( face == NULL || face->driver == NULL ) - return FT_Err_Bad_Argument; + return FT_Err_Invalid_Argument; /* we don't need anything more complex than that; all size objects */ /* are already listed by the face */ @@ -3325,7 +3786,7 @@ while ( renderer ) { error = renderer->render( renderer, slot, render_mode, NULL ); - if ( !error || + if ( !error || FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph ) break; @@ -3723,11 +4184,23 @@ library->memory = memory; +#ifdef FT_CONFIG_OPTION_PIC + /* initialize position independent code containers */ + error = ft_pic_container_init( library ); + if ( error ) + goto Fail; +#endif + /* allocate the render pool */ library->raster_pool_size = FT_RENDER_POOL_SIZE; - if ( FT_RENDER_POOL_SIZE > 0 ) - if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) ) - goto Fail; +#if FT_RENDER_POOL_SIZE > 0 + if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) ) + goto Fail; +#endif + + library->version_major = FREETYPE_MAJOR; + library->version_minor = FREETYPE_MINOR; + library->version_patch = FREETYPE_PATCH; /* That's ok now */ *alibrary = library; @@ -3735,6 +4208,9 @@ return FT_Err_Ok; Fail: +#ifdef FT_CONFIG_OPTION_PIC + ft_pic_container_destroy( library ); +#endif FT_FREE( library ); return error; } @@ -3812,7 +4288,11 @@ 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" )); + } } } @@ -3847,6 +4327,11 @@ FT_FREE( library->raster_pool ); library->raster_pool_size = 0; +#ifdef FT_CONFIG_OPTION_PIC + /* Destroy pic container contents */ + ft_pic_container_destroy( library ); +#endif + FT_FREE( library ); return FT_Err_Ok; } diff --git a/src/freetype2/base/ftotval.c b/src/freetype2/base/ftotval.c index b6de6db..20ed686 100644 --- a/src/freetype2/base/ftotval.c +++ b/src/freetype2/base/ftotval.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for validating OpenType tables (body). */ /* */ -/* Copyright 2004, 2006 by */ +/* Copyright 2004, 2006, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -18,6 +18,7 @@ #include #include FT_INTERNAL_OBJECTS_H #include FT_SERVICE_OPENTYPE_VALIDATE_H +#include FT_OPENTYPE_VALIDATE_H /* documentation is in ftotval.h */ diff --git a/src/freetype2/base/ftoutln.c b/src/freetype2/base/ftoutln.c index 6926f3a..49ef82e 100644 --- a/src/freetype2/base/ftoutln.c +++ b/src/freetype2/base/ftoutln.c @@ -4,7 +4,7 @@ /* */ /* FreeType outline management (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -26,6 +26,7 @@ #include #include FT_OUTLINE_H #include FT_INTERNAL_OBJECTS_H +#include FT_INTERNAL_DEBUG_H #include FT_TRIGONOMETRY_H @@ -83,21 +84,25 @@ 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_last = outline->points[last]; + v_start = outline->points[first]; + v_start.x = SCALED( v_start.x ); + v_start.y = SCALED( v_start.y ); - v_start.x = SCALED( v_start.x ); v_start.y = SCALED( v_start.y ); - v_last.x = SCALED( v_last.x ); v_last.y = SCALED( v_last.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; + tags = outline->tags + first; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ @@ -128,6 +133,8 @@ 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; @@ -148,6 +155,8 @@ 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; @@ -174,6 +183,10 @@ 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; @@ -186,6 +199,10 @@ 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; @@ -194,6 +211,10 @@ 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; @@ -209,8 +230,11 @@ 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 ); + 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 ) { @@ -220,12 +244,22 @@ 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; } @@ -233,6 +267,8 @@ } /* 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: @@ -242,9 +278,11 @@ first = last + 1; } - return 0; + FT_TRACE5(( "FT_Outline_Decompose: Done\n", n )); + return FT_Err_Ok; Exit: + FT_TRACE5(( "FT_Outline_Decompose: Error %d\n", error )); return error; Invalid_Outline: @@ -474,12 +512,14 @@ FT_Pos yOffset ) { FT_UShort n; - FT_Vector* vec = outline->points; + FT_Vector* vec; if ( !outline ) return; + vec = outline->points; + for ( n = 0; n < outline->n_points; n++ ) { vec->x += xOffset; @@ -556,7 +596,7 @@ FT_Raster_Params* params ) { FT_Error error; - FT_Bool update = 0; + FT_Bool update = FALSE; FT_Renderer renderer; FT_ListNode node; @@ -587,7 +627,7 @@ /* format */ renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, &node ); - update = 1; + update = TRUE; } /* if we changed the current renderer for the glyph image format */ @@ -626,13 +666,13 @@ } - /* documentation is in ftoutln.h */ + /* documentation is in freetype.h */ FT_EXPORT_DEF( void ) FT_Vector_Transform( FT_Vector* vector, const FT_Matrix* matrix ) { - FT_Pos xz, yz; + FT_Pos xz, yz; if ( !vector || !matrix ) @@ -1005,7 +1045,7 @@ } } - if ( xmin == 32768 ) + if ( xmin == 32768L ) return FT_ORIENTATION_TRUETYPE; ray_y[0] = ( xmin_ymin * 3 + xmin_ymax ) >> 2; diff --git a/src/freetype2/base/ftpatent.c b/src/freetype2/base/ftpatent.c index d63f191..236d9a6 100644 --- a/src/freetype2/base/ftpatent.c +++ b/src/freetype2/base/ftpatent.c @@ -5,7 +5,7 @@ /* FreeType API for checking patented TrueType bytecode instructions */ /* (body). */ /* */ -/* Copyright 2007 by David Turner. */ +/* Copyright 2007, 2008 by David Turner. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -103,6 +103,7 @@ } Exit: + FT_UNUSED( error ); FT_FRAME_EXIT(); return result; } @@ -113,7 +114,7 @@ FT_ULong tag ) { FT_Stream stream = face->stream; - FT_Error error; + FT_Error error = FT_Err_Ok; FT_Service_SFNT_Table service; FT_Bool result = FALSE; @@ -122,15 +123,18 @@ if ( service ) { - FT_ULong offset, size; + FT_UInt i = 0; + FT_ULong tag_i = 0, offset_i, length_i; + for ( i = 0; !error && tag_i != tag ; i++ ) + error = service->table_info( face, i, + &tag_i, &offset_i, &length_i ); - error = service->table_info( face, tag, &offset, &size ); if ( error || - FT_STREAM_SEEK( offset ) ) + FT_STREAM_SEEK( offset_i ) ) goto Exit; - result = _tt_check_patents_in_range( stream, size ); + result = _tt_check_patents_in_range( stream, length_i ); } Exit: @@ -260,7 +264,7 @@ FT_Face_SetUnpatentedHinting( FT_Face face, FT_Bool value ) { - FT_Bool result = 0; + FT_Bool result = FALSE; #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \ diff --git a/src/freetype2/base/ftpfr.c b/src/freetype2/base/ftpfr.c index 9e930dd..f9592bb 100644 --- a/src/freetype2/base/ftpfr.c +++ b/src/freetype2/base/ftpfr.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for accessing PFR-specific data (body). */ /* */ -/* Copyright 2002, 2003, 2004 by */ +/* Copyright 2002, 2003, 2004, 2008 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -46,6 +46,9 @@ FT_Service_PfrMetrics service; + if ( !face ) + return FT_Err_Invalid_Argument; + service = ft_pfr_check( face ); if ( service ) { @@ -55,14 +58,17 @@ ametrics_x_scale, ametrics_y_scale ); } - else if ( face ) + else { FT_Fixed x_scale, y_scale; /* this is not a PFR font */ - *aoutline_resolution = face->units_per_EM; - *ametrics_resolution = face->units_per_EM; + if ( aoutline_resolution ) + *aoutline_resolution = face->units_per_EM; + + if ( ametrics_resolution ) + *ametrics_resolution = face->units_per_EM; x_scale = y_scale = 0x10000L; if ( face->size ) @@ -70,11 +76,15 @@ x_scale = face->size->metrics.x_scale; y_scale = face->size->metrics.y_scale; } - *ametrics_x_scale = x_scale; - *ametrics_y_scale = y_scale; + + if ( ametrics_x_scale ) + *ametrics_x_scale = x_scale; + + if ( ametrics_y_scale ) + *ametrics_y_scale = y_scale; + + error = FT_Err_Unknown_File_Format; } - else - error = FT_Err_Invalid_Argument; return error; } @@ -92,14 +102,15 @@ FT_Service_PfrMetrics service; + if ( !face ) + return FT_Err_Invalid_Argument; + service = ft_pfr_check( face ); if ( service ) error = service->get_kerning( face, left, right, avector ); - else if ( face ) + else error = FT_Get_Kerning( face, left, right, FT_KERNING_UNSCALED, avector ); - else - error = FT_Err_Invalid_Argument; return error; } diff --git a/src/freetype2/base/ftpic.c b/src/freetype2/base/ftpic.c new file mode 100644 index 0000000..d5271a9 --- /dev/null +++ b/src/freetype2/base/ftpic.c @@ -0,0 +1,54 @@ +/***************************************************************************/ +/* */ +/* ftpic.c */ +/* */ +/* The FreeType position independent code services (body). */ +/* */ +/* Copyright 2009 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_Err_Ok; + + 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/src/freetype2/base/ftrfork.c b/src/freetype2/base/ftrfork.c index a4f726d..133c2de 100644 --- a/src/freetype2/base/ftrfork.c +++ b/src/freetype2/base/ftrfork.c @@ -4,7 +4,7 @@ /* */ /* Embedded resource forks accessor (body). */ /* */ -/* Copyright 2004, 2005, 2006 by */ +/* Copyright 2004, 2005, 2006, 2007, 2008, 2009 by */ /* Masatake YAMATO and Redhat K.K. */ /* */ /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ @@ -132,6 +132,19 @@ } + 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, @@ -141,12 +154,13 @@ 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; + 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; + FT_RFork_Ref *ref; error = FT_Stream_Seek( stream, map_offset ); @@ -179,28 +193,43 @@ if ( error ) return error; - if ( FT_NEW_ARRAY( offsets_internal, *count ) ) + if ( FT_NEW_ARRAY( ref, *count ) ) return error; for ( j = 0; j < *count; ++j ) { - (void)FT_STREAM_SKIP( 2 ); /* resource id */ - (void)FT_STREAM_SKIP( 2 ); /* rsource name */ - + if ( FT_READ_USHORT( ref[j].res_id ) ) + goto Exit; + if ( FT_STREAM_SKIP( 2 ) ) /* resource name */ + goto Exit; if ( FT_READ_LONG( temp ) ) - { - FT_FREE( offsets_internal ); - return error; - } - - offsets_internal[j] = rdata_pos + ( temp & 0xFFFFFFL ); + goto Exit; + if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ + goto Exit; - (void)FT_STREAM_SKIP( 4 ); /* mbz */ + ref[j].offset = temp & 0xFFFFFFL; } + ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), + ( int(*)(const void*, const void*) ) + ft_raccess_sort_ref_by_id ); + + 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; - return FT_Err_Ok; + Exit: + FT_FREE( ref ); + return error; } } @@ -227,7 +256,7 @@ typedef FT_Error (*raccess_guess_func)( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ); @@ -235,56 +264,63 @@ static FT_Error raccess_guess_apple_double( FT_Library library, FT_Stream stream, - char * base_file_name, + 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 *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 *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 *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 *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 *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 *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 *base_file_name, char **result_file_name, FT_Long *result_offset ); @@ -298,7 +334,7 @@ static FT_Error raccess_guess_apple_generic( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, FT_Int32 magic, FT_Long *result_offset ); @@ -329,6 +365,7 @@ raccess_guess_apple_double, raccess_guess_apple_single, raccess_guess_darwin_ufs_export, + raccess_guess_darwin_newvfs, raccess_guess_darwin_hfsplus, raccess_guess_vfat, raccess_guess_linux_cap, @@ -339,7 +376,11 @@ for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) { new_names[i] = NULL; - errors[i] = FT_Stream_Seek( stream, 0 ); + if ( NULL != stream ) + errors[i] = FT_Stream_Seek( stream, 0 ); + else + errors[i] = FT_Err_Ok; + if ( errors[i] ) continue ; @@ -354,14 +395,20 @@ static FT_Error raccess_guess_apple_double( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { - FT_Int32 magic = ( 0x00 << 24 | 0x05 << 16 | 0x16 << 8 | 0x07 ); + FT_Int32 magic = ( 0x00 << 24 ) | + ( 0x05 << 16 ) | + ( 0x16 << 8 ) | + 0x07; *result_file_name = NULL; + if ( NULL == stream ) + return FT_Err_Cannot_Open_Stream; + return raccess_guess_apple_generic( library, stream, base_file_name, magic, result_offset ); } @@ -370,14 +417,20 @@ static FT_Error raccess_guess_apple_single( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { - FT_Int32 magic = (0x00 << 24 | 0x05 << 16 | 0x16 << 8 | 0x00); + FT_Int32 magic = ( 0x00 << 24 ) | + ( 0x05 << 16 ) | + ( 0x16 << 8 ) | + 0x00; *result_file_name = NULL; + if ( NULL == stream ) + return FT_Err_Cannot_Open_Stream; + return raccess_guess_apple_generic( library, stream, base_file_name, magic, result_offset ); } @@ -386,7 +439,7 @@ static FT_Error raccess_guess_darwin_ufs_export( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -416,7 +469,7 @@ static FT_Error raccess_guess_darwin_hfsplus( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -433,7 +486,7 @@ memory = library->memory; - if ( base_file_len > FT_INT_MAX ) + if ( base_file_len + 6 > FT_INT_MAX ) return FT_Err_Array_Too_Large; if ( FT_ALLOC( newpath, base_file_len + 6 ) ) @@ -449,10 +502,46 @@ } + 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; + FT_Memory memory; + FT_Long base_file_len = ft_strlen( base_file_name ); + + FT_UNUSED( stream ); + + + memory = library->memory; + + if ( base_file_len + 18 > FT_INT_MAX ) + return FT_Err_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 *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -479,7 +568,7 @@ static FT_Error raccess_guess_linux_cap( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -505,7 +594,7 @@ static FT_Error raccess_guess_linux_double( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -536,7 +625,7 @@ static FT_Error raccess_guess_linux_netatalk( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, char **result_file_name, FT_Long *result_offset ) { @@ -568,7 +657,7 @@ static FT_Error raccess_guess_apple_generic( FT_Library library, FT_Stream stream, - char * base_file_name, + char *base_file_name, FT_Int32 magic, FT_Long *result_offset ) { @@ -620,8 +709,12 @@ return FT_Err_Ok; } else - FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */ + { + error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */ + if ( error ) + return error; } + } return FT_Err_Unknown_File_Format; } @@ -629,7 +722,7 @@ static FT_Error raccess_guess_linux_double_from_file_name( FT_Library library, - char * file_name, + char *file_name, FT_Long *result_offset ) { FT_Open_Args args2; @@ -659,9 +752,9 @@ const char *insertion ) { char* new_name; - char* tmp; + const char* tmp; const char* slash; - unsigned new_length; + size_t new_length; FT_Error error = FT_Err_Ok; FT_UNUSED( error ); @@ -701,7 +794,7 @@ FT_BASE_DEF( void ) FT_Raccess_Guess( FT_Library library, FT_Stream stream, - char* base_name, + char *base_name, char **new_names, FT_Long *offsets, FT_Error *errors ) diff --git a/src/freetype2/base/ftsnames.c b/src/freetype2/base/ftsnames.c new file mode 100644 index 0000000..3447888 --- /dev/null +++ b/src/freetype2/base/ftsnames.c @@ -0,0 +1,94 @@ +/***************************************************************************/ +/* */ +/* 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-2001, 2002, 2009 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 == NULL ) + { + 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/src/freetype2/base/ftstream.c b/src/freetype2/base/ftstream.c index a067a1f..b638599 100644 --- a/src/freetype2/base/ftstream.c +++ b/src/freetype2/base/ftstream.c @@ -4,7 +4,7 @@ /* */ /* I/O stream support (body). */ /* */ -/* Copyright 2000-2001, 2002, 2004, 2005, 2006 by */ +/* Copyright 2000-2001, 2002, 2004, 2005, 2006, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -60,13 +60,12 @@ FT_Error error = FT_Err_Ok; - stream->pos = pos; - 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", + FT_ERROR(( "FT_Stream_Seek:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); error = FT_Err_Invalid_Stream_Operation; @@ -75,12 +74,16 @@ /* 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", + FT_ERROR(( "FT_Stream_Seek:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); error = FT_Err_Invalid_Stream_Operation; } + if ( !error ) + stream->pos = pos; + return error; } @@ -89,6 +92,9 @@ FT_Stream_Skip( FT_Stream stream, FT_Long distance ) { + if ( distance < 0 ) + return FT_Err_Invalid_Stream_Operation; + return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); } @@ -121,7 +127,8 @@ if ( pos >= stream->size ) { - FT_ERROR(( "FT_Stream_ReadAt: invalid i/o; pos = 0x%lx, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_ReadAt:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); return FT_Err_Invalid_Stream_Operation; @@ -142,8 +149,8 @@ if ( read_bytes < count ) { - FT_ERROR(( "FT_Stream_ReadAt:" )); - FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n", + FT_ERROR(( "FT_Stream_ReadAt:" + " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); error = FT_Err_Invalid_Stream_Operation; @@ -208,7 +215,7 @@ FT_Stream_ReleaseFrame( FT_Stream stream, FT_Byte** pbytes ) { - if ( stream->read ) + if ( stream && stream->read ) { FT_Memory memory = stream->memory; @@ -253,8 +260,8 @@ stream->base, count ); if ( read_bytes < count ) { - FT_ERROR(( "FT_Stream_EnterFrame:" )); - FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n", + FT_ERROR(( "FT_Stream_EnterFrame:" + " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); FT_FREE( stream->base ); @@ -270,8 +277,8 @@ if ( stream->pos >= stream->size || stream->pos + count > stream->size ) { - FT_ERROR(( "FT_Stream_EnterFrame:" )); - FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_EnterFrame:" + " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", stream->pos, count, stream->size )); error = FT_Err_Invalid_Stream_Operation; @@ -456,7 +463,8 @@ Fail: *error = FT_Err_Invalid_Stream_Operation; - FT_ERROR(( "FT_Stream_ReadChar: invalid i/o; pos = 0x%lx, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_ReadChar:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; @@ -502,8 +510,8 @@ Fail: *error = FT_Err_Invalid_Stream_Operation; - FT_ERROR(( "FT_Stream_ReadShort:" )); - FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_ReadShort:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; @@ -549,8 +557,8 @@ Fail: *error = FT_Err_Invalid_Stream_Operation; - FT_ERROR(( "FT_Stream_ReadShortLE:" )); - FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_ReadShortLE:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; @@ -596,8 +604,8 @@ Fail: *error = FT_Err_Invalid_Stream_Operation; - FT_ERROR(( "FT_Stream_ReadOffset:" )); - FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + FT_ERROR(( "FT_Stream_ReadOffset:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); return 0; @@ -642,9 +650,10 @@ return result; Fail: - FT_ERROR(( "FT_Stream_ReadLong: invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR(( "FT_Stream_ReadLong:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size )); return 0; } @@ -688,10 +697,10 @@ return result; Fail: - FT_ERROR(( "FT_Stream_ReadLongLE:" )); - FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n", - stream->pos, stream->size )); *error = FT_Err_Invalid_Stream_Operation; + FT_ERROR(( "FT_Stream_ReadLongLE:" + " invalid i/o; pos = 0x%lx, size = 0x%lx\n", + stream->pos, stream->size )); return 0; } @@ -704,12 +713,13 @@ { FT_Error error; FT_Bool frame_accessed = 0; - FT_Byte* cursor = stream->cursor; - + FT_Byte* cursor; if ( !fields || !stream ) return FT_Err_Invalid_Argument; + cursor = stream->cursor; + error = FT_Err_Ok; do { diff --git a/src/freetype2/base/ftstroke.c b/src/freetype2/base/ftstroke.c index 8f7e045..0978b0e 100644 --- a/src/freetype2/base/ftstroke.c +++ b/src/freetype2/base/ftstroke.c @@ -4,7 +4,7 @@ /* */ /* FreeType path stroker (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006 by */ +/* Copyright 2002, 2003, 2004, 2005, 2006, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -230,7 +230,7 @@ /***************************************************************************/ /***************************************************************************/ - typedef enum + typedef enum FT_StrokeTags_ { FT_STROKE_TAG_ON = 1, /* on-curve point */ FT_STROKE_TAG_CUBIC = 2, /* cubic off-point */ @@ -261,7 +261,7 @@ { FT_UInt old_max = border->max_points; FT_UInt new_max = border->num_points + new_points; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; if ( new_max > old_max ) @@ -279,6 +279,7 @@ border->max_points = cur_max; } + Exit: return error; } @@ -346,7 +347,7 @@ } border->start = -1; - border->movable = 0; + border->movable = FALSE; } @@ -355,7 +356,7 @@ FT_Vector* to, FT_Bool movable ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_ASSERT( border->start >= 0 ); @@ -410,7 +411,7 @@ border->num_points += 2; } - border->movable = 0; + border->movable = FALSE; return error; } @@ -443,7 +444,7 @@ border->num_points += 3; } - border->movable = 0; + border->movable = FALSE; return error; } @@ -461,7 +462,7 @@ FT_Angle total, angle, step, rotate, next, theta; FT_Vector a, b, a2, b2; FT_Fixed length; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; /* compute start point */ @@ -527,12 +528,12 @@ { /* close current open path if any ? */ if ( border->start >= 0 ) - ft_stroke_border_close( border, 0 ); + ft_stroke_border_close( border, FALSE ); border->start = border->num_points; - border->movable = 0; + border->movable = FALSE; - return ft_stroke_border_lineto( border, to, 0 ); + return ft_stroke_border_lineto( border, to, FALSE ); } @@ -547,7 +548,7 @@ border->num_points = 0; border->max_points = 0; border->start = -1; - border->valid = 0; + border->valid = FALSE; } @@ -556,7 +557,7 @@ { border->num_points = 0; border->start = -1; - border->valid = 0; + border->valid = FALSE; } @@ -572,7 +573,7 @@ border->num_points = 0; border->max_points = 0; border->start = -1; - border->valid = 0; + border->valid = FALSE; } @@ -581,7 +582,7 @@ FT_UInt *anum_points, FT_UInt *anum_contours ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_UInt num_points = 0; FT_UInt num_contours = 0; @@ -605,9 +606,6 @@ if ( tags[0] & FT_STROKE_TAG_END ) { - if ( in_contour == 0 ) - goto Fail; - in_contour = 0; num_contours++; } @@ -616,7 +614,7 @@ if ( in_contour != 0 ) goto Fail; - border->valid = 1; + border->valid = TRUE; Exit: *anum_points = num_points; @@ -708,7 +706,7 @@ FT_Bool valid; FT_StrokeBorderRec borders[2]; - FT_Memory memory; + FT_Library library; } FT_StrokerRec; @@ -731,7 +729,7 @@ if ( !FT_NEW( stroker ) ) { - stroker->memory = memory; + stroker->library = library; ft_stroke_border_init( &stroker->borders[0], memory ); ft_stroke_border_init( &stroker->borders[1], memory ); @@ -779,13 +777,13 @@ { if ( stroker ) { - FT_Memory memory = stroker->memory; + FT_Memory memory = stroker->library->memory; ft_stroke_border_done( &stroker->borders[0] ); ft_stroke_border_done( &stroker->borders[1] ); - stroker->memory = NULL; + stroker->library = NULL; FT_FREE( stroker ); } } @@ -798,7 +796,7 @@ { FT_Angle total, rotate; FT_Fixed radius = stroker->radius; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_StrokeBorder border = stroker->borders + side; @@ -813,7 +811,7 @@ radius, stroker->angle_in + rotate, total ); - border->movable = 0; + border->movable = FALSE; return error; } @@ -824,7 +822,7 @@ FT_Angle angle, FT_Int side ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; if ( stroker->line_cap == FT_STROKER_LINECAP_ROUND ) @@ -849,7 +847,7 @@ delta.x += stroker->center.x + delta2.x; delta.y += stroker->center.y + delta2.y; - error = ft_stroke_border_lineto( border, &delta, 0 ); + error = ft_stroke_border_lineto( border, &delta, FALSE ); if ( error ) goto Exit; @@ -859,7 +857,32 @@ delta.x += delta2.x + stroker->center.x; delta.y += delta2.y + stroker->center.y; - error = ft_stroke_border_lineto( border, &delta, 0 ); + error = ft_stroke_border_lineto( border, &delta, FALSE ); + } + else if ( stroker->line_cap == FT_STROKER_LINECAP_BUTT ) + { + /* add a butt ending */ + FT_Vector delta; + FT_Angle rotate = FT_SIDE_TO_ROTATE( side ); + FT_Fixed radius = stroker->radius; + FT_StrokeBorder border = stroker->borders + side; + + + FT_Vector_From_Polar( &delta, radius, angle + rotate ); + + delta.x += stroker->center.x; + delta.y += stroker->center.y; + + error = ft_stroke_border_lineto( border, &delta, FALSE ); + if ( error ) + goto Exit; + + FT_Vector_From_Polar( &delta, radius, angle - rotate ); + + delta.x += stroker->center.x; + delta.y += stroker->center.y; + + error = ft_stroke_border_lineto( border, &delta, FALSE ); } Exit: @@ -876,7 +899,7 @@ FT_Angle phi, theta, rotate; FT_Fixed length, thcos, sigma; FT_Vector delta; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; rotate = FT_SIDE_TO_ROTATE( side ); @@ -900,7 +923,7 @@ stroker->angle_out + rotate ); delta.x += stroker->center.x; delta.y += stroker->center.y; - border->movable = 0; + border->movable = FALSE; } else { @@ -911,7 +934,7 @@ delta.y += stroker->center.y; } - error = ft_stroke_border_lineto( border, &delta, 0 ); + error = ft_stroke_border_lineto( border, &delta, FALSE ); return error; } @@ -928,9 +951,7 @@ if ( stroker->line_join == FT_STROKER_LINEJOIN_ROUND ) - { error = ft_stroker_arcto( stroker, side ); - } else { /* this is a mitered or beveled corner */ @@ -943,7 +964,7 @@ rotate = FT_SIDE_TO_ROTATE( side ); miter = FT_BOOL( stroker->line_join == FT_STROKER_LINEJOIN_MITER ); - theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ); + theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ); if ( theta == FT_ANGLE_PI ) { theta = rotate; @@ -959,7 +980,7 @@ sigma = FT_MulFix( stroker->miter_limit, thcos ); if ( sigma >= 0x10000L ) - miter = 0; + miter = FALSE; if ( miter ) /* this is a miter (broken angle) */ { @@ -983,7 +1004,7 @@ delta.x += middle.x; delta.y += middle.y; - error = ft_stroke_border_lineto( border, &delta, 0 ); + error = ft_stroke_border_lineto( border, &delta, FALSE ); if ( error ) goto Exit; @@ -992,7 +1013,7 @@ delta.x += middle.x; delta.y += middle.y; - error = ft_stroke_border_lineto( border, &delta, 0 ); + error = ft_stroke_border_lineto( border, &delta, FALSE ); if ( error ) goto Exit; @@ -1001,7 +1022,7 @@ delta.x += stroker->center.x; delta.y += stroker->center.y; - error = ft_stroke_border_lineto( border, &delta, 1 ); + error = ft_stroke_border_lineto( border, &delta, TRUE ); } else /* this is a bevel (intersection) */ @@ -1016,8 +1037,9 @@ delta.x += stroker->center.x; delta.y += stroker->center.y; - error = ft_stroke_border_lineto( border, &delta, 0 ); - if (error) goto Exit; + error = ft_stroke_border_lineto( border, &delta, FALSE ); + if ( error ) + goto Exit; /* now add end point */ FT_Vector_From_Polar( &delta, stroker->radius, @@ -1025,7 +1047,7 @@ delta.x += stroker->center.x; delta.y += stroker->center.y; - error = ft_stroke_border_lineto( border, &delta, 1 ); + error = ft_stroke_border_lineto( border, &delta, TRUE ); } } @@ -1037,7 +1059,7 @@ static FT_Error ft_stroker_process_corner( FT_Stroker stroker ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_Angle turn; FT_Int inside_side; @@ -1069,7 +1091,7 @@ /* add two points to the left and right borders corresponding to the */ - /* start of the subpath.. */ + /* start of the subpath */ static FT_Error ft_stroker_subpath_start( FT_Stroker stroker, FT_Angle start_angle ) @@ -1099,7 +1121,7 @@ /* save angle for last cap */ stroker->subpath_angle = start_angle; - stroker->first_point = 0; + stroker->first_point = FALSE; Exit: return error; @@ -1112,7 +1134,7 @@ FT_Stroker_LineTo( FT_Stroker stroker, FT_Vector* to ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_StrokeBorder border; FT_Vector delta; FT_Angle angle; @@ -1143,7 +1165,7 @@ goto Exit; } - /* now add a line segment to both the "inside" and "outside" paths */ + /* now add a line segment to both the `inside' and `outside' paths */ for ( border = stroker->borders, side = 1; side >= 0; side--, border++ ) { @@ -1153,7 +1175,7 @@ point.x = to->x + delta.x; point.y = to->y + delta.y; - error = ft_stroke_border_lineto( border, &point, 1 ); + error = ft_stroke_border_lineto( border, &point, TRUE ); if ( error ) goto Exit; @@ -1176,12 +1198,12 @@ FT_Vector* control, FT_Vector* to ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_Vector bez_stack[34]; FT_Vector* arc; FT_Vector* limit = bez_stack + 30; FT_Angle start_angle; - FT_Bool first_arc = 1; + FT_Bool first_arc = TRUE; arc = bez_stack; @@ -1206,7 +1228,7 @@ if ( first_arc ) { - first_arc = 0; + first_arc = FALSE; start_angle = angle_in; @@ -1275,12 +1297,12 @@ FT_Vector* control2, FT_Vector* to ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_Vector bez_stack[37]; FT_Vector* arc; FT_Vector* limit = bez_stack + 32; FT_Angle start_angle; - FT_Bool first_arc = 1; + FT_Bool first_arc = TRUE; arc = bez_stack; @@ -1308,7 +1330,7 @@ if ( first_arc ) { - first_arc = 0; + first_arc = FALSE; /* process corner if necessary */ start_angle = angle_in; @@ -1386,15 +1408,16 @@ { /* We cannot process the first point, because there is not enough */ /* information regarding its corner/cap. The latter will be processed */ - /* in the "end_subpath" routine. */ + /* in the `FT_Stroker_EndSubPath' routine. */ /* */ - stroker->first_point = 1; - stroker->center = *to; - stroker->subpath_open = open; + stroker->first_point = TRUE; + stroker->center = *to; + stroker->subpath_open = open; - /* record the subpath start point index for each border */ + /* record the subpath start point for each border */ stroker->subpath_start = *to; - return 0; + + return FT_Err_Ok; } @@ -1402,10 +1425,10 @@ ft_stroker_add_reverse_left( FT_Stroker stroker, FT_Bool open ) { - FT_StrokeBorder right = stroker->borders + 0; - FT_StrokeBorder left = stroker->borders + 1; + FT_StrokeBorder right = stroker->borders + 0; + FT_StrokeBorder left = stroker->borders + 1; FT_Int new_points; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; FT_ASSERT( left->start >= 0 ); @@ -1452,8 +1475,8 @@ left->num_points = left->start; right->num_points += new_points; - right->movable = 0; - left->movable = 0; + right->movable = FALSE; + left->movable = FALSE; } Exit: @@ -1467,7 +1490,8 @@ FT_EXPORT_DEF( FT_Error ) FT_Stroker_EndSubPath( FT_Stroker stroker ) { - FT_Error error = 0; + FT_Error error = FT_Err_Ok; + if ( stroker->subpath_open ) { @@ -1480,8 +1504,8 @@ if ( error ) goto Exit; - /* add reversed points from "left" to "right" */ - error = ft_stroker_add_reverse_left( stroker, 1 ); + /* add reversed points from `left' to `right' */ + error = ft_stroker_add_reverse_left( stroker, TRUE ); if ( error ) goto Exit; @@ -1494,7 +1518,7 @@ /* Now end the right subpath accordingly. The left one is */ /* rewind and doesn't need further processing. */ - ft_stroke_border_close( right, 0 ); + ft_stroke_border_close( right, FALSE ); } else { @@ -1536,8 +1560,8 @@ } /* then end our two subpaths */ - ft_stroke_border_close( stroker->borders + 0, 1 ); - ft_stroke_border_close( stroker->borders + 1, 0 ); + ft_stroke_border_close( stroker->borders + 0, TRUE ); + ft_stroke_border_close( stroker->borders + 1, FALSE ); } Exit: @@ -1692,7 +1716,7 @@ v_control = v_start; point = outline->points + first; - tags = outline->tags + first; + tags = outline->tags + first; tag = FT_CURVE_TAG( tags[0] ); /* A contour cannot start with a cubic control point! */ @@ -1836,7 +1860,7 @@ first = last + 1; } - return 0; + return FT_Err_Ok; Exit: return error; @@ -1845,8 +1869,13 @@ return FT_Err_Invalid_Outline; } - +/* declare an extern to access ft_outline_glyph_class global allocated + in ftglyph.c, and use the FT_OUTLINE_GLYPH_CLASS_GET macro to access + it when FT_CONFIG_OPTION_PIC is defined */ +#ifndef FT_CONFIG_OPTION_PIC extern const FT_Glyph_Class ft_outline_glyph_class; +#endif +#include "basepic.h" /* documentation is in ftstroke.h */ @@ -1858,13 +1887,14 @@ { FT_Error error = FT_Err_Invalid_Argument; FT_Glyph glyph = NULL; - + FT_Library library = stroker->library; + FT_UNUSED(library); if ( pglyph == NULL ) goto Exit; glyph = *pglyph; - if ( glyph == NULL || glyph->clazz != &ft_outline_glyph_class ) + if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET ) goto Exit; { @@ -1884,7 +1914,7 @@ FT_UInt num_points, num_contours; - error = FT_Stroker_ParseOutline( stroker, outline, 0 ); + error = FT_Stroker_ParseOutline( stroker, outline, FALSE ); if ( error ) goto Fail; @@ -1931,13 +1961,14 @@ { FT_Error error = FT_Err_Invalid_Argument; FT_Glyph glyph = NULL; - + FT_Library library = stroker->library; + FT_UNUSED(library); if ( pglyph == NULL ) goto Exit; glyph = *pglyph; - if ( glyph == NULL || glyph->clazz != &ft_outline_glyph_class ) + if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET ) goto Exit; { @@ -1967,7 +1998,7 @@ border = FT_STROKER_BORDER_LEFT; } - error = FT_Stroker_ParseOutline( stroker, outline, 0 ); + error = FT_Stroker_ParseOutline( stroker, outline, FALSE ); if ( error ) goto Fail; diff --git a/src/freetype2/base/ftsynth.c b/src/freetype2/base/ftsynth.c index ff88ce9..326d8e7 100644 --- a/src/freetype2/base/ftsynth.c +++ b/src/freetype2/base/ftsynth.c @@ -18,11 +18,21 @@ #include #include FT_SYNTHESIS_H +#include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_OBJECTS_H #include FT_OUTLINE_H #include FT_BITMAP_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_synth + /*************************************************************************/ /*************************************************************************/ /**** ****/ @@ -68,36 +78,13 @@ /*************************************************************************/ - 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_New( &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 ftsynth.h */ FT_EXPORT_DEF( void ) FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) { FT_Library library = slot->library; - FT_Face face = FT_SLOT_FACE( slot ); + FT_Face face = slot->face; FT_Error error; FT_Pos xstr, ystr; @@ -123,11 +110,24 @@ } else if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) { - xstr = FT_PIX_FLOOR( xstr ); + /* round to full pixels */ + xstr &= ~63; if ( xstr == 0 ) xstr = 1 << 6; - ystr = FT_PIX_FLOOR( ystr ); - + ystr &= ~63; + + /* + * XXX: overflow check for 16-bit system, for compatibility + * with FT_GlyphSlot_Embolden() since freetype-2.1.10. + * unfortunately, this function return no informations + * about the cause of error. + */ + if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN ) + { + FT_TRACE1(( "FT_GlyphSlot_Embolden:" )); + FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr )); + return; + } error = FT_GlyphSlot_Own_Bitmap( slot ); if ( error ) return; @@ -151,8 +151,9 @@ slot->metrics.vertBearingY += ystr; slot->metrics.vertAdvance += ystr; + /* XXX: 16-bit overflow case must be excluded before here */ if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) - slot->bitmap_top += ystr >> 6; + slot->bitmap_top += (FT_Int)( ystr >> 6 ); } diff --git a/src/freetype2/base/ftsystem.c b/src/freetype2/base/ftsystem.c index f61a3ed..4d06d6d 100644 --- a/src/freetype2/base/ftsystem.c +++ b/src/freetype2/base/ftsystem.c @@ -4,7 +4,7 @@ /* */ /* ANSI-specific FreeType low-level system interface (body). */ /* */ -/* Copyright 1996-2001, 2002, 2006 by */ +/* Copyright 1996-2001, 2002, 2006, 2008, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -205,7 +205,8 @@ file = STREAM_FILE( stream ); - ft_fseek( file, offset, SEEK_SET ); + if ( stream->pos != offset ) + ft_fseek( file, offset, SEEK_SET ); return (unsigned long)ft_fread( buffer, 1, count, file ); } @@ -226,8 +227,8 @@ file = ft_fopen( filepathname, "rb" ); if ( !file ) { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); + FT_ERROR(( "FT_Stream_Open:" + " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } @@ -294,7 +295,7 @@ #ifdef FT_DEBUG_MEMORY ft_mem_debug_done( memory ); #endif - memory->free( memory, memory ); + ft_sfree( memory ); } diff --git a/src/freetype2/base/fttrigon.c b/src/freetype2/base/fttrigon.c index 9f51394..fdf433a 100644 --- a/src/freetype2/base/fttrigon.c +++ b/src/freetype2/base/fttrigon.c @@ -72,10 +72,10 @@ val = ( val >= 0 ) ? val : -val; v1 = (FT_UInt32)val >> 16; - v2 = (FT_UInt32)val & 0xFFFFL; + v2 = (FT_UInt32)(val & 0xFFFFL); - k1 = FT_TRIG_SCALE >> 16; /* constant */ - k2 = FT_TRIG_SCALE & 0xFFFFL; /* constant */ + k1 = (FT_UInt32)FT_TRIG_SCALE >> 16; /* constant */ + k2 = (FT_UInt32)(FT_TRIG_SCALE & 0xFFFFL); /* constant */ hi = k1 * v1; lo1 = k1 * v2 + k2 * v1; /* can't overflow */ @@ -86,7 +86,7 @@ hi += lo1 >> 16; if ( lo1 < lo3 ) - hi += 0x10000UL; + hi += (FT_UInt32)0x10000UL; val = (FT_Fixed)hi; @@ -433,7 +433,7 @@ if ( shift > 0 ) { - FT_Int32 half = 1L << ( shift - 1 ); + FT_Int32 half = (FT_Int32)1L << ( shift - 1 ); vec->x = ( v.x + half + FT_SIGN_LONG( v.x ) ) >> shift; -- cgit v1.2.3