4 * Copyright (C) 2011 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.
16 /* This test program is a wrapper for `TTF_autohint'. */
26 #include <ttfautohint.h>
29 typedef struct Progress_Data_
{
37 progress(long curr_idx
,
43 Progress_Data
* data
= (Progress_Data
*)user
;
48 if (num_sfnts
> 1 && curr_sfnt
!= data
->last_sfnt
)
50 fprintf(stderr
, "subfont %ld of %ld\n", curr_sfnt
+ 1, num_sfnts
);
51 data
->last_sfnt
= curr_sfnt
;
57 fprintf(stderr
, " %ld glyphs\n"
62 /* print progress approx. all 10% */
63 curr_percent
= curr_idx
* 100 / num_glyphs
;
64 curr_diff
= curr_percent
- data
->last_percent
;
67 fprintf(stderr
, " %d%%", curr_percent
);
68 data
->last_percent
= curr_percent
- curr_percent
% 10;
71 if (curr_idx
+ 1 == num_glyphs
)
72 fprintf(stderr
, "\n");
77 show_help(char* program_name
,
80 FILE* handle
= is_error
? stderr
: stdout
;
84 "Usage: %s [OPTION] IN-FILE OUT-FILE\n"
85 "Replace hints in TrueType font IN-FILE and write output to OUT-FILE.\n"
86 "The new hints are based on FreeType's autohinter.\n"
88 "This program is a simple front-end to the `ttfautohint' library.\n"
93 " -f, --latin-fallback set fallback script to latin\n"
94 " -h, --help display this help and exit\n"
95 " -i, --ignore-permissions override font license restrictions\n"
96 " -l, --hinting-range-min=N the minimum ppem value for generating hints\n"
97 " -p, --pre-hinting apply original hints before generating hints\n");
99 " -r, --hinting-range-max=N the maximum ppem value for generating hints\n"
100 " -v, --verbose show progress information\n"
101 " -V, --version print version information and exit\n"
102 " -x, --x-height-snapping-exceptions=STRING\n"
103 " specify a comma-separated list of x-height\n"
104 " snapping exceptions ranges and single values\n"
107 "The program accepts both TTF and TTC files as input.\n"
108 "The `gasp' table of OUT-FILE enables grayscale hinting for all sizes.\n"
109 "Use option -i only if you have a legal permission to modify the font.\n"
110 "If option -f is not set, glyphs not in the latin range stay unhinted.\n"
111 "The used ppem value for option -p is FUnits per em, normally 2048.\n"
113 "Report bugs to: freetype-devel@nongnu.org\n"
114 "FreeType home page: <http://www.freetype.org>\n");
128 "ttfautohint version " VERSION
"\n"
129 "Copyright (C) 2011 Werner Lemberg <wl@gnu.org>.\n"
130 "License: FreeType License (FTL) or GNU GPLv2.\n"
131 "This is free software: you are free to change and redistribute it.\n"
132 "There is NO WARRANTY, to the extent permitted by law.\n"
150 const unsigned char* error_string
;
152 Progress_Data progress_data
= {-1, 1, 0};
153 TA_Progress_Func progress_func
= NULL
;
155 int hinting_range_min
= 0;
156 int hinting_range_max
= 0;
157 int have_hinting_range_min
= 0;
158 int have_hinting_range_max
= 0;
160 int ignore_permissions
= 0;
162 int latin_fallback
= 0;
167 static struct option long_options
[] = {
168 {"help", no_argument
, 0, 'h'},
169 {"hinting-range-max", required_argument
, 0, 'r'},
170 {"hinting-range-min", required_argument
, 0, 'l'},
171 {"ignore-permissions", no_argument
, 0, 'i'},
172 {"latin-fallback", no_argument
, 0, 'f'},
173 {"pre-hinting", no_argument
, 0, 'p'},
174 {"verbose", no_argument
, 0, 'v'},
175 {"version", no_argument
, 0, 'V'},
176 {"x-height-snapping-exceptions", required_argument
, 0, 'x'},
180 int option_index
= 0;
183 c
= getopt_long(argc
, argv
, "fhil:r:pVvx:", long_options
, &option_index
);
194 show_help(argv
[0], 0);
198 ignore_permissions
= 1;
202 hinting_range_min
= atoi(optarg
);
203 have_hinting_range_min
= 1;
207 hinting_range_max
= atoi(optarg
);
208 have_hinting_range_max
= 1;
216 progress_func
= progress
;
224 fprintf(stderr
, "Option `-x' not implemented yet\n");
232 if (!have_hinting_range_min
)
233 hinting_range_min
= 8;
234 if (!have_hinting_range_max
)
235 hinting_range_max
= 1000;
237 if (hinting_range_min
< 2)
239 fprintf(stderr
, "The hinting range minimum must be at least 2\n");
242 if (hinting_range_max
< hinting_range_min
)
244 fprintf(stderr
, "The hinting range maximum must not be smaller"
245 " than the minimum (%d)\n",
250 if (argc
- optind
!= 2)
251 show_help(argv
[0], 1);
253 in
= fopen(argv
[optind
], "rb");
256 fprintf(stderr
, "The following error occurred while opening font `%s':\n"
259 argv
[optind
], strerror(errno
));
263 out
= fopen(argv
[optind
+ 1], "wb");
266 fprintf(stderr
, "The following error occurred while opening font `%s':\n"
269 argv
[optind
+ 1], strerror(errno
));
273 error
= TTF_autohint("in-file, out-file,"
274 "hinting-range-min, hinting-range-max,"
276 "progress-callback, progress-callback-data,"
277 "ignore-permissions, pre-hinting, fallback-script",
279 hinting_range_min
, hinting_range_max
,
281 progress_func
, &progress_data
,
282 ignore_permissions
, pre_hinting
, latin_fallback
);
286 if (error
== TA_Err_Invalid_FreeType_Version
)
288 "FreeType version 2.4.5 or higher is needed.\n"
289 "Perhaps using a wrong FreeType DLL?\n");
290 else if (error
== TA_Err_Missing_Legal_Permission
)
292 "Bit 1 in the `fsType' field of the `OS/2' table is set:\n"
293 "This font must not be modified"
294 " without permission of the legal owner.\n"
295 "Use command line option `-i' to continue"
296 " if you have such a permission.\n");
297 else if (error
== TA_Err_Missing_Unicode_CMap
)
299 "No Unicode character map.\n");
300 else if (error
== TA_Err_Missing_Glyph
)
302 "No glyph for the key character"
303 " to derive standard width and height.\n"
304 "For the latin script, this key character is `o' (U+006F).\n");
307 "Error code `0x%02x' while autohinting font:\n"
308 " %s\n", error
, error_string
);