From b6978dd0c949aedbaa1773724e19fec47a34a29c Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 6 Jul 2012 19:38:44 +0200 Subject: [PATCH] [autofit] Do some code cleanup. * src/autofit/afglobal.c (af_face_globals_new): Simplify. * src/autofit/afhints.c: Use `FT_TRACE7' instead of `printf' everywhere. (FT_COMPONENT): New macro. (af_glyph_hints_done): Simplify. * include/freetype/internal/fttrace.h: Updated. --- ChangeLog | 13 ++ include/freetype/internal/fttrace.h | 3 +- src/autofit/afglobal.c | 34 ++--- src/autofit/afhints.c | 202 +++++++++++++++------------- src/autofit/afhints.h | 20 +-- src/base/ftgloadr.c | 2 +- 6 files changed, 149 insertions(+), 125 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5927fa59c..622de4e2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-07-06 Werner Lemberg + + [autofit] Do some code cleanup. + + * src/autofit/afglobal.c (af_face_globals_new): Simplify. + + * src/autofit/afhints.c: Use `FT_TRACE7' instead of `printf' + everywhere. + (FT_COMPONENT): New macro. + (af_glyph_hints_done): Simplify. + + * include/freetype/internal/fttrace.h: Updated. + 2012-07-05 Werner Lemberg [autofit] Improve output of debugging information. diff --git a/include/freetype/internal/fttrace.h b/include/freetype/internal/fttrace.h index fbefdbdf4..cc2e7d11e 100644 --- a/include/freetype/internal/fttrace.h +++ b/include/freetype/internal/fttrace.h @@ -4,7 +4,7 @@ /* */ /* Tracing handling (specification only). */ /* */ -/* Copyright 2002, 2004-2007, 2009, 2011 by */ +/* Copyright 2002, 2004-2007, 2009, 2011-2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -136,6 +136,7 @@ FT_TRACE_DEF( gxvprop ) FT_TRACE_DEF( gxvlcar ) /* autofit components */ +FT_TRACE_DEF( afhints ) FT_TRACE_DEF( afcjk ) FT_TRACE_DEF( aflatin ) FT_TRACE_DEF( aflatin2 ) diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c index 3e0c02d3f..008bf4c16 100644 --- a/src/autofit/afglobal.c +++ b/src/autofit/afglobal.c @@ -4,7 +4,7 @@ /* */ /* Auto-fitter routines to compute global hinting values (body). */ /* */ -/* Copyright 2003-2011 by */ +/* Copyright 2003-2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -82,7 +82,8 @@ FT_Face face = globals->face; FT_CharMap old_charmap = face->charmap; FT_Byte* gscripts = globals->glyph_scripts; - FT_UInt ss, i; + FT_UInt ss; + FT_UInt i; /* the value AF_SCRIPT_LIST_NONE means `uncovered glyph' */ @@ -112,7 +113,7 @@ continue; /* - * Scan all unicode points in the range and set the corresponding + * Scan all Unicode points in the range and set the corresponding * glyph script index. */ for ( range = clazz->script_uni_ranges; range->first != 0; range++ ) @@ -187,21 +188,22 @@ memory = face->memory; - if ( !FT_ALLOC( globals, sizeof ( *globals ) + - face->num_glyphs * sizeof ( FT_Byte ) ) ) - { - globals->face = face; - globals->glyph_count = face->num_glyphs; - globals->glyph_scripts = (FT_Byte*)( globals + 1 ); + if ( FT_ALLOC( globals, sizeof ( *globals ) + + face->num_glyphs * sizeof ( FT_Byte ) ) ) + goto Exit; - error = af_face_globals_compute_script_coverage( globals ); - if ( error ) - { - af_face_globals_free( globals ); - globals = NULL; - } + globals->face = face; + globals->glyph_count = face->num_glyphs; + globals->glyph_scripts = (FT_Byte*)( globals + 1 ); + + error = af_face_globals_compute_script_coverage( globals ); + if ( error ) + { + af_face_globals_free( globals ); + globals = NULL; } + Exit: *aglobals = globals; return error; } @@ -273,7 +275,7 @@ metrics = globals->metrics[clazz->script]; if ( metrics == NULL ) { - /* create the global metrics object when needed */ + /* create the global metrics object if necessary */ FT_Memory memory = globals->face->memory; diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c index fa6f497b9..8aca8e7ba 100644 --- a/src/autofit/afhints.c +++ b/src/autofit/afhints.c @@ -19,6 +19,17 @@ #include "afhints.h" #include "aferrors.h" #include FT_INTERNAL_CALC_H +#include FT_INTERNAL_DEBUG_H + + + /*************************************************************************/ + /* */ + /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ + /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ + /* messages during execution. */ + /* */ +#undef FT_COMPONENT +#define FT_COMPONENT trace_afhints /* Get new segment for given axis. */ @@ -70,7 +81,7 @@ FT_Int fpos, AF_Direction dir, FT_Memory memory, - AF_Edge *aedge ) + AF_Edge *anedge ) { FT_Error error = AF_Err_Ok; AF_Edge edge = NULL; @@ -124,7 +135,7 @@ edge->dir = (FT_Char)dir; Exit: - *aedge = edge; + *anedge = edge; return error; } @@ -175,29 +186,27 @@ AF_Point point; - printf( "Table of points:\n" ); - printf( " [ index | xorg | yorg | xscale | yscale" - " | xfit | yfit | flags ]\n" ); + FT_TRACE7(( "Table of points:\n" + " [ index | xorg | yorg | xscale | yscale" + " | xfit | yfit | flags ]\n" )); for ( point = points; point < limit; point++ ) - { - printf( " [ %5d | %5d | %5d | %6.2f | %6.2f" - " | %5.2f | %5.2f | %c%c%c%c%c%c ]\n", - point - points, - point->fx, - point->fy, - point->ox / 64.0, - point->oy / 64.0, - point->x / 64.0, - point->y / 64.0, - ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ', - ( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ', - ( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ', - ( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ', - ( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ', - ( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' '); - } - printf( "\n" ); + FT_TRACE7(( " [ %5d | %5d | %5d | %6.2f | %6.2f" + " | %5.2f | %5.2f | %c%c%c%c%c%c ]\n", + point - points, + point->fx, + point->fy, + point->ox / 64.0, + point->oy / 64.0, + point->x / 64.0, + point->y / 64.0, + ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ', + ( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ', + ( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ', + ( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ', + ( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ', + ( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' ')); + FT_TRACE7(( "\n" )); } #ifdef __cplusplus } @@ -226,7 +235,7 @@ if ( pos == 0 ) return "normal"; - temp[pos] = 0; + temp[pos] = '\0'; return temp; } @@ -253,34 +262,34 @@ AF_Segment seg; - printf( "Table of %s segments:\n", - dimension == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ); + FT_TRACE7(( "Table of %s segments:\n", + dimension == AF_DIMENSION_HORZ ? "vertical" + : "horizontal" )); if (axis->num_segments) - printf( " [ index | pos | dir | from" - " | to | link | serif | edge" - " | height | extra | flags ]\n" ); + FT_TRACE7(( " [ index | pos | dir | from" + " | to | link | serif | edge" + " | height | extra | flags ]\n" )); else - printf( " (none)\n" ); + FT_TRACE7(( " (none)\n" )); for ( seg = segments; seg < limit; seg++ ) - { - printf( " [ %5d | %5.2g | %5s | %4d" - " | %4d | %4d | %5d | %4d" - " | %6d | %5d | %11s ]\n", - seg - segments, - dimension == AF_DIMENSION_HORZ ? (int)seg->first->ox / 64.0 - : (int)seg->first->oy / 64.0, - af_dir_str( (AF_Direction)seg->dir ), - AF_INDEX_NUM( seg->first, points ), - AF_INDEX_NUM( seg->last, points ), - AF_INDEX_NUM( seg->link, segments ), - AF_INDEX_NUM( seg->serif, segments ), - AF_INDEX_NUM( seg->edge, edges ), - seg->height, - seg->height - ( seg->max_coord - seg->min_coord ), - af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) ); - } - printf( "\n" ); + FT_TRACE7(( " [ %5d | %5.2g | %5s | %4d" + " | %4d | %4d | %5d | %4d" + " | %6d | %5d | %11s ]\n", + seg - segments, + dimension == AF_DIMENSION_HORZ + ? (int)seg->first->ox / 64.0 + : (int)seg->first->oy / 64.0, + af_dir_str( (AF_Direction)seg->dir ), + AF_INDEX_NUM( seg->first, points ), + AF_INDEX_NUM( seg->last, points ), + AF_INDEX_NUM( seg->link, segments ), + AF_INDEX_NUM( seg->serif, segments ), + AF_INDEX_NUM( seg->edge, edges ), + seg->height, + seg->height - ( seg->max_coord - seg->min_coord ), + af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) )); + FT_TRACE7(( "\n" )); } } #ifdef __cplusplus @@ -374,29 +383,28 @@ * note: AF_DIMENSION_HORZ corresponds to _vertical_ edges * since they have a constant X coordinate. */ - printf( "Table of %s edges:\n", - dimension == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ); + FT_TRACE7(( "Table of %s edges:\n", + dimension == AF_DIMENSION_HORZ ? "vertical" + : "horizontal" )); if ( axis->num_edges ) - printf( " [ index | pos | dir | link" - " | serif | blue | opos | pos | flags ]\n" ); + FT_TRACE7(( " [ index | pos | dir | link" + " | serif | blue | opos | pos | flags ]\n" )); else - printf( " (none)\n" ); + FT_TRACE7(( " (none)\n" )); for ( edge = edges; edge < limit; edge++ ) - { - printf( " [ %5d | %5.2g | %5s | %4d" - " | %5d | %c | %5.2f | %5.2f | %11s ]\n", - edge - edges, - (int)edge->opos / 64.0, - af_dir_str( (AF_Direction)edge->dir ), - AF_INDEX_NUM( edge->link, edges ), - AF_INDEX_NUM( edge->serif, edges ), - edge->blue_edge ? 'y' : 'n', - edge->opos / 64.0, - edge->pos / 64.0, - af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) ); - } - printf( "\n" ); + FT_TRACE7(( " [ %5d | %5.2g | %5s | %4d" + " | %5d | %c | %5.2f | %5.2f | %11s ]\n", + edge - edges, + (int)edge->opos / 64.0, + af_dir_str( (AF_Direction)edge->dir ), + AF_INDEX_NUM( edge->link, edges ), + AF_INDEX_NUM( edge->serif, edges ), + edge->blue_edge ? 'y' : 'n', + edge->opos / 64.0, + edge->pos / 64.0, + af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) )); + FT_TRACE7(( "\n" )); } } #ifdef __cplusplus @@ -530,40 +538,40 @@ FT_LOCAL_DEF( void ) af_glyph_hints_done( AF_GlyphHints hints ) { - if ( hints && hints->memory ) + FT_Memory memory = hints->memory; + int dim; + + + if ( !( hints && hints->memory ) ) + return; + + /* + * note that we don't need to free the segment and edge + * buffers since they are really within the hints->points array + */ + for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) { - FT_Memory memory = hints->memory; - int dim; + AF_AxisHints axis = &hints->axis[dim]; - /* - * note that we don't need to free the segment and edge - * buffers since they are really within the hints->points array - */ - for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ ) - { - AF_AxisHints axis = &hints->axis[dim]; + axis->num_segments = 0; + axis->max_segments = 0; + FT_FREE( axis->segments ); - - axis->num_segments = 0; - axis->max_segments = 0; - FT_FREE( axis->segments ); - - axis->num_edges = 0; - axis->max_edges = 0; - FT_FREE( axis->edges ); - } - - FT_FREE( hints->contours ); - hints->max_contours = 0; - hints->num_contours = 0; - - FT_FREE( hints->points ); - hints->num_points = 0; - hints->max_points = 0; - - hints->memory = NULL; + axis->num_edges = 0; + axis->max_edges = 0; + FT_FREE( axis->edges ); } + + FT_FREE( hints->contours ); + hints->max_contours = 0; + hints->num_contours = 0; + + FT_FREE( hints->points ); + hints->num_points = 0; + hints->max_points = 0; + + hints->memory = NULL; } @@ -759,7 +767,7 @@ /* check for weak points */ - if ( point->flags & ( AF_FLAG_CONIC | AF_FLAG_CUBIC ) ) + if ( point->flags & AF_FLAG_CONTROL ) { Is_Weak_Point: point->flags |= AF_FLAG_WEAK_INTERPOLATION; diff --git a/src/autofit/afhints.h b/src/autofit/afhints.h index 1c52e0de7..776b3c844 100644 --- a/src/autofit/afhints.h +++ b/src/autofit/afhints.h @@ -4,7 +4,7 @@ /* */ /* Auto-fitter hinting routines (specification). */ /* */ -/* Copyright 2003-2008, 2010-2011 by */ +/* Copyright 2003-2008, 2010-2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -254,7 +254,7 @@ FT_BEGIN_HEADER FT_Char out_dir; /* direction of outwards vector */ FT_Pos ox, oy; /* original, scaled position */ - FT_Short fx, fy; /* original, unscaled position (font units) */ + FT_Short fx, fy; /* original, unscaled position (in font units) */ FT_Pos x, y; /* current position */ FT_Pos u, v; /* current (x,y) or (y,x) depending on context */ @@ -290,19 +290,19 @@ FT_BEGIN_HEADER typedef struct AF_EdgeRec_ { - FT_Short fpos; /* original, unscaled position (font units) */ - FT_Pos opos; /* original, scaled position */ - FT_Pos pos; /* current position */ + FT_Short fpos; /* original, unscaled position (in font units) */ + FT_Pos opos; /* original, scaled position */ + FT_Pos pos; /* current position */ FT_Byte flags; /* edge flags */ FT_Char dir; /* edge direction */ FT_Fixed scale; /* used to speed up interpolation between edges */ - AF_Width blue_edge; /* non-NULL if this is a blue edge */ - AF_Edge link; /* link edge */ - AF_Edge serif; /* primary edge for serifs */ - FT_Short num_linked; /* number of linked edges */ - FT_Int score; /* used during stem matching */ + AF_Width blue_edge; /* non-NULL if this is a blue edge */ + AF_Edge link; /* link edge */ + AF_Edge serif; /* primary edge for serifs */ + FT_Short num_linked; /* number of linked edges */ + FT_Int score; /* used during stem matching */ AF_Segment first; /* first segment in edge */ AF_Segment last; /* last segment in edge */ diff --git a/src/base/ftgloadr.c b/src/base/ftgloadr.c index 848345019..3a5615e5e 100644 --- a/src/base/ftgloadr.c +++ b/src/base/ftgloadr.c @@ -318,7 +318,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 ) {