[pango/harfbuzz-ng: 8/17] [GSUB] Hook new GSUB up in Pango



commit 0bb5d464baab47bb7b6e9852a5c7932bdb2df018
Author: Behdad Esfahbod <behdad behdad org>
Date:   Mon May 4 20:21:57 2009 -0400

    [GSUB] Hook new GSUB up in Pango
---
 pango/opentype/hb-ot-layout-gsub-private.h |   15 ++++--
 pango/pango-ot-info.c                      |   65 ++++++++++++++++------------
 pango/pango-ot-private.h                   |   14 +++++-
 pango/pango-ot-ruleset.c                   |   37 +--------------
 4 files changed, 62 insertions(+), 69 deletions(-)

diff --git a/pango/opentype/hb-ot-layout-gsub-private.h b/pango/opentype/hb-ot-layout-gsub-private.h
index 78c5701..73950dc 100644
--- a/pango/opentype/hb-ot-layout-gsub-private.h
+++ b/pango/opentype/hb-ot-layout-gsub-private.h
@@ -125,6 +125,14 @@ struct SingleSubst {
     }
   }
 
+  inline bool single_substitute (hb_codepoint_t &glyph_id) const {
+    switch (u.substFormat) {
+    case 1: return u.format1.single_substitute (glyph_id);
+    case 2: return u.format2.single_substitute (glyph_id);
+    default:return false;
+    }
+  }
+
   inline bool substitute (SUBTABLE_SUBSTITUTE_ARGS_DEF) const {
 
     HB_UNUSED (nesting_level_left);
@@ -138,11 +146,8 @@ struct SingleSubst {
 
     hb_codepoint_t glyph_id = IN_CURGLYPH ();
 
-    switch (u.substFormat) {
-    case 1: if (!u.format1.single_substitute (glyph_id)) return false;
-    case 2: if (!u.format2.single_substitute (glyph_id)) return false;
-    default:return false;
-    }
+    if (!single_substitute (glyph_id))
+      return false;
 
     _hb_buffer_replace_output_glyph (buffer, glyph_id, context_length == NO_CONTEXT);
 
diff --git a/pango/pango-ot-info.c b/pango/pango-ot-info.c
index b1a5dfd..fbd0377 100644
--- a/pango/pango-ot-info.c
+++ b/pango/pango-ot-info.c
@@ -83,11 +83,6 @@ pango_ot_info_finalize (GObject *object)
   if (info->layout)
     hb_ot_layout_destroy (info->layout);
 
-  if (info->gsub)
-    {
-      HB_Done_GSUB_Table (info->gsub);
-      info->gsub = NULL;
-    }
   if (info->gpos)
     {
       HB_Done_GPOS_Table (info->gpos);
@@ -290,29 +285,6 @@ synthesize_class_def (PangoOTInfo *info)
     FT_Set_Charmap (info->face, old_charmap);
 }
 
-HB_GSUB
-pango_ot_info_get_gsub (PangoOTInfo *info)
-{
-  g_return_val_if_fail (PANGO_IS_OT_INFO (info), NULL);
-
-  if (!(info->loaded & INFO_LOADED_GSUB))
-    {
-      HB_Error error;
-
-      info->loaded |= INFO_LOADED_GSUB;
-
-      if (FT_IS_SFNT (info->face))
-	{
-	  error = HB_Load_GSUB_Table (info->face, &info->gsub, _pango_ot_info_get_layout (info));
-
-	  if (error && error != HB_Err_Not_Covered)
-	    g_warning ("Error loading GSUB table 0x%04X", error);
-	}
-    }
-
-  return info->gsub;
-}
-
 HB_GPOS
 pango_ot_info_get_gpos (PangoOTInfo *info)
 {
@@ -573,3 +545,40 @@ pango_ot_info_list_features  (PangoOTInfo      *info,
 
   return result;
 }
+
+void
+_pango_ot_info_substitute  (const PangoOTInfo    *info,
+			    const PangoOTRuleset *ruleset,
+			    PangoOTBuffer        *buffer)
+{
+  unsigned int i;
+
+  for (i = 0; i < ruleset->rules->len; i++)
+    {
+      PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i);
+      hb_ot_layout_feature_mask_t mask;
+      unsigned int lookup_count, j;
+
+      if (rule->table_type != PANGO_OT_TABLE_GSUB)
+	continue;
+
+      mask = rule->property_bit;
+      lookup_count = hb_ot_layout_feature_get_lookup_count (info->layout,
+							    HB_OT_LAYOUT_TABLE_TYPE_GSUB,
+							    rule->feature_index);
+
+      for (j = 0; j < lookup_count; j++)
+        {
+	  unsigned int lookup_index;
+
+	  lookup_index = hb_ot_layout_feature_get_lookup_index (info->layout,
+								HB_OT_LAYOUT_TABLE_TYPE_GSUB,
+								rule->feature_index,
+								j);
+	  hb_ot_layout_substitute_lookup (info->layout,
+					  buffer->buffer,
+					  lookup_index,
+					  rule->property_bit);
+	}
+    }
+}
diff --git a/pango/pango-ot-private.h b/pango/pango-ot-private.h
index 0ba3984..c1ee455 100644
--- a/pango/pango-ot-private.h
+++ b/pango/pango-ot-private.h
@@ -40,7 +40,6 @@ struct _PangoOTInfo
   FT_Face face;
 
   hb_ot_layout_t *layout;
-  HB_GSUB gsub;
   HB_GPOS gpos;
 };
 
@@ -50,6 +49,15 @@ struct _PangoOTInfoClass
 };
 
 
