From 442bfb89137086811de13b9eae9cd6390ad5c204 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Mon, 12 Feb 2007 21:44:10 +0000 Subject: [PATCH] Formatting, copyright years, s/memcpy/ft_memcpy/. --- ChangeLog | 38 ++++++++++++++-------- include/freetype/internal/ftmemory.h | 25 ++++++++------- src/base/ftutil.c | 11 ++++--- src/bdf/bdfdrivr.c | 48 +++++++++++++++------------- src/bdf/bdflib.c | 3 +- src/cff/cffobjs.c | 3 +- src/pcf/pcfread.c | 43 +++++++++++++------------ src/sfnt/sfdriver.c | 2 +- src/type1/t1driver.c | 3 +- src/type42/t42drivr.c | 3 +- 10 files changed, 101 insertions(+), 78 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9372ffbe4..d83aed1ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,21 +1,32 @@ 2007-02-12 David Turner - * src/autofit/afloader.c: improve spacing adjustments for the - non-light auto-hinted modes. Gets rid of "inter-letter spacing - is too wide" + * src/truetype/ttinterp.h, src/truetype/ttinterp.c: Simplify + projection and dual-projection code interface. - * src/truetype/ttinterp.h, src/truetype/ttinterp.c: simplify - projection and dual-projection code interface + * src/autofit/afloader.c: Improve spacing adjustments for the + non-light auto-hinted modes. Gets rid of `inter-letter spacing is + too wide' problems. - * include/freetype/internal/ftmemory.h, src/base/ftutils.c, - src/bfd/bfddrivr.c, src/bdf/bdflib.c, src/pcf/pcfread.c, - src/cff/cffdrivr.c, src/cff/cffload.c, src/cff/cffobjs.c, - src/sfnt/sfdriver.c, src/type1/t1driver.c, src/type42/t42drivr.c: - introduce ft_mem_strdup, ft_mem_dup, ft_mem_strcpyn and the - corresponding macros, and modify code to use them. This is to - get rid of various uses of strcpy and other "evil" functions, - as well as simplify a few things + Introduce new string functions and the corresponding macros to get + rid of various uses of strcpy and other `evil' functions, as well as + to simplify a few things. + + * include/freetype/internal/ftmemory.h (ft_mem_strdup, ft_mem_dup, + ft_mem_strcpyn): New declarations. + (FT_MEM_STRDUP, FT_STRDUP, FT_MEM_DUP, FT_DUP, FT_STRCPYN): New + macros. + * src/base/ftutil.c (ft_mem_dup, ft_mem_strdup, ft_mem_strcpyn): New + functions. + + * src/bfd/bfddrivr.c (bdf_interpret_style, BDF_Face_Init), + src/bdf/bdflib.c (_bdf_add_property), src/pcf/pcfread.c + (pcf_get_properties, pcf_interpret_style, pcf_load_font), + src/cff/cffdrivr.c (cff_get_glyph_name), src/cff/cffload.c + (cff_index_get_sid_string), src/cff/cffobjs.c (cff_strcpy), + src/sfnt/sfdriver.c (sfnt_get_glyph_name), src/type1/t1driver.c + (t1_get_glyph_name), src/type42/t42drivr.c (t42_get_glyph_name, + t42_get_name_index): Use new functions and simplify code. 2007-02-11 Werner Lemberg @@ -85,7 +96,6 @@ (gxv_mort_subtable_type1_substTable_validate): Fix debugging message. ->>>>>>> 1.1514 2007-01-31 Werner Lemberg diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h index f52c9d8dc..c6ddc42ea 100644 --- a/include/freetype/internal/ftmemory.h +++ b/include/freetype/internal/ftmemory.h @@ -333,26 +333,29 @@ FT_BEGIN_HEADER FT_ULong size, FT_Error *p_error ); -#define FT_MEM_STRDUP(dst,str) \ - (dst) = ft_mem_strdup( memory, (const char*)(str), &error ) +#define FT_MEM_STRDUP( dst, str ) \ + (dst) = ft_mem_strdup( memory, (const char*)(str), &error ) -#define FT_STRDUP(dst,str) \ - FT_MEM_SET_ERROR( FT_MEM_STRDUP(dst,str) ) +#define FT_STRDUP( dst, str ) \ + FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) ) -#define FT_MEM_DUP(dst, address,size) \ - (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error ) +#define FT_MEM_DUP( dst, address, size ) \ + (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error ) -#define FT_DUP(dst,address,size) \ - FT_MEM_SET_ERROR( FT_MEM_DUP(dst,address,size) ) +#define FT_DUP( dst, address, size ) \ + FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) ) - /* returns 1 or more if a trunction occured, 0 if the source string fitted the buffer */ - /* this is *not* the same than the normal strlcpy() call */ + + /* Return >= 1 if a truncation occurs. */ + /* Return 0 if the source string fits the buffer. */ + /* This is *not* the same as strlcpy(). */ FT_BASE( FT_Int ) ft_mem_strcpyn( char* dst, const char* src, FT_ULong size ); -#define FT_STRCPYN(dst,src,size) ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) ) +#define FT_STRCPYN( dst, src, size ) \ + ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) ) /* */ diff --git a/src/base/ftutil.c b/src/base/ftutil.c index eb6f6b1be..e14aea79e 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 by */ +/* Copyright 2002, 2004, 2005, 2006, 2007 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -181,7 +181,8 @@ FT_Error error; FT_Pointer p = ft_mem_qalloc( memory, size, &error ); - if (!error && address) + + if ( !error && address ) ft_memcpy( p, address, size ); *p_error = error; @@ -194,7 +195,9 @@ const char* str, FT_Error *p_error ) { - FT_ULong len = str ? (FT_ULong)ft_strlen(str)+1 : 0; + FT_ULong len = str ? (FT_ULong)ft_strlen( str ) + 1 + : 0; + return ft_mem_dup( memory, str, len, p_error ); } @@ -210,7 +213,7 @@ *dst = 0; /* always zero-terminate */ - return (*src != 0); + return *src != 0; } diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c index beaa2676b..30580c566 100644 --- a/src/bdf/bdfdrivr.c +++ b/src/bdf/bdfdrivr.c @@ -2,7 +2,7 @@ FreeType font driver for bdf files - Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 by + Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy @@ -198,6 +198,7 @@ THE SOFTWARE. char* strings[4] = { NULL, NULL, NULL, NULL }; int lengths[4]; + face->style_flags = 0; prop = bdf_get_font_property( font, (char *)"SLANT" ); @@ -225,35 +226,31 @@ THE SOFTWARE. if ( prop && prop->format == BDF_ATOM && prop->value.atom && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - { strings[3] = (char *)(prop->value.atom); - } prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" ); if ( prop && prop->format == BDF_ATOM && prop->value.atom && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - { strings[0] = (char *)(prop->value.atom); - } - len = 0; + len = 0; - for (len = 0, nn = 0; nn < 4; nn++) + for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; - if (strings[nn]) + if ( strings[nn] ) { - lengths[nn] = ft_strlen(strings[nn]); - len += lengths[nn]+1; + lengths[nn] = ft_strlen( strings[nn] ); + len += lengths[nn] + 1; } } if ( len == 0 ) { strings[0] = "Regular"; - lengths[0] = ft_strlen(strings[0]); - len = lengths[0]+1; + lengths[0] = ft_strlen( strings[0] ); + len = lengths[0] + 1; } { @@ -265,27 +262,30 @@ THE SOFTWARE. s = face->style_name; - for (nn = 0; nn < 4; nn++) + for ( nn = 0; nn < 4; nn++ ) { char* src = strings[nn]; int len = lengths[nn]; + if ( src == NULL ) continue; /* separate elements with a space */ - if (s != face->style_name) + if ( s != face->style_name ) *s++ = ' '; - memcpy( s, src, len ); + ft_memcpy( s, src, len ); - /* need to convert spaces to dashes for add_style_name and setwidth_name */ - if (nn == 0 || nn == 3) + /* need to convert spaces to dashes for */ + /* add_style_name and setwidth_name */ + if ( nn == 0 || nn == 3 ) { int mm; - for (mm = 0; mm < len; mm++) - if (s[mm] == ' ') + + for ( mm = 0; mm < len; mm++ ) + if ( s[mm] == ' ' ) s[mm] = '-'; } @@ -495,12 +495,14 @@ THE SOFTWARE. const char* s; - if ( FT_STRDUP( face->charset_encoding, charset_encoding->value.atom ) || - FT_STRDUP( face->charset_registry, charset_registry->value.atom ) ) + if ( FT_STRDUP( face->charset_encoding, + charset_encoding->value.atom ) || + FT_STRDUP( face->charset_registry, + charset_registry->value.atom ) ) goto Exit; - /* Uh, oh, compare first letters manually to avoid dependency - on locales. */ + /* Uh, oh, compare first letters manually to avoid dependency */ + /* on locales. */ s = face->charset_registry; if ( ( s[0] == 'i' || s[0] == 'I' ) && ( s[1] == 's' || s[1] == 'S' ) && diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c index 7737e54cb..6c931add3 100644 --- a/src/bdf/bdflib.c +++ b/src/bdf/bdflib.c @@ -1,6 +1,7 @@ /* * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001, 2002, 2003, 2004, 2005, 2006 Francesco Zappa Nardelli + * Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 + * Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c index 6e6f839b2..c02cf33fc 100644 --- a/src/cff/cffobjs.c +++ b/src/cff/cffobjs.c @@ -287,7 +287,8 @@ FT_Error error; FT_String* result; - result = ft_mem_strdup(memory, source, &error); + + result = ft_mem_strdup( memory, source, &error ); return result; } diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 1a2064fe2..2a142fca4 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -1002,9 +1002,9 @@ THE SOFTWARE. *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) { face->style_flags |= FT_STYLE_FLAG_ITALIC; - strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) - ? (char *)"Oblique" - : (char *)"Italic"; + strings[2] = ( *(prop->value.atom) == 'O' || + *(prop->value.atom) == 'o' ) ? (char *)"Oblique" + : (char *)"Italic"; } prop = pcf_find_property( pcf, "WEIGHT_NAME" ); @@ -1019,33 +1019,29 @@ THE SOFTWARE. if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - { strings[3] = (char *)(prop->value.atom); - } prop = pcf_find_property( pcf, "ADD_STYLE_NAME" ); if ( prop && prop->isString && *(prop->value.atom) && !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - { strings[0] = (char *)(prop->value.atom); - } - for (len = 0, nn = 0; nn < 4; nn++) + for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; - if (strings[nn]) + if ( strings[nn] ) { - lengths[nn] = ft_strlen(strings[nn]); - len += lengths[nn]+1; + lengths[nn] = ft_strlen( strings[nn] ); + len += lengths[nn] + 1; } } if ( len == 0 ) { strings[0] = "Regular"; - lengths[0] = ft_strlen(strings[0]); - len = lengths[0]+1; + lengths[0] = ft_strlen( strings[0] ); + len = lengths[0] + 1; } { @@ -1057,26 +1053,29 @@ THE SOFTWARE. s = face->style_name; - for (nn = 0; nn < 4; nn++) + for ( nn = 0; nn < 4; nn++ ) { char* src = strings[nn]; int len = lengths[nn]; + if ( src == NULL ) continue; /* separate elements with a space */ - if (s != face->style_name) + if ( s != face->style_name ) *s++ = ' '; - memcpy( s, src, len ); + ft_memcpy( s, src, len ); - /* need to convert spaces to dashes for add_style_name and setwidth_name */ - if (nn == 0 || nn == 3) + /* need to convert spaces to dashes for */ + /* add_style_name and setwidth_name */ + if ( nn == 0 || nn == 3 ) { int mm; - for (mm = 0; mm < len; mm++) + + for ( mm = 0; mm < len; mm++ ) if (s[mm] == ' ') s[mm] = '-'; } @@ -1243,8 +1242,10 @@ THE SOFTWARE. if ( charset_registry && charset_registry->isString && charset_encoding && charset_encoding->isString ) { - if ( FT_STRDUP( face->charset_encoding, charset_encoding->value.atom ) || - FT_STRDUP( face->charset_registry, charset_registry->value.atom ) ) + if ( FT_STRDUP( face->charset_encoding, + charset_encoding->value.atom ) || + FT_STRDUP( face->charset_registry, + charset_registry->value.atom ) ) goto Exit; } } diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index 103e224c9..5ba22a6c5 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -4,7 +4,7 @@ /* */ /* High-level SFNT driver interface (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c index 56545dacd..3ca21dc17 100644 --- a/src/type1/t1driver.c +++ b/src/type1/t1driver.c @@ -4,7 +4,7 @@ /* */ /* Type 1 driver interface (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2006 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -60,6 +60,7 @@ FT_UInt buffer_max ) { FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max ); + return T1_Err_Ok; } diff --git a/src/type42/t42drivr.c b/src/type42/t42drivr.c index 4bba8f79f..a6e4cf4b6 100644 --- a/src/type42/t42drivr.c +++ b/src/type42/t42drivr.c @@ -4,7 +4,7 @@ /* */ /* High-level Type 42 driver interface (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2006 by Roberto Alameda. */ +/* Copyright 2002, 2003, 2004, 2006, 2007 by Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -62,6 +62,7 @@ FT_UInt buffer_max ) { FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max ); + return T42_Err_Ok; }