Call AM_PROG_AR only if available.
[ttfautohint.git] / frontend / info.cpp
blobe38547d6a12a416f5d2a967198e5230a7a62c232
1 // info.cpp
3 // Copyright (C) 2012 by Werner Lemberg.
4 //
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.
9 //
10 // The file `COPYING' mentioned in the previous paragraph is distributed
11 // with the ttfautohint library.
14 #include <config.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdlib.h>
19 #include "info.h"
22 // build string which gets appended to the `Version' field(s)
24 extern "C" {
26 void
27 build_version_string(Info_Data* idata)
29 char* d;
30 char* dw;
32 d = (char*)idata->data;
33 d += sprintf(d, "; ttfautohint (v%s)", VERSION);
35 if (idata->hinting_range_min != TA_HINTING_RANGE_MIN)
36 d += sprintf(d, " -l %d", idata->hinting_range_min);
37 if (idata->hinting_range_max != TA_HINTING_RANGE_MAX)
38 d += sprintf(d, " -r %d", idata->hinting_range_max);
39 if (idata->hinting_limit != TA_HINTING_LIMIT)
40 d += sprintf(d, " -G %d", idata->hinting_limit);
42 if (idata->pre_hinting)
43 d += sprintf(d, " -p");
44 if (idata->increase_x_height)
45 d += sprintf(d, " -x");
46 if (idata->latin_fallback)
47 d += sprintf(d, " -f");
48 if (idata->symbol)
49 d += sprintf(d, " -s");
51 idata->data_len = d - (char*)idata->data;
53 // prepare UTF16-BE version data
54 d = (char*)idata->data;
55 dw = (char*)idata->data_wide;
56 for (unsigned short i = 0; i < idata->data_len; i++)
58 *(dw++) = '\0';
59 *(dw++) = *(d++);
61 idata->data_wide_len = idata->data_len << 1;
65 int
66 info(unsigned short platform_id,
67 unsigned short encoding_id,
68 unsigned short /* language_id */,
69 unsigned short name_id,
70 unsigned short* len,
71 unsigned char** str,
72 void* user)
74 Info_Data* idata = (Info_Data*)user;
75 unsigned char* v;
76 unsigned short v_len;
78 // if it is a version string, append our data
79 if (name_id != 5)
80 return 0;
82 if (platform_id == 1
83 || (platform_id == 3 && !(encoding_id == 1
84 || encoding_id == 10)))
86 // one-byte or multi-byte encodings
87 v = idata->data;
88 v_len = idata->data_len;
90 else
92 // (two-byte) UTF-16BE for everything else
93 v = idata->data_wide;
94 v_len = idata->data_wide_len;
97 // do nothing if the string would become too long
98 if (*len > 0xFFFF - v_len)
99 return 0;
101 unsigned short len_new = *len + v_len;
102 unsigned char* str_new = (unsigned char*)realloc(*str, len_new);
103 if (!str_new)
104 return 1;
106 *str = str_new;
107 memcpy(*str + *len, v, v_len);
108 *len = len_new;
110 return 0;
113 } // extern "C"
115 // end of info.cpp