Update sds library to commit 14b8e8a1.
[ttfautohint.git] / lib / tadump.c
bloba64beadd70266f28df5fd8db4abb8de298d19f0b
1 /* tadump.c */
3 /*
4 * Copyright (C) 2014 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 if (!s) \
27 goto Exit; \
28 } while (0)
29 #define DUMPSTR(str, arg) \
30 do \
31 { \
32 s = sdscatprintf(s, \
33 "%*s = %s%s", \
34 width, (str), (arg), eol); \
35 if (!s) \
36 goto Exit; \
37 } while (0)
38 #define DUMPSTRX(arg) \
39 do \
40 { \
41 s = sdscatprintf(s, \
42 "%s%*s %s%s", \
43 prev_eol, width, "", (arg), eol); \
44 if (!s) \
45 goto Exit; \
46 } while (0)
50 /* if `format' is set, we present the data in a more friendly format */
52 char*
53 TA_font_dump_parameters(FONT* font,
54 FT_Bool format)
56 sds s;
57 size_t len;
58 char* res;
60 char* ns = NULL;
61 char* ds = NULL;
63 int width = 0;
64 const char* eol = "\n";
65 const char* prev_eol = "";
68 s = sdsempty();
69 if (!s)
70 return NULL;
72 if (format)
74 s = sdscat(s, "TTF_autohint parameters\n"
75 "=======================\n"
76 "\n");
77 if (!s)
78 goto Exit;
80 width = 33;
83 if (font->dehint)
85 if (format)
86 DUMPVAL("dehint",
87 font->dehint);
88 goto Exit;
91 DUMPVAL("adjust-subglyphs",
92 font->adjust_subglyphs);
93 DUMPSTR("default-script",
94 script_names[font->default_script]);
95 DUMPVAL("dw-cleartype-strong-stem-width",
96 font->dw_cleartype_strong_stem_width);
97 DUMPSTR("fallback-script",
98 script_names[ta_style_classes[font->fallback_style]->script]);
99 DUMPVAL("fallback-stem-width",
100 font->fallback_stem_width);
101 DUMPVAL("gdi-cleartype-strong-stem-width",
102 font->gdi_cleartype_strong_stem_width);
103 DUMPVAL("gray-strong-stem-width",
104 font->gray_strong_stem_width);
105 DUMPVAL("hinting-limit",
106 font->hinting_limit);
107 DUMPVAL("hinting-range-max",
108 font->hinting_range_max);
109 DUMPVAL("hinting-range-min",
110 font->hinting_range_min);
111 DUMPVAL("hint-composites",
112 font->hint_composites);
113 DUMPVAL("ignore-restrictions",
114 font->ignore_restrictions);
115 DUMPVAL("increase-x-height",
116 font->increase_x_height);
117 DUMPVAL("symbol",
118 font->symbol);
119 DUMPVAL("TTFA-info",
120 font->TTFA_info);
121 DUMPVAL("windows-compatibility",
122 font->windows_compatibility);
124 ns = number_set_show(font->x_height_snapping_exceptions,
125 TA_PROP_INCREASE_X_HEIGHT_MIN, 0x7FFF);
126 if (!ns)
128 sdsfree(s);
129 s = NULL;
130 goto Exit;
133 DUMPSTR("x-height-snapping-exceptions", ns);
135 ds = TA_deltas_show(font);
136 if (!ds)
138 sdsfree(s);
139 s = NULL;
140 goto Exit;
143 /* show delta exceptions data line by line */
144 if (!format)
146 eol = "";
147 prev_eol = "; \\\n";
150 if (*ds)
152 char* token;
153 char* saveptr;
156 token = strtok_r(ds, "\n", &saveptr);
157 DUMPSTR("delta exceptions", token);
159 for (;;)
161 token = strtok_r(NULL, "\n", &saveptr);
162 if (!token)
163 break;
165 DUMPSTRX(token);
168 else
169 DUMPSTR("delta exceptions", "");
171 if (!format)
173 s = sdscat(s, "\n");
174 if (!s)
175 goto Exit;
178 s = sdscat(s, "\n");
179 if (!s)
180 goto Exit;
182 Exit:
183 free(ns);
184 free(ds);
186 if (!s)
187 return NULL;
189 len = sdslen(s) + 1;
190 res = (char*)malloc(len);
191 if (res)
192 memcpy(res, s, len);
194 sdsfree(s);
196 return res;
199 /* end of tadump.c */