Simplify error handling thanks to the last change in the `sds' library.
[ttfautohint.git] / lib / tadump.c
blobbddfd9a84310ba07ea60c24c86203c810d58b082
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 } 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 "\n");
69 width = 33;
72 if (font->dehint)
74 if (format)
75 DUMPVAL("dehint",
76 font->dehint);
77 goto Exit;
80 DUMPVAL("adjust-subglyphs",
81 font->adjust_subglyphs);
82 DUMPSTR("default-script",
83 script_names[font->default_script]);
84 DUMPVAL("dw-cleartype-strong-stem-width",
85 font->dw_cleartype_strong_stem_width);
86 DUMPSTR("fallback-script",
87 script_names[ta_style_classes[font->fallback_style]->script]);
88 DUMPVAL("fallback-stem-width",
89 font->fallback_stem_width);
90 DUMPVAL("gdi-cleartype-strong-stem-width",
91 font->gdi_cleartype_strong_stem_width);
92 DUMPVAL("gray-strong-stem-width",
93 font->gray_strong_stem_width);
94 DUMPVAL("hinting-limit",
95 font->hinting_limit);
96 DUMPVAL("hinting-range-max",
97 font->hinting_range_max);
98 DUMPVAL("hinting-range-min",
99 font->hinting_range_min);
100 DUMPVAL("hint-composites",
101 font->hint_composites);
102 DUMPVAL("ignore-restrictions",
103 font->ignore_restrictions);
104 DUMPVAL("increase-x-height",
105 font->increase_x_height);
106 DUMPVAL("symbol",
107 font->symbol);
108 DUMPVAL("TTFA-info",
109 font->TTFA_info);
110 DUMPVAL("windows-compatibility",
111 font->windows_compatibility);
113 ns = number_set_show(font->x_height_snapping_exceptions,
114 TA_PROP_INCREASE_X_HEIGHT_MIN, 0x7FFF);
115 if (!ns)
117 sdsfree(s);
118 s = NULL;
119 goto Exit;
122 DUMPSTR("x-height-snapping-exceptions", ns);
124 ds = TA_deltas_show(font);
125 if (!ds)
127 sdsfree(s);
128 s = NULL;
129 goto Exit;
132 /* show delta exceptions data line by line */
133 if (!format)
135 eol = "";
136 prev_eol = "; \\\n";
139 if (*ds)
141 char* token;
142 char* saveptr;
145 token = strtok_r(ds, "\n", &saveptr);
146 DUMPSTR("delta exceptions", token);
148 for (;;)
150 token = strtok_r(NULL, "\n", &saveptr);
151 if (!token)
152 break;
154 DUMPSTRX(token);
157 else
158 DUMPSTR("delta exceptions", "");
160 if (!format)
161 s = sdscat(s, "\n");
162 s = sdscat(s, "\n");
164 Exit:
165 free(ns);
166 free(ds);
168 if (!s)
169 return NULL;
171 len = sdslen(s) + 1;
172 res = (char*)malloc(len);
173 if (res)
174 memcpy(res, s, len);
176 sdsfree(s);
178 return res;
181 /* end of tadump.c */