From 727dee178a392d20eb050d0c446f2fcc29058fa1 Mon Sep 17 00:00:00 2001 From: Victoria Lease Date: Mon, 10 Jun 2013 13:55:54 -0700 Subject: Update freetype to 5e094c6fb2ddd6e8901a5679e2cbb8fa476a38ee Integrated patches from freetype2 git repository, up to hashval 5e094c6fb2ddd6e8901a5679e2cbb8fa476a38ee, which is post-2.4.12. Most recent commit message from freetype git: [truetype] Improve handling of broken sbit advance widths. Noteworthy patches included: [cff] Add a new Type 2 interpreter and hinter. Add support for color embedded bitmaps (eg. color emoji). Change-Id: Ia8b6a67bc18f841b24f44edf80f81f663185b598 --- src/base/basepic.c | 47 +++-- src/base/basepic.h | 45 +++-- src/base/ftadvanc.c | 20 ++- src/base/ftbbox.c | 251 +++++++++++++------------- src/base/ftbitmap.c | 113 ++++++++++-- src/base/ftcalc.c | 110 +++++++----- src/base/ftdbgmem.c | 105 ++++++----- src/base/ftdebug.c | 28 ++- src/base/ftgloadr.c | 9 +- src/base/ftglyph.c | 30 ++-- src/base/ftinit.c | 8 +- src/base/ftlcdfil.c | 14 +- src/base/ftmm.c | 20 ++- src/base/ftobjs.c | 493 ++++++++++++++++++++++++++++++++-------------------- src/base/ftoutln.c | 298 +++++++++++++------------------ src/base/ftpic.c | 3 +- src/base/ftrfork.c | 44 ++--- src/base/ftsnames.c | 2 +- src/base/ftstream.c | 55 +++--- src/base/ftstroke.c | 25 ++- src/base/ftsynth.c | 25 +-- src/base/ftsystem.c | 8 +- src/base/fttrigon.c | 286 +++++++++++++----------------- src/base/fttype1.c | 4 +- src/base/ftutil.c | 79 +-------- src/base/ftwinfnt.c | 2 +- src/base/md5.c | 295 +++++++++++++++++++++++++++++++ src/base/md5.h | 45 +++++ 28 files changed, 1446 insertions(+), 1018 deletions(-) create mode 100644 src/base/md5.c create mode 100644 src/base/md5.h (limited to 'src/base') diff --git a/src/base/basepic.c b/src/base/basepic.c index d754eb1..0af770e 100644 --- a/src/base/basepic.c +++ b/src/base/basepic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for base. */ /* */ -/* Copyright 2009 by */ +/* Copyright 2009, 2012 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -21,14 +21,22 @@ #include FT_INTERNAL_OBJECTS_H #include "basepic.h" + #ifdef FT_CONFIG_OPTION_PIC /* forward declaration of PIC init functions from ftglyph.c */ - void FT_Init_Class_ft_outline_glyph_class( FT_Glyph_Class* clazz ); - void FT_Init_Class_ft_bitmap_glyph_class( FT_Glyph_Class* clazz ); + void + FT_Init_Class_ft_outline_glyph_class( FT_Glyph_Class* clazz ); + + void + FT_Init_Class_ft_bitmap_glyph_class( FT_Glyph_Class* clazz ); - /* forward declaration of PIC init function from ftrfork.c (not modularized) */ - void FT_Init_Table_raccess_guess_table( ft_raccess_guess_rec* record ); +#ifdef FT_CONFIG_OPTION_MAC_FONTS + /* forward declaration of PIC init function from ftrfork.c */ + /* (not modularized) */ + void + FT_Init_Table_raccess_guess_table( ft_raccess_guess_rec* record ); +#endif /* forward declaration of PIC init functions from ftinit.c */ FT_Error @@ -37,14 +45,18 @@ void ft_destroy_default_module_classes( FT_Library library ); + void ft_base_pic_free( FT_Library library ) { FT_PIC_Container* pic_container = &library->pic_container; - FT_Memory memory = library->memory; + FT_Memory memory = library->memory; + + if ( pic_container->base ) { - /* Destroy default module classes (in case FT_Add_Default_Modules was used) */ + /* destroy default module classes */ + /* (in case FT_Add_Default_Modules was used) */ ft_destroy_default_module_classes( library ); FT_FREE( pic_container->base ); @@ -57,12 +69,13 @@ 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; + FT_Error error = FT_Err_Ok; + BasePIC* container = NULL; + FT_Memory memory = library->memory; + /* allocate pointer, clear and set global container pointer */ - if ( FT_ALLOC ( container, sizeof ( *container ) ) ) + if ( FT_ALLOC( container, sizeof ( *container ) ) ) return error; FT_MEM_SET( container, 0, sizeof ( *container ) ); pic_container->base = container; @@ -72,21 +85,23 @@ if ( error ) goto Exit; - /* initialize pointer table - this is how the module usually expects this data */ + /* initialize pointer table - */ + /* this is how the module usually expects this data */ FT_Init_Class_ft_outline_glyph_class( &container->ft_outline_glyph_class ); FT_Init_Class_ft_bitmap_glyph_class( &container->ft_bitmap_glyph_class ); +#ifdef FT_CONFIG_OPTION_MAC_FONTS FT_Init_Table_raccess_guess_table( - (ft_raccess_guess_rec*)&container->ft_raccess_guess_table); + (ft_raccess_guess_rec*)&container->ft_raccess_guess_table ); +#endif -Exit: - if( error ) + Exit: + if ( error ) ft_base_pic_free( library ); return error; } - #endif /* FT_CONFIG_OPTION_PIC */ diff --git a/src/base/basepic.h b/src/base/basepic.h index bf90bef..329d7c8 100644 --- a/src/base/basepic.h +++ b/src/base/basepic.h @@ -25,11 +25,13 @@ 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 + +#define FT_OUTLINE_GLYPH_CLASS_GET &ft_outline_glyph_class +#define FT_BITMAP_GLYPH_CLASS_GET &ft_bitmap_glyph_class +#define FT_DEFAULT_MODULES_GET ft_default_modules + #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#define FT_RACCESS_GUESS_TABLE_GET ft_raccess_guess_table +#define FT_RACCESS_GUESS_TABLE_GET ft_raccess_guess_table #endif #else /* FT_CONFIG_OPTION_PIC */ @@ -41,25 +43,35 @@ FT_BEGIN_HEADER #endif - typedef struct BasePIC_ + typedef struct BasePIC_ { - FT_Module_Class** default_module_classes; - FT_Glyph_Class ft_outline_glyph_class; - FT_Glyph_Class ft_bitmap_glyph_class; + FT_Module_Class** default_module_classes; + FT_Glyph_Class ft_outline_glyph_class; + FT_Glyph_Class ft_bitmap_glyph_class; + #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK - ft_raccess_guess_rec ft_raccess_guess_table[FT_RACCESS_N_RULES]; + ft_raccess_guess_rec ft_raccess_guess_table[FT_RACCESS_N_RULES]; #endif + } BasePIC; -#define GET_PIC(lib) ((BasePIC*)((lib)->pic_container.base)) -#define FT_OUTLINE_GLYPH_CLASS_GET (&GET_PIC(library)->ft_outline_glyph_class) -#define FT_BITMAP_GLYPH_CLASS_GET (&GET_PIC(library)->ft_bitmap_glyph_class) -#define FT_DEFAULT_MODULES_GET (GET_PIC(library)->default_module_classes) + +#define GET_PIC( lib ) ( (BasePIC*)( (lib)->pic_container.base ) ) + +#define FT_OUTLINE_GLYPH_CLASS_GET \ + ( &GET_PIC( library )->ft_outline_glyph_class ) +#define FT_BITMAP_GLYPH_CLASS_GET \ + ( &GET_PIC( library )->ft_bitmap_glyph_class ) +#define FT_DEFAULT_MODULES_GET \ + ( GET_PIC( library )->default_module_classes ) + #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#define FT_RACCESS_GUESS_TABLE_GET (GET_PIC(library)->ft_raccess_guess_table) +#define FT_RACCESS_GUESS_TABLE_GET \ + ( GET_PIC( library )->ft_raccess_guess_table ) #endif - /* see basepic.c for the implementation. */ + + /* see basepic.c for the implementation */ void ft_base_pic_free( FT_Library library ); @@ -67,7 +79,8 @@ FT_BEGIN_HEADER ft_base_pic_init( FT_Library library ); #endif /* FT_CONFIG_OPTION_PIC */ - /* */ + + /* */ FT_END_HEADER diff --git a/src/base/ftadvanc.c b/src/base/ftadvanc.c index a8bb43d..5207847 100644 --- a/src/base/ftadvanc.c +++ b/src/base/ftadvanc.c @@ -4,7 +4,7 @@ /* */ /* Quick computation of advance widths (body). */ /* */ -/* Copyright 2008, 2009, 2011 by */ +/* Copyright 2008, 2009, 2011, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_ADVANCES_H #include FT_INTERNAL_OBJECTS_H @@ -35,7 +37,7 @@ return FT_Err_Ok; if ( face->size == NULL ) - return FT_Err_Invalid_Size_Handle; + return FT_THROW( Invalid_Size_Handle ); if ( flags & FT_LOAD_VERTICAL_LAYOUT ) scale = face->size->metrics.y_scale; @@ -76,10 +78,10 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( gindex >= (FT_UInt)face->num_glyphs ) - return FT_Err_Invalid_Glyph_Index; + return FT_THROW( Invalid_Glyph_Index ); func = face->driver->clazz->get_advances; if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) @@ -91,7 +93,7 @@ if ( !error ) return _ft_face_scale_advances( face, padvance, 1, flags ); - if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) + if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) return error; } @@ -114,12 +116,12 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( 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; + return FT_THROW( Invalid_Glyph_Index ); if ( count == 0 ) return FT_Err_Ok; @@ -131,14 +133,14 @@ if ( !error ) return _ft_face_scale_advances( face, padvances, count, flags ); - if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) + if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) return error; } error = FT_Err_Ok; if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY; for ( nn = 0; nn < count; nn++ ) diff --git a/src/base/ftbbox.c b/src/base/ftbbox.c index 4b8e911..6d1c44c 100644 --- a/src/base/ftbbox.c +++ b/src/base/ftbbox.c @@ -4,7 +4,7 @@ /* */ /* FreeType bbox computation (body). */ /* */ -/* Copyright 1996-2001, 2002, 2004, 2006, 2010 by */ +/* Copyright 1996-2002, 2004, 2006, 2010, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used */ @@ -25,6 +25,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_BBOX_H #include FT_IMAGE_H #include FT_OUTLINE_H @@ -222,65 +224,100 @@ FT_Pos* min, FT_Pos* max ) { - FT_Pos stack[32*3 + 1], *arc; - + FT_Pos q1, q2, q3, q4; - arc = stack; - arc[0] = p1; - arc[1] = p2; - arc[2] = p3; - arc[3] = p4; + q1 = p1; + q2 = p2; + q3 = p3; + q4 = p4; - do + /* for a conic segment to possibly reach new maximum */ + /* one of its off-points must be above the current value */ + while ( q2 > *max || q3 > *max ) { - FT_Pos y1 = arc[0]; - FT_Pos y2 = arc[1]; - FT_Pos y3 = arc[2]; - FT_Pos y4 = arc[3]; - - - if ( y1 == y4 ) + /* determine which half contains the maximum and split */ + if ( q1 + q2 > q3 + q4 ) /* first half */ { - if ( y1 == y2 && y1 == y3 ) /* flat */ - goto Test; + q4 = q4 + q3; + q3 = q3 + q2; + q2 = q2 + q1; + q4 = q4 + q3; + q3 = q3 + q2; + q4 = ( q4 + q3 ) / 8; + q3 = q3 / 4; + q2 = q2 / 2; } - else if ( y1 < y4 ) + else /* second half */ { - if ( y2 >= y1 && y2 <= y4 && y3 >= y1 && y3 <= y4 ) /* ascending */ - goto Test; + q1 = q1 + q2; + q2 = q2 + q3; + q3 = q3 + q4; + q1 = q1 + q2; + q2 = q2 + q3; + q1 = ( q1 + q2 ) / 8; + q2 = q2 / 4; + q3 = q3 / 2; } - else + + /* check if either end reached the maximum */ + if ( q1 == q2 && q1 >= q3 ) { - if ( y2 >= y4 && y2 <= y1 && y3 >= y4 && y3 <= y1 ) /* descending */ - { - y2 = y1; - y1 = y4; - y4 = y2; - goto Test; - } + *max = q1; + break; } + if ( q3 == q4 && q2 <= q4 ) + { + *max = q4; + break; + } + } - /* unknown direction -- split the arc in two */ - arc[6] = y4; - arc[1] = y1 = ( y1 + y2 ) / 2; - arc[5] = y4 = ( y4 + y3 ) / 2; - y2 = ( y2 + y3 ) / 2; - arc[2] = y1 = ( y1 + y2 ) / 2; - arc[4] = y4 = ( y4 + y2 ) / 2; - arc[3] = ( y1 + y4 ) / 2; - - arc += 3; - goto Suite; + q1 = p1; + q2 = p2; + q3 = p3; + q4 = p4; - Test: - if ( y1 < *min ) *min = y1; - if ( y4 > *max ) *max = y4; - arc -= 3; + /* for a conic segment to possibly reach new minimum */ + /* one of its off-points must be below the current value */ + while ( q2 < *min || q3 < *min ) + { + /* determine which half contains the minimum and split */ + if ( q1 + q2 < q3 + q4 ) /* first half */ + { + q4 = q4 + q3; + q3 = q3 + q2; + q2 = q2 + q1; + q4 = q4 + q3; + q3 = q3 + q2; + q4 = ( q4 + q3 ) / 8; + q3 = q3 / 4; + q2 = q2 / 2; + } + else /* second half */ + { + q1 = q1 + q2; + q2 = q2 + q3; + q3 = q3 + q4; + q1 = q1 + q2; + q2 = q2 + q3; + q1 = ( q1 + q2 ) / 8; + q2 = q2 / 4; + q3 = q3 / 2; + } - Suite: - ; - } while ( arc >= stack ); + /* check if either end reached the minimum */ + if ( q1 == q2 && q1 <= q3 ) + { + *min = q1; + break; + } + if ( q3 == q4 && q2 >= q4 ) + { + *min = q4; + break; + } + } } #else @@ -358,107 +395,57 @@ return; } - /* There are some split points. Find them. */ + /* There are some split points. Find them. */ + /* We already made sure that a, b, and c below cannot be all zero. */ { FT_Pos a = y4 - 3*y3 + 3*y2 - y1; FT_Pos b = y3 - 2*y2 + y1; FT_Pos c = y2 - y1; FT_Pos d; FT_Fixed t; + FT_Int shift; /* We need to solve `ax^2+2bx+c' here, without floating points! */ /* The trick is to normalize to a different representation in order */ - /* to use our 16.16 fixed point routines. */ + /* to use our 16.16 fixed-point routines. */ /* */ /* We compute FT_MulFix(b,b) and FT_MulFix(a,c) after normalization. */ /* These values must fit into a single 16.16 value. */ /* */ - /* We normalize a, b, and c to `8.16' fixed float values to ensure */ - /* that its product is held in a `16.16' value. */ + /* We normalize a, b, and c to `8.16' fixed-point values to ensure */ + /* that their product is held in a `16.16' value including the sign. */ + /* Necessarily, we need to shift `a', `b', and `c' so that the most */ + /* significant bit of their absolute values is at position 22. */ + /* */ + /* This also means that we are using 23 bits of precision to compute */ + /* the zeros, independently of the range of the original polynomial */ + /* coefficients. */ + /* */ + /* This algorithm should ensure reasonably accurate values for the */ + /* zeros. Note that they are only expressed with 16 bits when */ + /* computing the extrema (the zeros need to be in 0..1 exclusive */ + /* to be considered part of the arc). */ - { - FT_ULong t1, t2; - int shift = 0; - - - /* The following computation is based on the fact that for */ - /* any value `y', if `n' is the position of the most */ - /* significant bit of `abs(y)' (starting from 0 for the */ - /* least significant bit), then `y' is in the range */ - /* */ - /* -2^n..2^n-1 */ - /* */ - /* We want to shift `a', `b', and `c' concurrently in order */ - /* to ensure that they all fit in 8.16 values, which maps */ - /* to the integer range `-2^23..2^23-1'. */ - /* */ - /* Necessarily, we need to shift `a', `b', and `c' so that */ - /* the most significant bit of its absolute values is at */ - /* _most_ at position 23. */ - /* */ - /* We begin by computing `t1' as the bitwise `OR' of the */ - /* absolute values of `a', `b', `c'. */ - - t1 = (FT_ULong)( ( a >= 0 ) ? a : -a ); - t2 = (FT_ULong)( ( b >= 0 ) ? b : -b ); - t1 |= t2; - t2 = (FT_ULong)( ( c >= 0 ) ? c : -c ); - t1 |= t2; - - /* Now we can be sure that the most significant bit of `t1' */ - /* is the most significant bit of either `a', `b', or `c', */ - /* depending on the greatest integer range of the particular */ - /* variable. */ - /* */ - /* Next, we compute the `shift', by shifting `t1' as many */ - /* times as necessary to move its MSB to position 23. This */ - /* corresponds to a value of `t1' that is in the range */ - /* 0x40_0000..0x7F_FFFF. */ - /* */ - /* Finally, we shift `a', `b', and `c' by the same amount. */ - /* This ensures that all values are now in the range */ - /* -2^23..2^23, i.e., they are now expressed as 8.16 */ - /* fixed-float numbers. This also means that we are using */ - /* 24 bits of precision to compute the zeros, independently */ - /* of the range of the original polynomial coefficients. */ - /* */ - /* This algorithm should ensure reasonably accurate values */ - /* for the zeros. Note that they are only expressed with */ - /* 16 bits when computing the extrema (the zeros need to */ - /* be in 0..1 exclusive to be considered part of the arc). */ - - if ( t1 == 0 ) /* all coefficients are 0! */ - return; + shift = FT_MSB( FT_ABS( a ) | FT_ABS( b ) | FT_ABS( c ) ); - if ( t1 > 0x7FFFFFUL ) - { - do - { - shift++; - t1 >>= 1; - - } while ( t1 > 0x7FFFFFUL ); - - /* this loses some bits of precision, but we use 24 of them */ - /* for the computation anyway */ - a >>= shift; - b >>= shift; - c >>= shift; - } - else if ( t1 < 0x400000UL ) - { - do - { - shift++; - t1 <<= 1; + if ( shift > 22 ) + { + shift -= 22; - } while ( t1 < 0x400000UL ); + /* this loses some bits of precision, but we use 23 of them */ + /* for the computation anyway */ + a >>= shift; + b >>= shift; + c >>= shift; + } + else + { + shift = 22 - shift; - a <<= shift; - b <<= shift; - c <<= shift; - } + a <<= shift; + b <<= shift; + c <<= shift; } /* handle a == 0 */ @@ -581,10 +568,10 @@ FT_DEFINE_OUTLINE_FUNCS(bbox_interface, if ( !abbox ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( !outline ) - return FT_Err_Invalid_Outline; + return FT_THROW( Invalid_Outline ); /* if outline is empty, return (0,0,0,0) */ if ( outline->n_points == 0 || outline->n_contours <= 0 ) diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c index 84fa322..975818e 100644 --- a/src/base/ftbitmap.c +++ b/src/base/ftbitmap.c @@ -4,7 +4,7 @@ /* */ /* FreeType utility functions for bitmaps (body). */ /* */ -/* Copyright 2004-2009, 2011 by */ +/* Copyright 2004-2009, 2011, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_BITMAP_H #include FT_IMAGE_H #include FT_INTERNAL_OBJECTS_H @@ -135,7 +137,7 @@ new_pitch = ( width + xpixels ); break; default: - return FT_Err_Invalid_Glyph_Format; + return FT_THROW( Invalid_Glyph_Format ); } /* if no need to allocate memory */ @@ -223,14 +225,14 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !bitmap || !bitmap->buffer ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) || ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6; ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6; @@ -238,7 +240,7 @@ if ( xstr == 0 && ystr == 0 ) return FT_Err_Ok; else if ( xstr < 0 || ystr < 0 ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); switch ( bitmap->pixel_mode ) { @@ -277,6 +279,10 @@ case FT_PIXEL_MODE_LCD_V: ystr *= 3; break; + + case FT_PIXEL_MODE_BGRA: + /* We don't embolden color glyphs. */ + return FT_Err_Ok; } error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr ); @@ -369,6 +375,59 @@ } + FT_Byte + ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra ) + { + FT_Long a = bgra[3]; + FT_Long b = bgra[0]; + FT_Long g = bgra[1]; + FT_Long r = bgra[2]; + FT_Long l; + + + /* + * Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722 + * coefficients for RGB channels *on the linear colors*. + * A gamma of 2.2 is fair to assume. And then, we need to + * undo the premultiplication too. + * + * http://accessibility.kde.org/hsl-adjusted.php + * + * We do the computation with integers only. + */ + + /* Undo premultification, get the number in a 16.16 form. */ + b = FT_MulDiv( b, 65536, a ); + g = FT_MulDiv( g, 65536, a ); + r = FT_MulDiv( r, 65536, a ); + a = a * 256; + + /* Apply gamma of 2.0 instead of 2.2. */ + b = FT_MulFix( b, b ); + g = FT_MulFix( g, g ); + r = FT_MulFix( r, r ); + + /* Apply coefficients. */ + b = FT_MulFix( b, 4731 /* 0.0722 * 65536 */ ); + g = FT_MulFix( g, 46871 /* 0.7152 * 65536 */ ); + r = FT_MulFix( r, 13933 /* 0.2126 * 65536 */ ); + + l = r + g + b; + + /* + * Final transparency can be determined this way: + * + * - If alpha is zero, we want 0. + * - If alpha is zero and luminosity is zero, we want 255. + * - If alpha is zero and luminosity is one, we want 0. + * + * So the formula is a * (1 - l). + */ + + return (FT_Byte)( FT_MulFix( 65535 - l, a ) >> 8 ); + } + + /* documentation is in ftbitmap.h */ FT_EXPORT_DEF( FT_Error ) @@ -382,7 +441,7 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); memory = library->memory; @@ -394,6 +453,7 @@ case FT_PIXEL_MODE_GRAY4: case FT_PIXEL_MODE_LCD: case FT_PIXEL_MODE_LCD_V: + case FT_PIXEL_MODE_BGRA: { FT_Int pad; FT_Long old_size; @@ -419,7 +479,7 @@ if ( target->pitch > 0 && (FT_ULong)target->rows > FT_ULONG_MAX / target->pitch ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( target->rows * target->pitch > old_size && FT_QREALLOC( target->buffer, @@ -429,7 +489,7 @@ break; default: - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); } switch ( source->pixel_mode ) @@ -606,6 +666,37 @@ } break; + case FT_PIXEL_MODE_BGRA: + { + FT_Byte* s = source->buffer; + FT_Byte* t = target->buffer; + FT_Int s_pitch = source->pitch; + FT_Int t_pitch = target->pitch; + FT_Int i; + + + target->num_grays = 256; + + for ( i = source->rows; i > 0; i-- ) + { + FT_Byte* ss = s; + FT_Byte* tt = t; + FT_Int j; + + + for ( j = source->width; j > 0; j-- ) + { + tt[0] = ft_gray_for_premultiplied_srgb_bgra( ss ); + + ss += 4; + tt += 1; + } + + s += s_pitch; + t += t_pitch; + } + } + break; default: ; @@ -650,10 +741,10 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !bitmap ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); memory = library->memory; diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c index 2aeea04..0ec0d78 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -4,7 +4,7 @@ /* */ /* Arithmetic computations (body). */ /* */ -/* Copyright 1996-2006, 2008, 2012 by */ +/* Copyright 1996-2006, 2008, 2012-2013 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 #include FT_GLYPH_H +#include FT_TRIGONOMETRY_H #include FT_INTERNAL_CALC_H #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_OBJECTS_H @@ -42,13 +43,9 @@ #undef FT_MulFix #endif -/* we need to define a 64-bits data type here */ +/* we need to emulate a 64-bit data type if a real one isn't available */ -#ifdef FT_LONG64 - - typedef FT_INT64 FT_Int64; - -#else +#ifndef FT_LONG64 typedef struct FT_Int64_ { @@ -57,7 +54,7 @@ } FT_Int64; -#endif /* FT_LONG64 */ +#endif /* !FT_LONG64 */ /*************************************************************************/ @@ -103,39 +100,57 @@ } -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS + FT_BASE_DEF ( FT_Int ) + FT_MSB( FT_UInt32 z ) + { + FT_Int shift = 0; - /* documentation is in ftcalc.h */ + /* determine msb bit index in `shift' */ + if ( z >= ( 1L << 16 ) ) + { + z >>= 16; + shift += 16; + } + if ( z >= ( 1L << 8 ) ) + { + z >>= 8; + shift += 8; + } + if ( z >= ( 1L << 4 ) ) + { + z >>= 4; + shift += 4; + } + if ( z >= ( 1L << 2 ) ) + { + z >>= 2; + shift += 2; + } + if ( z >= ( 1L << 1 ) ) + { + z >>= 1; + shift += 1; + } - FT_EXPORT_DEF( FT_Int32 ) - FT_Sqrt32( FT_Int32 x ) - { - FT_UInt32 val, root, newroot, mask; + return shift; + } - root = 0; - mask = (FT_UInt32)0x40000000UL; - val = (FT_UInt32)x; + /* documentation is in ftcalc.h */ - do - { - newroot = root + mask; - if ( newroot <= val ) - { - val -= newroot; - root = newroot + mask; - } + FT_BASE_DEF( FT_Fixed ) + FT_Hypot( FT_Fixed x, + FT_Fixed y ) + { + FT_Vector v; - root >>= 1; - mask >>= 2; - } while ( mask != 0 ); + v.x = x; + v.y = y; - return root; + return FT_Vector_Length( &v ); } -#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ - #ifdef FT_LONG64 @@ -163,8 +178,6 @@ } -#ifdef TT_USE_BYTECODE_INTERPRETER - /* documentation is in ftcalc.h */ FT_BASE_DEF( FT_Long ) @@ -187,8 +200,6 @@ return ( s > 0 ) ? d : -d; } -#endif /* TT_USE_BYTECODE_INTERPRETER */ - /* documentation is in freetype.h */ @@ -235,16 +246,25 @@ FT_Int32 s; FT_UInt32 q; + s = 1; - 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; + } if ( b == 0 ) /* check for division by 0 */ q = 0x7FFFFFFFL; else /* compute result directly */ - q = (FT_UInt32)( ( ( (FT_Int64)a << 16 ) + ( b >> 1 ) ) / b ); + q = (FT_UInt32)( ( ( (FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b ); return ( s < 0 ? -(FT_Long)q : (FT_Long)q ); } @@ -392,8 +412,6 @@ } -#ifdef TT_USE_BYTECODE_INTERPRETER - FT_BASE_DEF( FT_Long ) FT_MulDiv_No_Round( FT_Long a, FT_Long b, @@ -426,8 +444,6 @@ return ( s < 0 ? -a : a ); } -#endif /* TT_USE_BYTECODE_INTERPRETER */ - /* documentation is in freetype.h */ @@ -552,7 +568,7 @@ else if ( ( a >> 16 ) == 0 ) { /* compute result directly */ - q = (FT_UInt32)( ( a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b; + q = (FT_UInt32)( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b; } else { @@ -560,8 +576,8 @@ FT_Int64 temp, temp2; - temp.hi = (FT_Int32) ( a >> 16 ); - temp.lo = (FT_UInt32)( a << 16 ); + temp.hi = (FT_Int32)( a >> 16 ); + temp.lo = (FT_UInt32)a << 16; temp2.hi = 0; temp2.lo = (FT_UInt32)( b >> 1 ); FT_Add64( &temp, &temp2, &temp ); @@ -727,14 +743,14 @@ if ( !matrix ) - return FT_Err_Invalid_Argument; + return FT_THROW( 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 */ + return FT_THROW( Invalid_Argument ); /* matrix can't be inverted */ matrix->xy = - FT_DivFix( matrix->xy, delta ); matrix->yx = - FT_DivFix( matrix->yx, delta ); diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c index 12fed04..6fb86fe 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, 2009 by */ +/* Copyright 2001-2006, 2009, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -344,85 +344,80 @@ ft_mem_table_destroy( FT_MemTable table ) { FT_ULong i; + FT_Long leak_count = 0; + FT_ULong leaks = 0; FT_DumpMemory( table->memory ); - if ( table ) + /* remove all blocks from the table, revealing leaked ones */ + for ( i = 0; i < table->size; i++ ) { - FT_Long leak_count = 0; - FT_ULong leaks = 0; + FT_MemNode *pnode = table->buckets + i, next, node = *pnode; - /* remove all blocks from the table, revealing leaked ones */ - for ( i = 0; i < table->size; i++ ) + while ( node ) { - FT_MemNode *pnode = table->buckets + i, next, node = *pnode; + next = node->link; + node->link = 0; - - while ( node ) + if ( node->size > 0 ) { - next = node->link; - node->link = 0; - - if ( node->size > 0 ) - { - printf( - "leaked memory block at address %p, size %8ld in (%s:%ld)\n", - node->address, node->size, - FT_FILENAME( node->source->file_name ), - node->source->line_no ); + printf( + "leaked memory block at address %p, size %8ld in (%s:%ld)\n", + node->address, node->size, + FT_FILENAME( node->source->file_name ), + node->source->line_no ); - leak_count++; - leaks += node->size; + leak_count++; + leaks += node->size; - ft_mem_table_free( table, node->address ); - } + ft_mem_table_free( table, node->address ); + } - node->address = NULL; - node->size = 0; + node->address = NULL; + node->size = 0; - ft_mem_table_free( table, node ); - node = next; - } - table->buckets[i] = 0; + ft_mem_table_free( table, node ); + node = next; } + table->buckets[i] = 0; + } - ft_mem_table_free( table, table->buckets ); - table->buckets = NULL; - - table->size = 0; - table->nodes = 0; + ft_mem_table_free( table, table->buckets ); + table->buckets = NULL; - /* remove all sources */ - for ( i = 0; i < FT_MEM_SOURCE_BUCKETS; i++ ) - { - FT_MemSource source, next; + table->size = 0; + table->nodes = 0; + /* remove all sources */ + for ( i = 0; i < FT_MEM_SOURCE_BUCKETS; i++ ) + { + FT_MemSource source, next; - for ( source = table->sources[i]; source != NULL; source = next ) - { - next = source->link; - ft_mem_table_free( table, source ); - } - table->sources[i] = NULL; + for ( source = table->sources[i]; source != NULL; source = next ) + { + next = source->link; + ft_mem_table_free( table, source ); } - printf( - "FreeType: total memory allocations = %ld\n", table->alloc_total ); - printf( - "FreeType: maximum memory footprint = %ld\n", table->alloc_max ); + table->sources[i] = NULL; + } - ft_mem_table_free( table, table ); + printf( "FreeType: total memory allocations = %ld\n", + table->alloc_total ); + printf( "FreeType: maximum memory footprint = %ld\n", + table->alloc_max ); - if ( leak_count > 0 ) - ft_mem_debug_panic( - "FreeType: %ld bytes of memory leaked in %ld blocks\n", - leaks, leak_count ); + ft_mem_table_free( table, table ); - printf( "FreeType: no memory leaks detected\n" ); - } + if ( leak_count > 0 ) + ft_mem_debug_panic( + "FreeType: %ld bytes of memory leaked in %ld blocks\n", + leaks, leak_count ); + + printf( "FreeType: no memory leaks detected\n" ); } diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c index 2adbeab..b9156d1 100644 --- a/src/base/ftdebug.c +++ b/src/base/ftdebug.c @@ -4,7 +4,7 @@ /* */ /* Debugging and logging component (body). */ /* */ -/* Copyright 1996-2001, 2002, 2004, 2008 by */ +/* Copyright 1996-2001, 2002, 2004, 2008, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -51,7 +51,8 @@ /* documentation is in ftdebug.h */ FT_BASE_DEF( void ) - FT_Message( const char* fmt, ... ) + FT_Message( const char* fmt, + ... ) { va_list ap; @@ -65,7 +66,8 @@ /* documentation is in ftdebug.h */ FT_BASE_DEF( void ) - FT_Panic( const char* fmt, ... ) + FT_Panic( const char* fmt, + ... ) { va_list ap; @@ -77,6 +79,21 @@ exit( EXIT_FAILURE ); } + + /* documentation is in ftdebug.h */ + + FT_BASE_DEF( int ) + FT_Throw( FT_Error error, + int line, + const char* file ) + { + FT_UNUSED( error ); + FT_UNUSED( line ); + FT_UNUSED( file ); + + return 0; + } + #endif /* FT_DEBUG_LEVEL_ERROR */ @@ -164,6 +181,9 @@ while ( *p && *p != ':' ) p++; + if ( !*p ) + break; + if ( *p == ':' && p > q ) { FT_Int n, i, len = (FT_Int)( p - q ); @@ -192,7 +212,7 @@ p++; if ( *p ) { - level = *p++ - '0'; + level = *p - '0'; if ( level < 0 || level > 7 ) level = -1; } diff --git a/src/base/ftgloadr.c b/src/base/ftgloadr.c index 8483450..663db26 100644 --- a/src/base/ftgloadr.c +++ b/src/base/ftgloadr.c @@ -4,7 +4,7 @@ /* */ /* The FreeType glyph loader (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2010 by */ +/* Copyright 2002-2006, 2010, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,7 @@ #include +#include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_GLYPH_LOADER_H #include FT_INTERNAL_MEMORY_H #include FT_INTERNAL_OBJECTS_H @@ -219,7 +220,7 @@ new_max = FT_PAD_CEIL( new_max, 8 ); if ( new_max > FT_OUTLINE_POINTS_MAX ) - return FT_Err_Array_Too_Large; + return FT_THROW( Array_Too_Large ); if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) || FT_RENEW_ARRAY( base->tags, old_max, new_max ) ) @@ -251,7 +252,7 @@ new_max = FT_PAD_CEIL( new_max, 4 ); if ( new_max > FT_OUTLINE_CONTOURS_MAX ) - return FT_Err_Array_Too_Large; + return FT_THROW( Array_Too_Large ); if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) ) goto Exit; @@ -318,7 +319,7 @@ } - /* add current glyph to the base image - and prepare for another */ + /* add current glyph to the base image -- and prepare for another */ FT_BASE_DEF( void ) FT_GlyphLoader_Add( FT_GlyphLoader loader ) { diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index 591b57a..5dd28a8 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, 2008, 2010 by */ +/* Copyright 1996-2005, 2007, 2008, 2010, 2012, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -29,6 +29,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_GLYPH_H #include FT_OUTLINE_H #include FT_BITMAP_H @@ -65,7 +67,7 @@ if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) { - error = FT_Err_Invalid_Glyph_Format; + error = FT_THROW( Invalid_Glyph_Format ); goto Exit; } @@ -166,7 +168,7 @@ /* check format in glyph slot */ if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) { - error = FT_Err_Invalid_Glyph_Format; + error = FT_THROW( Invalid_Glyph_Format ); goto Exit; } @@ -314,7 +316,7 @@ /* check arguments */ if ( !target ) { - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -322,7 +324,7 @@ if ( !source || !source->clazz ) { - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -361,12 +363,12 @@ if ( !slot ) - return FT_Err_Invalid_Slot_Handle; + return FT_THROW( Invalid_Slot_Handle ); library = slot->library; if ( !aglyph ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* if it is a bitmap, that's easy :-) */ if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) @@ -388,7 +390,7 @@ if ( !clazz ) { - error = FT_Err_Invalid_Glyph_Format; + error = FT_THROW( Invalid_Glyph_Format ); goto Exit; } @@ -427,7 +429,7 @@ if ( !glyph || !glyph->clazz ) - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); else { clazz = glyph->clazz; @@ -441,7 +443,7 @@ FT_Vector_Transform( &glyph->advance, matrix ); } else - error = FT_Err_Invalid_Glyph_Format; + error = FT_THROW( Invalid_Glyph_Format ); } return error; } @@ -510,7 +512,7 @@ FT_GlyphSlotRec dummy; FT_GlyphSlot_InternalRec dummy_internal; FT_Error error = FT_Err_Ok; - FT_Glyph glyph; + FT_Glyph b, glyph; FT_BitmapGlyph bitmap = NULL; const FT_Glyph_Class* clazz; @@ -547,10 +549,10 @@ dummy.format = clazz->glyph_format; /* create result bitmap glyph */ - error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, - (FT_Glyph*)(void*)&bitmap ); + error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, &b ); if ( error ) goto Exit; + bitmap = (FT_BitmapGlyph)b; #if 1 /* if `origin' is set, translate the glyph image */ @@ -600,7 +602,7 @@ return error; Bad: - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } diff --git a/src/base/ftinit.c b/src/base/ftinit.c index 91f8e2a..85f321f 100644 --- a/src/base/ftinit.c +++ b/src/base/ftinit.c @@ -4,7 +4,7 @@ /* */ /* FreeType initialization layer (body). */ /* */ -/* Copyright 1996-2001, 2002, 2005, 2007, 2009, 2012 by */ +/* Copyright 1996-2002, 2005, 2007, 2009, 2012, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -156,7 +156,7 @@ { FT_Error error; FT_Memory memory; - FT_Module_Class* *classes; + FT_Module_Class* *classes = NULL; FT_Module_Class* clazz; FT_UInt i; BasePIC* pic_container = (BasePIC*)library->pic_container.base; @@ -166,7 +166,7 @@ pic_container->default_module_classes = 0; - if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) * + if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) * ( FT_NUM_MODULE_CLASSES + 1 ) ) ) return error; @@ -242,7 +242,7 @@ if ( !memory ) { FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" )); - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); } /* build a library out of it, then fill it with the set of */ diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c index 0da4ba1..852fb32 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, 2009, 2010 by */ +/* Copyright 2006, 2008-2010, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_LCD_FILTER_H #include FT_IMAGE_H #include FT_INTERNAL_OBJECTS_H @@ -271,7 +273,7 @@ unsigned char *weights ) { if ( !library || !weights ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); ft_memcpy( library->lcd_weights, weights, 5 ); @@ -292,7 +294,7 @@ if ( !library ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); switch ( filter ) { @@ -339,7 +341,7 @@ #endif default: - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } library->lcd_filter = filter; @@ -356,7 +358,7 @@ FT_UNUSED( library ); FT_UNUSED( weights ); - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); } @@ -367,7 +369,7 @@ FT_UNUSED( library ); FT_UNUSED( filter ); - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); } #endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ diff --git a/src/base/ftmm.c b/src/base/ftmm.c index 0307729..18ff879 100644 --- a/src/base/ftmm.c +++ b/src/base/ftmm.c @@ -4,7 +4,7 @@ /* */ /* Multiple Master font support (body). */ /* */ -/* Copyright 1996-2001, 2003, 2004, 2009 by */ +/* Copyright 1996-2001, 2003, 2004, 2009, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -17,6 +17,8 @@ #include +#include FT_INTERNAL_DEBUG_H + #include FT_MULTIPLE_MASTERS_H #include FT_INTERNAL_OBJECTS_H #include FT_SERVICE_MULTIPLE_MASTERS_H @@ -42,9 +44,9 @@ *aservice = NULL; if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( FT_HAS_MULTIPLE_MASTERS( face ) ) { @@ -73,7 +75,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->get_mm ) error = service->get_mm( face, amaster ); } @@ -95,7 +97,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->get_mm_var ) error = service->get_mm_var( face, amaster ); } @@ -118,7 +120,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->set_mm_design ) error = service->set_mm_design( face, num_coords, coords ); } @@ -141,7 +143,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->set_var_design ) error = service->set_var_design( face, num_coords, coords ); } @@ -164,7 +166,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->set_mm_blend ) error = service->set_mm_blend( face, num_coords, coords ); } @@ -190,7 +192,7 @@ error = ft_face_get_mm_service( face, &service ); if ( !error ) { - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( service->set_mm_blend ) error = service->set_mm_blend( face, num_coords, coords ); } diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 36ee797..ac2a39c 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (body). */ /* */ -/* Copyright 1996-2012 by */ +/* Copyright 1996-2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -29,6 +29,7 @@ #include FT_TRUETYPE_TAGS_H #include FT_TRUETYPE_IDS_H +#include FT_SERVICE_PROPERTIES_H #include FT_SERVICE_SFNT_H #include FT_SERVICE_POSTSCRIPT_NAME_H #include FT_SERVICE_GLYPH_DICT_H @@ -40,6 +41,32 @@ #include "ftbase.h" #endif + +#ifdef FT_DEBUG_LEVEL_TRACE + +#include FT_BITMAP_H + +#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */ + /* We disable the warning `conversion from XXX to YYY, */ + /* possible loss of data' in order to compile cleanly with */ + /* the maximum level of warnings: `md5.c' is non-FreeType */ + /* code, and it gets used during development builds only. */ +#pragma warning( push ) +#pragma warning( disable : 4244 ) +#endif /* _MSC_VER */ + + /* it's easiest to include `md5.c' directly */ +#define free md5_free /* suppress a shadow warning */ +#include "md5.c" +#undef free + +#if defined( _MSC_VER ) +#pragma warning( pop ) +#endif + +#endif /* FT_DEBUG_LEVEL_TRACE */ + + #define GRID_FIT_METRICS @@ -136,10 +163,10 @@ *astream = 0; if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !args ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); memory = library->memory; @@ -177,7 +204,7 @@ #endif else - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); if ( error ) FT_FREE( stream ); @@ -384,7 +411,7 @@ if ( !face || !face->driver ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); driver = face->driver; clazz = driver->clazz; @@ -574,7 +601,7 @@ if ( !face || !face->size || !face->glyph ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); /* The validity test for `glyph_index' is performed by the */ /* font drivers. */ @@ -651,7 +678,7 @@ if ( autohint ) { - FT_AutoHinter_Service hinting; + FT_AutoHinter_Interface hinting; /* try to load embedded bitmaps first if available */ @@ -680,7 +707,7 @@ internal->transform_flags = 0; /* load auto-hinted outline */ - hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface; + hinting = (FT_AutoHinter_Interface)hinter->clazz->module_interface; error = hinting->load_glyph( (FT_AutoHinter)hinter, slot, face->size, @@ -814,7 +841,7 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); glyph_index = (FT_UInt)char_code; if ( face->charmap ) @@ -965,7 +992,7 @@ first = face->charmaps; if ( !first ) - return FT_Err_Invalid_CharMap_Handle; + return FT_THROW( Invalid_CharMap_Handle ); /* * The original TrueType specification(s) only specified charmap @@ -1043,7 +1070,7 @@ } } - return FT_Err_Invalid_CharMap_Handle; + return FT_THROW( Invalid_CharMap_Handle ); } @@ -1165,7 +1192,7 @@ /* is returned. */ /* no error should happen, but we want to play safe */ - if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle ) + if ( error2 && FT_ERR_NEQ( error2, Invalid_CharMap_Handle ) ) { error = error2; goto Fail; @@ -1206,7 +1233,7 @@ /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; @@ -1232,7 +1259,7 @@ /* test for valid `library' and `face' delayed to FT_Open_Face() */ if ( !file_base ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); args.flags = FT_OPEN_MEMORY; args.memory_base = file_base; @@ -1304,10 +1331,10 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !base ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); *astream = 0; memory = library->memory; @@ -1421,7 +1448,7 @@ if ( FT_READ_ULONG( tag ) ) return error; if ( tag != TTAG_typ1 ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); if ( FT_READ_USHORT( numTables ) ) return error; @@ -1458,7 +1485,7 @@ if ( face_index >= 0 && pstable_index == face_index ) return FT_Err_Ok; } - return FT_Err_Table_Missing; + return FT_THROW( Table_Missing ); } @@ -1504,7 +1531,7 @@ error = open_face_from_buffer( library, sfnt_ps, length, - face_index < 0 ? face_index : 0, + FT_MIN( face_index, 0 ), is_sfnt_cid ? "cid" : "type1", aface ); Exit: @@ -1512,7 +1539,7 @@ FT_Error error1; - if ( error == FT_Err_Unknown_File_Format ) + if ( FT_ERR_EQ( error, Unknown_File_Format ) ) { error1 = FT_Stream_Seek( stream, pos ); if ( error1 ) @@ -1540,7 +1567,7 @@ FT_Long face_index, FT_Face *aface ) { - FT_Error error = FT_Err_Cannot_Open_Resource; + FT_Error error = FT_ERR( Cannot_Open_Resource ); FT_Memory memory = library->memory; FT_Byte* pfb_data = NULL; int i, type, flags; @@ -1633,7 +1660,7 @@ pfb_data[pfb_pos++] = 0; } - error = FT_Err_Cannot_Open_Resource; + error = FT_ERR( Cannot_Open_Resource ); if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len ) goto Exit2; @@ -1695,7 +1722,7 @@ if ( face_index == -1 ) face_index = 0; if ( face_index >= resource_cnt ) - return FT_Err_Cannot_Open_Resource; + return FT_THROW( Cannot_Open_Resource ); flag_offset = offsets[face_index]; error = FT_Stream_Seek( stream, flag_offset ); @@ -1705,7 +1732,7 @@ if ( FT_READ_LONG( rlen ) ) goto Exit; if ( rlen == -1 ) - return FT_Err_Cannot_Open_Resource; + return FT_THROW( Cannot_Open_Resource ); error = open_face_PS_from_sfnt_stream( library, stream, @@ -1812,7 +1839,7 @@ if ( NULL == stream ) - return FT_Err_Invalid_Stream_Operation; + return FT_THROW( Invalid_Stream_Operation ); error = FT_Stream_Seek( stream, 0 ); if ( error ) @@ -1829,7 +1856,7 @@ header[ 1] > 33 || header[63] != 0 || header[2 + header[1]] != 0 ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); dlen = ( header[0x53] << 24 ) | ( header[0x54] << 16 ) | @@ -1862,7 +1889,7 @@ #define FT_COMPONENT trace_raccess FT_Memory memory = library->memory; - FT_Error error = FT_Err_Unknown_File_Format; + FT_Error error = FT_ERR( Unknown_File_Format ); int i; char * file_names[FT_RACCESS_N_RULES]; @@ -1901,7 +1928,7 @@ i, args2.pathname, offsets[i] )); error = FT_Stream_New( library, &args2, &stream2 ); - if ( is_darwin_vfs && error == FT_Err_Cannot_Open_Stream ) + if ( is_darwin_vfs && FT_ERR_EQ( error, Cannot_Open_Stream ) ) vfs_rfork_has_no_font = TRUE; if ( error ) @@ -1930,7 +1957,7 @@ /* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */ if ( error ) - error = FT_Err_Unknown_File_Format; + error = FT_ERR( Unknown_File_Format ); return error; @@ -1959,7 +1986,7 @@ error = IsMacBinary( library, stream, face_index, aface ); - if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format ) + if ( FT_ERR_EQ( error, Unknown_File_Format ) ) { #undef FT_COMPONENT @@ -1976,9 +2003,9 @@ } - if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format || - FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation ) && - ( args->flags & FT_OPEN_PATHNAME ) ) + if ( ( FT_ERR_EQ( error, Unknown_File_Format ) || + FT_ERR_EQ( error, Invalid_Stream_Operation ) ) && + ( args->flags & FT_OPEN_PATHNAME ) ) error = load_face_in_embedded_rfork( library, stream, face_index, aface, args ); return error; @@ -2011,7 +2038,7 @@ /* FT_Stream_New() */ if ( ( !aface && face_index >= 0 ) || !args ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) && args->stream ); @@ -2048,18 +2075,19 @@ goto Success; } else - error = FT_Err_Invalid_Handle; + error = FT_THROW( Invalid_Handle ); FT_Stream_Free( stream, external_stream ); goto Fail; } else { + error = FT_ERR( Missing_Module ); + /* check each font driver for an appropriate format */ cur = library->modules; limit = cur + library->num_modules; - for ( ; cur < limit; cur++ ) { /* not all modules are font drivers, so check... */ @@ -2084,7 +2112,7 @@ #ifdef FT_CONFIG_OPTION_MAC_FONTS if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 && - FT_ERROR_BASE( error ) == FT_Err_Table_Missing ) + FT_ERR_EQ( error, Table_Missing ) ) { /* TrueType but essential tables are missing */ if ( FT_Stream_Seek( stream, 0 ) ) @@ -2104,39 +2132,39 @@ } #endif - if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format ) + if ( FT_ERR_NEQ( error, Unknown_File_Format ) ) goto Fail3; } } - Fail3: - /* If we are on the mac, and we get an FT_Err_Invalid_Stream_Operation */ - /* it may be because we have an empty data fork, so we need to check */ - /* the resource fork. */ - if ( FT_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; + Fail3: + /* If we are on the mac, and we get an */ + /* FT_Err_Invalid_Stream_Operation it may be because we have an */ + /* empty data fork, so we need to check the resource fork. */ + if ( FT_ERR_NEQ( error, Cannot_Open_Stream ) && + FT_ERR_NEQ( error, Unknown_File_Format ) && + FT_ERR_NEQ( error, Invalid_Stream_Operation ) ) + goto Fail2; #if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS ) - error = load_mac_face( library, stream, face_index, aface, args ); - if ( !error ) - { - /* We don't want to go to Success here. We've already done that. */ - /* On the other hand, if we succeeded we still need to close this */ - /* stream (we opened a different stream which extracted the */ - /* interesting information out of this stream here. That stream */ - /* will still be open and the face will point to it). */ - FT_Stream_Free( stream, external_stream ); - return error; - } + error = load_mac_face( library, stream, face_index, aface, args ); + if ( !error ) + { + /* We don't want to go to Success here. We've already done that. */ + /* On the other hand, if we succeeded we still need to close this */ + /* stream (we opened a different stream which extracted the */ + /* interesting information out of this stream here. That stream */ + /* will still be open and the face will point to it). */ + FT_Stream_Free( stream, external_stream ); + return error; + } - if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format ) - goto Fail2; + if ( FT_ERR_NEQ( error, Unknown_File_Format ) ) + goto Fail2; #endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */ /* no driver is able to handle this format */ - error = FT_Err_Unknown_File_Format; + error = FT_THROW( Unknown_File_Format ); Fail2: FT_Stream_Free( stream, external_stream ); @@ -2258,7 +2286,7 @@ /* test for valid `face' delayed to FT_Attach_Stream() */ if ( !filepathname ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); open.stream = NULL; open.flags = FT_OPEN_PATHNAME; @@ -2284,11 +2312,11 @@ /* test for valid `parameters' delayed to FT_Stream_New() */ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); driver = face->driver; if ( !driver ) - return FT_Err_Invalid_Driver_Handle; + return FT_THROW( Invalid_Driver_Handle ); error = FT_Stream_New( driver->root.library, parameters, &stream ); if ( error ) @@ -2297,7 +2325,7 @@ /* we implement FT_Attach_Stream in each driver through the */ /* `attach_file' interface */ - error = FT_Err_Unimplemented_Feature; + error = FT_ERR( Unimplemented_Feature ); clazz = driver->clazz; if ( clazz->attach_file ) error = clazz->attach_file( face, stream ); @@ -2334,7 +2362,7 @@ FT_ListNode node; - error = FT_Err_Invalid_Face_Handle; + error = FT_ERR( Invalid_Face_Handle ); if ( face && face->driver ) { face->internal->refcount--; @@ -2380,13 +2408,13 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( !asize ) - return FT_Err_Invalid_Size_Handle; + return FT_THROW( Invalid_Size_Handle ); if ( !face->driver ) - return FT_Err_Invalid_Driver_Handle; + return FT_THROW( Invalid_Driver_Handle ); *asize = 0; @@ -2438,15 +2466,15 @@ if ( !size ) - return FT_Err_Invalid_Size_Handle; + return FT_THROW( Invalid_Size_Handle ); face = size->face; if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); driver = face->driver; if ( !driver ) - return FT_Err_Invalid_Driver_Handle; + return FT_THROW( Invalid_Driver_Handle ); memory = driver->root.memory; @@ -2467,7 +2495,7 @@ destroy_size( memory, size, driver ); } else - error = FT_Err_Invalid_Size_Handle; + error = FT_THROW( Invalid_Size_Handle ); return error; } @@ -2486,11 +2514,11 @@ if ( !FT_HAS_FIXED_SIZES( face ) ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); /* FT_Bitmap_Size doesn't provide enough info... */ if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL ) - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); w = FT_REQUEST_WIDTH ( req ); h = FT_REQUEST_HEIGHT( req ); @@ -2513,6 +2541,8 @@ if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width ) { + FT_TRACE3(( "FT_Match_Size: bitmap strike %d matches\n", i )); + if ( size_index ) *size_index = (FT_ULong)i; @@ -2520,7 +2550,7 @@ } } - return FT_Err_Invalid_Pixel_Size; + return FT_THROW( Invalid_Pixel_Size ); } @@ -2763,10 +2793,10 @@ if ( !face || !FT_HAS_FIXED_SIZES( face ) ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( strike_index < 0 || strike_index >= face->num_fixed_sizes ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); clazz = face->driver->clazz; @@ -2816,11 +2846,11 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( !req || req->width < 0 || req->height < 0 || req->type >= FT_SIZE_REQUEST_TYPE_MAX ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); clazz = face->driver->clazz; @@ -2869,9 +2899,6 @@ if ( error ) return error; - FT_TRACE3(( "FT_Request_Size: bitmap strike %lu matched\n", - strike_index )); - return FT_Select_Size( face, (FT_Int)strike_index ); } @@ -2971,10 +2998,10 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( !akerning ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); driver = face->driver; @@ -3030,14 +3057,14 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( !akerning ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); FT_FACE_FIND_SERVICE( face, service, KERNING ); if ( !service ) - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); error = service->get_track( face, point_size, @@ -3059,10 +3086,10 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); if ( encoding == FT_ENCODING_NONE ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */ /* charmap available, i.e., one with UCS-4 characters, if possible. */ @@ -3073,7 +3100,7 @@ cur = face->charmaps; if ( !cur ) - return FT_Err_Invalid_CharMap_Handle; + return FT_THROW( Invalid_CharMap_Handle ); limit = cur + face->num_charmaps; @@ -3095,7 +3122,7 @@ } } - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } @@ -3110,13 +3137,13 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); cur = face->charmaps; if ( !cur ) - return FT_Err_Invalid_CharMap_Handle; + return FT_THROW( Invalid_CharMap_Handle ); if ( FT_Get_CMap_Format( charmap ) == 14 ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); limit = cur + face->num_charmaps; @@ -3137,7 +3164,7 @@ return 0; } } - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } @@ -3176,7 +3203,7 @@ { FT_CMap_Class clazz = cmap->clazz; FT_Face face = cmap->charmap.face; - FT_Memory memory = FT_FACE_MEMORY(face); + FT_Memory memory = FT_FACE_MEMORY( face ); if ( clazz->done ) @@ -3245,7 +3272,7 @@ if ( clazz == NULL || charmap == NULL || charmap->face == NULL ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); face = charmap->face; memory = FT_FACE_MEMORY( face ); @@ -3578,7 +3605,7 @@ FT_Pointer buffer, FT_UInt buffer_max ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); /* clean up buffer */ @@ -3667,11 +3694,11 @@ if ( !face || !FT_IS_SFNT( face ) ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE ); if ( service == NULL ) - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); return service->load_table( face, tag, offset, buffer, length ); } @@ -3690,11 +3717,11 @@ if ( !face || !FT_IS_SFNT( face ) ) - return FT_Err_Invalid_Face_Handle; + return FT_THROW( Invalid_Face_Handle ); FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE ); if ( service == NULL ) - return FT_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); return service->table_info( face, table_index, tag, &offset, length ); } @@ -3757,11 +3784,11 @@ if ( size == NULL ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); face = size->face; if ( face == NULL || face->driver == NULL ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* we don't need anything more complex than that; all size objects */ /* are already listed by the face */ @@ -3953,15 +3980,15 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !renderer ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); node = FT_List_Find( &library->renderers, renderer ); if ( !node ) { - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -4019,12 +4046,12 @@ else renderer = FT_Lookup_Renderer( library, slot->format, &node ); - error = FT_Err_Unimplemented_Feature; + error = FT_ERR( Unimplemented_Feature ); while ( renderer ) { error = renderer->render( renderer, slot, render_mode, NULL ); - if ( !error || - FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph ) + if ( !error || + FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) break; /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ @@ -4044,6 +4071,47 @@ } } +#ifdef FT_DEBUG_LEVEL_TRACE + +#undef FT_COMPONENT +#define FT_COMPONENT trace_bitmap + + /* we convert to a single bitmap format for computing the checksum */ + { + FT_Bitmap bitmap; + FT_Error err; + + + FT_Bitmap_New( &bitmap ); + + err = FT_Bitmap_Convert( library, &slot->bitmap, &bitmap, 1 ); + if ( !err ) + { + MD5_CTX ctx; + unsigned char md5[16]; + int i; + + + MD5_Init( &ctx); + MD5_Update( &ctx, bitmap.buffer, bitmap.rows * bitmap.pitch ); + MD5_Final( md5, &ctx ); + + FT_TRACE3(( "MD5 checksum for %dx%d bitmap:\n" + " ", + bitmap.rows, bitmap.pitch )); + for ( i = 0; i < 16; i++ ) + FT_TRACE3(( "%02X", md5[i] )); + FT_TRACE3(( "\n" )); + } + + FT_Bitmap_Done( library, &bitmap ); + } + +#undef FT_COMPONENT +#define FT_COMPONENT trace_objs + +#endif /* FT_DEBUG_LEVEL_TRACE */ + return error; } @@ -4058,7 +4126,7 @@ if ( !slot || !slot->face ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); library = FT_FACE_LIBRARY( slot->face ); @@ -4138,14 +4206,14 @@ FREETYPE_MINOR ) if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !clazz ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* check freetype version */ if ( clazz->module_requires > FREETYPE_VER_FIXED ) - return FT_Err_Invalid_Version; + return FT_THROW( Invalid_Version ); /* look for a module with the same name in the library's table */ for ( nn = 0; nn < library->num_modules; nn++ ) @@ -4155,7 +4223,7 @@ { /* this installed module has the same name, compare their versions */ if ( clazz->module_version <= module->clazz->module_version ) - return FT_Err_Lower_Module_Version; + return FT_THROW( Lower_Module_Version ); /* remove the module from our list, then exit the loop to replace */ /* it by our new version.. */ @@ -4169,7 +4237,7 @@ if ( library->num_modules >= FT_MAX_MODULES ) { - error = FT_Err_Too_Many_Drivers; + error = FT_THROW( Too_Many_Drivers ); goto Exit; } @@ -4301,19 +4369,18 @@ { FT_Pointer result = NULL; + if ( module ) { FT_ASSERT( module->clazz && module->clazz->get_interface ); - /* first, look for the service in the module - */ + /* first, look for the service in the module */ if ( module->clazz->get_interface ) result = module->clazz->get_interface( module, service_id ); if ( result == NULL ) { - /* we didn't find it, look in all other modules then - */ + /* we didn't find it, look in all other modules then */ FT_Library library = module->library; FT_Module* cur = library->modules; FT_Module* limit = cur + library->num_modules; @@ -4349,7 +4416,7 @@ /* try to find the module from the table, then remove it from there */ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( module ) { @@ -4378,7 +4445,119 @@ } } } - return FT_Err_Invalid_Driver_Handle; + return FT_THROW( Invalid_Driver_Handle ); + } + + + FT_Error + ft_property_do( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + void* value, + FT_Bool set ) + { + FT_Module* cur; + FT_Module* limit; + FT_Module_Interface interface; + + FT_Service_Properties service; + +#ifdef FT_DEBUG_LEVEL_ERROR + const FT_String* set_name = "FT_Property_Set"; + const FT_String* get_name = "FT_Property_Get"; + const FT_String* func_name = set ? set_name : get_name; +#endif + + FT_Bool missing_func; + + + if ( !library ) + return FT_THROW( Invalid_Library_Handle ); + + if ( !module_name || !property_name || !value ) + return FT_THROW( Invalid_Argument ); + + cur = library->modules; + limit = cur + library->num_modules; + + /* search module */ + for ( ; cur < limit; cur++ ) + if ( !ft_strcmp( cur[0]->clazz->module_name, module_name ) ) + break; + + if ( cur == limit ) + { + FT_ERROR(( "%s: can't find module `%s'\n", + func_name, module_name )); + return FT_THROW( Missing_Module ); + } + + /* check whether we have a service interface */ + if ( !cur[0]->clazz->get_interface ) + { + FT_ERROR(( "%s: module `%s' doesn't support properties\n", + func_name, module_name )); + return FT_THROW( Unimplemented_Feature ); + } + + /* search property service */ + interface = cur[0]->clazz->get_interface( cur[0], + FT_SERVICE_ID_PROPERTIES ); + if ( !interface ) + { + FT_ERROR(( "%s: module `%s' doesn't support properties\n", + func_name, module_name )); + return FT_THROW( Unimplemented_Feature ); + } + + service = (FT_Service_Properties)interface; + + if ( set ) + missing_func = !service->set_property; + else + missing_func = !service->get_property; + + if ( missing_func ) + { + FT_ERROR(( "%s: property service of module `%s' is broken\n", + func_name, module_name )); + return FT_THROW( Unimplemented_Feature ); + } + + return set ? service->set_property( cur[0], property_name, value ) + : service->get_property( cur[0], property_name, value ); + } + + + /* documentation is in ftmodapi.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Property_Set( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + const void* value ) + { + return ft_property_do( library, + module_name, + property_name, + (void*)value, + TRUE ); + } + + + /* documentation is in ftmodapi.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Property_Get( FT_Library library, + const FT_String* module_name, + const FT_String* property_name, + void* value ) + { + return ft_property_do( library, + module_name, + property_name, + value, + FALSE ); } @@ -4417,7 +4596,7 @@ if ( !memory ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); #ifdef FT_DEBUG_LEVEL_ERROR /* init debugging support */ @@ -4504,7 +4683,7 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); library->refcount--; if ( library->refcount > 0 ) @@ -4651,70 +4830,6 @@ } -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS - - FT_BASE_DEF( FT_Error ) - ft_stub_set_char_sizes( FT_Size size, - FT_F26Dot6 width, - FT_F26Dot6 height, - FT_UInt horz_res, - FT_UInt vert_res ) - { - FT_Size_RequestRec req; - FT_Driver driver = size->face->driver; - - - if ( driver->clazz->request_size ) - { - req.type = FT_SIZE_REQUEST_TYPE_NOMINAL; - req.width = width; - req.height = height; - - if ( horz_res == 0 ) - horz_res = vert_res; - - if ( vert_res == 0 ) - vert_res = horz_res; - - if ( horz_res == 0 ) - horz_res = vert_res = 72; - - req.horiResolution = horz_res; - req.vertResolution = vert_res; - - return driver->clazz->request_size( size, &req ); - } - - return 0; - } - - - FT_BASE_DEF( FT_Error ) - ft_stub_set_pixel_sizes( FT_Size size, - FT_UInt width, - FT_UInt height ) - { - FT_Size_RequestRec req; - FT_Driver driver = size->face->driver; - - - if ( driver->clazz->request_size ) - { - req.type = FT_SIZE_REQUEST_TYPE_NOMINAL; - req.width = width << 6; - req.height = height << 6; - req.horiResolution = 0; - req.vertResolution = 0; - - return driver->clazz->request_size( size, &req ); - } - - return 0; - } - -#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ - - /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) @@ -4726,7 +4841,7 @@ FT_Int *p_arg2, FT_Matrix *p_transform ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); if ( glyph && diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c index 9ae276d..54ca5cd 100644 --- a/src/base/ftoutln.c +++ b/src/base/ftoutln.c @@ -4,7 +4,7 @@ /* */ /* FreeType outline management (body). */ /* */ -/* Copyright 1996-2008, 2010, 2012 by */ +/* Copyright 1996-2008, 2010, 2012-2013 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_CALC_H #include FT_INTERNAL_DEBUG_H #include FT_TRIGONOMETRY_H @@ -73,7 +74,7 @@ if ( !outline || !func_interface ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); shift = func_interface->shift; delta = func_interface->delta; @@ -286,7 +287,7 @@ return error; Invalid_Outline: - return FT_Err_Invalid_Outline; + return FT_THROW( Invalid_Outline ); } @@ -300,10 +301,17 @@ if ( !anoutline || !memory ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); *anoutline = null_outline; + if ( numContours < 0 || + (FT_UInt)numContours > numPoints ) + return FT_THROW( Invalid_Argument ); + + if ( numPoints > FT_OUTLINE_POINTS_MAX ) + return FT_THROW( Array_Too_Large ); + if ( FT_NEW_ARRAY( anoutline->points, numPoints ) || FT_NEW_ARRAY( anoutline->tags, numPoints ) || FT_NEW_ARRAY( anoutline->contours, numContours ) ) @@ -332,7 +340,7 @@ FT_Outline *anoutline ) { if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); return FT_Outline_New_Internal( library->memory, numPoints, numContours, anoutline ); @@ -380,7 +388,7 @@ } Bad: - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } @@ -396,7 +404,7 @@ if ( !source || !target || source->n_points != target->n_points || source->n_contours != target->n_contours ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( source == target ) return FT_Err_Ok; @@ -435,7 +443,7 @@ return FT_Err_Ok; } else - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } @@ -448,7 +456,7 @@ /* check for valid `outline' in FT_Outline_Done_Internal() */ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); return FT_Outline_Done_Internal( library->memory, outline ); } @@ -602,21 +610,21 @@ if ( !library ) - return FT_Err_Invalid_Library_Handle; + return FT_THROW( Invalid_Library_Handle ); if ( !outline || !params ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); renderer = library->cur_renderer; node = library->renderers.head; params->source = (void*)outline; - error = FT_Err_Cannot_Render_Glyph; + error = FT_ERR( Cannot_Render_Glyph ); while ( renderer ) { error = renderer->raster_render( renderer->raster, params ); - if ( !error || FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph ) + if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) ) break; /* FT_Err_Cannot_Render_Glyph is returned if the render mode */ @@ -650,7 +658,7 @@ if ( !abitmap ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); /* other checks are delayed to FT_Outline_Render() */ @@ -881,86 +889,127 @@ FT_EXPORT_DEF( FT_Error ) FT_Outline_Embolden( FT_Outline* outline, FT_Pos strength ) + { + return FT_Outline_EmboldenXY( outline, strength, strength ); + } + + + /* documentation is in ftoutln.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Outline_EmboldenXY( FT_Outline* outline, + FT_Pos xstrength, + FT_Pos ystrength ) { FT_Vector* points; FT_Vector v_prev, v_first, v_next, v_cur; - FT_Angle rotate, angle_in, angle_out; FT_Int c, n, first; FT_Int orientation; if ( !outline ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); - strength /= 2; - if ( strength == 0 ) + xstrength /= 2; + ystrength /= 2; + if ( xstrength == 0 && ystrength == 0 ) return FT_Err_Ok; orientation = FT_Outline_Get_Orientation( outline ); if ( orientation == FT_ORIENTATION_NONE ) { if ( outline->n_contours ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); else return FT_Err_Ok; } - if ( orientation == FT_ORIENTATION_TRUETYPE ) - rotate = -FT_ANGLE_PI2; - else - rotate = FT_ANGLE_PI2; - points = outline->points; first = 0; for ( c = 0; c < outline->n_contours; c++ ) { - int last = outline->contours[c]; + FT_Vector in, out, shift; + FT_Fixed l_in, l_out, l, q, d; + int last = outline->contours[c]; v_first = points[first]; v_prev = points[last]; v_cur = v_first; - for ( n = first; n <= last; n++ ) + /* compute incoming normalized vector */ + in.x = v_cur.x - v_prev.x; + in.y = v_cur.y - v_prev.y; + l_in = FT_Vector_Length( &in ); + if ( l_in ) { - FT_Vector in, out; - FT_Angle angle_diff; - FT_Pos d; - FT_Fixed scale; - + in.x = FT_DivFix( in.x, l_in ); + in.y = FT_DivFix( in.y, l_in ); + } + for ( n = first; n <= last; n++ ) + { if ( n < last ) v_next = points[n + 1]; else v_next = v_first; - /* compute the in and out vectors */ - in.x = v_cur.x - v_prev.x; - in.y = v_cur.y - v_prev.y; - + /* compute outgoing normalized vector */ out.x = v_next.x - v_cur.x; out.y = v_next.y - v_cur.y; + l_out = FT_Vector_Length( &out ); + if ( l_out ) + { + out.x = FT_DivFix( out.x, l_out ); + out.y = FT_DivFix( out.y, l_out ); + } - angle_in = FT_Atan2( in.x, in.y ); - angle_out = FT_Atan2( out.x, out.y ); - angle_diff = FT_Angle_Diff( angle_in, angle_out ); - scale = FT_Cos( angle_diff / 2 ); + d = FT_MulFix( in.x, out.x ) + FT_MulFix( in.y, out.y ); - if ( scale < 0x4000L && scale > -0x4000L ) - in.x = in.y = 0; - else + /* shift only if turn is less than ~160 degrees */ + if ( d > -0xF000L ) { - d = FT_DivFix( strength, scale ); + d = d + 0x10000L; - FT_Vector_From_Polar( &in, d, angle_in + angle_diff / 2 - rotate ); + /* shift components are aligned along lateral bisector */ + /* and directed according to the outline orientation. */ + shift.x = in.y + out.y; + shift.y = in.x + out.x; + + if ( orientation == FT_ORIENTATION_TRUETYPE ) + shift.x = -shift.x; + else + shift.y = -shift.y; + + /* restrict shift magnitude to better handle collapsing segments */ + q = FT_MulFix( out.x, in.y ) - FT_MulFix( out.y, in.x ); + if ( orientation == FT_ORIENTATION_TRUETYPE ) + q = -q; + + l = FT_MIN( l_in, l_out ); + + /* non-strict inequalities avoid divide-by-zero when q == l == 0 */ + if ( FT_MulFix( xstrength, q ) <= FT_MulFix( d, l ) ) + shift.x = FT_MulDiv( shift.x, xstrength, d ); + else + shift.x = FT_MulDiv( shift.x, l, q ); + + + if ( FT_MulFix( ystrength, q ) <= FT_MulFix( d, l ) ) + shift.y = FT_MulDiv( shift.y, ystrength, d ); + else + shift.y = FT_MulDiv( shift.y, l, q ); } + else + shift.x = shift.y = 0; - outline->points[n].x = v_cur.x + strength + in.x; - outline->points[n].y = v_cur.y + strength + in.y; + outline->points[n].x = v_cur.x + xstrength + shift.x; + outline->points[n].y = v_cur.y + ystrength + shift.y; - v_prev = v_cur; - v_cur = v_next; + in = out; + l_in = l_out; + v_cur = v_next; } first = last + 1; @@ -975,23 +1024,12 @@ FT_EXPORT_DEF( FT_Orientation ) FT_Outline_Get_Orientation( FT_Outline* outline ) { - FT_Pos xmin = 32768L; - FT_Pos xmin_ymin = 32768L; - FT_Pos xmin_ymax = -32768L; - FT_Vector* xmin_first = NULL; - FT_Vector* xmin_last = NULL; - - short* contour; - - FT_Vector* first; - FT_Vector* last; - FT_Vector* prev; - FT_Vector* point; - - int i; - FT_Pos ray_y[3]; - FT_Orientation result[3] = - { FT_ORIENTATION_NONE, FT_ORIENTATION_NONE, FT_ORIENTATION_NONE }; + FT_BBox cbox; + FT_Int xshift, yshift; + FT_Vector* points; + FT_Vector v_prev, v_cur; + FT_Int c, n, first; + FT_Pos area = 0; if ( !outline || outline->n_points <= 0 ) @@ -1002,127 +1040,41 @@ /* cubic or quadratic curves, this test deals with the polygon */ /* only which is spanned up by the control points. */ - first = outline->points; - for ( contour = outline->contours; - contour < outline->contours + outline->n_contours; - contour++, first = last + 1 ) - { - FT_Pos contour_xmin = 32768L; - FT_Pos contour_xmax = -32768L; - FT_Pos contour_ymin = 32768L; - FT_Pos contour_ymax = -32768L; - - - last = outline->points + *contour; + FT_Outline_Get_CBox( outline, &cbox ); - /* skip degenerate contours */ - if ( last < first + 2 ) - continue; - - for ( point = first; point <= last; ++point ) - { - if ( point->x < contour_xmin ) - contour_xmin = point->x; - - if ( point->x > contour_xmax ) - contour_xmax = point->x; - - if ( point->y < contour_ymin ) - contour_ymin = point->y; - - if ( point->y > contour_ymax ) - contour_ymax = point->y; - } - - if ( contour_xmin < xmin && - contour_xmin != contour_xmax && - contour_ymin != contour_ymax ) - { - xmin = contour_xmin; - xmin_ymin = contour_ymin; - xmin_ymax = contour_ymax; - xmin_first = first; - xmin_last = last; - } - } + xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14; + xshift = FT_MAX( xshift, 0 ); - if ( xmin == 32768L ) - return FT_ORIENTATION_TRUETYPE; + yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14; + yshift = FT_MAX( yshift, 0 ); - ray_y[0] = ( xmin_ymin * 3 + xmin_ymax ) >> 2; - ray_y[1] = ( xmin_ymin + xmin_ymax ) >> 1; - ray_y[2] = ( xmin_ymin + xmin_ymax * 3 ) >> 2; + points = outline->points; - for ( i = 0; i < 3; i++ ) + first = 0; + for ( c = 0; c < outline->n_contours; c++ ) { - FT_Pos left_x; - FT_Pos right_x; - FT_Vector* left1; - FT_Vector* left2; - FT_Vector* right1; - FT_Vector* right2; - + FT_Int last = outline->contours[c]; - RedoRay: - left_x = 32768L; - right_x = -32768L; - left1 = left2 = right1 = right2 = NULL; + v_prev = points[last]; - prev = xmin_last; - for ( point = xmin_first; point <= xmin_last; prev = point, ++point ) + for ( n = first; n <= last; n++ ) { - FT_Pos tmp_x; - - - if ( point->y == ray_y[i] || prev->y == ray_y[i] ) - { - ray_y[i]++; - goto RedoRay; - } - - if ( ( point->y < ray_y[i] && prev->y < ray_y[i] ) || - ( point->y > ray_y[i] && prev->y > ray_y[i] ) ) - continue; - - tmp_x = FT_MulDiv( point->x - prev->x, - ray_y[i] - prev->y, - point->y - prev->y ) + prev->x; - - if ( tmp_x < left_x ) - { - left_x = tmp_x; - left1 = prev; - left2 = point; - } - - if ( tmp_x > right_x ) - { - right_x = tmp_x; - right1 = prev; - right2 = point; - } + v_cur = points[n]; + area += ( ( v_cur.y - v_prev.y ) >> yshift ) * + ( ( v_cur.x + v_prev.x ) >> xshift ); + v_prev = v_cur; } - if ( left1 && right1 ) - { - if ( left1->y < left2->y && right1->y > right2->y ) - result[i] = FT_ORIENTATION_TRUETYPE; - else if ( left1->y > left2->y && right1->y < right2->y ) - result[i] = FT_ORIENTATION_POSTSCRIPT; - else - result[i] = FT_ORIENTATION_NONE; - } + first = last + 1; } - if ( result[0] != FT_ORIENTATION_NONE && - ( result[0] == result[1] || result[0] == result[2] ) ) - return result[0]; - - if ( result[1] != FT_ORIENTATION_NONE && result[1] == result[2] ) - return result[1]; - - return FT_ORIENTATION_TRUETYPE; + if ( area > 0 ) + return FT_ORIENTATION_POSTSCRIPT; + else if ( area < 0 ) + return FT_ORIENTATION_TRUETYPE; + else + return FT_ORIENTATION_NONE; } diff --git a/src/base/ftpic.c b/src/base/ftpic.c index b74e90d..1c87101 100644 --- a/src/base/ftpic.c +++ b/src/base/ftpic.c @@ -29,7 +29,8 @@ ft_pic_container_init( FT_Library library ) { FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error = FT_Err_Ok; + FT_Error error = FT_Err_Ok; + FT_MEM_SET( pic_container, 0, sizeof ( *pic_container ) ); diff --git a/src/base/ftrfork.c b/src/base/ftrfork.c index 01d8625..8049117 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, 2008, 2009, 2010 by */ +/* Copyright 2004-2010, 2013 by */ /* Masatake YAMATO and Redhat K.K. */ /* */ /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ @@ -86,7 +86,7 @@ /* map_len = head[12] .. head[15] */ if ( *rdata_pos + rdata_len != map_pos || map_pos == rfork_offset ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); error = FT_Stream_Seek( stream, map_pos ); if ( error ) @@ -108,7 +108,7 @@ allmatch = 0; } if ( !allzeros && !allmatch ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); /* If we have reached this point then it is probably a mac resource */ /* file. Now, does it contain any interesting resources? */ @@ -121,7 +121,7 @@ if ( FT_READ_USHORT( type_list ) ) return error; if ( type_list == -1 ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); error = FT_Stream_Seek( stream, map_pos + type_list ); if ( error ) @@ -233,7 +233,7 @@ } } - return FT_Err_Cannot_Open_Resource; + return FT_THROW( Cannot_Open_Resource ); } @@ -362,7 +362,7 @@ FT_Long *offsets, FT_Error *errors ) { - FT_Long i; + FT_Int i; for ( i = 0; i < FT_RACCESS_N_RULES; i++ ) @@ -435,7 +435,7 @@ *result_file_name = NULL; if ( NULL == stream ) - return FT_Err_Cannot_Open_Stream; + return FT_THROW( Cannot_Open_Stream ); return raccess_guess_apple_generic( library, stream, base_file_name, magic, result_offset ); @@ -457,7 +457,7 @@ *result_file_name = NULL; if ( NULL == stream ) - return FT_Err_Cannot_Open_Stream; + return FT_THROW( Cannot_Open_Stream ); return raccess_guess_apple_generic( library, stream, base_file_name, magic, result_offset ); @@ -481,7 +481,7 @@ memory = library->memory; newpath = raccess_make_file_name( memory, base_file_name, "._" ); if ( !newpath ) - return FT_Err_Out_Of_Memory; + return FT_THROW( Out_Of_Memory ); error = raccess_guess_linux_double_from_file_name( library, newpath, result_offset ); @@ -507,7 +507,7 @@ FT_Error error; char* newpath = NULL; FT_Memory memory; - FT_Long base_file_len = ft_strlen( base_file_name ); + FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name ); FT_UNUSED( stream ); @@ -515,7 +515,7 @@ memory = library->memory; if ( base_file_len + 6 > FT_INT_MAX ) - return FT_Err_Array_Too_Large; + return FT_THROW( Array_Too_Large ); if ( FT_ALLOC( newpath, base_file_len + 6 ) ) return error; @@ -543,7 +543,7 @@ FT_Error error; char* newpath = NULL; FT_Memory memory; - FT_Long base_file_len = ft_strlen( base_file_name ); + FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name ); FT_UNUSED( stream ); @@ -551,7 +551,7 @@ memory = library->memory; if ( base_file_len + 18 > FT_INT_MAX ) - return FT_Err_Array_Too_Large; + return FT_THROW( Array_Too_Large ); if ( FT_ALLOC( newpath, base_file_len + 18 ) ) return error; @@ -584,7 +584,7 @@ newpath = raccess_make_file_name( memory, base_file_name, "resource.frk/" ); if ( !newpath ) - return FT_Err_Out_Of_Memory; + return FT_THROW( Out_Of_Memory ); *result_file_name = newpath; *result_offset = 0; @@ -610,7 +610,7 @@ newpath = raccess_make_file_name( memory, base_file_name, ".resource/" ); if ( !newpath ) - return FT_Err_Out_Of_Memory; + return FT_THROW( Out_Of_Memory ); *result_file_name = newpath; *result_offset = 0; @@ -637,7 +637,7 @@ newpath = raccess_make_file_name( memory, base_file_name, "%" ); if ( !newpath ) - return FT_Err_Out_Of_Memory; + return FT_THROW( Out_Of_Memory ); error = raccess_guess_linux_double_from_file_name( library, newpath, result_offset ); @@ -669,7 +669,7 @@ newpath = raccess_make_file_name( memory, base_file_name, ".AppleDouble/" ); if ( !newpath ) - return FT_Err_Out_Of_Memory; + return FT_THROW( Out_Of_Memory ); error = raccess_guess_linux_double_from_file_name( library, newpath, result_offset ); @@ -708,7 +708,7 @@ if ( FT_READ_LONG( magic_from_stream ) ) return error; if ( magic_from_stream != magic ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); if ( FT_READ_LONG( version_number ) ) return error; @@ -721,7 +721,7 @@ if ( FT_READ_USHORT( n_of_entries ) ) return error; if ( n_of_entries == 0 ) - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); for ( i = 0; i < n_of_entries; i++ ) { @@ -744,7 +744,7 @@ } } - return FT_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); } @@ -827,7 +827,7 @@ FT_Long *offsets, FT_Error *errors ) { - int i; + FT_Int i; FT_UNUSED( library ); FT_UNUSED( stream ); @@ -838,7 +838,7 @@ { new_names[i] = NULL; offsets[i] = 0; - errors[i] = FT_Err_Unimplemented_Feature; + errors[i] = FT_ERR( Unimplemented_Feature ); } } diff --git a/src/base/ftsnames.c b/src/base/ftsnames.c index 3447888..260e91c 100644 --- a/src/base/ftsnames.c +++ b/src/base/ftsnames.c @@ -44,7 +44,7 @@ FT_UInt idx, FT_SfntName *aname ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); if ( aname && face && FT_IS_SFNT( face ) ) diff --git a/src/base/ftstream.c b/src/base/ftstream.c index fc2868e..d965333 100644 --- a/src/base/ftstream.c +++ b/src/base/ftstream.c @@ -4,7 +4,7 @@ /* */ /* I/O stream support (body). */ /* */ -/* Copyright 2000-2002, 2004-2006, 2008-2011 by */ +/* Copyright 2000-2002, 2004-2006, 2008-2011, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -68,7 +68,7 @@ " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); } } /* note that seeking to the first position after the file is valid */ @@ -78,7 +78,7 @@ " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); } if ( !error ) @@ -93,7 +93,7 @@ FT_Long distance ) { if ( distance < 0 ) - return FT_Err_Invalid_Stream_Operation; + return FT_THROW( Invalid_Stream_Operation ); return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); } @@ -131,7 +131,7 @@ " invalid i/o; pos = 0x%lx, size = 0x%lx\n", pos, stream->size )); - return FT_Err_Invalid_Stream_Operation; + return FT_THROW( Invalid_Stream_Operation ); } if ( stream->read ) @@ -153,7 +153,7 @@ " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); } return error; @@ -254,7 +254,7 @@ " frame size (%lu) larger than stream size (%lu)\n", count, stream->size )); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); goto Exit; } @@ -277,7 +277,7 @@ count, read_bytes )); FT_FREE( stream->base ); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); } stream->cursor = stream->base; stream->limit = stream->cursor + count; @@ -293,7 +293,7 @@ " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", stream->pos, count, stream->size )); - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); goto Exit; } @@ -474,7 +474,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadChar:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -521,7 +521,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadUShort:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -568,7 +568,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadUShortLE:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -615,7 +615,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadUOffset:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -662,7 +662,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadULong:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -709,7 +709,7 @@ return result; Fail: - *error = FT_Err_Invalid_Stream_Operation; + *error = FT_THROW( Invalid_Stream_Operation ); FT_ERROR(( "FT_Stream_ReadULongLE:" " invalid i/o; pos = 0x%lx, size = 0x%lx\n", stream->pos, stream->size )); @@ -727,8 +727,9 @@ FT_Bool frame_accessed = 0; FT_Byte* cursor; + if ( !fields || !stream ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); cursor = stream->cursor; @@ -760,7 +761,7 @@ if ( cursor + len > stream->limit ) { - error = FT_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); goto Exit; } @@ -776,43 +777,43 @@ case ft_frame_byte: case ft_frame_schar: /* read a single byte */ - value = FT_NEXT_BYTE(cursor); + value = FT_NEXT_BYTE( cursor ); sign_shift = 24; break; case ft_frame_short_be: case ft_frame_ushort_be: /* read a 2-byte big-endian short */ - value = FT_NEXT_USHORT(cursor); + value = FT_NEXT_USHORT( cursor) ; sign_shift = 16; break; case ft_frame_short_le: case ft_frame_ushort_le: /* read a 2-byte little-endian short */ - value = FT_NEXT_USHORT_LE(cursor); + value = FT_NEXT_USHORT_LE( cursor ); sign_shift = 16; break; case ft_frame_long_be: case ft_frame_ulong_be: /* read a 4-byte big-endian long */ - value = FT_NEXT_ULONG(cursor); + value = FT_NEXT_ULONG( cursor ); sign_shift = 0; break; case ft_frame_long_le: case ft_frame_ulong_le: /* read a 4-byte little-endian long */ - value = FT_NEXT_ULONG_LE(cursor); + value = FT_NEXT_ULONG_LE( cursor ); sign_shift = 0; break; case ft_frame_off3_be: case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ - value = FT_NEXT_UOFF3(cursor); + value = FT_NEXT_UOFF3( cursor ); sign_shift = 8; break; case ft_frame_off3_le: case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ - value = FT_NEXT_UOFF3_LE(cursor); + value = FT_NEXT_UOFF3_LE( cursor ); sign_shift = 8; break; @@ -831,15 +832,15 @@ p = (FT_Byte*)structure + fields->offset; switch ( fields->size ) { - case (8 / FT_CHAR_BIT): + case ( 8 / FT_CHAR_BIT ): *(FT_Byte*)p = (FT_Byte)value; break; - case (16 / FT_CHAR_BIT): + case ( 16 / FT_CHAR_BIT ): *(FT_UShort*)p = (FT_UShort)value; break; - case (32 / FT_CHAR_BIT): + case ( 32 / FT_CHAR_BIT ): *(FT_UInt32*)p = (FT_UInt32)value; break; diff --git a/src/base/ftstroke.c b/src/base/ftstroke.c index 5399efe..ee61cec 100644 --- a/src/base/ftstroke.c +++ b/src/base/ftstroke.c @@ -4,7 +4,7 @@ /* */ /* FreeType path stroker (body). */ /* */ -/* Copyright 2002-2006, 2008-2011 by */ +/* Copyright 2002-2006, 2008-2011, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -789,13 +789,13 @@ FT_Stroker_New( FT_Library library, FT_Stroker *astroker ) { - FT_Error error; + FT_Error error; /* assigned in FT_NEW */ FT_Memory memory; FT_Stroker stroker = NULL; if ( !library ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); memory = library->memory; @@ -1126,9 +1126,8 @@ middle.y += stroker->center.y; /* compute first angle point */ - length = FT_MulFix( radius, - FT_DivFix( 0x10000L - sigma, - ft_pos_abs( FT_Sin( theta ) ) ) ); + length = FT_MulDiv( radius, 0x10000L - sigma, + ft_pos_abs( FT_Sin( theta ) ) ); FT_Vector_From_Polar( &delta, length, phi + rotate ); delta.x += middle.x; @@ -1495,7 +1494,7 @@ sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) ); sinB = ft_pos_abs( FT_Sin( beta - gamma ) ); - alen = FT_DivFix( FT_MulFix( blen, sinA ), sinB ); + alen = FT_MulDiv( blen, sinA, sinB ); FT_Vector_From_Polar( &delta, alen, beta ); delta.x += start.x; @@ -1702,7 +1701,7 @@ sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) ); sinB = ft_pos_abs( FT_Sin( beta - gamma ) ); - alen = FT_DivFix( FT_MulFix( blen, sinA ), sinB ); + alen = FT_MulDiv( blen, sinA, sinB ); FT_Vector_From_Polar( &delta, alen, beta ); delta.x += start.x; @@ -1955,7 +1954,7 @@ if ( !stroker || border > 1 ) { - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -2061,7 +2060,7 @@ if ( !outline || !stroker ) - return FT_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); FT_Stroker_Rewind( stroker ); @@ -2239,7 +2238,7 @@ return error; Invalid_Outline: - return FT_Err_Invalid_Outline; + return FT_THROW( Invalid_Outline ); } @@ -2259,7 +2258,7 @@ FT_Stroker stroker, FT_Bool destroy ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); FT_Glyph glyph = NULL; FT_Library library = stroker->library; @@ -2335,7 +2334,7 @@ FT_Bool inside, FT_Bool destroy ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); FT_Glyph glyph = NULL; FT_Library library = stroker->library; diff --git a/src/base/ftsynth.c b/src/base/ftsynth.c index d4ec0da..241d37f 100644 --- a/src/base/ftsynth.c +++ b/src/base/ftsynth.c @@ -4,7 +4,7 @@ /* */ /* FreeType synthesizing code for emboldening and slanting (body). */ /* */ -/* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2010 by */ +/* Copyright 2000-2006, 2010, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -33,6 +33,7 @@ #undef FT_COMPONENT #define FT_COMPONENT trace_synth + /*************************************************************************/ /*************************************************************************/ /**** ****/ @@ -62,7 +63,7 @@ transform.xx = 0x10000L; transform.yx = 0x00000L; - transform.xy = 0x06000L; + transform.xy = 0x0366AL; transform.yy = 0x10000L; FT_Outline_Transform( outline, &transform ); @@ -72,7 +73,7 @@ /*************************************************************************/ /*************************************************************************/ /**** ****/ - /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/ + /**** EXPERIMENTAL EMBOLDENING SUPPORT ****/ /**** ****/ /*************************************************************************/ /*************************************************************************/ @@ -101,12 +102,7 @@ if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) { /* ignore error */ - (void)FT_Outline_Embolden( &slot->outline, xstr ); - - /* this is more than enough for most glyphs; if you need accurate */ - /* values, you have to call FT_Outline_Get_CBox */ - xstr = xstr * 2; - ystr = xstr; + (void)FT_Outline_EmboldenXY( &slot->outline, xstr, ystr ); } else /* slot->format == FT_GLYPH_FORMAT_BITMAP */ { @@ -143,13 +139,10 @@ if ( slot->advance.y ) slot->advance.y += ystr; - slot->metrics.width += xstr; - slot->metrics.height += ystr; - slot->metrics.horiBearingY += ystr; - slot->metrics.horiAdvance += xstr; - slot->metrics.vertBearingX -= xstr / 2; - slot->metrics.vertBearingY += ystr; - slot->metrics.vertAdvance += ystr; + slot->metrics.width += xstr; + slot->metrics.height += ystr; + slot->metrics.horiAdvance += xstr; + slot->metrics.vertAdvance += ystr; /* XXX: 16-bit overflow case must be excluded before here */ if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c index 7e203be..2c6ddac 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-2002, 2006, 2008-2011 by */ +/* Copyright 1996-2002, 2006, 2008-2011, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -228,7 +228,7 @@ if ( !stream ) - return FT_Err_Invalid_Stream_Handle; + return FT_THROW( Invalid_Stream_Handle ); stream->descriptor.pointer = NULL; stream->pathname.pointer = (char*)filepathname; @@ -243,7 +243,7 @@ FT_ERROR(( "FT_Stream_Open:" " could not open `%s'\n", filepathname )); - return FT_Err_Cannot_Open_Resource; + return FT_THROW( Cannot_Open_Resource ); } ft_fseek( file, 0, SEEK_END ); @@ -253,7 +253,7 @@ FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); ft_fclose( file ); - return FT_Err_Cannot_Open_Stream; + return FT_THROW( Cannot_Open_Stream ); } ft_fseek( file, 0, SEEK_SET ); diff --git a/src/base/fttrigon.c b/src/base/fttrigon.c index fdf433a..4ffdcb7 100644 --- a/src/base/fttrigon.c +++ b/src/base/fttrigon.c @@ -4,7 +4,7 @@ /* */ /* FreeType trigonometric functions (body). */ /* */ -/* Copyright 2001, 2002, 2003, 2004, 2005 by */ +/* Copyright 2001-2005, 2012-2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -15,31 +15,46 @@ /* */ /***************************************************************************/ + /*************************************************************************/ + /* */ + /* This is a fixed-point CORDIC implementation of trigonometric */ + /* functions as well as transformations between Cartesian and polar */ + /* coordinates. The angles are represented as 16.16 fixed-point values */ + /* in degrees, i.e., the angular resolution is 2^-16 degrees. Note that */ + /* only vectors longer than 2^16*180/pi (or at least 22 bits) on a */ + /* discrete Cartesian grid can have the same or better angular */ + /* resolution. Therefore, to maintain this precision, some functions */ + /* require an interim upscaling of the vectors, whereas others operate */ + /* with 24-bit long vectors directly. */ + /* */ + /*************************************************************************/ #include #include FT_INTERNAL_OBJECTS_H +#include FT_INTERNAL_CALC_H #include FT_TRIGONOMETRY_H - /* the following is 0.2715717684432231 * 2^30 */ -#define FT_TRIG_COSCALE 0x11616E8EUL + /* the Cordic shrink factor 0.858785336480436 * 2^32 */ +#define FT_TRIG_SCALE 0xDBD95B16UL + + /* the highest bit in overflow-safe vector components, */ + /* MSB of 0.858785336480436 * sqrt(0.5) * 2^30 */ +#define FT_TRIG_SAFE_MSB 29 /* this table was generated for FT_PI = 180L << 16, i.e. degrees */ #define FT_TRIG_MAX_ITERS 23 static const FT_Fixed - ft_trig_arctan_table[24] = + ft_trig_arctan_table[] = { - 4157273L, 2949120L, 1740967L, 919879L, 466945L, 234379L, 117304L, - 58666L, 29335L, 14668L, 7334L, 3667L, 1833L, 917L, 458L, 229L, 115L, + 1740967L, 919879L, 466945L, 234379L, 117304L, 58666L, 29335L, + 14668L, 7334L, 3667L, 1833L, 917L, 458L, 229L, 115L, 57L, 29L, 14L, 7L, 4L, 2L, 1L }; - /* the Cordic shrink factor, multiplied by 2^32 */ -#define FT_TRIG_SCALE 1166391785UL /* 0x4585BA38UL */ - -#ifdef FT_CONFIG_HAS_INT64 +#ifdef FT_LONG64 /* multiply a given value by the CORDIC shrink factor */ static FT_Fixed @@ -50,7 +65,7 @@ s = val; - val = ( val >= 0 ) ? val : -val; + val = FT_ABS( val ); v = ( val * (FT_Int64)FT_TRIG_SCALE ) + 0x100000000UL; val = (FT_Fixed)( v >> 32 ); @@ -58,7 +73,7 @@ return ( s >= 0 ) ? val : -val; } -#else /* !FT_CONFIG_HAS_INT64 */ +#else /* !FT_LONG64 */ /* multiply a given value by the CORDIC shrink factor */ static FT_Fixed @@ -69,19 +84,19 @@ s = val; - val = ( val >= 0 ) ? val : -val; + val = FT_ABS( val ); v1 = (FT_UInt32)val >> 16; - v2 = (FT_UInt32)(val & 0xFFFFL); + v2 = (FT_UInt32)( val & 0xFFFFL ); - k1 = (FT_UInt32)FT_TRIG_SCALE >> 16; /* constant */ - k2 = (FT_UInt32)(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 */ lo2 = ( k2 * v2 ) >> 16; - lo3 = ( lo1 >= lo2 ) ? lo1 : lo2; + lo3 = FT_MAX( lo1, lo2 ); lo1 += lo2; hi += lo1 >> 16; @@ -93,91 +108,35 @@ return ( s >= 0 ) ? val : -val; } -#endif /* !FT_CONFIG_HAS_INT64 */ +#endif /* !FT_LONG64 */ static FT_Int ft_trig_prenorm( FT_Vector* vec ) { - FT_Fixed x, y, z; - FT_Int shift; + FT_Pos x, y; + FT_Int shift; x = vec->x; y = vec->y; - z = ( ( x >= 0 ) ? x : - x ) | ( (y >= 0) ? y : -y ); - shift = 0; + shift = FT_MSB( FT_ABS( x ) | FT_ABS( y ) ); -#if 1 - /* determine msb bit index in `shift' */ - if ( z >= ( 1L << 16 ) ) - { - z >>= 16; - shift += 16; - } - if ( z >= ( 1L << 8 ) ) - { - z >>= 8; - shift += 8; - } - if ( z >= ( 1L << 4 ) ) - { - z >>= 4; - shift += 4; - } - if ( z >= ( 1L << 2 ) ) + if ( shift <= FT_TRIG_SAFE_MSB ) { - z >>= 2; - shift += 2; - } - if ( z >= ( 1L << 1 ) ) - { - z >>= 1; - shift += 1; - } - - if ( shift <= 27 ) - { - shift = 27 - shift; - vec->x = x << shift; - vec->y = y << shift; + shift = FT_TRIG_SAFE_MSB - shift; + vec->x = (FT_Pos)( (FT_ULong)x << shift ); + vec->y = (FT_Pos)( (FT_ULong)y << shift ); } else { - shift -= 27; - vec->x = x >> shift; - vec->y = y >> shift; - shift = -shift; - } - -#else /* 0 */ - - if ( z < ( 1L << 27 ) ) - { - do - { - shift++; - z <<= 1; - } while ( z < ( 1L << 27 ) ); - vec->x = x << shift; - vec->y = y << shift; - } - else if ( z > ( 1L << 28 ) ) - { - do - { - shift++; - z >>= 1; - } while ( z > ( 1L << 28 ) ); - + shift -= FT_TRIG_SAFE_MSB; vec->x = x >> shift; vec->y = y >> shift; shift = -shift; } -#endif /* 0 */ - return shift; } @@ -187,65 +146,50 @@ FT_Angle theta ) { FT_Int i; - FT_Fixed x, y, xtemp; + FT_Fixed x, y, xtemp, b; const FT_Fixed *arctanptr; x = vec->x; y = vec->y; - /* Get angle between -90 and 90 degrees */ - while ( theta <= -FT_ANGLE_PI2 ) + /* Rotate inside [-PI/4,PI/4] sector */ + while ( theta < -FT_ANGLE_PI4 ) { - x = -x; - y = -y; - theta += FT_ANGLE_PI; + xtemp = y; + y = -x; + x = xtemp; + theta += FT_ANGLE_PI2; } - while ( theta > FT_ANGLE_PI2 ) + while ( theta > FT_ANGLE_PI4 ) { - x = -x; - y = -y; - theta -= FT_ANGLE_PI; + xtemp = -y; + y = x; + x = xtemp; + theta -= FT_ANGLE_PI2; } - /* Initial pseudorotation, with left shift */ arctanptr = ft_trig_arctan_table; - if ( theta < 0 ) - { - xtemp = x + ( y << 1 ); - y = y - ( x << 1 ); - x = xtemp; - theta += *arctanptr++; - } - else - { - xtemp = x - ( y << 1 ); - y = y + ( x << 1 ); - x = xtemp; - theta -= *arctanptr++; - } - - /* Subsequent pseudorotations, with right shifts */ - i = 0; - do + /* Pseudorotations, with right shifts */ + for ( i = 1, b = 1; i < FT_TRIG_MAX_ITERS; b <<= 1, i++ ) { if ( theta < 0 ) { - xtemp = x + ( y >> i ); - y = y - ( x >> i ); + xtemp = x + ( ( y + b ) >> i ); + y = y - ( ( x + b ) >> i ); x = xtemp; theta += *arctanptr++; } else { - xtemp = x - ( y >> i ); - y = y + ( x >> i ); + xtemp = x - ( ( y + b ) >> i ); + y = y + ( ( x + b ) >> i ); x = xtemp; theta -= *arctanptr++; } - } while ( ++i < FT_TRIG_MAX_ITERS ); + } vec->x = x; vec->y = y; @@ -255,66 +199,67 @@ static void ft_trig_pseudo_polarize( FT_Vector* vec ) { - FT_Fixed theta; - FT_Fixed yi, i; - FT_Fixed x, y; + FT_Angle theta; + FT_Int i; + FT_Fixed x, y, xtemp, b; const FT_Fixed *arctanptr; x = vec->x; y = vec->y; - /* Get the vector into the right half plane */ - theta = 0; - if ( x < 0 ) + /* Get the vector into [-PI/4,PI/4] sector */ + if ( y > x ) { - x = -x; - y = -y; - theta = 2 * FT_ANGLE_PI2; - } - - if ( y > 0 ) - theta = - theta; - - arctanptr = ft_trig_arctan_table; - - if ( y < 0 ) - { - /* Rotate positive */ - yi = y + ( x << 1 ); - x = x - ( y << 1 ); - y = yi; - theta -= *arctanptr++; /* Subtract angle */ + if ( y > -x ) + { + theta = FT_ANGLE_PI2; + xtemp = y; + y = -x; + x = xtemp; + } + else + { + theta = y > 0 ? FT_ANGLE_PI : -FT_ANGLE_PI; + x = -x; + y = -y; + } } else { - /* Rotate negative */ - yi = y - ( x << 1 ); - x = x + ( y << 1 ); - y = yi; - theta += *arctanptr++; /* Add angle */ + if ( y < -x ) + { + theta = -FT_ANGLE_PI2; + xtemp = -y; + y = x; + x = xtemp; + } + else + { + theta = 0; + } } - i = 0; - do + arctanptr = ft_trig_arctan_table; + + /* Pseudorotations, with right shifts */ + for ( i = 1, b = 1; i < FT_TRIG_MAX_ITERS; b <<= 1, i++ ) { - if ( y < 0 ) + if ( y > 0 ) { - /* Rotate positive */ - yi = y + ( x >> i ); - x = x - ( y >> i ); - y = yi; - theta -= *arctanptr++; + xtemp = x + ( ( y + b ) >> i ); + y = y - ( ( x + b ) >> i ); + x = xtemp; + theta += *arctanptr++; } else { - /* Rotate negative */ - yi = y - ( x >> i ); - x = x + ( y >> i ); - y = yi; - theta += *arctanptr++; + xtemp = x - ( ( y + b ) >> i ); + y = y + ( ( x + b ) >> i ); + x = xtemp; + theta -= *arctanptr++; } - } while ( ++i < FT_TRIG_MAX_ITERS ); + } /* round theta */ if ( theta >= 0 ) @@ -335,11 +280,11 @@ FT_Vector v; - v.x = FT_TRIG_COSCALE >> 2; + v.x = FT_TRIG_SCALE >> 8; v.y = 0; ft_trig_pseudo_rotate( &v, angle ); - return v.x / ( 1 << 12 ); + return ( v.x + 0x80L ) >> 8; } @@ -360,7 +305,7 @@ FT_Vector v; - v.x = FT_TRIG_COSCALE >> 2; + v.x = FT_TRIG_SCALE >> 8; v.y = 0; ft_trig_pseudo_rotate( &v, angle ); @@ -395,11 +340,11 @@ FT_Vector_Unit( FT_Vector* vec, FT_Angle angle ) { - vec->x = FT_TRIG_COSCALE >> 2; + vec->x = FT_TRIG_SCALE >> 8; vec->y = 0; ft_trig_pseudo_rotate( vec, angle ); - vec->x >>= 12; - vec->y >>= 12; + vec->x = ( vec->x + 0x80L ) >> 8; + vec->y = ( vec->y + 0x80L ) >> 8; } @@ -442,8 +387,8 @@ else { shift = -shift; - vec->x = v.x << shift; - vec->y = v.y << shift; + vec->x = (FT_Pos)( (FT_ULong)v.x << shift ); + vec->y = (FT_Pos)( (FT_ULong)v.y << shift ); } } } @@ -463,11 +408,11 @@ /* handle trivial cases */ if ( v.x == 0 ) { - return ( v.y >= 0 ) ? v.y : -v.y; + return FT_ABS( v.y ); } else if ( v.y == 0 ) { - return ( v.x >= 0 ) ? v.x : -v.x; + return FT_ABS( v.x ); } /* general case */ @@ -479,7 +424,7 @@ if ( shift > 0 ) return ( v.x + ( 1 << ( shift - 1 ) ) ) >> shift; - return v.x << -shift; + return (FT_Fixed)( (FT_UInt32)v.x << -shift ); } @@ -504,7 +449,8 @@ v.x = ft_trig_downscale( v.x ); - *length = ( shift >= 0 ) ? ( v.x >> shift ) : ( v.x << -shift ); + *length = ( shift >= 0 ) ? ( v.x >> shift ) + : (FT_Fixed)( (FT_UInt32)v.x << -shift ); *angle = v.y; } diff --git a/src/base/fttype1.c b/src/base/fttype1.c index c30124f..1d17402 100644 --- a/src/base/fttype1.c +++ b/src/base/fttype1.c @@ -28,7 +28,7 @@ FT_Get_PS_Font_Info( FT_Face face, PS_FontInfoRec* afont_info ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); if ( face ) @@ -73,7 +73,7 @@ FT_Get_PS_Font_Private( FT_Face face, PS_PrivateRec* afont_private ) { - FT_Error error = FT_Err_Invalid_Argument; + FT_Error error = FT_ERR( Invalid_Argument ); if ( face ) diff --git a/src/base/ftutil.c b/src/base/ftutil.c index 5f77be5..879d027 100644 --- a/src/base/ftutil.c +++ b/src/base/ftutil.c @@ -4,7 +4,7 @@ /* */ /* FreeType utility file for memory and list management (body). */ /* */ -/* Copyright 2002, 2004, 2005, 2006, 2007 by */ +/* Copyright 2002, 2004-2007, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -75,12 +75,12 @@ { block = memory->alloc( memory, size ); if ( block == NULL ) - error = FT_Err_Out_Of_Memory; + error = FT_THROW( Out_Of_Memory ); } else if ( size < 0 ) { /* may help catch/prevent security issues */ - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); } *p_error = error; @@ -98,6 +98,7 @@ { FT_Error error = FT_Err_Ok; + block = ft_mem_qrealloc( memory, item_size, cur_count, new_count, block, &error ); if ( !error && new_count > cur_count ) @@ -127,7 +128,7 @@ if ( cur_count < 0 || new_count < 0 || item_size < 0 ) { /* may help catch/prevent nasty security issues */ - error = FT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); } else if ( new_count == 0 || item_size == 0 ) { @@ -136,7 +137,7 @@ } else if ( new_count > FT_INT_MAX/item_size ) { - error = FT_Err_Array_Too_Large; + error = FT_THROW( Array_Too_Large ); } else if ( cur_count == 0 ) { @@ -153,7 +154,7 @@ block2 = memory->realloc( memory, cur_size, new_size, block ); if ( block2 == NULL ) - error = FT_Err_Out_Of_Memory; + error = FT_THROW( Out_Of_Memory ); else block = block2; } @@ -432,70 +433,4 @@ } -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS - - FT_BASE_DEF( FT_Error ) - FT_Alloc( FT_Memory memory, - FT_Long size, - void* *P ) - { - FT_Error error; - - - (void)FT_ALLOC( *P, size ); - return error; - } - - - FT_BASE_DEF( FT_Error ) - FT_QAlloc( FT_Memory memory, - FT_Long size, - void* *p ) - { - FT_Error error; - - - (void)FT_QALLOC( *p, size ); - return error; - } - - - FT_BASE_DEF( FT_Error ) - FT_Realloc( FT_Memory memory, - FT_Long current, - FT_Long size, - void* *P ) - { - FT_Error error; - - - (void)FT_REALLOC( *P, current, size ); - return error; - } - - - FT_BASE_DEF( FT_Error ) - FT_QRealloc( FT_Memory memory, - FT_Long current, - FT_Long size, - void* *p ) - { - FT_Error error; - - - (void)FT_QREALLOC( *p, current, size ); - return error; - } - - - FT_BASE_DEF( void ) - FT_Free( FT_Memory memory, - void* *P ) - { - if ( *P ) - FT_MEM_FREE( *P ); - } - -#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ - /* END */ diff --git a/src/base/ftwinfnt.c b/src/base/ftwinfnt.c index bc2e90e..463ae76 100644 --- a/src/base/ftwinfnt.c +++ b/src/base/ftwinfnt.c @@ -32,7 +32,7 @@ FT_Error error; - error = FT_Err_Invalid_Argument; + error = FT_ERR( Invalid_Argument ); if ( face != NULL ) { diff --git a/src/base/md5.c b/src/base/md5.c new file mode 100644 index 0000000..2f01c93 --- /dev/null +++ b/src/base/md5.c @@ -0,0 +1,295 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * (This is a heavily cut-down "BSD license".) + * + * This differs from Colin Plumb's older public domain implementation in that + * no exactly 32-bit integer data type is required (any 32-bit or wider + * unsigned integer data type will do), there's no compile-time endianness + * configuration, and the function prototypes match OpenSSL's. No code from + * Colin Plumb's implementation has been reused; this comment merely compares + * the properties of the two independent implementations. + * + * The primary goals of this implementation are portability and ease of use. + * It is meant to be fast, but not as fast as possible. Some known + * optimizations are not included to reduce source code size and avoid + * compile-time configuration. + */ + +#ifndef HAVE_OPENSSL + +#include + +#include "md5.h" + +/* + * The basic MD5 functions. + * + * F and G are optimized compared to their RFC 1321 definitions for + * architectures that lack an AND-NOT instruction, just like in Colin Plumb's + * implementation. + */ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | ~(z))) + +/* + * The MD5 transformation for all four rounds. + */ +#define STEP(f, a, b, c, d, x, t, s) \ + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ + (a) += (b); + +/* + * SET reads 4 input bytes in little-endian byte order and stores them + * in a properly aligned word in host byte order. + * + * The check for little-endian architectures that tolerate unaligned + * memory accesses is just an optimization. Nothing will break if it + * doesn't work. + */ +#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) +#define SET(n) \ + (*(MD5_u32plus *)&ptr[(n) * 4]) +#define GET(n) \ + SET(n) +#else +#define SET(n) \ + (ctx->block[(n)] = \ + (MD5_u32plus)ptr[(n) * 4] | \ + ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) +#define GET(n) \ + (ctx->block[(n)]) +#endif + +/* + * This processes one or more 64-byte data blocks, but does NOT update + * the bit counters. There are no alignment requirements. + */ +static void *body(MD5_CTX *ctx, void *data, unsigned long size) +{ + unsigned char *ptr; + MD5_u32plus a, b, c, d; + MD5_u32plus saved_a, saved_b, saved_c, saved_d; + + ptr = (unsigned char *)data; + + a = ctx->a; + b = ctx->b; + c = ctx->c; + d = ctx->d; + + do { + saved_a = a; + saved_b = b; + saved_c = c; + saved_d = d; + +/* Round 1 */ + STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) + STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) + STEP(F, c, d, a, b, SET(2), 0x242070db, 17) + STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) + STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) + STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) + STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) + STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) + STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) + STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) + STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) + STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) + STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) + STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) + STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) + STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) + +/* Round 2 */ + STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) + STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) + STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) + STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) + STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) + STEP(G, d, a, b, c, GET(10), 0x02441453, 9) + STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) + STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) + STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) + STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) + STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) + STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) + STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) + STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) + STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) + STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) + +/* Round 3 */ + STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) + STEP(H, d, a, b, c, GET(8), 0x8771f681, 11) + STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) + STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23) + STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) + STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11) + STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) + STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23) + STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) + STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11) + STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) + STEP(H, b, c, d, a, GET(6), 0x04881d05, 23) + STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) + STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11) + STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) + STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23) + +/* Round 4 */ + STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) + STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) + STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) + STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) + STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) + STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) + STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) + STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) + STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) + STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) + STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) + STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) + STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) + STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) + STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) + STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) + + a += saved_a; + b += saved_b; + c += saved_c; + d += saved_d; + + ptr += 64; + } while (size -= 64); + + ctx->a = a; + ctx->b = b; + ctx->c = c; + ctx->d = d; + + return ptr; +} + +void MD5_Init(MD5_CTX *ctx) +{ + ctx->a = 0x67452301; + ctx->b = 0xefcdab89; + ctx->c = 0x98badcfe; + ctx->d = 0x10325476; + + ctx->lo = 0; + ctx->hi = 0; +} + +void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size) +{ + MD5_u32plus saved_lo; + unsigned long used, free; + + saved_lo = ctx->lo; + if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) + ctx->hi++; + ctx->hi += size >> 29; + + used = saved_lo & 0x3f; + + if (used) { + free = 64 - used; + + if (size < free) { + memcpy(&ctx->buffer[used], data, size); + return; + } + + memcpy(&ctx->buffer[used], data, free); + data = (unsigned char *)data + free; + size -= free; + body(ctx, ctx->buffer, 64); + } + + if (size >= 64) { + data = body(ctx, data, size & ~(unsigned long)0x3f); + size &= 0x3f; + } + + memcpy(ctx->buffer, data, size); +} + +void MD5_Final(unsigned char *result, MD5_CTX *ctx) +{ + unsigned long used, free; + + used = ctx->lo & 0x3f; + + ctx->buffer[used++] = 0x80; + + free = 64 - used; + + if (free < 8) { + memset(&ctx->buffer[used], 0, free); + body(ctx, ctx->buffer, 64); + used = 0; + free = 64; + } + + memset(&ctx->buffer[used], 0, free - 8); + + ctx->lo <<= 3; + ctx->buffer[56] = ctx->lo; + ctx->buffer[57] = ctx->lo >> 8; + ctx->buffer[58] = ctx->lo >> 16; + ctx->buffer[59] = ctx->lo >> 24; + ctx->buffer[60] = ctx->hi; + ctx->buffer[61] = ctx->hi >> 8; + ctx->buffer[62] = ctx->hi >> 16; + ctx->buffer[63] = ctx->hi >> 24; + + body(ctx, ctx->buffer, 64); + + result[0] = ctx->a; + result[1] = ctx->a >> 8; + result[2] = ctx->a >> 16; + result[3] = ctx->a >> 24; + result[4] = ctx->b; + result[5] = ctx->b >> 8; + result[6] = ctx->b >> 16; + result[7] = ctx->b >> 24; + result[8] = ctx->c; + result[9] = ctx->c >> 8; + result[10] = ctx->c >> 16; + result[11] = ctx->c >> 24; + result[12] = ctx->d; + result[13] = ctx->d >> 8; + result[14] = ctx->d >> 16; + result[15] = ctx->d >> 24; + + memset(ctx, 0, sizeof(*ctx)); +} + +#endif diff --git a/src/base/md5.h b/src/base/md5.h new file mode 100644 index 0000000..f1a6857 --- /dev/null +++ b/src/base/md5.h @@ -0,0 +1,45 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * See md5.c for more information. + */ + +#ifdef HAVE_OPENSSL +#include +#elif !defined(_MD5_H) +#define _MD5_H + +/* Any 32-bit or wider unsigned integer data type will do */ +typedef unsigned int MD5_u32plus; + +typedef struct { + MD5_u32plus lo, hi; + MD5_u32plus a, b, c, d; + unsigned char buffer[64]; + MD5_u32plus block[16]; +} MD5_CTX; + +extern void MD5_Init(MD5_CTX *ctx); +extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size); +extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); + +#endif -- cgit v1.2.3