+typedef struct _PangoOTRule PangoOTRule;
+
+struct _PangoOTRule
+{
+  gulong     property_bit;
+  HB_UShort  feature_index;
+  guint      table_type : 1;
+};
+
 typedef struct _PangoOTRulesetClass PangoOTRulesetClass;
 
 struct _PangoOTRuleset
@@ -81,7 +89,9 @@ struct _PangoOTBuffer
 };
 
 hb_ot_layout_t *_pango_ot_info_get_layout (PangoOTInfo *info);
-HB_GSUB pango_ot_info_get_gsub (PangoOTInfo *info);
+void _pango_ot_info_substitute  (const PangoOTInfo    *info,
+				 const PangoOTRuleset *ruleset,
+				 PangoOTBuffer        *buffer);
 HB_GPOS pango_ot_info_get_gpos (PangoOTInfo *info);
 
 G_END_DECLS
diff --git a/pango/pango-ot-ruleset.c b/pango/pango-ot-ruleset.c
index 2d0492b..23f37cb 100644
--- a/pango/pango-ot-ruleset.c
+++ b/pango/pango-ot-ruleset.c
@@ -24,15 +24,6 @@
 #include "pango-ot-private.h"
 #include "pango-impl-utils.h"
 
-typedef struct _PangoOTRule PangoOTRule;
-
-struct _PangoOTRule
-{
-  gulong     property_bit;
-  HB_UShort  feature_index;
-  guint      table_type : 1;
-};
-
 static void pango_ot_ruleset_class_init (GObjectClass   *object_class);
 static void pango_ot_ruleset_init       (PangoOTRuleset *ruleset);
 static void pango_ot_ruleset_finalize   (GObject        *object);
@@ -491,34 +482,12 @@ void
 pango_ot_ruleset_substitute  (const PangoOTRuleset *ruleset,
 			      PangoOTBuffer        *buffer)
 {
-  unsigned int i;
-
-  HB_GSUB gsub = NULL;
-
   g_return_if_fail (PANGO_IS_OT_RULESET (ruleset));
   g_return_if_fail (ruleset->info != NULL);
 
-  for (i = 0; i < ruleset->rules->len; i++)
-    {
-      PangoOTRule *rule = &g_array_index (ruleset->rules, PangoOTRule, i);
-
-      if (rule->table_type != PANGO_OT_TABLE_GSUB)
-	continue;
-
-      if (!gsub)
-	{
-	  gsub = pango_ot_info_get_gsub (ruleset->info);
-
-	  if (gsub)
-	    HB_GSUB_Clear_Features (gsub);
-	  else
-	    return;
-	}
-
-      HB_GSUB_Add_Feature (gsub, rule->feature_index, rule->property_bit);
-    }
-
-  HB_GSUB_Apply_String (gsub, buffer->buffer);
+  _pango_ot_info_substitute (ruleset->info,
+			     ruleset,
+			     buffer);
 }
 
 /**



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