3 // Copyright (C) 2012 by Werner Lemberg.
5 // This file is part of the ttfautohint library, and may only be used,
6 // modified, and distributed under the terms given in `COPYING'. By
7 // continuing to use, modify, or distribute this file you indicate that you
8 // have read `COPYING' and understand and accept it fully.
10 // The file `COPYING' mentioned in the previous paragraph is distributed
11 // with the ttfautohint library.
22 #define TTFAUTOHINT_STRING "; ttfautohint"
23 #define TTFAUTOHINT_STRING_WIDE "\0;\0 \0t\0t\0f\0a\0u\0t\0o\0h\0i\0n\0t"
25 // build string which gets appended to the `Version' field(s)
30 build_version_string(Info_Data
* idata
)
37 d
= (char*)idata
->data
;
38 d
+= sprintf(d
, TTFAUTOHINT_STRING
" (v%s)", VERSION
);
40 d
+= sprintf(d
, " -l %d", idata
->hinting_range_min
);
41 d
+= sprintf(d
, " -r %d", idata
->hinting_range_max
);
42 d
+= sprintf(d
, " -G %d", idata
->hinting_limit
);
43 d
+= sprintf(d
, " -x %d", idata
->increase_x_height
);
49 if (idata
->gray_strong_stem_width
)
50 strong
[count
++] = 'g';
51 if (idata
->gdi_cleartype_strong_stem_width
)
52 strong
[count
++] = 'G';
53 if (idata
->dw_cleartype_strong_stem_width
)
54 strong
[count
++] = 'D';
55 d
+= sprintf(d
, " -w \"%s\"", strong
);
57 if (idata
->pre_hinting
)
58 d
+= sprintf(d
, " -p");
59 if (idata
->hint_with_components
)
60 d
+= sprintf(d
, " -c");
61 if (idata
->latin_fallback
)
62 d
+= sprintf(d
, " -f");
64 d
+= sprintf(d
, " -s");
66 idata
->data_len
= d
- (char*)idata
->data
;
68 // prepare UTF16-BE version data
69 d
= (char*)idata
->data
;
70 dw
= (char*)idata
->data_wide
;
71 for (unsigned short i
= 0; i
< idata
->data_len
; i
++)
76 idata
->data_wide_len
= idata
->data_len
<< 1;
81 info(unsigned short platform_id
,
82 unsigned short encoding_id
,
83 unsigned short /* language_id */,
84 unsigned short name_id
,
89 Info_Data
* idata
= (Info_Data
*)user
;
90 unsigned char ttfautohint_string
[] = TTFAUTOHINT_STRING
;
91 unsigned char ttfautohint_string_wide
[] = TTFAUTOHINT_STRING_WIDE
;
93 // we use memmem, so don't count the trailing \0 character
94 size_t ttfautohint_string_len
= sizeof (TTFAUTOHINT_STRING
) - 1;
95 size_t ttfautohint_string_wide_len
= sizeof (TTFAUTOHINT_STRING_WIDE
) - 1;
103 // if it is a version string, append our data
108 || (platform_id
== 3 && !(encoding_id
== 1
109 || encoding_id
== 10)))
111 // one-byte or multi-byte encodings
113 v_len
= idata
->data_len
;
114 s
= ttfautohint_string
;
115 s_len
= ttfautohint_string_len
;
120 // (two-byte) UTF-16BE for everything else
121 v
= idata
->data_wide
;
122 v_len
= idata
->data_wide_len
;
123 s
= ttfautohint_string_wide
;
124 s_len
= ttfautohint_string_wide_len
;
128 // if we already have an ttfautohint info string,
129 // remove it up to a following `;' character (or end of string)
130 unsigned char* s_start
= (unsigned char*)memmem(*str
, *len
, s
, s_len
);
133 unsigned char* s_end
= s_start
+ offset
;
134 unsigned char* limit
= *str
+ *len
;
136 while (s_end
< limit
)
144 if (*(s_end
- 1) == '\0') // UTF-16BE
155 while (s_end
< limit
)
156 *s_start
++ = *s_end
++;
158 *len
-= s_end
- s_start
;
161 // do nothing if the string would become too long
162 if (*len
> 0xFFFF - v_len
)
165 unsigned short len_new
= *len
+ v_len
;
166 unsigned char* str_new
= (unsigned char*)realloc(*str
, len_new
);
171 memcpy(*str
+ *len
, v
, v_len
);