forked from minhngoc25a/freetype2
[base] Implement vertical alignment of log printing.
Based on a patch by Priyesh. * include/freetype/internal/fttrace.h (FT_MAX_TRACE_LEVEL_LENGTH): New macro. * src/base/ftdebug.c, builds/windows/ftdebug.c (ft_log_handler): Print logs after a fixed width to handle different lengths of `FT_COMPONENT` entries. Use `ft_strrchr` to check for final newline character.
This commit is contained in:
parent
ab0ea068ee
commit
ce43d808dc
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2020-12-01 Werner Lemberg <wl@gnu.org>
|
||||
|
||||
[base] Implement vertical alignment of log printing.
|
||||
|
||||
Based on a patch by Priyesh.
|
||||
|
||||
* include/freetype/internal/fttrace.h (FT_MAX_TRACE_LEVEL_LENGTH):
|
||||
New macro.
|
||||
|
||||
* src/base/ftdebug.c, builds/windows/ftdebug.c (ft_log_handler):
|
||||
Print logs after a fixed width to handle different lengths of
|
||||
`FT_COMPONENT` entries.
|
||||
Use `ft_strrchr` to check for final newline character.
|
||||
|
||||
2020-11-30 Priyesh Kumar <priyeshkkumar@gmail.com>
|
||||
|
||||
Update logging related documentation.
|
||||
|
|
|
@ -466,24 +466,73 @@
|
|||
const char* string,
|
||||
void* data )
|
||||
{
|
||||
const char* features;
|
||||
char features_buf[128];
|
||||
char* bufp = features_buf;
|
||||
|
||||
FT_UNUSED( data );
|
||||
|
||||
|
||||
if ( ft_timestamp_flag && ft_component_flag && ft_have_newline_char )
|
||||
features = "[%h:%m %t] %c";
|
||||
else if ( ft_component_flag && ft_have_newline_char )
|
||||
features = "[%t] %c";
|
||||
else if ( ft_timestamp_flag && ft_have_newline_char )
|
||||
features = "[%h:%m] %c";
|
||||
else
|
||||
features = "%c";
|
||||
if ( ft_have_newline_char )
|
||||
{
|
||||
const char* features = NULL;
|
||||
size_t features_length = 0;
|
||||
|
||||
dlg_generic_outputf_stream( ft_fileptr, features, origin, string,
|
||||
dlg_default_output_styles, true );
|
||||
|
||||
if ( strchr( string, '\n' ) )
|
||||
#define FEATURES_TIMESTAMP "[%h:%m] "
|
||||
#define FEATURES_COMPONENT "[%t] "
|
||||
#define FEATURES_TIMESTAMP_COMPONENT "[%h:%m %t] "
|
||||
|
||||
if ( ft_timestamp_flag && ft_component_flag )
|
||||
{
|
||||
features = FEATURES_TIMESTAMP_COMPONENT;
|
||||
features_length = sizeof ( FEATURES_TIMESTAMP_COMPONENT );
|
||||
}
|
||||
else if ( ft_timestamp_flag )
|
||||
{
|
||||
features = FEATURES_TIMESTAMP;
|
||||
features_length = sizeof ( FEATURES_TIMESTAMP );
|
||||
}
|
||||
else if ( ft_component_flag )
|
||||
{
|
||||
features = FEATURES_COMPONENT;
|
||||
features_length = sizeof ( FEATURES_COMPONENT );
|
||||
}
|
||||
|
||||
if ( ft_component_flag || ft_timestamp_flag )
|
||||
{
|
||||
ft_strncpy( features_buf, features, features_length );
|
||||
bufp += features_length - 1;
|
||||
}
|
||||
|
||||
if ( ft_component_flag )
|
||||
{
|
||||
size_t tag_length = ft_strlen( *origin->tags );
|
||||
size_t i;
|
||||
|
||||
|
||||
/* To vertically align tracing messages we compensate the */
|
||||
/* different FT_COMPONENT string lengths by inserting an */
|
||||
/* appropriate amount of space characters. */
|
||||
for ( i = 0;
|
||||
i < FT_MAX_TRACE_LEVEL_LENGTH - tag_length;
|
||||
i++ )
|
||||
*bufp++ = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally add the format string for the tracing message. */
|
||||
*bufp++ = '%';
|
||||
*bufp++ = 'c';
|
||||
*bufp = '\0';
|
||||
|
||||
dlg_generic_outputf_stream( ft_fileptr,
|
||||
(const char*)features_buf,
|
||||
origin,
|
||||
string,
|
||||
dlg_default_output_styles,
|
||||
true );
|
||||
|
||||
if ( ft_strrchr( string, '\n' ) )
|
||||
ft_have_newline_char = TRUE;
|
||||
else
|
||||
ft_have_newline_char = FALSE;
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
/* definitions of trace levels for FreeType 2 */
|
||||
|
||||
/* the maximum string length (if the argument to `FT_TRACE_DEF` */
|
||||
/* gets used as a string) */
|
||||
#define FT_MAX_TRACE_LEVEL_LENGTH 9
|
||||
|
||||
/* the first level must always be `trace_any' */
|
||||
FT_TRACE_DEF( any )
|
||||
|
||||
|
|
|
@ -453,24 +453,73 @@
|
|||
const char* string,
|
||||
void* data )
|
||||
{
|
||||
const char* features;
|
||||
char features_buf[128];
|
||||
char* bufp = features_buf;
|
||||
|
||||
FT_UNUSED( data );
|
||||
|
||||
|
||||
if ( ft_timestamp_flag && ft_component_flag && ft_have_newline_char )
|
||||
features = "[%h:%m %t] %c";
|
||||
else if ( ft_component_flag && ft_have_newline_char )
|
||||
features = "[%t] %c";
|
||||
else if ( ft_timestamp_flag && ft_have_newline_char )
|
||||
features = "[%h:%m] %c";
|
||||
else
|
||||
features = "%c";
|
||||
if ( ft_have_newline_char )
|
||||
{
|
||||
const char* features = NULL;
|
||||
size_t features_length = 0;
|
||||
|
||||
dlg_generic_outputf_stream( ft_fileptr, features, origin, string,
|
||||
dlg_default_output_styles, true );
|
||||
|
||||
if ( strchr( string, '\n' ) )
|
||||
#define FEATURES_TIMESTAMP "[%h:%m] "
|
||||
#define FEATURES_COMPONENT "[%t] "
|
||||
#define FEATURES_TIMESTAMP_COMPONENT "[%h:%m %t] "
|
||||
|
||||
if ( ft_timestamp_flag && ft_component_flag )
|
||||
{
|
||||
features = FEATURES_TIMESTAMP_COMPONENT;
|
||||
features_length = sizeof ( FEATURES_TIMESTAMP_COMPONENT );
|
||||
}
|
||||
else if ( ft_timestamp_flag )
|
||||
{
|
||||
features = FEATURES_TIMESTAMP;
|
||||
features_length = sizeof ( FEATURES_TIMESTAMP );
|
||||
}
|
||||
else if ( ft_component_flag )
|
||||
{
|
||||
features = FEATURES_COMPONENT;
|
||||
features_length = sizeof ( FEATURES_COMPONENT );
|
||||
}
|
||||
|
||||
if ( ft_component_flag || ft_timestamp_flag )
|
||||
{
|
||||
ft_strncpy( features_buf, features, features_length );
|
||||
bufp += features_length - 1;
|
||||
}
|
||||
|
||||
if ( ft_component_flag )
|
||||
{
|
||||
size_t tag_length = ft_strlen( *origin->tags );
|
||||
size_t i;
|
||||
|
||||
|
||||
/* To vertically align tracing messages we compensate the */
|
||||
/* different FT_COMPONENT string lengths by inserting an */
|
||||
/* appropriate amount of space characters. */
|
||||
for ( i = 0;
|
||||
i < FT_MAX_TRACE_LEVEL_LENGTH - tag_length;
|
||||
i++ )
|
||||
*bufp++ = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally add the format string for the tracing message. */
|
||||
*bufp++ = '%';
|
||||
*bufp++ = 'c';
|
||||
*bufp = '\0';
|
||||
|
||||
dlg_generic_outputf_stream( ft_fileptr,
|
||||
(const char*)features_buf,
|
||||
origin,
|
||||
string,
|
||||
dlg_default_output_styles,
|
||||
true );
|
||||
|
||||
if ( ft_strrchr( string, '\n' ) )
|
||||
ft_have_newline_char = TRUE;
|
||||
else
|
||||
ft_have_newline_char = FALSE;
|
||||
|
|
Loading…
Reference in New Issue