freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2020-priyesh 8021768: [base] Added a public API to chan


From: Priyesh Kumar
Subject: [freetype2] GSoC-2020-priyesh 8021768: [base] Added a public API to change the log handling function at run-time.
Date: Thu, 27 Aug 2020 03:32:58 -0400 (EDT)

branch: GSoC-2020-priyesh
commit 802176853b5418d34704f1705617333145410625
Author: Priyeshkkumar <priyeshkkumar@gmail.com>
Commit: Priyeshkkumar <priyeshkkumar@gmail.com>

        [base] Added a public API to change the log handling function at 
run-time.
    
        * include/freetype/ftlogging.h (FT_Custom_Log_Handler): New function
        pointer to store the custom callback logging function.
        (FT_Set_Log_Handler, FT_Set_Default_Log_Handler): New functions to set 
and
        reset custom log handler.
    
        * include/freetype/internal/ftdebug.h: Added variables to support custom
        callback logging function.
        (FT_Callback): A function to print log using custom callback logging
        function, which is set using `FT_Set_Log_Handler'.
    
        * src/base/ftdebug.c: Added support for handling custom logging callback
        function.
        (FT_Set_Log_Handler, FT_Set_Default_Log_Handler, FT_Callback): Added
        function definitions.
---
 include/freetype/ftlogging.h        | 60 +++++++++++++++++++++++++++++++++++++
 include/freetype/internal/ftdebug.h | 18 +++++++++++
 src/base/ftdebug.c                  | 30 +++++++++++++++++++
 3 files changed, 108 insertions(+)

diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h
index eae6efc..ba61679 100644
--- a/include/freetype/ftlogging.h
+++ b/include/freetype/ftlogging.h
@@ -82,6 +82,66 @@ FT_BEGIN_HEADER
   FT_EXPORT( void )
   FT_Trace_Set_Default_Level( void );
 
+  /**************************************************************************
+   *
+   * @functype:
+   *   FT_Custom_Log_Handler
+   *
+   * @description:
+   *   Function which is used to handle the logging of tracing and debug 
messages
+   *   on a file system.
+   *
+   * @input:
+   *   ft_component ::
+   *     The name of `FT_COMPONENT' from  which  the  current debug or error
+   *     message is produced.
+   *
+   *   fmt ::
+   *     Actual debug or tracing message.
+   *
+   *   args::
+   *     Arguments of debug or tracing messages.
+   *
+   */
+  typedef void
+  (*FT_Custom_Log_Handler)( const char* ft_component,
+                            const char* fmt,
+                            va_list args );
+
+
+  /**************************************************************************
+   *
+   * @function:
+   *   FT_Set_Log_Handler
+   *
+   * @description:
+   *   A function to set a custom log handler
+   *
+   * @input:
+   *
+   *   handler ::
+   *     New logging function
+   *
+   */
+  FT_EXPORT( void )
+  FT_Set_Log_Handler( FT_Custom_Log_Handler handler );
+
+
+  /**************************************************************************
+   *
+   * @function:
+   *   FT_Set_Default_Log_Handler
+   *
+   * @description:
+   *   If previously, `FT_Set_Log_Handler'  functions is used  to set new
+   *   custom logging function, this API could be  used to reset the back
+   *   the log handler to FreeType's inbuilt log handler.
+   *
+   */
+
+  FT_EXPORT( void )
+  FT_Set_Default_Log_Handler( void );
+
   /* */
 
 FT_END_HEADER
diff --git a/include/freetype/internal/ftdebug.h 
b/include/freetype/internal/ftdebug.h
index ff93afe..d09401a 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -126,7 +126,12 @@ FT_BEGIN_HEADER
             const char* dlg_tag =  FT_LOGGING_TAG( FT_COMPONENT );         \
             ft_add_tag( dlg_tag );                                         \
             if( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level )  \
+            {                                                              \
+              if( custom_output_handler != NULL )                          \
+                FT_Callback varformat;                                     \
+              else                                                         \
                 dlg_trace varformat;                                       \
+            }                                                              \
             ft_remove_tag( dlg_tag );                                      \
           }while( 0 )
 
@@ -381,9 +386,13 @@ FT_BEGIN_HEADER
    * 1. ft_default_log_handler: stores the function pointer which is used
    *    internally by FreeType to print logs to file.
    *
+   * 2. custom_output_handler: stores the function pointer to the callback
+   *    function provided by user.
+   *
    * These are defined in ftdebug.c
    */
   extern dlg_handler ft_default_log_handler;
+  extern FT_Custom_Log_Handler custom_output_handler;
 
   /**************************************************************************
    *
@@ -411,6 +420,15 @@ FT_BEGIN_HEADER
   FT_BASE( void )
   ft_remove_tag( const char* tag );
 
+  /**************************************************************************
+   *
+   *
+   *
+   */
+  FT_BASE( void )
+  FT_Callback( const char* fmt,
+               ... );
+
 #endif /* FT_LOGGING */
 
 FT_END_HEADER
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 0a0b4e5..296c5bb 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -81,7 +81,10 @@
   static bool ft_have_newline_char = true;
   static const char* ft_custom_trace_level = NULL;
 
+/* declared in ftdebug.h */
+
   dlg_handler ft_default_log_handler = NULL;
+  FT_Custom_Log_Handler custom_output_handler = NULL;
 
 #endif
 
@@ -496,6 +499,33 @@ else
     ft_debug_init();
   }
 
+/****************************************************************************
+ *
+ * Functions to handle custom log handler:
+ *
+ */
+
+  FT_EXPORT_DEF( void )
+  FT_Set_Log_Handler( FT_Custom_Log_Handler handler )
+  {
+    custom_output_handler = handler;
+  }
+
+  FT_EXPORT_DEF( void )
+  FT_Set_Default_Log_Handler()
+  {
+    custom_output_handler = NULL;
+  }
+
+  FT_BASE_DEF( void )
+  FT_Callback( const char* fmt, ... )
+  {
+    va_list ap;
+    va_start( ap, fmt );
+    custom_output_handler( ft_component , fmt, ap );
+    va_end( ap );
+  }
+
 #endif /* FT_LOGGING */
 
 /* END */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]