Fix OTS warning about `maxp.maxSizeOfInstructions`.
[ttfautohint.git] / lib / tadump.c
blob92aeb17a4a1a9ef5a23bb7d9064614465ce698f6
1 /* tadump.c */
3 /*
4 * Copyright (C) 2014-2022 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
15 #include "ta.h"
17 #include <stdarg.h>
20 #define DUMPVAL(str, arg) \
21 do \
22 { \
23 s = sdscatprintf(s, \
24 "%*s = %ld\n", \
25 width, (str), (FT_Long)(arg)); \
26 } while (0)
27 #define DUMPSTR(str, arg) \
28 do \
29 { \
30 s = sdscatprintf(s, \
31 "%*s = %s%s", \
32 width, (str), (arg), eol); \
33 } while (0)
34 #define DUMPSTRX(arg) \
35 do \
36 { \
37 s = sdscatprintf(s, \
38 "%s%*s %s%s", \
39 prev_eol, width, "", (arg), eol); \
40 } while (0)
44 /* if `format' is set, we present the data in a more friendly format */
46 char*
47 TA_font_dump_parameters(FONT* font,
48 FT_Bool format)
50 sds s;
51 size_t len;
52 char* res;
54 char* ns = NULL;
55 char* ds = NULL;
57 int width = 0;
58 const char* eol = "\n";
59 const char* prev_eol = "";
62 s = sdsempty();
64 if (format)
66 s = sdscat(s, "TTF_autohint parameters\n"
67 "=======================\n");
68 width = 33;
71 s = sdscat(s, "\n");
73 DUMPSTR("ttfautohint version",
74 VERSION);
76 s = sdscat(s, "\n");
78 if (font->dehint)
80 if (format)
81 DUMPVAL("dehint",
82 font->dehint);
83 goto Exit;
86 DUMPVAL("adjust-subglyphs",
87 font->adjust_subglyphs);
88 DUMPSTR("default-script",
89 script_names[font->default_script]);
90 DUMPSTR("dw-cleartype-stem-width-mode",
91 (font->dw_cleartype_stem_width_mode == TA_STEM_WIDTH_MODE_NATURAL)
92 ? "natural"
93 : (font->dw_cleartype_stem_width_mode == TA_STEM_WIDTH_MODE_QUANTIZED)
94 ? "quantized"
95 : "strong");
96 DUMPVAL("fallback-scaling",
97 font->fallback_scaling);
98 DUMPSTR("fallback-script",
99 script_names[ta_style_classes[font->fallback_style]->script]);
100 DUMPVAL("fallback-stem-width",
101 font->fallback_stem_width);
102 DUMPSTR("gdi-cleartype-stem-width-mode",
103 (font->gdi_cleartype_stem_width_mode == TA_STEM_WIDTH_MODE_NATURAL)
104 ? "natural"
105 : (font->gdi_cleartype_stem_width_mode == TA_STEM_WIDTH_MODE_QUANTIZED)
106 ? "quantized"
107 : "strong");
108 DUMPSTR("gray-stem-width-mode",
109 (font->gray_stem_width_mode == TA_STEM_WIDTH_MODE_NATURAL)
110 ? "natural"
111 : (font->gray_stem_width_mode == TA_STEM_WIDTH_MODE_QUANTIZED)
112 ? "quantized"
113 : "strong");
114 DUMPVAL("hinting-limit",
115 font->hinting_limit);
116 DUMPVAL("hinting-range-max",
117 font->hinting_range_max);
118 DUMPVAL("hinting-range-min",
119 font->hinting_range_min);
120 DUMPVAL("hint-composites",
121 font->hint_composites);
122 DUMPVAL("ignore-restrictions",
123 font->ignore_restrictions);
124 DUMPVAL("increase-x-height",
125 font->increase_x_height);
126 if (font->reference_name)
127 DUMPSTR("reference",
128 font->reference_name);
129 else if (font->reference_buf)
130 DUMPSTR("reference",
131 "<yes>");
132 else
133 DUMPSTR("reference",
134 "");
135 DUMPVAL("reference-index",
136 font->reference_index);
137 DUMPVAL("symbol",
138 font->symbol);
139 DUMPVAL("TTFA-info",
140 font->TTFA_info);
141 DUMPVAL("windows-compatibility",
142 font->windows_compatibility);
144 ns = number_set_show(font->x_height_snapping_exceptions,
145 TA_PROP_INCREASE_X_HEIGHT_MIN, 0x7FFF);
146 if (!ns)
148 sdsfree(s);
149 s = NULL;
150 goto Exit;
153 DUMPSTR("x-height-snapping-exceptions", ns);
155 ds = TA_control_show(font);
156 if (!ds)
158 sdsfree(s);
159 s = NULL;
160 goto Exit;
163 if (*ds)
165 char* token;
166 char* saveptr;
169 token = strtok_r(ds, "\n", &saveptr);
170 if (format)
171 DUMPSTR("control-instructions", token);
172 else
174 DUMPSTR("control-instructions", "\\");
175 eol = "";
176 /* show control instructions line by line */
177 DUMPSTRX(token);
178 prev_eol = "; \\\n";
181 for (;;)
183 token = strtok_r(NULL, "\n", &saveptr);
184 if (!token)
185 break;
187 DUMPSTRX(token);
190 else
191 DUMPSTR("control-instructions", "");
193 if (!format)
194 s = sdscat(s, "\n");
195 s = sdscat(s, "\n");
197 Exit:
198 free(ns);
199 free(ds);
201 if (!s)
202 return NULL;
204 len = sdslen(s) + 1;
205 res = (char*)malloc(len);
206 if (res)
207 memcpy(res, s, len);
209 sdsfree(s);
211 return res;
214 /* end of tadump.c */