[pango] Let people enable font features through fontconfig snippets



commit db410d8ebdbc5b697430617e761da6b5ce4940dd
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Jan 10 16:25:11 2013 -0600

    Let people enable font features through fontconfig snippets
    
    Like this:
    
    <match target="font">
      <edit name="pangofontfeatures" mode="append">
        <string>smcp</string>
        <string>ss20</string>
      </edit>
    </match>
    
    Finally we are starting to see new features coming out of the HarfBuzz integration...

 docs/pango-sections.txt  |    1 +
 modules/basic/basic-fc.c |   24 +++++++++++++++++++++++-
 pango/pangofc-fontmap.h  |   14 ++++++++++++++
 3 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 5adfa93..02eba9d 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -915,6 +915,7 @@ pango_fc_font_map_find_decoder
 pango_fc_font_map_cache_clear
 pango_fc_font_map_shutdown
 pango_fc_font_description_from_pattern
+PANGO_FC_FONT_FEATURES
 PANGO_FC_GRAVITY
 PANGO_FC_VERSION
 PANGO_FC_PRGNAME
diff --git a/modules/basic/basic-fc.c b/modules/basic/basic-fc.c
index 548cee6..1ceaeab 100644
--- a/modules/basic/basic-fc.c
+++ b/modules/basic/basic-fc.c
@@ -29,6 +29,7 @@
 
 #include "pango-engine.h"
 #include "pango-utils.h"
+#include "pangofc-fontmap.h"
 #include "pangofc-font.h"
 #include <hb-ft.h>
 #include <hb-glib.h>
@@ -318,6 +319,8 @@ basic_engine_shape (PangoEngineShape    *engine G_GNUC_UNUSED,
   int last_cluster;
   guint i, num_glyphs;
   unsigned int item_offset = item_text - paragraph_text;
+  hb_feature_t features[8];
+  unsigned int num_features = 0;
 
   g_return_if_fail (font != NULL);
   g_return_if_fail (analysis != NULL);
@@ -367,7 +370,26 @@ basic_engine_shape (PangoEngineShape    *engine G_GNUC_UNUSED,
 		       (item_offset + item_length == paragraph_length ? HB_BUFFER_FLAG_EOT : 0));
 
   hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_offset, item_length);
-  hb_shape (hb_font, hb_buffer, NULL, 0);
+
+  /* Setup features from fontconfig pattern. */
+  if (fc_font->font_pattern)
+    {
+      char *s;
+      while (num_features < G_N_ELEMENTS (features) &&
+	     FcResultMatch == FcPatternGetString (fc_font->font_pattern,
+						  PANGO_FC_FONT_FEATURES,
+						  num_features,
+						  (FcChar8 **) &s))
+	{
+	  features[num_features].tag   = hb_tag_from_string (s, -1);
+	  features[num_features].value = 1;
+	  features[num_features].start = 0;
+	  features[num_features].end   = (unsigned int) -1;
+	  num_features++;
+	}
+    }
+
+  hb_shape (hb_font, hb_buffer, features, num_features);
 
   if (PANGO_GRAVITY_IS_IMPROPER (analysis->gravity))
     hb_buffer_reverse (hb_buffer);
diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h
index 3809446..73d1cc9 100644
--- a/pango/pangofc-fontmap.h
+++ b/pango/pangofc-fontmap.h
@@ -266,6 +266,20 @@ PangoFontDescription *pango_fc_font_description_from_pattern (FcPattern *pattern
  */
 #define PANGO_FC_PRGNAME "pangoprgname"
 
+/**
+ * PANGO_FC_FONT_FEATURES:
+ *
+ * String representing a fontconfig property name that Pango reads from font
+ * patterns to populate list of OpenType features to be enabled for the font
+ * by default.
+ *
+ * The property will have a number of string elements, each of which is the
+ * OpenType feature tag of one feature to enable.
+ *
+ * Since: 1.34
+ */
+#define PANGO_FC_FONT_FEATURES "pangofontfeatures"
+
 G_END_DECLS
 
 #endif /* __PANGO_FC_FONT_MAP_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]