3 // Copyright (C) 2011-2022 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.
14 // This program is a wrapper for `TTF_autohint'.
18 # define CONSOLE_OUTPUT
21 # define CONSOLE_OUTPUT
39 # include <QApplication>
42 # include <ft2build.h>
43 # include FT_FREETYPE_H
44 # include FT_TRUETYPE_TABLES_H // for option `-T'
48 #include <ttfautohint.h>
49 #include <numberset.h>
55 # define SET_BINARY(f) do { \
56 if (!isatty(fileno(f))) \
57 setmode(fileno(f), O_BINARY); \
62 # define SET_BINARY(f) do {} while (0)
70 typedef struct Tag_Names_
73 const char* description
;
77 // the available script tags and its descriptions are directly extracted
78 // from `ttfautohint-scripts.h'
80 #define SCRIPT(s, S, d, h, H, ss) \
83 const Tag_Names script_names
[] =
85 #include <ttfautohint-scripts.h>
91 // the available feature tags and its descriptions are directly extracted
92 // from `ttfautohint-coverages.h'
94 # define COVERAGE(n, N, d, t, t1, t2, t3, t4) \
97 const Tag_Names feature_names
[] =
99 #include <ttfautohint-coverages.h>
108 typedef struct Progress_Data_
117 progress(long curr_idx
,
123 Progress_Data
* data
= (Progress_Data
*)user
;
125 if (num_sfnts
> 1 && curr_sfnt
!= data
->last_sfnt
)
127 fprintf(stderr
, "subfont %ld of %ld\n", curr_sfnt
+ 1, num_sfnts
);
128 data
->last_sfnt
= curr_sfnt
;
129 data
->last_percent
= 0;
135 fprintf(stderr
, " %ld glyphs\n"
140 // print progress approx. every 10%
141 int curr_percent
= int(curr_idx
* 100 / num_glyphs
);
142 int curr_diff
= curr_percent
- data
->last_percent
;
146 fprintf(stderr
, " %d%%", curr_percent
);
147 data
->last_percent
= curr_percent
- curr_percent
% 10;
150 if (curr_idx
+ 1 == num_glyphs
)
151 fprintf(stderr
, "\n");
157 typedef struct Error_Data_
159 const char* control_name
;
165 const char* error_string
,
166 unsigned int errlinenum
,
171 Error_Data
* data
= static_cast<Error_Data
*>(user
);
176 // We replace some terse error strings with more user-friendly versions.
177 if (error
== TA_Err_Invalid_FreeType_Version
)
179 "FreeType version 2.4.5 or higher is needed.\n"
180 "Perhaps using a wrong FreeType DLL?\n");
181 else if (error
== TA_Err_Invalid_Font_Type
)
183 "This font is not a valid font"
184 " in SFNT format with TrueType outlines.\n"
185 "In particular, CFF outlines are not supported.\n");
186 else if (error
== TA_Err_Already_Processed
)
188 "This font has already been processed with ttfautohint.\n");
189 else if (error
== TA_Err_Missing_Legal_Permission
)
191 "Bit 1 in the `fsType' field of the `OS/2' table is set:\n"
192 "This font must not be modified"
193 " without permission of the legal owner.\n"
194 "Use command line option `-i' to continue"
195 " if you have such a permission.\n");
196 else if (error
== TA_Err_Missing_Unicode_CMap
)
198 "No Unicode character map.\n");
199 else if (error
== TA_Err_Missing_Symbol_CMap
)
201 "No symbol character map.\n");
202 else if (error
== TA_Err_Missing_Glyph
)
204 "No glyph for a standard character"
205 " to derive standard width and height.\n"
206 "Please check the documentation for a list of"
207 " script-specific standard characters,\n"
208 "or use option `--symbol'.\n");
213 fprintf(stderr
, "An error with code 0x%02x occurred"
214 " while autohinting fonts\n",
217 fprintf(stderr
, " %s", error_string
);
219 else if (error
>= 0x100 && error
< 0x200)
221 fprintf(stderr
, "An error with code 0x%03x occurred"
222 " while parsing the argument of option `-X'",
224 fprintf(stderr
, errline
? ":\n" : ".\n");
227 fprintf(stderr
, " %s\n", errline
);
228 if (errpos
&& errline
)
229 fprintf(stderr
, " %*s\n", int(errpos
- errline
+ 1), "^");
231 else if (error
>= 0x200 && error
< 0x300)
233 fprintf(stderr
, "%s:", data
->control_name
);
235 fprintf(stderr
, "%u:", errlinenum
);
236 if (errpos
&& errline
)
237 fprintf(stderr
, "%d:", int(errpos
- errline
+ 1));
239 fprintf(stderr
, " %s", error_string
);
240 fprintf(stderr
, " (0x%02X)\n", error
);
242 fprintf(stderr
, " %s\n", errline
);
243 if (errpos
&& errline
)
244 fprintf(stderr
, " %*s\n", int(errpos
- errline
+ 1), "^");
246 else if (error
>= 0x300 && error
< 0x400)
249 fprintf(stderr
, "An error with code 0x%02x occurred"
250 " while loading the reference font\n",
253 fprintf(stderr
, " %s", error_string
);
263 #ifdef CONSOLE_OUTPUT
272 FILE* handle
= is_error
? stderr
: stdout
;
276 "Usage: ttfautohintGUI [OPTION]...\n"
277 "A GUI application to replace hints in a TrueType font.\n"
279 "Usage: ttfautohint [OPTION]... [IN-FILE [OUT-FILE]]\n"
280 "Replace hints in TrueType font IN-FILE and write output to OUT-FILE.\n"
281 "If OUT-FILE is missing, standard output is used instead;\n"
282 "if IN-FILE is missing also, standard input and output are used.\n"
285 "The new hints are based on FreeType's auto-hinter.\n"
287 "This program is a simple front-end to the `ttfautohint' library.\n"
291 "Long options can be given with one or two dashes,\n"
292 "and with and without equal sign between option and argument.\n"
293 "This means that the following forms are acceptable:\n"
294 "`-foo=bar', `--foo=bar', `-foo bar', `--foo bar'.\n"
296 "Mandatory arguments to long options are mandatory for short options too.\n"
298 "Options not related to Qt or X11 set default values.\n"
306 " --debug print debugging information\n"
308 " -a, --stem-width-mode=S select stem width mode for grayscale, GDI\n"
309 " ClearType, and DW ClearType, where S is a\n"
310 " string of three letters with possible values\n"
311 " `n' for natural, `q' for quantized, and `s'\n"
312 " for strong (default: qsq)\n"
313 " -c, --composites hint glyph composites also\n"
314 " -d, --dehint remove all hints\n"
315 " -D, --default-script=S set default OpenType script (default: latn)\n"
316 " -f, --fallback-script=S set fallback script (default: none)\n"
317 " -F, --family-suffix=S append suffix to the family name string(s)\n"
318 " in the `name' table\n"
319 " -G, --hinting-limit=N switch off hinting above this PPEM value\n"
320 " (default: %d); value 0 means no limit\n"
321 " -h, --help display this help and exit\n"
322 " -H, --fallback-stem-width=N\n"
323 " set fallback stem width\n"
324 " (default: 50 font units at 2048 UPEM)\n"
326 " --help-all show Qt and X11 specific options also\n"
328 " -i, --ignore-restrictions override font license restrictions\n"
329 " -I, --detailed-info add detailed ttfautohint info\n"
330 " to the version string(s) in the `name' table\n"
331 " -l, --hinting-range-min=N the minimum PPEM value for hint sets\n"
334 " -m, --control-file=FILE get control instructions from FILE\n"
336 " -n, --no-info don't add ttfautohint info\n"
337 " to the version string(s) in the `name' table\n"
338 " -p, --adjust-subglyphs handle subglyph adjustments in exotic fonts\n",
339 TA_HINTING_LIMIT
, TA_HINTING_RANGE_MIN
);
341 " -r, --hinting-range-max=N the maximum PPEM value for hint sets\n"
344 " -R, --reference=FILE derive blue zones from reference font FILE\n"
346 " -s, --symbol input is symbol font\n"
347 " -S, --fallback-scaling use fallback scaling, not hinting\n"
348 " -t, --ttfa-table add TTFA information table\n"
350 " -T, --ttfa-info display TTFA table in IN-FILE and exit\n"
352 " -v, --verbose show progress information\n"
353 " -V, --version print version information and exit\n"
354 " -W, --windows-compatibility\n"
355 " add blue zones for `usWinAscent' and\n"
356 " `usWinDescent' to avoid clipping\n"
357 " -x, --increase-x-height=N increase x height for sizes in the range\n"
358 " 6<=PPEM<=N; value 0 switches off this feature\n"
360 " -X, --x-height-snapping-exceptions=STRING\n"
361 " specify a comma-separated list of\n"
362 " x-height snapping exceptions, for example\n"
363 " \"-9, 13-17, 19\" (default: \"\")\n"
365 " -Z, --reference-index=N face index of reference font (default: 0)\n"
368 TA_HINTING_RANGE_MAX
, TA_INCREASE_X_HEIGHT
);
375 #if QT_VERSION < 0x050000
376 " --graphicssystem=SYSTEM\n"
377 " select a different graphics system backend\n"
378 " instead of the default one\n"
379 " (possible values: `raster', `opengl')\n"
381 " --reverse set layout direction to right-to-left\n");
383 #if QT_VERSION < 0x050000
384 " --session=ID restore the application for the given ID\n"
386 " --style=STYLE set application GUI style\n"
387 " (available values like `windows' or `gtk'\n"
388 " depend on Qt version and installed plug-ins)\n"
389 " --stylesheet=SHEET apply the given Qt stylesheet\n"
390 " to the application widgets\n"
393 #if QT_VERSION < 0x050000
396 " --background=COLOR set the default background color\n"
397 " and an application palette\n"
398 " (light and dark shades are calculated)\n"
399 " --bg=COLOR same as --background\n"
400 " --btn=COLOR set the default button color\n"
401 " --button=COLOR same as --btn\n"
402 " --cmap use a private color map on an 8-bit display\n"
403 " --display=NAME use the given X-server display\n");
405 " --fg=COLOR set the default foreground color\n"
406 " --fn=FONTNAME set the application font\n"
407 " --font=FONTNAME same as --fn\n"
408 " --foreground=COLOR same as --fg\n"
409 " --geometry=GEOMETRY set the client geometry of first window\n"
410 " --im=SERVER set the X Input Method (XIM) server\n"
411 " --inputstyle=STYLE set X Input Method input style\n"
412 " (possible values: onthespot, overthespot,\n"
413 " offthespot, root)\n");
415 " --name=NAME set the application name\n"
416 " --ncols=COUNT limit the number of colors allocated\n"
417 " in the color cube on an 8-bit display,\n"
418 " if the application is using the\n"
419 " QApplication::ManyColor color specification\n"
420 " --title=TITLE set the application title (caption)\n"
421 " --visual=VISUAL force the application\n"
422 " to use the given visual on an 8-bit display\n"
423 " (only possible value: TrueColor)\n"
430 "The program accepts both TTF and TTC files as input.\n"
431 "Use option -i only if you have a legal permission to modify the font.\n"
432 "The used PPEM value for option -p is FUnits per em, normally 2048.\n"
433 "With option -s, use default values for standard stem width and height,\n"
434 "otherwise they are derived from script-specific characters\n"
435 "resembling the shape of character `o'.\n"
438 "A hint set contains the optimal hinting for a certain PPEM value;\n"
439 "the larger the hint set range (as given by options -l and -r),\n"
440 "the more hint sets get computed, usually increasing the output font size.\n"
441 "The `gasp' table of the output file always enables grayscale hinting\n"
442 "for all sizes (limited by option -G, which is handled in the bytecode).\n"
443 "Increasing the value of -G does not increase the output font size.\n"
446 "Options -f and -D take a four-letter string that identifies a script.\n"
447 "Option -f sets the script used as a fallback for glyphs that can't be\n"
448 "associated with a known script. By default, such glyphs are hinted;\n"
449 "if option -S is set, they are scaled only instead. Option -D sets the\n"
450 "default script for handling OpenType features.\n"
452 "Possible four-letter string values are\n"
454 const Tag_Names
* sn
= script_names
;
457 fprintf(handle
, " %s (%s)",
458 sn
->tag
, sn
->description
);
461 fprintf(handle
, ",\n");
464 fprintf(handle
, ".\n");
471 "A control instructions file contains entries of the form\n"
473 " [<font idx>] <script> <feature> @ <glyph ids>\n"
475 " [<font idx>] <script> <feature> w <stem widths>\n"
477 " [<font idx>] <glyph id> l|r <points> [(<left offset>,<right offset>)]\n"
479 " [<font idx>] <glyph id> n <points>\n"
481 " [<font idx>] <glyph id> t|p <points> [x <shift>] [y <shift>] @ <ppems>\n"
483 "<font idx> is the current subfont, <glyph id> is a glyph name or index,\n"
484 "<glyph ids> is a set of <glyph id>s, <stem widths> is an unordered set of\n"
485 "integer stem widths in font units, <shift> is a real number in px,\n"
486 "<points> and <ppems> are integer ranges as with option `-X'.\n"
488 "<script> and <feature> are four-letter tags that define a style\n"
489 "the <glyph ids> are assigned to; possible values for <script> are the same\n"
490 "as with option -D, possible values for <feature> are\n"
492 const Tag_Names
* fn
= feature_names
;
495 fprintf(handle
, " %s (%s)",
496 fn
->tag
, fn
->description
);
499 fprintf(handle
, ",\n");
502 fprintf(handle
, ".\n");
508 "`w' assigns stem widths to a style; the first value sets the default.\n"
509 "`l' (`r') creates one-point segments with direction left (right).\n"
510 "<left offset> and <right offset> specify offsets (in font units)\n"
511 "relative to the corresponding points to give the segments a length.\n"
512 "`n' removes points from horizontal segments, making them `weak' points.\n"
513 "`t' (`p') applies delta exceptions to the given points before (after) IUP.\n"
515 "`#' starts a line comment, which gets ignored.\n"
516 "Empty lines are ignored, too.\n"
518 "Key letters `l', `r', `n', `p', `t', `w', `x', and `y'\n"
519 "have the verbose aliases `left', `right', `nodir', `point', `touch',\n"
520 "`width', `xshift', and `yshift', respectively.\n"
524 "A command-line version of this program is called `ttfautohint'.\n"
526 "A GUI version of this program is called `ttfautohintGUI'.\n"
529 "Report bugs to: freetype-devel@nongnu.org\n"
531 "ttfautohint home page: <https://www.freetype.org/ttfautohint>\n");
545 "ttfautohintGUI " VERSION
"\n"
547 "ttfautohint " VERSION
"\n"
549 "Copyright (C) 2011-2022 Werner Lemberg <wl@gnu.org>.\n"
550 "License: FreeType License (FTL) or GNU GPLv2.\n"
551 "This is free software: you are free to change and redistribute it.\n"
552 "There is NO WARRANTY, to the extent permitted by law.\n");
556 #endif // CONSOLE_OUTPUT
561 typedef const struct FT_error_
567 static FT_error FT_errors
[] =
569 #undef __FTERRORS_H__
570 #define FT_ERRORDEF(e, v, s) { e, s },
571 #define FT_ERROR_START_LIST {
572 #define FT_ERROR_END_LIST { 0, NULL } };
577 FT_get_error_message(FT_Error error
)
579 FT_error
* e
= FT_errors
;
581 while (e
->err_code
|| e
->err_msg
)
583 if (e
->err_code
== error
)
592 #define BUF_SIZE 0x10000
594 #define TTAG_TTFA FT_MAKE_TAG('T', 'T', 'F', 'A')
597 display_TTFA(FILE* in
)
599 FT_Byte buf
[BUF_SIZE
];
607 in_buf
= (FT_Byte
*)malloc(BUF_SIZE
);
610 fprintf(stderr
, "Can't allocate enough memory.\n");
614 while ((read_bytes
= fread(buf
, 1, BUF_SIZE
, in
)) > 0)
616 FT_Byte
* in_buf_new
= (FT_Byte
*)realloc(in_buf
, in_len
+ read_bytes
);
619 fprintf(stderr
, "Can't reallocate enough memory.\n");
625 memcpy(in_buf
+ in_len
, buf
, read_bytes
);
627 in_len
+= read_bytes
;
632 fprintf(stderr
, "Stream error while handling input font.\n");
636 FT_Library library
= NULL
;
640 error
= FT_Init_FreeType(&library
);
643 fprintf(stderr
, "Can't initialize FreeType library:\n"
645 FT_get_error_message(error
));
649 // in a TTC, a `TTFA' table is part of the first subfont,
650 // thus we can simply pass 0 as the face index
651 error
= FT_New_Memory_Face(library
, in_buf
, (FT_Long
)in_len
, 0, &face
);
654 fprintf(stderr
, "Can't open input font:\n"
656 FT_get_error_message(error
));
660 FT_Byte
* ttfa_buf
= NULL
;
661 FT_ULong ttfa_len
= 0;
663 error
= FT_Load_Sfnt_Table(face
, TTAG_TTFA
, 0, NULL
, &ttfa_len
);
666 fprintf(stderr
, "No `TTFA' table in font.\n");
670 ttfa_buf
= (FT_Byte
*)malloc(ttfa_len
);
673 fprintf(stderr
, "Can't allocate enough memory.\n");
677 error
= FT_Load_Sfnt_Table(face
, TTAG_TTFA
, 0, ttfa_buf
, &ttfa_len
);
680 fprintf(stderr
, "Error loading `TTFA' table:\n"
682 FT_get_error_message(error
));
686 fprintf(stdout
, "%s", ttfa_buf
);
690 FT_Done_FreeType(library
);
706 int hinting_range_min
= 0;
707 int hinting_range_max
= 0;
708 int hinting_limit
= 0;
709 int increase_x_height
= 0;
710 int fallback_stem_width
= 0;
712 bool have_hinting_range_min
= false;
713 bool have_hinting_range_max
= false;
714 bool have_hinting_limit
= false;
715 bool have_increase_x_height
= false;
716 bool have_fallback_stem_width
= false;
718 int gray_stem_width_mode
= TA_STEM_WIDTH_MODE_QUANTIZED
;
719 int gdi_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_STRONG
;
720 int dw_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_QUANTIZED
;
723 bool have_option_w
= false;
724 const char* option_w_arg
;
727 bool ignore_restrictions
= false;
728 bool windows_compatibility
= false;
729 bool adjust_subglyphs
= false;
730 bool hint_composites
= false;
731 bool no_info
= false;
732 bool detailed_info
= false;
733 bool TTFA_info
= false;
735 bool show_TTFA_info
= false;
738 bool fallback_scaling
= false;
740 const char* default_script
= NULL
;
741 bool have_default_script
= false;
742 const char* fallback_script
= NULL
;
743 bool have_fallback_script
= false;
744 const char* x_height_snapping_exceptions_string
= NULL
;
745 bool have_x_height_snapping_exceptions_string
= false;
746 const char* family_suffix
= NULL
;
747 bool have_family_suffix
= false;
754 TA_Progress_Func progress_func
= NULL
;
755 TA_Error_Func err_func
= err
;
756 TA_Info_Func info_func
= info
;
757 TA_Info_Post_Func info_post_func
= info_post
;
759 const char* control_name
= NULL
;
760 const char* reference_name
= NULL
;
761 int reference_index
= 0;
763 unsigned long long epoch
= ULLONG_MAX
;
766 // For real numbers (both parsing and displaying) we only use `.' as the
767 // decimal separator; similarly, we don't want localized formats like a
768 // thousands separator for any number.
769 setlocale(LC_NUMERIC
, "C");
771 // make GNU, Qt, and X11 command line options look the same;
772 // we allow `--foo=bar', `--foo bar', `-foo=bar', `-foo bar',
773 // and short options specific to ttfautohint
775 // set up a new argument string
776 vector
<string
> new_arg_string
;
777 new_arg_string
.push_back(argv
[0]);
781 // use pseudo short options for long-only options
784 PASS_THROUGH
= CHAR_MAX
+ 1,
789 static struct option long_options
[] =
791 {"help", no_argument
, NULL
, 'h'},
793 {"help-all", no_argument
, NULL
, HELP_ALL_OPTION
},
796 // ttfautohint options
797 {"adjust-subglyphs", no_argument
, NULL
, 'p'},
798 {"composites", no_argument
, NULL
, 'c'},
800 {"control-file", required_argument
, NULL
, 'm'},
801 {"debug", no_argument
, NULL
, DEBUG_OPTION
},
803 {"default-script", required_argument
, NULL
, 'D'},
804 {"dehint", no_argument
, NULL
, 'd'},
805 {"detailed-info", no_argument
, NULL
, 'I'},
806 {"fallback-scaling", no_argument
, NULL
, 'S'},
807 {"fallback-script", required_argument
, NULL
, 'f'},
808 {"fallback-stem-width", required_argument
, NULL
, 'H'},
809 {"family-suffix", required_argument
, NULL
, 'F'},
810 {"hinting-limit", required_argument
, NULL
, 'G'},
811 {"hinting-range-max", required_argument
, NULL
, 'r'},
812 {"hinting-range-min", required_argument
, NULL
, 'l'},
813 {"ignore-restrictions", no_argument
, NULL
, 'i'},
814 {"increase-x-height", required_argument
, NULL
, 'x'},
815 {"no-info", no_argument
, NULL
, 'n'},
816 {"pre-hinting", no_argument
, NULL
, 'p'},
818 {"reference", required_argument
, NULL
, 'R'},
819 {"reference-index", required_argument
, NULL
, 'Z'},
821 {"stem-width-mode", required_argument
, NULL
, 'a'},
822 {"strong-stem-width", required_argument
, NULL
, 'w'},
823 {"symbol", no_argument
, NULL
, 's'},
824 {"ttfa-table", no_argument
, NULL
, 't'},
826 {"ttfa-info", no_argument
, NULL
, 'T'},
828 {"verbose", no_argument
, NULL
, 'v'},
829 {"version", no_argument
, NULL
, 'V'},
830 {"windows-compatibility", no_argument
, NULL
, 'W'},
831 {"x-height-snapping-exceptions", required_argument
, NULL
, 'X'},
834 {"graphicssystem", required_argument
, NULL
, PASS_THROUGH
},
835 {"reverse", no_argument
, NULL
, PASS_THROUGH
},
836 {"session", required_argument
, NULL
, PASS_THROUGH
},
837 {"style", required_argument
, NULL
, PASS_THROUGH
},
838 {"stylesheet", required_argument
, NULL
, PASS_THROUGH
},
841 {"background", required_argument
, NULL
, PASS_THROUGH
},
842 {"bg", required_argument
, NULL
, PASS_THROUGH
},
843 {"btn", required_argument
, NULL
, PASS_THROUGH
},
844 {"button", required_argument
, NULL
, PASS_THROUGH
},
845 {"cmap", no_argument
, NULL
, PASS_THROUGH
},
846 {"display", required_argument
, NULL
, PASS_THROUGH
},
847 {"fg", required_argument
, NULL
, PASS_THROUGH
},
848 {"fn", required_argument
, NULL
, PASS_THROUGH
},
849 {"font", required_argument
, NULL
, PASS_THROUGH
},
850 {"foreground", required_argument
, NULL
, PASS_THROUGH
},
851 {"geometry", required_argument
, NULL
, PASS_THROUGH
},
852 {"im", required_argument
, NULL
, PASS_THROUGH
},
853 {"inputstyle", required_argument
, NULL
, PASS_THROUGH
},
854 {"name", required_argument
, NULL
, PASS_THROUGH
},
855 {"ncols", required_argument
, NULL
, PASS_THROUGH
},
856 {"title", required_argument
, NULL
, PASS_THROUGH
},
857 {"visual", required_argument
, NULL
, PASS_THROUGH
},
863 int c
= getopt_long_only(argc
, argv
,
865 "a:cdD:f:F:G:hH:iIl:npr:sStvVw:Wx:X:",
867 "a:cdD:f:F:G:hH:iIl:m:npr:R:sStTvVw:Wx:X:Z:",
869 long_options
, &option_index
);
876 if (strlen(optarg
) != 3)
878 fprintf(stderr
, "Stem width mode string must consist of exactly"
886 gray_stem_width_mode
= TA_STEM_WIDTH_MODE_NATURAL
;
889 gray_stem_width_mode
= TA_STEM_WIDTH_MODE_QUANTIZED
;
892 gray_stem_width_mode
= TA_STEM_WIDTH_MODE_STRONG
;
895 fprintf(stderr
, "Stem width mode letter for grayscale rendering"
896 " must be `n', `q', or `s'\n");
903 gdi_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_NATURAL
;
906 gdi_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_QUANTIZED
;
909 gdi_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_STRONG
;
912 fprintf(stderr
, "Stem width mode letter for GDI ClearType rendering"
913 " must be `n', `q', or `s'\n");
920 dw_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_NATURAL
;
923 dw_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_QUANTIZED
;
926 dw_cleartype_stem_width_mode
= TA_STEM_WIDTH_MODE_STRONG
;
929 fprintf(stderr
, "Stem width mode letter for DW ClearType rendering"
930 " must be `n', `q', or `s'\n");
937 hint_composites
= true;
945 default_script
= optarg
;
946 have_default_script
= true;
950 fallback_script
= optarg
;
951 have_fallback_script
= true;
955 family_suffix
= optarg
;
956 have_family_suffix
= true;
960 hinting_limit
= atoi(optarg
);
961 have_hinting_limit
= true;
965 #ifdef CONSOLE_OUTPUT
966 show_help(false, false);
971 fallback_stem_width
= atoi(optarg
);
972 have_fallback_stem_width
= true;
976 ignore_restrictions
= true;
980 detailed_info
= true;
985 hinting_range_min
= atoi(optarg
);
986 have_hinting_range_min
= true;
991 control_name
= optarg
;
997 detailed_info
= false;
1001 adjust_subglyphs
= true;
1005 hinting_range_max
= atoi(optarg
);
1006 have_hinting_range_max
= true;
1011 reference_name
= optarg
;
1020 fallback_scaling
= true;
1029 show_TTFA_info
= true;
1035 progress_func
= progress
;
1040 #ifdef CONSOLE_OUTPUT
1046 gray_stem_width_mode
= strchr(optarg
, 'g')
1047 ? TA_STEM_WIDTH_MODE_STRONG
1048 : TA_STEM_WIDTH_MODE_QUANTIZED
;
1049 gdi_cleartype_stem_width_mode
= strchr(optarg
, 'G')
1050 ? TA_STEM_WIDTH_MODE_STRONG
1051 : TA_STEM_WIDTH_MODE_QUANTIZED
;
1052 dw_cleartype_stem_width_mode
= strchr(optarg
, 'D')
1053 ? TA_STEM_WIDTH_MODE_STRONG
1054 : TA_STEM_WIDTH_MODE_QUANTIZED
;
1056 have_option_w
= true;
1057 option_w_arg
= optarg
;
1062 windows_compatibility
= true;
1066 increase_x_height
= atoi(optarg
);
1067 have_increase_x_height
= true;
1071 x_height_snapping_exceptions_string
= optarg
;
1072 have_x_height_snapping_exceptions_string
= true;
1077 reference_index
= atoi(optarg
);
1088 case HELP_ALL_OPTION
:
1089 #ifdef CONSOLE_OUTPUT
1090 show_help(true, false);
1097 // append argument with proper syntax for Qt
1100 arg
+= long_options
[option_index
].name
;
1102 new_arg_string
.push_back(arg
);
1104 new_arg_string
.push_back(optarg
);
1115 // -d makes ttfautohint ignore all other hinting options
1116 have_default_script
= false;
1117 have_fallback_script
= false;
1118 have_fallback_stem_width
= false;
1119 have_hinting_limit
= false;
1120 have_hinting_range_max
= false;
1121 have_hinting_range_min
= false;
1122 have_increase_x_height
= false;
1123 have_x_height_snapping_exceptions_string
= false;
1129 // -T makes ttfautohint ignore even more options
1130 have_default_script
= false;
1131 have_fallback_script
= false;
1132 have_fallback_stem_width
= false;
1133 have_family_suffix
= false;
1134 have_hinting_limit
= false;
1135 have_hinting_range_max
= false;
1136 have_hinting_range_min
= false;
1137 have_increase_x_height
= false;
1138 have_x_height_snapping_exceptions_string
= false;
1143 if (!have_default_script
)
1144 default_script
= "latn";
1145 if (!have_fallback_script
)
1146 fallback_script
= "none";
1147 if (!have_hinting_range_min
)
1148 hinting_range_min
= TA_HINTING_RANGE_MIN
;
1149 if (!have_hinting_range_max
)
1150 hinting_range_max
= TA_HINTING_RANGE_MAX
;
1151 if (!have_hinting_limit
)
1152 hinting_limit
= TA_HINTING_LIMIT
;
1153 if (!have_increase_x_height
)
1154 increase_x_height
= TA_INCREASE_X_HEIGHT
;
1155 if (!have_x_height_snapping_exceptions_string
)
1156 x_height_snapping_exceptions_string
= "";
1157 if (!have_fallback_stem_width
)
1158 fallback_stem_width
= 0; // redundant, but avoids a compiler warning
1159 if (!have_family_suffix
)
1164 // check SOURE_DATE_EPOCH environment variable
1165 const char* source_date_epoch
= getenv("SOURCE_DATE_EPOCH");
1166 if (source_date_epoch
)
1171 epoch
= strtoull(source_date_epoch
, &endptr
, 10);
1172 if ((errno
== ERANGE
&& (epoch
== ULLONG_MAX
1178 "Environment variable `SOURCE_DATE_EPOCH' ignored:\n"
1183 else if (endptr
== source_date_epoch
)
1186 "Environment variable `SOURCE_DATE_EPOCH' ignored:\n"
1187 " No digits were found: %s\n",
1191 else if (*endptr
!= '\0')
1194 "Environment variable `SOURCE_DATE_EPOCH' ignored:\n"
1195 " Trailing garbage: %s\n",
1199 else if (epoch
> ULONG_MAX
)
1202 "Environment variable `SOURCE_DATE_EPOCH' ignored\n"
1203 " value must be smaller than or equal to %lu\n"
1204 " but was found to be %llu\n",
1212 char option_a_arg
[4];
1215 gray_stem_width_mode
== TA_STEM_WIDTH_MODE_STRONG
? 's' : 'q';
1217 gdi_cleartype_stem_width_mode
== TA_STEM_WIDTH_MODE_STRONG
? 's' : 'q';
1219 dw_cleartype_stem_width_mode
== TA_STEM_WIDTH_MODE_STRONG
? 's' : 'q';
1220 option_a_arg
[3] = '\0';
1223 "Warning: Option `-w %s' is deprecated!"
1224 " Use option `-a %s' instead\n",
1229 if (!isatty(fileno(stderr
)) && !debug
)
1230 setvbuf(stderr
, (char*)NULL
, _IONBF
, BUFSIZ
);
1232 if (hinting_range_min
< 2)
1234 fprintf(stderr
, "The hinting range minimum must be at least 2\n");
1237 if (hinting_range_max
< hinting_range_min
)
1239 fprintf(stderr
, "The hinting range maximum must not be smaller"
1240 " than the minimum (%d)\n",
1244 if (hinting_limit
!= 0 && hinting_limit
< hinting_range_max
)
1246 fprintf(stderr
, "A non-zero hinting limit must not be smaller"
1247 " than the hinting range maximum (%d)\n",
1251 if (increase_x_height
!= 0 && increase_x_height
< 6)
1253 fprintf(stderr
, "A non-zero x height increase limit"
1254 " must be larger than or equal to 6\n");
1257 if (have_fallback_stem_width
&& fallback_stem_width
<= 0)
1259 fprintf(stderr
, "The fallback stem width"
1260 " must be a positive integer\n");
1264 if (have_default_script
)
1266 const Tag_Names
* sn
;
1268 for (sn
= script_names
; sn
->tag
; sn
++)
1269 if (!strcmp(default_script
, sn
->tag
))
1273 fprintf(stderr
, "Unknown script tag `%s'\n", default_script
);
1278 if (have_fallback_script
)
1280 const Tag_Names
* sn
;
1282 for (sn
= script_names
; sn
->tag
; sn
++)
1283 if (!strcmp(fallback_script
, sn
->tag
))
1287 fprintf(stderr
, "Unknown script tag `%s'\n", fallback_script
);
1293 && have_fallback_stem_width
1294 && fallback_scaling
)
1296 "Warning: Setting a fallback stem width for a symbol font\n"
1297 " with fallback scaling only has no effect\n");
1299 if (const char* pos
= check_family_suffix(family_suffix
))
1302 "Invalid character in family suffix:\n"
1306 int(pos
- family_suffix
+ 1), "^");
1310 int num_args
= argc
- optind
;
1313 show_help(false, true);
1318 in
= fopen(argv
[optind
], "rb");
1322 "The following error occurred while opening font `%s':\n"
1325 argv
[optind
], strerror(errno
));
1331 if (isatty(fileno(stdin
)))
1332 show_help(false, true);
1337 display_TTFA(in
); // this function doesn't return
1342 if (!strcmp(argv
[optind
], argv
[optind
+ 1]))
1344 fprintf(stderr
, "Input and output file names must not be identical\n");
1348 out
= fopen(argv
[optind
+ 1], "wb");
1352 "The following error occurred while opening font `%s':\n"
1355 argv
[optind
+ 1], strerror(errno
));
1361 if (isatty(fileno(stdout
)))
1362 show_help(false, true);
1366 FILE* control
= NULL
;
1369 control
= fopen(control_name
, "r");
1373 "The following error occurred"
1374 " while opening control file `%s':\n"
1377 control_name
, strerror(errno
));
1384 FILE* reference
= NULL
;
1387 reference
= fopen(reference_name
, "rb");
1391 "The following error occurred"
1392 " while opening reference font `%s':\n"
1395 reference_name
, strerror(errno
));
1399 if (reference_index
!= 0)
1401 FT_Library library
= NULL
;
1402 FT_Face face
= NULL
;
1405 error
= FT_Init_FreeType(&library
);
1408 fprintf(stderr
, "Can't initialize FreeType library:\n"
1410 FT_get_error_message(error
));
1414 error
= FT_New_Face(library
, reference_name
, -1, &face
);
1417 fprintf(stderr
, "Can't check number of faces in reference font:\n"
1419 FT_get_error_message(error
));
1423 if (reference_index
< 0
1424 || reference_index
>= face
->num_faces
)
1426 fprintf(stderr
, "Face index for reference font must be"
1427 " in the range [0;%ld]\n",
1428 face
->num_faces
- 1);
1433 FT_Done_FreeType(library
);
1439 Progress_Data progress_data
= {-1, 1, 0};
1440 Error_Data error_data
= {control_name
};
1441 Info_Data info_data
;
1443 if (!*family_suffix
)
1444 info_post_func
= NULL
;
1446 info_data
.no_info
= no_info
;
1447 info_data
.detailed_info
= detailed_info
;
1448 info_data
.info_string
= NULL
; // must be deallocated after use
1449 info_data
.info_string_wide
= NULL
; // must be deallocated after use
1450 info_data
.info_string_len
= 0;
1451 info_data
.info_string_wide_len
= 0;
1453 info_data
.control_name
= control_name
;
1454 info_data
.reference_name
= reference_name
;
1455 info_data
.reference_index
= reference_index
;
1457 info_data
.hinting_range_min
= hinting_range_min
;
1458 info_data
.hinting_range_max
= hinting_range_max
;
1459 info_data
.hinting_limit
= hinting_limit
;
1461 info_data
.gray_stem_width_mode
= gray_stem_width_mode
;
1462 info_data
.gdi_cleartype_stem_width_mode
= gdi_cleartype_stem_width_mode
;
1463 info_data
.dw_cleartype_stem_width_mode
= dw_cleartype_stem_width_mode
;
1465 info_data
.windows_compatibility
= windows_compatibility
;
1466 info_data
.adjust_subglyphs
= adjust_subglyphs
;
1467 info_data
.hint_composites
= hint_composites
;
1468 info_data
.increase_x_height
= increase_x_height
;
1469 info_data
.x_height_snapping_exceptions_string
= x_height_snapping_exceptions_string
;
1470 info_data
.family_suffix
= family_suffix
;
1471 info_data
.family_data_head
= NULL
;
1472 info_data
.fallback_stem_width
= fallback_stem_width
;
1473 info_data
.symbol
= symbol
;
1474 info_data
.fallback_scaling
= fallback_scaling
;
1475 info_data
.TTFA_info
= TTFA_info
;
1477 strncpy(info_data
.default_script
,
1479 sizeof (info_data
.default_script
));
1480 strncpy(info_data
.fallback_script
,
1482 sizeof (info_data
.fallback_script
));
1484 info_data
.dehint
= dehint
;
1488 int ret
= build_version_string(&info_data
);
1490 fprintf(stderr
, "Warning: Can't allocate memory"
1491 " for ttfautohint options string in `name' table\n");
1493 fprintf(stderr
, "Warning: ttfautohint options string"
1494 " in `name' table too long\n");
1503 TTF_autohint("in-file, out-file, control-file,"
1504 "reference-file, reference-index, reference-name,"
1505 "hinting-range-min, hinting-range-max, hinting-limit,"
1506 "gray-stem-width-mode, gdi-cleartype-stem-width-mode,"
1507 "dw-cleartype-stem-width-mode,"
1508 "progress-callback, progress-callback-data,"
1509 "error-callback, error-callback-data,"
1510 "info-callback, info-post-callback, info-callback-data,"
1511 "ignore-restrictions, windows-compatibility,"
1512 "adjust-subglyphs, hint-composites,"
1513 "increase-x-height, x-height-snapping-exceptions,"
1514 "fallback-stem-width, default-script,"
1515 "fallback-script, fallback-scaling,"
1516 "symbol, dehint, debug, TTFA-info, epoch",
1518 reference
, reference_index
, reference_name
,
1519 hinting_range_min
, hinting_range_max
, hinting_limit
,
1520 gray_stem_width_mode
, gdi_cleartype_stem_width_mode
,
1521 dw_cleartype_stem_width_mode
,
1522 progress_func
, &progress_data
,
1523 err_func
, &error_data
,
1524 info_func
, info_post_func
, &info_data
,
1525 ignore_restrictions
, windows_compatibility
,
1526 adjust_subglyphs
, hint_composites
,
1527 increase_x_height
, x_height_snapping_exceptions_string
,
1528 fallback_stem_width
, default_script
,
1529 fallback_script
, fallback_scaling
,
1530 symbol
, dehint
, debug
, TTFA_info
, epoch
);
1534 free(info_data
.info_string
);
1535 free(info_data
.info_string_wide
);
1547 exit(error
? EXIT_FAILURE
: EXIT_SUCCESS
);
1549 return 0; // never reached
1553 int new_argc
= (int)new_arg_string
.size();
1554 char** new_argv
= new char*[new_argc
];
1556 // construct new argc and argv variables from collected data
1557 for (unsigned int i
= 0; i
< (unsigned int)new_argc
; i
++)
1558 new_argv
[i
] = const_cast<char*>(new_arg_string
[i
].data());
1560 QApplication
app(new_argc
, new_argv
);
1561 app
.setApplicationName("TTFautohint");
1562 app
.setApplicationVersion(VERSION
);
1563 app
.setOrganizationName("FreeType");
1564 app
.setOrganizationDomain("freetype.org");
1566 bool alternative_layout
= false;
1568 // Display the window off the screen -- to get proper window dimensions
1569 // including the frame, the window manager must have a chance to
1572 // We don't want to change the default window positioning algorithm of
1573 // the platform's window manager, so we create the main GUI window
1576 // The original idea, however, was to simply move the off-screen window
1577 // back to the screen with
1579 // gui.move(100, 100);
1580 // gui.setAttribute(Qt::WA_Moved, false);
1583 // (unsetting the `WA_Moved' attribute makes the window manager handle
1584 // the previous call to `move' as a position suggestion instead of a
1585 // request). Unfortuntely, there seems to be a bug in Qt 4.8.4 which
1586 // prevents any effect of unsetting `WA_Moved' if `show' has already
1589 Main_GUI
dummy(alternative_layout
,
1590 hinting_range_min
, hinting_range_max
, hinting_limit
,
1591 gray_stem_width_mode
, gdi_cleartype_stem_width_mode
,
1592 dw_cleartype_stem_width_mode
, increase_x_height
,
1593 x_height_snapping_exceptions_string
, fallback_stem_width
,
1594 ignore_restrictions
, windows_compatibility
, adjust_subglyphs
,
1595 hint_composites
, no_info
, detailed_info
,
1596 default_script
, fallback_script
, fallback_scaling
,
1597 family_suffix
, symbol
, dehint
, TTFA_info
);
1599 dummy
.move(-50000, -50000);
1602 // if the vertical size of our window is too large,
1603 // select a horizontal layout
1604 QRect
screen(QApplication::desktop()->availableGeometry());
1605 if (dummy
.frameGeometry().height() > screen
.height())
1606 alternative_layout
= true;
1609 Main_GUI
gui(alternative_layout
,
1610 hinting_range_min
, hinting_range_max
, hinting_limit
,
1611 gray_stem_width_mode
, gdi_cleartype_stem_width_mode
,
1612 dw_cleartype_stem_width_mode
, increase_x_height
,
1613 x_height_snapping_exceptions_string
, fallback_stem_width
,
1614 ignore_restrictions
, windows_compatibility
, adjust_subglyphs
,
1615 hint_composites
, no_info
, detailed_info
,
1616 default_script
, fallback_script
, fallback_scaling
,
1617 family_suffix
, symbol
, dehint
, TTFA_info
);