From c9bbc2419ae7d3cf73a597afbf02cb335ede952f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 8 Aug 2018 18:12:31 +0200 Subject: [PATCH] Add internal functions `FT_Trace_Disable' and `FT_Trace_Enable'. It sometimes makes sense to suppress tracing informations, for example, if it outputs identical messages again and again. * include/freetype/internal/ftdebug.h: Make `ft_trace_levels' a pointer. (FT_Trace_Disable, FT_Trace_Enable): New declarations. * src/base/ftdebug.c (ft_trace_levels): Rename to... (ft_trace_levels_enabled): ... this. (ft_trace_levels_disabled): New array. (ft_trace_levels): New pointer. (FT_Trace_Disable, FT_Trace_Enable): Implement. (ft_debug_init): Updated. --- ChangeLog | 18 ++++++++++ include/freetype/internal/ftdebug.h | 40 +++++++++++++++++----- src/base/ftdebug.c | 51 ++++++++++++++++++++++++++--- 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91bb37a4d..73259c673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2018-08-08 Werner Lemberg + + Add internal functions `FT_Trace_Disable' and `FT_Trace_Enable'. + + It sometimes makes sense to suppress tracing informations, for + example, if it outputs identical messages again and again. + + * include/freetype/internal/ftdebug.h: Make `ft_trace_levels' a + pointer. + (FT_Trace_Disable, FT_Trace_Enable): New declarations. + + * src/base/ftdebug.c (ft_trace_levels): Rename to... + (ft_trace_levels_enabled): ... this. + (ft_trace_levels_disabled): New array. + (ft_trace_levels): New pointer. + (FT_Trace_Disable, FT_Trace_Enable): Implement. + (ft_debug_init): Updated. + 2018-08-08 Werner Lemberg Debugging improvements. diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h index 1b4f6997c..d6e8a3a50 100644 --- a/include/freetype/internal/ftdebug.h +++ b/include/freetype/internal/ftdebug.h @@ -62,8 +62,9 @@ FT_BEGIN_HEADER } FT_Trace; - /* defining the array of trace levels, provided by `src/base/ftdebug.c' */ - extern int ft_trace_levels[trace_count]; + /* a pointer to the array of trace levels, */ + /* provided by `src/base/ftdebug.c' */ + extern int* ft_trace_levels; #undef FT_TRACE_DEF @@ -111,7 +112,7 @@ FT_BEGIN_HEADER * * @note: * This function may be useful if you want to access elements of - * the internal `ft_trace_levels' array by an index. + * the internal trace levels array by an index. */ FT_BASE( FT_Int ) FT_Trace_Get_Count( void ); @@ -130,20 +131,43 @@ FT_BEGIN_HEADER * * @return: * The name of the trace component. This is a statically allocated - * C string, so do not free it after use. NULL if FreeType 2 is not - * built with FT_DEBUG_LEVEL_TRACE definition. + * C~string, so do not free it after use. NULL if FreeType is not built + * with FT_DEBUG_LEVEL_TRACE definition. * * @note: * Use @FT_Trace_Get_Count to get the number of available trace * components. - * - * This function may be useful if you want to control FreeType 2's - * debug level in your application. */ FT_BASE( const char* ) FT_Trace_Get_Name( FT_Int idx ); + /************************************************************************** + * + * @function: + * FT_Trace_Disable + * + * @description: + * Switch off tracing temporarily. It can be activated again with + * @FT_Trace_Enable. + */ + FT_BASE( void ) + FT_Trace_Disable( void ); + + + /************************************************************************** + * + * @function: + * FT_Trace_Enable + * + * @description: + * Activate tracing. Use it after tracing has been switched off with + * @FT_Trace_Disable. + */ + FT_BASE( void ) + FT_Trace_Enable( void ); + + /************************************************************************** * * You need two opening and closing parentheses! diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c index a5fae2789..8c7e51c85 100644 --- a/src/base/ftdebug.c +++ b/src/base/ftdebug.c @@ -100,9 +100,16 @@ #ifdef FT_DEBUG_LEVEL_TRACE - /* array of trace levels, initialized to 0 */ - int ft_trace_levels[trace_count]; + /* array of trace levels, initialized to 0; */ + /* this gets adjusted at run-time */ + int ft_trace_levels_enabled[trace_count]; + /* array of trace levels, always initialized to 0 */ + int ft_trace_levels_disabled[trace_count]; + + /* a pointer to either `ft_trace_levels_enabled' */ + /* or `ft_trace_levels_disabled' */ + int* ft_trace_levels; /* define array of trace toggle names */ #define FT_TRACE_DEF( x ) #x , @@ -140,6 +147,24 @@ } + /* documentation is in ftdebug.h */ + + FT_BASE_DEF( void ) + FT_Trace_Disable( void ) + { + ft_trace_levels = ft_trace_levels_disabled; + } + + + /* documentation is in ftdebug.h */ + + FT_BASE_DEF( void ) + FT_Trace_Enable( void ) + { + ft_trace_levels = ft_trace_levels_enabled; + } + + /************************************************************************** * * Initialize the tracing sub-system. This is done by retrieving the @@ -223,14 +248,16 @@ { /* special case for `any' */ for ( n = 0; n < trace_count; n++ ) - ft_trace_levels[n] = level; + ft_trace_levels_enabled[n] = level; } else - ft_trace_levels[found] = level; + ft_trace_levels_enabled[found] = level; } } } } + + ft_trace_levels = ft_trace_levels_enabled; } @@ -260,6 +287,22 @@ } + FT_BASE_DEF( void ) + FT_Trace_Disable( void ) + { + /* nothing */ + } + + + /* documentation is in ftdebug.h */ + + FT_BASE_DEF( void ) + FT_Trace_Enable( void ) + { + /* nothing */ + } + + #endif /* !FT_DEBUG_LEVEL_TRACE */