From 0fd518beb13ed45448492ecc782825412f2cff01 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 11 Jun 2018 13:25:39 +0200 Subject: Improvements to the Font Features dialog. Better OpenType coverage. --- src/ui/widget/font-variants.cpp | 202 +++++++++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 55 deletions(-) (limited to 'src/ui/widget/font-variants.cpp') diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index 6d1da6d60..abe5add62 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -340,18 +340,19 @@ namespace Widget { // Add tooltips _feature_entry.set_tooltip_text( _("Feature settings in CSS form. No sanity checking is performed.")); - _feature_list.set_justify( Gtk::JUSTIFY_LEFT ); - _feature_list.set_line_wrap( true ); - _feature_substitutions.set_justify( Gtk::JUSTIFY_LEFT ); _feature_substitutions.set_line_wrap( true ); _feature_substitutions.set_line_wrap_mode( Pango::WRAP_WORD_CHAR ); + _feature_list.set_justify( Gtk::JUSTIFY_LEFT ); + _feature_list.set_line_wrap( true ); + // Add to frame _feature_vbox.pack_start( _feature_entry ); _feature_vbox.pack_start( _feature_label ); - _feature_vbox.pack_start( _feature_list ); _feature_vbox.pack_start( _feature_substitutions ); + _feature_vbox.pack_start( _feature_list ); + _feature_frame.add( _feature_vbox ); pack_start( _feature_frame, Gtk::PACK_SHRINK ); @@ -582,7 +583,7 @@ namespace Widget { font_instance* res = font_factory::Default()->FaceFromFontSpecification( font_spec.c_str() ); if( res ) { - std::map::iterator it; + std::map::iterator it; if((it = res->openTypeTables.find("liga"))!= res->openTypeTables.end() || (it = res->openTypeTables.find("clig"))!= res->openTypeTables.end()) { @@ -767,20 +768,28 @@ namespace Widget { Glib::ustring markup_dlig; Glib::ustring markup_hlig; Glib::ustring markup_calt; - for (auto table: res->openTypeLigatures) { - - Glib::ustring markup; - markup += ""; - markup += Glib::Markup::escape_text(table.second); - markup += ""; - if (table.first == "liga") markup_liga += markup; - if (table.first == "clig") markup_liga += markup; - if (table.first == "dlig") markup_dlig += markup; - if (table.first == "hlig") markup_hlig += markup; - if (table.first == "calt") markup_calt += markup; + for (auto table: res->openTypeTables) { + + if (table.first == "liga" || + table.first == "dlig" || + table.first == "dlig" || + table.first == "hgli" || + table.first == "calt") { + + Glib::ustring markup; + markup += ""; + markup += Glib::Markup::escape_text(table.second.output); + markup += ""; + + if (table.first == "liga") markup_liga += markup; + if (table.first == "clig") markup_liga += markup; + if (table.first == "dlig") markup_dlig += markup; + if (table.first == "hlig") markup_hlig += markup; + if (table.first == "calt") markup_calt += markup; + } } _ligatures_label_common.set_markup ( markup_liga.c_str() ); @@ -797,7 +806,8 @@ namespace Widget { Glib::ustring markup_afrc; Glib::ustring markup_ordn; Glib::ustring markup_zero; - for (auto table: res->openTypeNumeric) { + + for (auto table: res->openTypeTables) { Glib::ustring markup; markup += "descr); + markup += "'>"; + markup += Glib::Markup::escape_text(table.second.input); + markup += ""; + + markup += " "; + + markup += ""; + markup += ""; + markup += Glib::Markup::escape_text(table.second.input); + markup += ""; + markup += "\n"; + } + } + + // GSUB lookup type 3 (1 to many mapping). Optionally type 1. + for (auto table: res->openTypeTables) { + if (table.first == "salt" || + table.first == "swsh" || + table.first == "cwsh" || + table.first == "ornm" || + table.first == "nalt" || + table.first[0] == 'c' && table.first[1] == 'v') { + + if (table.second.input.length() == 0) { + // This can happen if a table is not in the 'DFLT' script and 'dflt' language. + // We should be using the 'lang' attribute to find the correct tables. + // std::cerr << "FontVariants::open_type_update: " + // << table.first << " has no entries!" << std::endl; + continue; + } + + if( (it = table_copy.find(table.first)) != table_copy.end() ) table_copy.erase( it ); + + // Our lame attempt at determining number of alternative glyphs for one glyph: + int number = table.second.output.length() / table.second.input.length(); + + for (int i = 0; i < number; ++i) { + markup += ""; + markup += table.first; + if (i != 0) { + markup += " "; + markup += std::to_string (i + 1); + } + markup += ""; + markup += ": "; + + markup += ""; + markup += Glib::Markup::escape_text(table.second.input); + markup += ""; + + markup += " "; + + markup += ""; + markup += ""; + markup += Glib::Markup::escape_text(table.second.input); + markup += ""; + markup += "\n"; + } + } + } + + _feature_substitutions.set_markup ( markup.c_str() ); + std::string ott_list = "OpenType tables not included above: "; for(it = table_copy.begin(); it != table_copy.end(); ++it) { - // std::cout << "Other: " << it->first << " Occurrences: " << it->second << std::endl; ott_list += it->first; ott_list += ", "; } - _feature_list.set_text( ott_list.c_str() ); - - // ""; - Glib::ustring markup; - - for (auto table: res->openTypeStylistic) { - - markup += ""; - markup += table.first; - markup += ""; - markup += ": "; - - markup += ""; - markup += Glib::Markup::escape_text(table.second); - markup += ""; - - markup += " → "; - - markup += ""; - markup += ""; - markup += Glib::Markup::escape_text(table.second); - markup += ""; - markup += "\n"; - + if (table_copy.size() > 0) { + ott_list.pop_back(); + ott_list.pop_back(); + _feature_list.set_text( ott_list.c_str() ); + } else { + _feature_list.set_text( "" ); } - _feature_substitutions.set_markup ( markup.c_str() ); } else { std::cerr << "FontVariants::update(): Couldn't find font_instance for: " -- cgit v1.2.3