[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
diff --git a/ChangeLog b/ChangeLog
index fb6da40..b657c66 100644
--- a/ChangeLog
+++ b/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.
diff --git a/builds/windows/ftdebug.c b/builds/windows/ftdebug.c
index abbe322..c8e811e 100644
--- a/builds/windows/ftdebug.c
+++ b/builds/windows/ftdebug.c
@@ -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;
+
+
+#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, features, origin, string,
- dlg_default_output_styles, true );
+ dlg_generic_outputf_stream( ft_fileptr,
+ (const char*)features_buf,
+ origin,
+ string,
+ dlg_default_output_styles,
+ true );
- if ( strchr( string, '\n' ) )
+ if ( ft_strrchr( string, '\n' ) )
ft_have_newline_char = TRUE;
else
ft_have_newline_char = FALSE;
diff --git a/include/freetype/internal/fttrace.h b/include/freetype/internal/fttrace.h
index 58bd774..2df2045 100644
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -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 )
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index c84b887..e0b050d 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -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;
+
+
+#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, features, origin, string,
- dlg_default_output_styles, true );
+ dlg_generic_outputf_stream( ft_fileptr,
+ (const char*)features_buf,
+ origin,
+ string,
+ dlg_default_output_styles,
+ true );
- if ( strchr( string, '\n' ) )
+ if ( ft_strrchr( string, '\n' ) )
ft_have_newline_char = TRUE;
else
ft_have_newline_char = FALSE;