From 0a9d06e2b5cf75c3d6ba958026bfdf4745f576d6 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 18 Mar 2009 22:20:25 -0700 Subject: auto import //branches/master/...@140412 --- src/base/ftadvanc.c | 122 +++++++++++++-------- src/base/ftbase.c | 5 +- src/base/ftbase.h | 57 ++++++++++ src/base/ftbitmap.c | 35 +++++- src/base/ftcalc.c | 152 ++++++++++++++++++++++++-- src/base/ftdbgmem.c | 7 +- src/base/ftdebug.c | 2 +- src/base/ftglyph.c | 64 +---------- src/base/ftinit.c | 6 +- src/base/ftlcdfil.c | 12 +- src/base/ftobjs.c | 308 ++++++++++++++++++++++++++++++++++++++-------------- src/base/ftoutln.c | 62 +++++++++-- src/base/ftpatent.c | 4 +- src/base/ftrfork.c | 12 +- src/base/ftstream.c | 5 +- src/base/ftstroke.c | 132 +++++++++++----------- src/base/ftsynth.c | 30 +---- src/base/ftsystem.c | 4 +- 18 files changed, 691 insertions(+), 328 deletions(-) create mode 100644 src/base/ftbase.h (limited to 'src/base') diff --git a/src/base/ftadvanc.c b/src/base/ftadvanc.c index 626a0cf..504f9d2 100644 --- a/src/base/ftadvanc.c +++ b/src/base/ftadvanc.c @@ -1,71 +1,97 @@ +/***************************************************************************/ +/* */ +/* 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_UInt flags ) + FT_Int32 flags ) { FT_Fixed scale; FT_UInt nn; - if ( (flags & FT_LOAD_NO_SCALE) ) + + 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.x_scale; - else + if ( flags & FT_LOAD_VERTICAL_LAYOUT ) scale = face->size->metrics.y_scale; + else + scale = face->size->metrics.x_scale; - /* this must be the same computation than to get linearHori/VertAdvance - * (see FT_Load_Glyph() implementation in src/base/ftobjs.c */ - for (nn = 0; nn < count; nn++) + /* 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 0; + return FT_Err_Ok; } -/* at the moment, we can perform fast advance retrieval only in - the following cases: + /* 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 ) - - unscaled load - - unhinted load - - light-hinted load - */ -#define LOAD_ADVANCE_FAST_CHECK(flags) \ - (((flags & (FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING)) != 0) || \ - FT_LOAD_TARGET_MODE(flags) == FT_RENDER_MODE_LIGHT) - FT_EXPORT_DEF(FT_Error) + /* documentation is in ftadvanc.h */ + + FT_EXPORT_DEF( FT_Error ) FT_Get_Advance( FT_Face face, FT_UInt gindex, - FT_UInt flags, + 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 ) + if ( gindex >= (FT_UInt)face->num_glyphs ) return FT_Err_Invalid_Glyph_Index; func = face->driver->clazz->get_advances; - if (func != NULL && LOAD_ADVANCE_FAST_CHECK(flags)) + if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) { FT_Error error; + error = func( face, gindex, 1, flags, padvance ); - if (!error) + if ( !error ) return _ft_face_scale_advances( face, padvance, 1, flags ); - if (error != FT_Err_Unimplemented_Feature) + if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) return error; } @@ -73,55 +99,65 @@ } - FT_EXPORT_DEF(FT_Error) + /* documentation is in ftadvanc.h */ + + FT_EXPORT_DEF( FT_Error ) FT_Get_Advances( FT_Face face, FT_UInt start, FT_UInt count, - FT_UInt flags, + FT_Int32 flags, FT_Fixed *padvances ) { FT_Face_GetAdvancesFunc func; FT_UInt num, end, nn; - FT_Error error = 0; + FT_Error error = FT_Err_Ok; + if ( !face ) return FT_Err_Invalid_Face_Handle; - num = (FT_UInt) face->num_glyphs; + num = (FT_UInt)face->num_glyphs; end = start + count; - if (start >= num || end < start || end > num) + if ( start >= num || end < start || end > num ) return FT_Err_Invalid_Glyph_Index; - if (count == 0) - return FT_Err_Ok; + if ( count == 0 ) + return FT_Err_Ok; func = face->driver->clazz->get_advances; - if (func != NULL && LOAD_ADVANCE_FAST_CHECK(flags)) + if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) { error = func( face, start, count, flags, padvances ); - if (!error) goto Exit; + if ( !error ) + goto Exit; - if (error != FT_Err_Unimplemented_Feature) + if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) return error; } - error = 0; + error = FT_Err_Ok; - if ((flags & FT_ADVANCE_FLAG_FAST_ONLY) != 0) + if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) return FT_Err_Unimplemented_Feature; flags |= FT_LOAD_ADVANCE_ONLY; - for (nn = 0; nn < count; nn++) + for ( nn = 0; nn < count; nn++ ) { - error = FT_Load_Glyph( face, start+nn, flags ); - if (error) break; + error = FT_Load_Glyph( face, start + nn, flags ); + if ( error ) + break; - padvances[nn] = (flags & FT_LOAD_VERTICAL_LAYOUT) - ? face->glyph->advance.x - : face->glyph->advance.y; + padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) + ? face->glyph->advance.y + : face->glyph->advance.x; } - if (error) return error; + + if ( error ) + return error; Exit: return _ft_face_scale_advances( face, padvances, count, flags ); } + + +/* END */ diff --git a/src/base/ftbase.c b/src/base/ftbase.c index 300e02d..d1fe6e6 100644 --- a/src/base/ftbase.c +++ b/src/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 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -20,6 +20,7 @@ #define FT_MAKE_OPTION_SINGLE_OBJECT +#include "ftadvanc.c" #include "ftcalc.c" #include "ftdbgmem.c" #include "ftgloadr.c" @@ -31,7 +32,7 @@ #include "fttrigon.c" #include "ftutil.c" -#if defined( __APPLE__ ) && !defined ( DARWIN_NO_CARBON ) +#if defined( FT_MACINTOSH ) && !defined ( DARWIN_NO_CARBON ) #include "ftmac.c" #endif diff --git a/src/base/ftbase.h b/src/base/ftbase.h new file mode 100644 index 0000000..9cae85d --- /dev/null +++ b/src/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/base/ftbitmap.c b/src/base/ftbitmap.c index 4c1cdf2..8810cfa 100644 --- a/src/base/ftbitmap.c +++ b/src/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 @@ -388,6 +388,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 +484,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 +607,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/base/ftcalc.c b/src/base/ftcalc.c index 9193c32..04295a6 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -33,12 +33,13 @@ #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 +#ifdef FT_MULFIX_INLINED +#undef FT_MulFix #endif /* we need to define a 64-bits data type here */ @@ -196,18 +197,32 @@ FT_Long b ) { #ifdef FT_MULFIX_ASSEMBLER - return FT_MULFIX_ASSEMBLER(a,b); + + 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 ; -#endif + + return ( s > 0 ) ? c : -c; + +#endif /* FT_MULFIX_ASSEMBLER */ } @@ -420,8 +435,18 @@ FT_Long b ) { #ifdef FT_MULFIX_ASSEMBLER - return FT_MULFIX_ASSEMBLER(a,b); -#else + + return FT_MULFIX_ASSEMBLER( a, b ); + +#elif 0 + + /* + * This code is nonportable. See comment below. + * + * However, on a platform where right-shift of a signed quantity fills + * the leftmost bits by copying the sign bit, it might be faster. + */ + FT_Long sa, sb; FT_ULong ua, ub; @@ -429,6 +454,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 ) ); @@ -452,7 +495,37 @@ ua = (FT_ULong)(( ua ^ sa ) - sa); return (FT_Long)ua; -#endif + +#else /* 0 */ + + FT_Long s; + FT_ULong ua, ub; + + + if ( a == 0 || b == 0x10000L ) + return a; + + s = a; a = FT_ABS( a ); + s ^= b; b = FT_ABS( b ); + + ua = (FT_ULong)a; + ub = (FT_ULong)b; + + if ( ua <= 2048 && ub <= 1048576L ) + ua = ( ua * ub + 0x8000UL ) >> 16; + else + { + FT_ULong al = ua & 0xFFFFUL; + + + ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) + + ( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 ); + } + + return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua ); + +#endif /* 0 */ + } @@ -466,8 +539,8 @@ FT_UInt32 q; - s = a; a = FT_ABS(a); - s ^= b; b = FT_ABS(b); + s = a; a = FT_ABS( a ); + s ^= b; b = FT_ABS( b ); if ( b == 0 ) { @@ -618,6 +691,61 @@ #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 ) diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c index 52a5c20..8b2a330 100644 --- a/src/base/ftdbgmem.c +++ b/src/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; @@ -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/base/ftdebug.c b/src/base/ftdebug.c index 356c8c2..2adbeab 100644 --- a/src/base/ftdebug.c +++ b/src/base/ftdebug.c @@ -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 */ diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index db0e79f..4130cb1 100644 --- a/src/base/ftglyph.c +++ b/src/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, */ @@ -45,68 +45,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; - } - - /*************************************************************************/ /*************************************************************************/ /**** ****/ diff --git a/src/base/ftinit.c b/src/base/ftinit.c index 7af19c3..dac30b0 100644 --- a/src/base/ftinit.c +++ b/src/base/ftinit.c @@ -55,9 +55,9 @@ #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 +65,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[] = diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c index 5f1fa0b..8064011 100644 --- a/src/base/ftlcdfil.c +++ b/src/base/ftlcdfil.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for color filtering of subpixel bitmap glyphs (body). */ /* */ -/* Copyright 2006, 2008 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, */ @@ -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/base/ftobjs.c b/src/base/ftobjs.c index f167b2f..89892df 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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,13 +37,11 @@ #include FT_SERVICE_KERNING_H #include FT_SERVICE_TRUETYPE_ENGINE_H -#ifdef ANDROID_FONT_HACK -#include -#include -#endif +#include "ftbase.h" #define GRID_FIT_METRICS + FT_BASE_DEF( FT_Pointer ) ft_service_list_lookup( FT_ServiceDesc service_descriptors, const char* service_id ) @@ -133,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 ) ) @@ -201,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 @@ -249,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 ); @@ -547,7 +553,7 @@ FT_Driver driver; FT_GlyphSlot slot; FT_Library library; - FT_Bool autohint = 0; + FT_Bool autohint = FALSE; FT_Module hinter; @@ -577,38 +583,6 @@ load_flags &= ~FT_LOAD_RENDER; } -#ifdef ANDROID_FONT_HACK - else - { - static int hack_mode; - - if (hack_mode == 0) { - do { - int fd = open("/data/misc/font-hack", O_RDONLY); - char buff[2]; - int ret; - - hack_mode = 1; /*means light node by default */ - if (fd < 0) - break; - - ret = read(fd, buff, 1); - if (ret == 1) - hack_mode = 1 + (buff[0] - '0'); - - close(fd); - } while (0); - } - - switch (hack_mode) - { - case 1: - load_flags &= 0xfff0ffff; - load_flags |= FT_LOAD_TARGET_LIGHT; - break; - } - } -#endif /* * Determine whether we need to auto-hint or not. @@ -623,22 +597,22 @@ * * - 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 ( 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.yy > 0 && + face->internal->transform_matrix.yx == 0 ) { - if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) != 0 || - !FT_DRIVER_HAS_HINTER( driver ) ) - autohint = 1; + 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 ); @@ -646,7 +620,7 @@ if ( mode == FT_RENDER_MODE_LIGHT || face->internal->ignore_unpatented_hinter ) - autohint = 1; + autohint = TRUE; } } @@ -729,7 +703,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; @@ -1147,7 +1121,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 */ @@ -1170,7 +1144,7 @@ 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 */ @@ -1197,7 +1171,7 @@ } -#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. */ @@ -1226,9 +1200,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 ) { @@ -1244,7 +1218,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, @@ -1281,7 +1255,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, @@ -1314,20 +1288,161 @@ 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_Stream_Seek( stream, pos ); + 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. */ @@ -1482,17 +1597,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, @@ -1531,7 +1654,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 ) { @@ -1546,7 +1669,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 ) { @@ -1637,7 +1760,7 @@ FT_Error errors[FT_RACCESS_N_RULES]; FT_Open_Args args2; - FT_Stream stream2; + FT_Stream stream2 = 0; FT_Raccess_Guess( library, stream, @@ -1692,7 +1815,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) */ @@ -1735,6 +1858,7 @@ face_index, aface, args ); return error; } +#endif #endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */ @@ -1750,7 +1874,7 @@ 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; @@ -1833,6 +1957,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; } @@ -2308,8 +2454,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; @@ -2420,8 +2566,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; } } @@ -3302,11 +3448,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 */ @@ -4054,7 +4200,11 @@ faces = &FT_DRIVER(module)->faces_list; while ( faces->head ) + { FT_Done_Face( FT_FACE( faces->head->data ) ); + if ( faces->head ) + FT_ERROR(( "FT_Done_Library: failed to free some faces\n" )); + } } } diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c index 2bae857..49ef82e 100644 --- a/src/base/ftoutln.c +++ b/src/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: @@ -558,7 +596,7 @@ FT_Raster_Params* params ) { FT_Error error; - FT_Bool update = 0; + FT_Bool update = FALSE; FT_Renderer renderer; FT_ListNode node; @@ -589,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 */ @@ -1007,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/base/ftpatent.c b/src/base/ftpatent.c index d63f191..9f129d8 100644 --- a/src/base/ftpatent.c +++ b/src/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 */ @@ -260,7 +260,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/base/ftrfork.c b/src/base/ftrfork.c index 5a835ee..719570d 100644 --- a/src/base/ftrfork.c +++ b/src/base/ftrfork.c @@ -4,7 +4,7 @@ /* */ /* Embedded resource forks accessor (body). */ /* */ -/* Copyright 2004, 2005, 2006, 2007 by */ +/* Copyright 2004, 2005, 2006, 2007, 2008 by */ /* Masatake YAMATO and Redhat K.K. */ /* */ /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ @@ -399,7 +399,10 @@ 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; @@ -418,7 +421,10 @@ 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; diff --git a/src/base/ftstream.c b/src/base/ftstream.c index 569e46c..cff67e0 100644 --- a/src/base/ftstream.c +++ b/src/base/ftstream.c @@ -707,12 +707,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/base/ftstroke.c b/src/base/ftstroke.c index 5dfee8b..fd04d27 100644 --- a/src/base/ftstroke.c +++ b/src/base/ftstroke.c @@ -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; @@ -616,7 +617,7 @@ if ( in_contour != 0 ) goto Fail; - border->valid = 1; + border->valid = TRUE; Exit: *anum_points = num_points; @@ -798,7 +799,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 +814,7 @@ radius, stroker->angle_in + rotate, total ); - border->movable = 0; + border->movable = FALSE; return error; } @@ -824,7 +825,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 +850,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 +860,7 @@ 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 ); } Exit: @@ -876,7 +877,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 +901,7 @@ stroker->angle_out + rotate ); delta.x += stroker->center.x; delta.y += stroker->center.y; - border->movable = 0; + border->movable = FALSE; } else { @@ -911,7 +912,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 +929,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 +942,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 +958,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 +982,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 +991,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 +1000,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 +1015,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 +1025,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 +1037,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 +1069,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 +1099,7 @@ /* save angle for last cap */ stroker->subpath_angle = start_angle; - stroker->first_point = 0; + stroker->first_point = FALSE; Exit: return error; @@ -1112,7 +1112,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 +1143,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 +1153,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 +1176,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 +1206,7 @@ if ( first_arc ) { - first_arc = 0; + first_arc = FALSE; start_angle = angle_in; @@ -1275,12 +1275,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 +1308,7 @@ if ( first_arc ) { - first_arc = 0; + first_arc = FALSE; /* process corner if necessary */ start_angle = angle_in; @@ -1386,15 +1386,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 +1403,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 +1453,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 +1468,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 +1482,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 +1496,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 +1538,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 +1694,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 +1838,7 @@ first = last + 1; } - return 0; + return FT_Err_Ok; Exit: return error; @@ -1884,7 +1886,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; @@ -1967,7 +1969,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/base/ftsynth.c b/src/base/ftsynth.c index ff88ce9..443d272 100644 --- a/src/base/ftsynth.c +++ b/src/base/ftsynth.c @@ -68,36 +68,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,10 +100,11 @@ } 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; error = FT_GlyphSlot_Own_Bitmap( slot ); if ( error ) diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c index f61a3ed..f64908f 100644 --- a/src/base/ftsystem.c +++ b/src/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 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -294,7 +294,7 @@ #ifdef FT_DEBUG_MEMORY ft_mem_debug_done( memory ); #endif - memory->free( memory, memory ); + ft_sfree( memory ); } -- cgit v1.2.3