Addded logic to print trace messages to a file

This commit is contained in:
Priyeshkkumar 2020-06-30 17:44:52 +05:30
parent 421bb589e6
commit 52926578db
4 changed files with 68 additions and 14 deletions

View File

@ -1,3 +1,19 @@
2020-06-30 Priyesh Kumar <priyeshkkumar@gmail.com>
* include/freetype/internal/ftdebug.h: Added a FreeType specific dlg
output handler to print trace logs to file ~
`ft_freetype_output_handler()`
* src/base/ftdebug.c:
1. If FT_LOGGING is enabled `ft_debug_init()` will be called from
`ft_logging_init()`
2. Added function definition of `ft_freetype_output_handler)()`
* src/base/ftobjs.c: If FT_LOGGING macro is disabled, only then FreeType
will call `ft_debug_init()` else it is controlled by logging APIs.
* Fixed Scaling
2020-06-29 Priyesh Kumar <priyeshkkumar@gmail.com> 2020-06-29 Priyesh Kumar <priyeshkkumar@gmail.com>
* Added submodule - dlg library (https://github.com/nyorain/dlg) * Added submodule - dlg library (https://github.com/nyorain/dlg)
@ -13,8 +29,9 @@
* include/freetype/internal/ftdebug.h: Created an environment for dlg * include/freetype/internal/ftdebug.h: Created an environment for dlg
support in FreeType. support in FreeType.
* include/freetype/internal/ftdebug.h: Added functions `ft_logging_init()` and `ft_logging_deinit()` for * include/freetype/internal/ftdebug.h: Added functions
initializing and un-initalizing FILE*. `ft_logging_init()` and `ft_logging_deinit()` for initializing and
un-initalizing FILE*.
* src/base/ftdebug.c: * src/base/ftdebug.c:
1. Added a FILE* to write logs to file 1. Added a FILE* to write logs to file
@ -22,5 +39,7 @@
`ft_logging_init()` and `ft_logging_deinit()`. `ft_logging_init()` and `ft_logging_deinit()`.
* src/base/ftinit.c: * src/base/ftinit.c:
1. Added a function call to `ft_logging_init()` in `FT_Init_FreeType()` if FT_LOGGING macro is enabled. 1. Added a function call to `ft_logging_init()` in `FT_Init_FreeType()`
2. Added a function call to `ft_logging_deinit()` in `FT_Done_FreeType()` if FT_LOGGING macro is enabled. if FT_LOGGING macro is enabled.
2. Added function call to `ft_logging_deinit()` in `FT_Done_FreeType()`
if FT_LOGGING macro is enabled.

View File

@ -29,9 +29,9 @@
#include FT_CONFIG_CONFIG_H #include FT_CONFIG_CONFIG_H
#include <freetype/freetype.h> #include <freetype/freetype.h>
/* Additional include files for supporting logging in FreeType using */ /* Additional include files for supporting logging in FreeType using */
/* external logging library ~ src/dlg */ /* external logging library ~ src/dlg */
/* */ /* */
#include <../src/dlg/include/dlg/dlg.h> #include <../src/dlg/include/dlg/dlg.h>
#include <../src/dlg/include/dlg/output.h> #include <../src/dlg/include/dlg/output.h>
@ -95,8 +95,8 @@ FT_BEGIN_HEADER
* Each component must define the macro FT_COMPONENT to a valid FT_Trace * Each component must define the macro FT_COMPONENT to a valid FT_Trace
* value before using any TRACE macro. * value before using any TRACE macro.
* *
* If FT_LOGGING is enabled, trace messages will be sent to * If FT_LOGGING is enabled, trace messages will be sent to dlg's API and
* dlg's APIs and is FT_LOGGING is disabled trace messages will be sent to * if is FT_LOGGING is disabled trace messages will be sent to
* FT_Message(defined in ftdebug.c) * FT_Message(defined in ftdebug.c)
* Therefore the following macros: * Therefore the following macros:
* *
@ -107,6 +107,19 @@ FT_BEGIN_HEADER
#undef FT_Log #undef FT_Log
#define FT_Log dlg_trace #define FT_Log dlg_trace
/****************************************************************************
*
* dlg uses output handlers to control how and where the log messages are
* printed.
* Therefore we need to define an output handler specific to FreeType, it
* will act as a default output handler of Freetype.
*
*/
FT_BASE( void )
ft_freetype_output_handler( const struct dlg_origin* origin,
const char* string, void* data );
#else #else
#undef FT_Log #undef FT_Log
@ -309,7 +322,7 @@ FT_BEGIN_HEADER
#ifdef FT_LOGGING #ifdef FT_LOGGING
/************************************************************************ /**************************************************************************
* *
* If FT_LOGGING macro is enabled, Freetype needs to initialize and * If FT_LOGGING macro is enabled, Freetype needs to initialize and
* un-initialize FILE* using following functions * un-initialize FILE* using following functions

View File

@ -317,7 +317,7 @@
#ifdef FT_LOGGING #ifdef FT_LOGGING
/****************************************************************** /**************************************************************************
* If FT_LOGGING is enabled FreeType needs a FILE* to write logs * If FT_LOGGING is enabled FreeType needs a FILE* to write logs
* to file. * to file.
*/ */
@ -325,7 +325,7 @@
/******************************************************************* /**************************************************************************
* *
* If FT_LOGGING is enabled, FreeType needs a FILE* to write logs * If FT_LOGGING is enabled, FreeType needs a FILE* to write logs
* therefore it uses `ft_logging_init()` function to initialize a * therefore it uses `ft_logging_init()` function to initialize a
@ -336,7 +336,11 @@
FT_BASE_DEF( void ) FT_BASE_DEF( void )
ft_logging_init( void ) ft_logging_init( void )
{ {
fileptr = fopen( "freetype2.logs", "w" ); fileptr = fopen( "freetype2.log", "w" );
ft_debug_init();
/* We need to set the default FreeType specific dlg's output handler */
dlg_set_handler( &ft_freetype_output_handler, NULL );
} }
FT_BASE_DEF( void ) FT_BASE_DEF( void )
@ -345,6 +349,22 @@
fclose( fileptr ); fclose( fileptr );
} }
FT_BASE_DEF( void )
/*************************************************************************
*
* TODO:
* 1. Add support for priniting FT_COMPONENT
*
*/
ft_freetype_output_handler( const struct dlg_origin* origin,
const char* string, void* data )
{
unsigned int features = dlg_output_threadsafe /*| dlg_output_tags*/ ;
dlg_generic_output_stream( fileptr, features, origin, string,
dlg_default_output_styles );
}
#endif /* FT_LOGGING */ #endif /* FT_LOGGING */
/* END */ /* END */

View File

@ -5273,10 +5273,12 @@
if ( !memory || !alibrary ) if ( !memory || !alibrary )
return FT_THROW( Invalid_Argument ); return FT_THROW( Invalid_Argument );
#ifndef FT_LOGGING
#ifdef FT_DEBUG_LEVEL_ERROR #ifdef FT_DEBUG_LEVEL_ERROR
/* init debugging support */ /* init debugging support */
ft_debug_init(); ft_debug_init();
#endif #endif /* FT_DEBUG_LEVEL_ERROR */
#endif /* FT_LOGGING */
/* first of all, allocate the library object */ /* first of all, allocate the library object */
if ( FT_NEW( library ) ) if ( FT_NEW( library ) )