summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-05-13 12:51:42 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-05-13 12:51:42 +0000
commit8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0 (patch)
tree8e1184830a0b10843c2d6c1a8daffac721c60db7 /src
parentFix rendering of hatches when hatchContentUnits and hatchUnits have different... (diff)
downloadinkscape-8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0.tar.gz
inkscape-8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0.zip
Add preview for numeric OpenType features.
Diffstat (limited to 'src')
-rw-r--r--src/libnrtype/FontInstance.cpp3
-rw-r--r--src/libnrtype/OpenTypeUtil.cpp32
-rw-r--r--src/libnrtype/OpenTypeUtil.h3
-rw-r--r--src/libnrtype/font-instance.h1
-rw-r--r--src/ui/widget/font-variants.cpp156
-rw-r--r--src/ui/widget/font-variants.h33
6 files changed, 163 insertions, 65 deletions
diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp
index 47d4baa51..f8ee41108 100644
--- a/src/libnrtype/FontInstance.cpp
+++ b/src/libnrtype/FontInstance.cpp
@@ -211,7 +211,8 @@ void font_instance::InitTheFace()
#ifndef USE_PANGO_WIN32
- readOpenTypeGsubTable( theFace, openTypeTables, openTypeStylistic, openTypeLigatures );
+ readOpenTypeGsubTable( theFace, openTypeTables, openTypeStylistic,
+ openTypeLigatures, openTypeNumeric );
readOpenTypeFvarAxes( theFace, openTypeVarAxes );
#if PANGO_VERSION_CHECK(1,41,1)
diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp
index a2506e1d7..14130db48 100644
--- a/src/libnrtype/OpenTypeUtil.cpp
+++ b/src/libnrtype/OpenTypeUtil.cpp
@@ -44,12 +44,14 @@ Glib::ustring extract_tag( guint32 *tag ) {
void readOpenTypeGsubTable (const FT_Face ft_face,
std::map<Glib::ustring, int>& tables,
std::map<Glib::ustring, Glib::ustring>& stylistic,
- std::map<Glib::ustring, Glib::ustring>& ligatures
+ std::map<Glib::ustring, Glib::ustring>& ligatures,
+ std::map<Glib::ustring, Glib::ustring>& numerical
) {
tables.clear();
stylistic.clear();
ligatures.clear();
+ numerical.clear();
// Use Harfbuzz, Pango's equivalent calls are deprecated.
auto const hb_face = hb_ft_face_create(ft_face, NULL);
@@ -121,7 +123,16 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
table.first == "hlig" || // Historical ligatures
table.first == "calt" ); // Contextual alternatives
- if (style || ligature ) {
+ bool numeric = ( table.first == "lnum" || // Lining numerals
+ table.first == "onum" || // Old style
+ table.first == "pnum" || // Proportional
+ table.first == "tnum" || // Tabular
+ table.first == "frac" || // Diagonal fractions
+ table.first == "afrc" || // Stacked fractions
+ table.first == "ordn" || // Ordinal fractions
+ table.first == "zero" ); // Slashed zero
+
+ if (style || ligature || numeric) {
unsigned int feature_index;
if ( hb_ot_layout_language_find_feature (hb_face, HB_OT_TAG_GSUB,
@@ -201,6 +212,23 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
ligatures[table.first] = unicode_characters;
}
+ if (numeric) {
+ while (hb_set_next (glyphs_output, &codepoint)) {
+
+ // There is a unicode to glyph mapping function but not the inverse!
+ for (hb_codepoint_t unicode_i = 0; unicode_i < 0xffff; ++unicode_i) {
+ hb_codepoint_t glyph = 0;
+ hb_font_get_nominal_glyph (hb_font, unicode_i, &glyph);
+ if ( glyph == codepoint) {
+ unicode_characters += (gunichar)unicode_i;
+ unicode_characters += " "; // Add space
+ continue;
+ }
+ }
+ }
+ numerical[table.first] = unicode_characters;
+ }
+
hb_set_destroy (glyphs_input);
hb_font_destroy (hb_font);
}
diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h
index 48d97b0f7..9a792eb0e 100644
--- a/src/libnrtype/OpenTypeUtil.h
+++ b/src/libnrtype/OpenTypeUtil.h
@@ -56,7 +56,8 @@ inline FT_Fixed FTDoubleToFixed (double value) {
void readOpenTypeGsubTable (const FT_Face ft_face,
std::map<Glib::ustring, int>& tables,
std::map<Glib::ustring, Glib::ustring>& stylistic,
- std::map<Glib::ustring, Glib::ustring>& ligatures);
+ std::map<Glib::ustring, Glib::ustring>& ligatures,
+ std::map<Glib::ustring, Glib::ustring>& numeric);
void readOpenTypeFvarAxes (const FT_Face ft_face,
std::map<Glib::ustring, OTVarAxis>& axes);
diff --git a/src/libnrtype/font-instance.h b/src/libnrtype/font-instance.h
index d70bf4f6a..ec26ba358 100644
--- a/src/libnrtype/font-instance.h
+++ b/src/libnrtype/font-instance.h
@@ -45,6 +45,7 @@ public:
// Map of substitutions indexed by table
std::map<Glib::ustring, Glib::ustring> openTypeStylistic;
std::map<Glib::ustring, Glib::ustring> openTypeLigatures;
+ std::map<Glib::ustring, Glib::ustring> openTypeNumeric;
// Maps for font variations.
std::map<Glib::ustring, OTVarAxis> openTypeVarAxes; // Axes with ranges
diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp
index be5ae255c..ad7431bd3 100644
--- a/src/ui/widget/font-variants.cpp
+++ b/src/ui/widget/font-variants.cpp
@@ -28,41 +28,41 @@ namespace Widget {
FontVariants::FontVariants () :
Gtk::VBox (),
- _ligatures_frame ( Glib::ustring(C_("Font variant", "Ligatures" )) ),
- _ligatures_common ( Glib::ustring(C_("Font variant", "Common" )) ),
- _ligatures_discretionary ( Glib::ustring(C_("Font variant", "Discretionary")) ),
- _ligatures_historical ( Glib::ustring(C_("Font variant", "Historical" )) ),
- _ligatures_contextual ( Glib::ustring(C_("Font variant", "Contextual" )) ),
-
- _position_frame ( Glib::ustring(C_("Font variant", "Position" )) ),
- _position_normal ( Glib::ustring(C_("Font variant", "Normal" )) ),
- _position_sub ( Glib::ustring(C_("Font variant", "Subscript" )) ),
- _position_super ( Glib::ustring(C_("Font variant", "Superscript" )) ),
-
- _caps_frame ( Glib::ustring(C_("Font variant", "Capitals" )) ),
- _caps_normal ( Glib::ustring(C_("Font variant", "Normal" )) ),
- _caps_small ( Glib::ustring(C_("Font variant", "Small" )) ),
- _caps_all_small ( Glib::ustring(C_("Font variant", "All small" )) ),
- _caps_petite ( Glib::ustring(C_("Font variant", "Petite" )) ),
- _caps_all_petite ( Glib::ustring(C_("Font variant", "All petite" )) ),
- _caps_unicase ( Glib::ustring(C_("Font variant", "Unicase" )) ),
- _caps_titling ( Glib::ustring(C_("Font variant", "Titling" )) ),
-
- _numeric_frame ( Glib::ustring(C_("Font variant", "Numeric" )) ),
- _numeric_lining ( Glib::ustring(C_("Font variant", "Lining" )) ),
- _numeric_old_style ( Glib::ustring(C_("Font variant", "Old Style" )) ),
- _numeric_default_style ( Glib::ustring(C_("Font variant", "Default Style")) ),
- _numeric_proportional ( Glib::ustring(C_("Font variant", "Proportional" )) ),
- _numeric_tabular ( Glib::ustring(C_("Font variant", "Tabular" )) ),
- _numeric_default_width ( Glib::ustring(C_("Font variant", "Default Width")) ),
- _numeric_diagonal ( Glib::ustring(C_("Font variant", "Diagonal" )) ),
- _numeric_stacked ( Glib::ustring(C_("Font variant", "Stacked" )) ),
- _numeric_default_fractions( Glib::ustring(C_("Font variant", "Default Fractions")) ),
- _numeric_ordinal ( Glib::ustring(C_("Font variant", "Ordinal" )) ),
- _numeric_slashed_zero ( Glib::ustring(C_("Font variant", "Slashed Zero" )) ),
-
- _feature_frame ( Glib::ustring(C_("Font variant", "Feature Settings")) ),
- _feature_label ( Glib::ustring(C_("Font variant", "Selection has different Feature Settings!")) ),
+ _ligatures_frame ( Glib::ustring(C_("Font feature", "Ligatures" )) ),
+ _ligatures_common ( Glib::ustring(C_("Font feature", "Common" )) ),
+ _ligatures_discretionary ( Glib::ustring(C_("Font feature", "Discretionary")) ),
+ _ligatures_historical ( Glib::ustring(C_("Font feature", "Historical" )) ),
+ _ligatures_contextual ( Glib::ustring(C_("Font feature", "Contextual" )) ),
+
+ _position_frame ( Glib::ustring(C_("Font feature", "Position" )) ),
+ _position_normal ( Glib::ustring(C_("Font feature", "Normal" )) ),
+ _position_sub ( Glib::ustring(C_("Font feature", "Subscript" )) ),
+ _position_super ( Glib::ustring(C_("Font feature", "Superscript" )) ),
+
+ _caps_frame ( Glib::ustring(C_("Font feature", "Capitals" )) ),
+ _caps_normal ( Glib::ustring(C_("Font feature", "Normal" )) ),
+ _caps_small ( Glib::ustring(C_("Font feature", "Small" )) ),
+ _caps_all_small ( Glib::ustring(C_("Font feature", "All small" )) ),
+ _caps_petite ( Glib::ustring(C_("Font feature", "Petite" )) ),
+ _caps_all_petite ( Glib::ustring(C_("Font feature", "All petite" )) ),
+ _caps_unicase ( Glib::ustring(C_("Font feature", "Unicase" )) ),
+ _caps_titling ( Glib::ustring(C_("Font feature", "Titling" )) ),
+
+ _numeric_frame ( Glib::ustring(C_("Font feature", "Numeric" )) ),
+ _numeric_lining ( Glib::ustring(C_("Font feature", "Lining" )) ),
+ _numeric_old_style ( Glib::ustring(C_("Font feature", "Old Style" )) ),
+ _numeric_default_style ( Glib::ustring(C_("Font feature", "Default Style")) ),
+ _numeric_proportional ( Glib::ustring(C_("Font feature", "Proportional" )) ),
+ _numeric_tabular ( Glib::ustring(C_("Font feature", "Tabular" )) ),
+ _numeric_default_width ( Glib::ustring(C_("Font feature", "Default Width")) ),
+ _numeric_diagonal ( Glib::ustring(C_("Font feature", "Diagonal" )) ),
+ _numeric_stacked ( Glib::ustring(C_("Font feature", "Stacked" )) ),
+ _numeric_default_fractions( Glib::ustring(C_("Font feature", "Default Fractions")) ),
+ _numeric_ordinal ( Glib::ustring(C_("Font feature", "Ordinal" )) ),
+ _numeric_slashed_zero ( Glib::ustring(C_("Font feature", "Slashed Zero" )) ),
+
+ _feature_frame ( Glib::ustring(C_("Font feature", "Feature Settings")) ),
+ _feature_label ( Glib::ustring(C_("Font feature", "Selection has different Feature Settings!")) ),
_ligatures_changed( false ),
_position_changed( false ),
@@ -213,21 +213,31 @@ namespace Widget {
_numeric_slashed_zero.signal_clicked().connect ( sigc::mem_fun(*this, &FontVariants::numeric_callback) );
// Add to frame
- _numeric_stylebox.pack_start( _numeric_default_style );
- _numeric_stylebox.pack_start( _numeric_lining );
- _numeric_stylebox.pack_start( _numeric_old_style );
- _numeric_vbox.pack_start( _numeric_stylebox );
- _numeric_widthbox.pack_start( _numeric_default_width );
- _numeric_widthbox.pack_start( _numeric_proportional );
- _numeric_widthbox.pack_start( _numeric_tabular );
- _numeric_vbox.pack_start( _numeric_widthbox );
- _numeric_fractionbox.pack_start( _numeric_default_fractions );
- _numeric_fractionbox.pack_start( _numeric_diagonal );
- _numeric_fractionbox.pack_start( _numeric_stacked );
- _numeric_vbox.pack_start( _numeric_fractionbox );
- _numeric_vbox.pack_start( _numeric_ordinal );
- _numeric_vbox.pack_start( _numeric_slashed_zero );
- _numeric_frame.add( _numeric_vbox );
+ _numeric_grid.attach (_numeric_default_style, 0, 0, 1, 1);
+ _numeric_grid.attach (_numeric_lining, 1, 0, 1, 1);
+ _numeric_grid.attach (_numeric_lining_label, 2, 0, 1, 1);
+ _numeric_grid.attach (_numeric_old_style, 3, 0, 1, 1);
+ _numeric_grid.attach (_numeric_old_style_label, 4, 0, 1, 1);
+
+ _numeric_grid.attach (_numeric_default_width, 0, 1, 1, 1);
+ _numeric_grid.attach (_numeric_proportional, 1, 1, 1, 1);
+ _numeric_grid.attach (_numeric_proportional_label, 2, 1, 1, 1);
+ _numeric_grid.attach (_numeric_tabular, 3, 1, 1, 1);
+ _numeric_grid.attach (_numeric_tabular_label, 4, 1, 1, 1);
+
+ _numeric_grid.attach (_numeric_default_fractions, 0, 2, 1, 1);
+ _numeric_grid.attach (_numeric_diagonal, 1, 2, 1, 1);
+ _numeric_grid.attach (_numeric_diagonal_label, 2, 2, 1, 1);
+ _numeric_grid.attach (_numeric_stacked, 3, 2, 1, 1);
+ _numeric_grid.attach (_numeric_stacked_label, 4, 2, 1, 1);
+
+ _numeric_grid.attach (_numeric_ordinal, 0, 3, 1, 1);
+ _numeric_grid.attach (_numeric_ordinal_label, 1, 3, 1, 1);
+
+ _numeric_grid.attach (_numeric_slashed_zero, 0, 4, 1, 1);
+ _numeric_grid.attach (_numeric_slashed_zero_label, 1, 4, 1, 1);
+
+ _numeric_frame.add( _numeric_grid );
pack_start( _numeric_frame, Gtk::PACK_SHRINK );
@@ -570,6 +580,52 @@ namespace Widget {
_ligatures_label_historical.set_markup ( markup_hlig.c_str() );
_ligatures_label_contextual.set_markup ( markup_calt.c_str() );
+ // List available numeric variants
+ Glib::ustring markup_lnum;
+ Glib::ustring markup_onum;
+ Glib::ustring markup_pnum;
+ Glib::ustring markup_tnum;
+ Glib::ustring markup_frac;
+ Glib::ustring markup_afrc;
+ Glib::ustring markup_ordn;
+ Glib::ustring markup_zero;
+ for (auto table: res->openTypeNumeric) {
+
+ Glib::ustring markup;
+ markup += "<span font_family='";
+ markup += sp_font_description_get_family(res->descr);
+ markup += "' font_features='";
+ markup += table.first;
+ markup += "'>";
+ if (table.first == "lnum" ||
+ table.first == "onum" ||
+ table.first == "pnum" ||
+ table.first == "tnum") markup += "0123456789";
+ if (table.first == "zero") markup += "0";
+ if (table.first == "ordn") markup += table.second;
+ if (table.first == "frac" ||
+ table.first == "afrc" ) markup += "1/2 2/3 3/4 4/5 5/6"; // Can we do better?
+ markup += "</span>";
+
+ if (table.first == "lnum") markup_lnum += markup;
+ if (table.first == "onum") markup_onum += markup;
+ if (table.first == "pnum") markup_pnum += markup;
+ if (table.first == "tnum") markup_tnum += markup;
+ if (table.first == "frac") markup_frac += markup;
+ if (table.first == "afrc") markup_afrc += markup;
+ if (table.first == "ordn") markup_ordn += markup;
+ if (table.first == "zero") markup_zero += markup;
+ }
+
+ _numeric_lining_label.set_markup ( markup_lnum.c_str() );
+ _numeric_old_style_label.set_markup ( markup_onum.c_str() );
+ _numeric_proportional_label.set_markup ( markup_pnum.c_str() );
+ _numeric_tabular_label.set_markup ( markup_tnum.c_str() );
+ _numeric_diagonal_label.set_markup ( markup_frac.c_str() );
+ _numeric_stacked_label.set_markup ( markup_afrc.c_str() );
+ _numeric_ordinal_label.set_markup ( markup_ordn.c_str() );
+ _numeric_slashed_zero_label.set_markup ( markup_zero.c_str() );
+
// Make list of tables not handled above... eventually add Gtk::Label with
// this info.
std::map<Glib::ustring,int> table_copy = res->openTypeTables;
diff --git a/src/ui/widget/font-variants.h b/src/ui/widget/font-variants.h
index da0609609..36e955890 100644
--- a/src/ui/widget/font-variants.h
+++ b/src/ui/widget/font-variants.h
@@ -39,7 +39,7 @@ public:
FontVariants();
protected:
- // To start, use four check buttons.
+ // Ligatures: To start, use four check buttons.
Gtk::Expander _ligatures_frame;
Gtk::Grid _ligatures_grid;
Gtk::CheckButton _ligatures_common;
@@ -51,14 +51,14 @@ protected:
Gtk::Label _ligatures_label_historical;
Gtk::Label _ligatures_label_contextual;
- // Exclusive options
+ // Position: Exclusive options
Gtk::Expander _position_frame;
Gtk::VBox _position_vbox;
Gtk::RadioButton _position_normal;
Gtk::RadioButton _position_sub;
Gtk::RadioButton _position_super;
- // Exclusive options (maybe a dropdown menu to save space?)
+ // Caps: Exclusive options (maybe a dropdown menu to save space?)
Gtk::Expander _caps_frame;
Gtk::VBox _caps_vbox;
Gtk::RadioButton _caps_normal;
@@ -69,23 +69,34 @@ protected:
Gtk::RadioButton _caps_unicase;
Gtk::RadioButton _caps_titling;
- // Complicated!
+ // Numeric: Complicated!
Gtk::Expander _numeric_frame;
- Gtk::VBox _numeric_vbox;
- Gtk::HBox _numeric_stylebox;
+ Gtk::Grid _numeric_grid;
+
+ Gtk::RadioButton _numeric_default_style;
Gtk::RadioButton _numeric_lining;
+ Gtk::Label _numeric_lining_label;
Gtk::RadioButton _numeric_old_style;
- Gtk::RadioButton _numeric_default_style;
- Gtk::HBox _numeric_widthbox;
+ Gtk::Label _numeric_old_style_label;
+
+ Gtk::RadioButton _numeric_default_width;
Gtk::RadioButton _numeric_proportional;
+ Gtk::Label _numeric_proportional_label;
Gtk::RadioButton _numeric_tabular;
- Gtk::RadioButton _numeric_default_width;
- Gtk::HBox _numeric_fractionbox;
+ Gtk::Label _numeric_tabular_label;
+
+ Gtk::RadioButton _numeric_default_fractions;
Gtk::RadioButton _numeric_diagonal;
+ Gtk::Label _numeric_diagonal_label;
Gtk::RadioButton _numeric_stacked;
- Gtk::RadioButton _numeric_default_fractions;
+ Gtk::Label _numeric_stacked_label;
+
Gtk::CheckButton _numeric_ordinal;
+ Gtk::Label _numeric_ordinal_label;
+
Gtk::CheckButton _numeric_slashed_zero;
+ Gtk::Label _numeric_slashed_zero_label;
+
Gtk::Expander _feature_frame;
Gtk::VBox _feature_vbox;