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;
161 int latin_fallback
= 0;
166 static struct option long_options
[] = {
167 {"help", no_argument
, 0, 'h'},
168 {"hinting-range-max", required_argument
, 0, 'r'},
169 {"hinting-range-min", required_argument
, 0, 'l'},
170 {"ignore-permissions", no_argument
, 0, 'i'},
171 {"latin-fallback", no_argument
, 0, 'f'},
172 {"pre-hinting", no_argument
, 0, 'p'},
173 {"verbose", no_argument
, 0, 'v'},
174 {"version", no_argument
, 0, 'V'},
175 {"x-height-snapping-exceptions", required_argument
, 0, 'x'},
179 int option_index
= 0;
182 c
= getopt_long(argc
, argv
, "fhil:r:pVvx:", long_options
, &option_index
);
193 show_help(argv
[0], 0);
197 ignore_permissions
= 1;
201 hinting_range_min
= atoi(optarg
);
202 have_hinting_range_min
= 1;
206 hinting_range_max
= atoi(optarg
);
207 have_hinting_range_max
= 1;
211 fprintf(stderr
, "Option `-p' not implemented yet\n");
215 progress_func
= progress
;
223 fprintf(stderr
, "Option `-x' not implemented yet\n");
231 if (!have_hinting_range_min
)
232 hinting_range_min
= 8;
233 if (!have_hinting_range_max
)
234 hinting_range_max
= 1000;
236 if (hinting_range_min
< 2)
238 fprintf(stderr
, "The hinting range minimum must be at least 2\n");
241 if (hinting_range_max
< hinting_range_min
)
243 fprintf(stderr
, "The hinting range maximum must not be smaller"
244 " than the minimum (%d)\n",
249 if (argc
- optind
!= 2)
250 show_help(argv
[0], 1);
252 in
= fopen(argv
[optind
], "rb");
255 fprintf(stderr
, "The following error occurred while opening font `%s':\n"
258 argv
[optind
], strerror(errno
));
262 out
= fopen(argv
[optind
+ 1], "wb");
265 fprintf(stderr
, "The following error occurred while opening font `%s':\n"
268 argv
[optind
+ 1], strerror(errno
));
272 error
= TTF_autohint("in-file, out-file,"
273 "hinting-range-min, hinting-range-max,"
275 "progress-callback, progress-callback-data,"
276 "ignore-permissions, fallback-script",
278 hinting_range_min
, hinting_range_max
,
280 progress_func
, &progress_data
,
281 ignore_permissions
, latin_fallback
);
285 if (error
== TA_Err_Invalid_FreeType_Version
)
287 "FreeType version 2.4.5 or higher is needed.\n"
288 "Perhaps using a wrong FreeType DLL?\n");
289 else if (error
== TA_Err_Missing_Legal_Permission
)
291 "Bit 1 in the `fsType' field of the `OS/2' table is set:\n"
292 "This font must not be modified"
293 " without permission of the legal owner.\n"
294 "Use command line option `-i' to continue"
295 " if you have such a permission.\n");
296 else if (error
== TA_Err_Missing_Unicode_CMap
)
298 "No Unicode character map.\n");
299 else if (error
== TA_Err_Missing_Glyph
)
301 "No glyph for the key character"
302 " to derive standard width and height.\n"
303 "For the latin script, this key character is `o' (U+006F).\n");
306 "Error code `0x%02x' while autohinting font:\n"
307 " %s\n", error
, error_string
);