shithub: freetype+ttf2subf

Download patch

ref: c9bbc2419ae7d3cf73a597afbf02cb335ede952f
parent: 2e3dec55093d7853bf741e24a3d5d4c6c4d68ced
author: Werner Lemberg <[email protected]>
date: Wed Aug 8 14:12:31 EDT 2018

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.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2018-08-08  Werner Lemberg  <[email protected]>
 
+	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  <[email protected]>
+
 	Debugging improvements.
 
 	* src/base/ftobjs.c (pixel_modes): Move this array to top level
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -62,8 +62,9 @@
   } 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 @@
    *
    * @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,18 +131,41 @@
    *
    * @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 );
 
 
   /**************************************************************************
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -100,10 +100,17 @@
 
 #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;
   }
 
 
@@ -257,6 +284,22 @@
     FT_UNUSED( idx );
 
     return NULL;
+  }
+
+
+  FT_BASE_DEF( void )
+  FT_Trace_Disable( void )
+  {
+    /* nothing */
+  }
+
+
+  /* documentation is in ftdebug.h */
+
+  FT_BASE_DEF( void )
+  FT_Trace_Enable( void )
+  {
+    /* nothing */
   }