RIP, Vernon...
[ttfautohint.git] / lib / tadump.c
blob7cfeaa461476577a067308cba185e1c773e4ffa5
1 /* tadump.c */
3 /*
4 * Copyright (C) 2014-2016 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 if (font->dehint)
75 if (format)
76 DUMPVAL("dehint",
77 font->dehint);
78 goto Exit;
81 DUMPVAL("adjust-subglyphs",
82 font->adjust_subglyphs);
83 DUMPSTR("default-script",
84 script_names[font->default_script]);
85 DUMPVAL("dw-cleartype-strong-stem-width",
86 font->dw_cleartype_strong_stem_width);
87 DUMPVAL("fallback-scaling",
88 font->fallback_scaling);
89 DUMPSTR("fallback-script",
90 script_names[ta_style_classes[font->fallback_style]->script]);
91 DUMPVAL("fallback-stem-width",
92 font->fallback_stem_width);
93 DUMPVAL("gdi-cleartype-strong-stem-width",
94 font->gdi_cleartype_strong_stem_width);
95 DUMPVAL("gray-strong-stem-width",
96 font->gray_strong_stem_width);
97 DUMPVAL("hinting-limit",
98 font->hinting_limit);
99 DUMPVAL("hinting-range-max",
100 font->hinting_range_max);
101 DUMPVAL("hinting-range-min",
102 font->hinting_range_min);
103 DUMPVAL("hint-composites",
104 font->hint_composites);
105 DUMPVAL("ignore-restrictions",
106 font->ignore_restrictions);
107 DUMPVAL("increase-x-height",
108 font->increase_x_height);
109 DUMPVAL("symbol",
110 font->symbol);
111 DUMPVAL("TTFA-info",
112 font->TTFA_info);
113 DUMPVAL("windows-compatibility",
114 font->windows_compatibility);
116 ns = number_set_show(font->x_height_snapping_exceptions,
117 TA_PROP_INCREASE_X_HEIGHT_MIN, 0x7FFF);
118 if (!ns)
120 sdsfree(s);
121 s = NULL;
122 goto Exit;
125 DUMPSTR("x-height-snapping-exceptions", ns);
127 ds = TA_control_show(font);
128 if (!ds)
130 sdsfree(s);
131 s = NULL;
132 goto Exit;
135 if (*ds)
137 char* token;
138 char* saveptr;
141 token = strtok_r(ds, "\n", &saveptr);
142 if (format)
143 DUMPSTR("control-instructions", token);
144 else
146 DUMPSTR("control-instructions", "\\");
147 eol = "";
148 /* show control instructions line by line */
149 DUMPSTRX(token);
150 prev_eol = "; \\\n";
153 for (;;)
155 token = strtok_r(NULL, "\n", &saveptr);
156 if (!token)
157 break;
159 DUMPSTRX(token);
162 else
163 DUMPSTR("control-instructions", "");
165 if (!format)
166 s = sdscat(s, "\n");
167 s = sdscat(s, "\n");
169 Exit:
170 free(ns);
171 free(ds);
173 if (!s)
174 return NULL;
176 len = sdslen(s) + 1;
177 res = (char*)malloc(len);
178 if (res)
179 memcpy(res, s, len);
181 sdsfree(s);
183 return res;
186 /* end of tadump.c */