diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-05-13 12:51:42 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-05-13 12:51:42 +0000 |
| commit | 8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0 (patch) | |
| tree | 8e1184830a0b10843c2d6c1a8daffac721c60db7 /src/libnrtype | |
| parent | Fix rendering of hatches when hatchContentUnits and hatchUnits have different... (diff) | |
| download | inkscape-8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0.tar.gz inkscape-8b3f3c5ce777e1e4e94b1740035d3144b3f3dec0.zip | |
Add preview for numeric OpenType features.
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/FontInstance.cpp | 3 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.cpp | 32 | ||||
| -rw-r--r-- | src/libnrtype/OpenTypeUtil.h | 3 | ||||
| -rw-r--r-- | src/libnrtype/font-instance.h | 1 |
4 files changed, 35 insertions, 4 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 |
