From 18f8bd4bf870c489d76ee5fc202f69b093037c67 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 19 Jan 2014 08:21:11 +0100 Subject: [PATCH] Add option `--default-script' to front-ends. --- doc/ttfautohint-1.pandoc | 9 ++++++++ frontend/info.cpp | 1 + frontend/info.h | 1 + frontend/main.cpp | 54 +++++++++++++++++++++++++++++++++------------ frontend/maingui.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++----- frontend/maingui.h | 7 ++++-- 6 files changed, 107 insertions(+), 22 deletions(-) diff --git a/doc/ttfautohint-1.pandoc b/doc/ttfautohint-1.pandoc index 57a2b95..8a2fe5b 100644 --- a/doc/ttfautohint-1.pandoc +++ b/doc/ttfautohint-1.pandoc @@ -228,6 +228,15 @@ See ['Hint Sets'](#hint-sets) for a definition and explanation. : The maximum PPEM value (in pixels) at which hint sets are created. The default value for *n* is 50. +### Default Script + +`--default-script=`*s*, `-D-`\ *s* +: Set default script to tag *s*, which is a string consisting of four + lowercase characters like `latn` or `dflt`. It is needed to specify the + OpenType default script: After applying all features that are handled + specially (like small caps or superscript), ttfautohint uses this value + for the remaining features. The default value is `latn`. + ### Fallback Script `--fallback-script=`*s*, `-f`\ *s* diff --git a/frontend/info.cpp b/frontend/info.cpp index b82dac7..0099674 100644 --- a/frontend/info.cpp +++ b/frontend/info.cpp @@ -63,6 +63,7 @@ build_version_string(Info_Data* idata) d += sprintf(d, " -r %d", idata->hinting_range_max); d += sprintf(d, " -G %d", idata->hinting_limit); d += sprintf(d, " -x %d", idata->increase_x_height); + d += sprintf(d, " -D %s", idata->default_script); d += sprintf(d, " -f %s", idata->fallback_script); count = 0; diff --git a/frontend/info.h b/frontend/info.h index 87ae589..3bb845c 100644 --- a/frontend/info.h +++ b/frontend/info.h @@ -40,6 +40,7 @@ typedef struct Info_Data_ bool windows_compatibility; bool pre_hinting; bool hint_composites; + char default_script[5]; char fallback_script[5]; bool symbol; bool dehint; diff --git a/frontend/main.cpp b/frontend/main.cpp index 50a4837..4c88cdd 100644 --- a/frontend/main.cpp +++ b/frontend/main.cpp @@ -182,6 +182,7 @@ show_help(bool #endif " -c, --composites hint glyph composites also\n" " -d, --dehint remove all hints\n" +" -D, --default-script=S set default OpenType script (default: latn)\n" " -f, --fallback-script=S set fallback script (default: none)\n" " -G, --hinting-limit=N switch off hinting above this PPEM value\n" " (default: %d); value 0 means no limit\n" @@ -288,9 +289,10 @@ show_help(bool "for all sizes (limited by option -G, which is handled in the bytecode).\n" "\n"); fprintf(handle, -"Option -f takes a four-letter string that identifies the script\n" -"to be used as a fallback for glyphs that have character codes\n" -"outside of known script ranges. Possible values are\n" +"Options -f and -D take a four-letter string that identifies a script.\n" +"Option -f sets the script used as a fallback for glyphs that have\n" +"character codes outside of known script ranges. Option -D sets the\n" +"default script for handling OpenType features. Possible values are\n" "\n"); const Script_Names* sn = script_names; for(;;) @@ -308,10 +310,6 @@ show_help(bool } fprintf(handle, "\n" -"If no option -f is given, or if its value is `none',\n" -"no fallback script is used.\n" -"\n"); - fprintf(handle, #ifdef BUILD_GUI "A command-line version of this program is called `ttfautohint'.\n" #else @@ -371,6 +369,8 @@ main(int argc, bool no_info = false; bool symbol = false; + const char* default_script = NULL; + bool have_default_script = false; const char* fallback_script = NULL; bool have_fallback_script = false; const char* x_height_snapping_exceptions_string = NULL; @@ -415,6 +415,7 @@ main(int argc, #ifndef BUILD_GUI {"debug", no_argument, NULL, DEBUG_OPTION}, #endif + {"default-script", required_argument, NULL, 'D'}, {"dehint", no_argument, NULL, 'd'}, {"fallback-script", required_argument, NULL, 'f'}, {"hinting-limit", required_argument, NULL, 'G'}, @@ -461,7 +462,7 @@ main(int argc, }; int option_index; - int c = getopt_long_only(argc, argv, "cdf:G:hil:npr:stVvw:Wx:X:", + int c = getopt_long_only(argc, argv, "cdD:f:G:hil:npr:stVvw:Wx:X:", long_options, &option_index); if (c == -1) break; @@ -476,6 +477,11 @@ main(int argc, dehint = true; break; + case 'D': + default_script = optarg; + have_default_script = true; + break; + case 'f': fallback_script = optarg; have_fallback_script = true; @@ -585,6 +591,7 @@ main(int argc, if (dehint) { // -d makes ttfautohint ignore all other hinting options + have_default_script = false; have_fallback_script = false; have_hinting_range_min = false; have_hinting_range_max = false; @@ -593,6 +600,8 @@ main(int argc, have_x_height_snapping_exceptions_string = false; } + if (!have_default_script) + default_script = "latn"; if (!have_fallback_script) fallback_script = "none"; if (!have_hinting_range_min) @@ -673,6 +682,20 @@ main(int argc, } } + if (have_default_script) + { + const Script_Names* sn; + + for (sn = script_names; sn->tag; sn++) + if (!strcmp(default_script, sn->tag)) + break; + if (!sn->tag) + { + fprintf(stderr, "Unknown script tag `%s'\n", default_script); + exit(EXIT_FAILURE); + } + } + if (have_fallback_script) { const Script_Names* sn; @@ -766,6 +789,9 @@ main(int argc, info_data.x_height_snapping_exceptions = x_height_snapping_exceptions; info_data.symbol = symbol; + strncpy(info_data.default_script, + default_script, + sizeof (info_data.default_script)); strncpy(info_data.fallback_script, fallback_script, sizeof (info_data.fallback_script)); @@ -797,7 +823,7 @@ main(int argc, "ignore-restrictions, windows-compatibility," "pre-hinting, hint-composites," "increase-x-height, x-height-snapping-exceptions," - "fallback-script, symbol," + "default-script, fallback-script, symbol," "dehint, debug", in, out, hinting_range_min, hinting_range_max, hinting_limit, @@ -809,7 +835,7 @@ main(int argc, ignore_restrictions, windows_compatibility, pre_hinting, hint_composites, increase_x_height, x_height_snapping_exceptions_string, - fallback_script, symbol, + default_script, fallback_script, symbol, dehint, debug); if (!no_info) @@ -912,8 +938,8 @@ main(int argc, dw_cleartype_strong_stem_width, increase_x_height, x_height_snapping_exceptions_string, ignore_restrictions, windows_compatibility, pre_hinting, - hint_composites, no_info, fallback_script, symbol, - dehint); + hint_composites, no_info, default_script, fallback_script, + symbol, dehint); dummy.move(-50000, -50000); dummy.show(); @@ -931,8 +957,8 @@ main(int argc, dw_cleartype_strong_stem_width, increase_x_height, x_height_snapping_exceptions_string, ignore_restrictions, windows_compatibility, pre_hinting, - hint_composites, no_info, fallback_script, symbol, - dehint); + hint_composites, no_info, default_script, fallback_script, + symbol, dehint); gui.show(); return app.exec(); diff --git a/frontend/maingui.cpp b/frontend/maingui.cpp index d3e73db..d4740e6 100644 --- a/frontend/maingui.cpp +++ b/frontend/maingui.cpp @@ -70,6 +70,7 @@ Main_GUI::Main_GUI(bool horizontal_layout, bool pre, bool composites, bool no, + const char* dflt, const char* fallback, bool symb, bool dh) @@ -90,10 +91,22 @@ Main_GUI::Main_GUI(bool horizontal_layout, dehint(dh) { int i; - int none_script_idx = 0; + + // map default script tag to an index, + // replacing an invalid one with the default value + int latn_script_idx = 0; + for (i = 0; script_names[i].tag; i++) + { + if (!strcmp("latn", script_names[i].tag)) + latn_script_idx = i; + if (!strcmp(dflt, script_names[i].tag)) + break; + } + default_script_idx = script_names[i].tag ? i : latn_script_idx; // map fallback script tag to an index, // replacing an invalid one with the default value + int none_script_idx = 0; for (i = 0; script_names[i].tag; i++) { if (!strcmp("none", script_names[i].tag)) @@ -241,6 +254,8 @@ Main_GUI::check_dehint() max_label->setEnabled(false); max_box->setEnabled(false); + default_label->setEnabled(false); + default_box->setEnabled(false); fallback_label->setEnabled(false); fallback_box->setEnabled(false); @@ -273,6 +288,8 @@ Main_GUI::check_dehint() max_label->setEnabled(true); max_box->setEnabled(true); + default_label->setEnabled(true); + default_box->setEnabled(true); fallback_label->setEnabled(true); fallback_box->setEnabled(true); @@ -786,6 +803,9 @@ again: info_data.symbol = symbol_box->isChecked(); info_data.dehint = dehint_box->isChecked(); + strncpy(info_data.default_script, + script_names[default_box->currentIndex()].tag, + sizeof (info_data.default_script)); strncpy(info_data.fallback_script, script_names[fallback_box->currentIndex()].tag, sizeof (info_data.fallback_script)); @@ -831,8 +851,8 @@ again: "hint-composites," "increase-x-height," "x-height-snapping-exceptions," - "fallback-script, symbol," - "dehint", + "default-script, fallback-script," + "symbol, dehint", input, output, info_data.hinting_range_min, info_data.hinting_range_max, info_data.hinting_limit, @@ -848,8 +868,8 @@ again: info_data.hint_composites, info_data.increase_x_height, snapping_string.constData(), - info_data.fallback_script, info_data.symbol, - info_data.dehint); + info_data.default_script, info_data.fallback_script, + info_data.symbol, info_data.dehint); if (info_box->isChecked()) { @@ -936,13 +956,33 @@ Main_GUI::create_layout(bool horizontal_layout) max_box->setRange(2, 10000); // + // OpenType default script + // + default_label = new QLabel(tr("Defa&ult Script:")); + default_box = new QComboBox; + default_label->setBuddy(default_box); + default_label->setToolTip( + tr("This sets the default script for OpenType features:" + " After applying all features that are handled specially" + " (for example small caps or superscript glyphs)," + " TTFautohint uses this value for the remaining features.")); + for (int i = 0; script_names[i].tag; i++) + { + // XXX: how to provide translations? + default_box->insertItem(i, + QString("%1 (%2)") + .arg(script_names[i].tag) + .arg(script_names[i].description)); + } + + // // hinting and fallback controls // fallback_label = new QLabel(tr("Fallback &Script:")); fallback_box = new QComboBox; fallback_label->setBuddy(fallback_box); fallback_label->setToolTip( - tr("This sets the fallback script module for glyphs" + tr("This sets the fallback script for glyphs" " that TTFautohint can't map to a script automatically.")); for (int i = 0; script_names[i].tag; i++) { @@ -1158,6 +1198,8 @@ Main_GUI::create_vertical_layout() gui_layout->setRowMinimumHeight(row, 20); // XXX urgh, pixels... gui_layout->setRowStretch(row++, 1); + gui_layout->addWidget(default_label, row, 0, Qt::AlignRight); + gui_layout->addWidget(default_box, row++, 1, Qt::AlignLeft); gui_layout->addWidget(fallback_label, row, 0, Qt::AlignRight); gui_layout->addWidget(fallback_box, row++, 1, Qt::AlignLeft); @@ -1254,6 +1296,8 @@ Main_GUI::create_horizontal_layout() gui_layout->setRowMinimumHeight(row, 20); // XXX urgh, pixels... gui_layout->setRowStretch(row++, 1); + gui_layout->addWidget(default_label, row, 1, Qt::AlignRight); + gui_layout->addWidget(default_box, row++, 2, Qt::AlignLeft); gui_layout->addWidget(fallback_label, row, 1, Qt::AlignRight); gui_layout->addWidget(fallback_box, row++, 2, Qt::AlignLeft); @@ -1399,6 +1443,7 @@ Main_GUI::set_defaults() min_box->setValue(hinting_range_min); max_box->setValue(hinting_range_max); + default_box->setCurrentIndex(default_script_idx); fallback_box->setCurrentIndex(fallback_script_idx); limit_box->setValue(hinting_limit ? hinting_limit : hinting_range_max); diff --git a/frontend/maingui.h b/frontend/maingui.h index e3c5cc8..03d0956 100644 --- a/frontend/maingui.h +++ b/frontend/maingui.h @@ -50,8 +50,8 @@ public: bool, int, const char*, bool, bool, bool, - bool, bool, const char*, bool, - bool); + bool, bool, const char*, const char*, + bool, bool); ~Main_GUI(); protected: @@ -89,6 +89,7 @@ private: int pre_hinting; int hint_composites; int no_info; + int default_script_idx; int fallback_script_idx; int symbol; int dehint; @@ -131,6 +132,8 @@ private: QCheckBox* gdi_box; QCheckBox* dw_box; + QLabel* default_label; + QComboBox* default_box; QLabel* fallback_label; QComboBox* fallback_box; -- 2.11.4.GIT