summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-04-05 13:05:17 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-04-05 13:05:17 +0000
commitc2fbc03b37ca44ad31db6503046a99c47a520313 (patch)
tree67df8583465fd6ef4c5bf0abf6d02edcf7a023d1 /src/libnrtype
parentReduce error messages. (diff)
downloadinkscape-c2fbc03b37ca44ad31db6503046a99c47a520313.tar.gz
inkscape-c2fbc03b37ca44ad31db6503046a99c47a520313.zip
Extract and display ligatures in a font.
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/FontFactory.cpp2
-rw-r--r--src/libnrtype/OpenTypeUtil.cpp71
-rw-r--r--src/libnrtype/OpenTypeUtil.h3
-rw-r--r--src/libnrtype/font-instance.h3
4 files changed, 57 insertions, 22 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index 8cccd6ff3..98c9fa69f 100644
--- a/src/libnrtype/FontFactory.cpp
+++ b/src/libnrtype/FontFactory.cpp
@@ -705,7 +705,7 @@ font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail)
#ifndef USE_PANGO_WIN32
if (res) {
- readOpenTypeGsubTable( res->theFace, res->openTypeTables, res->openTypeSubstitutions );
+ readOpenTypeGsubTable( res->theFace, res->openTypeTables, res->openTypeStylistic, res->openTypeLigatures );
std::map<Glib::ustring, OTVarAxis> axes;
std::map<Glib::ustring, OTVarNamed> named;
readOpenTypeFvarTable( res->theFace, axes, named );
diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp
index ba6fe8ec7..38b60c212 100644
--- a/src/libnrtype/OpenTypeUtil.cpp
+++ b/src/libnrtype/OpenTypeUtil.cpp
@@ -39,14 +39,17 @@ Glib::ustring extract_tag( guint32 *tag ) {
}
-// Make a list of all tables fount in the GSUB
+// Make a list of all tables found in the GSUB
// This list includes all tables regardless of script or language.
void readOpenTypeGsubTable (const FT_Face ft_face,
std::map<Glib::ustring, int>& tables,
- std::map<Glib::ustring, Glib::ustring>& substitutions) {
+ std::map<Glib::ustring, Glib::ustring>& stylistic,
+ std::map<Glib::ustring, Glib::ustring>& ligatures
+ ) {
tables.clear();
- substitutions.clear();
+ stylistic.clear();
+ ligatures.clear();
// Use Harfbuzz, Pango's equivalent calls are deprecated.
auto const hb_face = hb_ft_face_create(ft_face, NULL);
@@ -109,11 +112,16 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
for (auto table: tables) {
// Only look at style substitution tables ('salt', 'ss01', etc. but not 'ssty').
- if (table.first == "salt" ||
- (table.first[0] == 's' && table.first[1] == 's' && !(table.first[2] == 't') ) ) {
- // std::cout << " Table: " << table.first << std::endl;
+ bool style = table.first == "salt" ||
+ (table.first[0] == 's' && table.first[1] == 's' && !(table.first[2] == 't'));
- Glib::ustring unicode_characters;
+ bool ligature = ( table.first == "liga" || // Standard ligatures
+ table.first == "clig" || // Common ligatures
+ table.first == "dlig" || // Discretionary ligatures
+ table.first == "hlig" || // Historical ligatures
+ table.first == "calt" ); // Contextual alternatives
+
+ if (style || ligature ) {
unsigned int feature_index;
if ( hb_ot_layout_language_find_feature (hb_face, HB_OT_TAG_GSUB,
@@ -137,9 +145,9 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
if (count > 0) {
hb_set_t* glyphs_before = NULL; // hb_set_create();
- hb_set_t* glyphs_input = hb_set_create();
+ hb_set_t* glyphs_input = hb_set_create(); // For stylistic
hb_set_t* glyphs_after = NULL; // hb_set_create();
- hb_set_t* glyphs_output = NULL; // hb_set_create();
+ hb_set_t* glyphs_output = hb_set_create(); // For ligatures
// For now, just look at first index
hb_ot_layout_lookup_collect_glyphs (hb_face, HB_OT_TAG_GSUB,
@@ -154,20 +162,44 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
// Without this, all functions return 0, etc.
hb_ft_font_set_funcs (hb_font);
+ Glib::ustring unicode_characters;
+
hb_codepoint_t codepoint = -1;
- while (hb_set_next (glyphs_input, &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;
- continue;
+
+ if (style) {
+ while (hb_set_next (glyphs_input, &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;
+ continue;
+ }
+ }
+ }
+ stylistic[table.first] = unicode_characters;
+ }
+
+ // Don't know how to extract all input glyphs...
+ // glyphs_input contains last input glyph, so just use output.
+ if (ligature) {
+ 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;
+ }
}
}
+ ligatures[table.first] = unicode_characters;
}
- substitutions[table.first] = unicode_characters;
hb_set_destroy (glyphs_input);
hb_font_destroy (hb_font);
@@ -176,6 +208,7 @@ void readOpenTypeGsubTable (const FT_Face ft_face,
// std::cout << " Did not find '" << table.first << "'!" << std::endl;
}
}
+
}
// for (auto table: res->openTypeSubstitutions) {
// std::cout << table.first << ": " << table.second << std::endl;
diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h
index 5c0780492..b4f7593dd 100644
--- a/src/libnrtype/OpenTypeUtil.h
+++ b/src/libnrtype/OpenTypeUtil.h
@@ -50,7 +50,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>& substitutions);
+ std::map<Glib::ustring, Glib::ustring>& stylistic,
+ std::map<Glib::ustring, Glib::ustring>& ligatures);
void readOpenTypeFvarTable (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 ee23ff62d..f6408eccb 100644
--- a/src/libnrtype/font-instance.h
+++ b/src/libnrtype/font-instance.h
@@ -39,7 +39,8 @@ public:
std::map<Glib::ustring, int> openTypeTables;
// Map of substitutions indexed by table
- std::map<Glib::ustring, Glib::ustring> openTypeSubstitutions;
+ std::map<Glib::ustring, Glib::ustring> openTypeStylistic;
+ std::map<Glib::ustring, Glib::ustring> openTypeLigatures;
font_instance(void);
virtual ~font_instance(void);