[HarfBuzz] harfbuzz: Branch 'master' - 3 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Oct 31 08:19:49 UTC 2018


 src/hb-aat-layout-morx-table.hh |  109 ++++++++++++++++++++++++++++++----------
 1 file changed, 84 insertions(+), 25 deletions(-)

New commits:
commit c962d5e714a6f88c4cb20bed219177b1bc4a2dfd
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Oct 31 01:16:33 2018 -0700

    [mort] Make ligatures work
    
     ./hb-shape Apple_Chancery_10_12.ttf  "Th th ll te to tr fr fu fj"
    [T_h=0+2308|space=2+569|t_h=3+1687|space=5+569|l_l=6+1108|space=8+569|t_e=9+1408|space=11+569|t_o=12+1531|space=14+569|t_r=15+1385|space=17+569|f_r=18+1432|space=20+569|f_u=21+1733|space=23+569|f_j=24+1098]
    
    Part of https://github.com/harfbuzz/harfbuzz/issues/1331

diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh
index 28cdc8de..08a380a4 100644
--- a/src/hb-aat-layout-morx-table.hh
+++ b/src/hb-aat-layout-morx-table.hh
@@ -448,10 +448,11 @@ struct LigatureSubtable
 					 * into the component table. */
     };
 
-    inline driver_context_t (const LigatureSubtable *table,
+    inline driver_context_t (const LigatureSubtable *table_,
 			     hb_aat_apply_context_t *c_) :
 	ret (false),
 	c (c_),
+	table (table_),
 	ligAction (table+table->ligAction),
 	component (table+table->component),
 	ligature (table+table->ligature),
@@ -497,6 +498,9 @@ struct LigatureSubtable
 	  return false; // TODO Work on previous instead?
 
 	unsigned int cursor = match_length;
+	const HBUINT32 *actionData = Types::extended ?
+				     &ligAction[action_idx] :
+				     &StructAtOffset<HBUINT32> (table, action_idx);
         do
 	{
 	  if (unlikely (!cursor))
@@ -510,17 +514,20 @@ struct LigatureSubtable
 	  DEBUG_MSG (APPLY, nullptr, "Moving to stack position %d", cursor - 1);
 	  buffer->move_to (match_positions[--cursor]);
 
-	  const HBUINT32 &actionData = ligAction[action_idx];
-	  if (unlikely (!actionData.sanitize (&c->sanitizer))) return false;
-	  action = actionData;
+	  if (unlikely (!actionData->sanitize (&c->sanitizer))) return false;
+	  action = *actionData;
 
 	  uint32_t uoffset = action & LigActionOffset;
 	  if (uoffset & 0x20000000)
 	    uoffset |= 0xC0000000; /* Sign-extend. */
 	  int32_t offset = (int32_t) uoffset;
 	  unsigned int component_idx = buffer->cur().codepoint + offset;
+	  if (!Types::extended)
+	    component_idx *= 2;
 
-	  const HBUINT16 &componentData = component[component_idx];
+	  const HBUINT16 &componentData = Types::extended ?
+					  component[component_idx] :
+					  StructAtOffset<HBUINT16> (table, component_idx);
 	  if (unlikely (!componentData.sanitize (&c->sanitizer))) return false;
 	  ligature_idx += componentData;
 
@@ -529,8 +536,9 @@ struct LigatureSubtable
 		     bool (action & LigActionLast));
 	  if (action & (LigActionStore | LigActionLast))
 	  {
-
-	    const GlyphID &ligatureData = ligature[ligature_idx];
+	    const GlyphID &ligatureData = Types::extended ?
+					  ligature[ligature_idx] :
+					  StructAtOffset<GlyphID> (table, ligature_idx);
 	    if (unlikely (!ligatureData.sanitize (&c->sanitizer))) return false;
 	    hb_codepoint_t lig = ligatureData;
 
@@ -550,7 +558,7 @@ struct LigatureSubtable
 	    buffer->merge_out_clusters (match_positions[cursor], buffer->out_len);
 	  }
 
-	  action_idx++;
+	  actionData++;
 	}
 	while (!(action & LigActionLast));
 	buffer->move_to (end);
@@ -563,6 +571,7 @@ struct LigatureSubtable
     bool ret;
     private:
     hb_aat_apply_context_t *c;
+    const LigatureSubtable *table;
     const UnsizedArrayOf<HBUINT32> &ligAction;
     const UnsizedArrayOf<HBUINT16> &component;
     const UnsizedArrayOf<GlyphID> &ligature;
commit c07798960004439fcd8fa0f4ae33e225428d1065
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Oct 31 00:36:03 2018 -0700

    [mort] More Ligature work

diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh
index cc83987d..28cdc8de 100644
--- a/src/hb-aat-layout-morx-table.hh
+++ b/src/hb-aat-layout-morx-table.hh
@@ -366,6 +366,17 @@ struct LigatureEntry;
 template <>
 struct LigatureEntry<true>
 {
+  enum Flags
+  {
+    SetComponent	= 0x8000,	/* Push this glyph onto the component stack for
+					 * eventual processing. */
+    DontAdvance		= 0x4000,	/* Leave the glyph pointer at this glyph for the
+					   next iteration. */
+    PerformAction	= 0x2000,	/* Use the ligActionIndex to process a ligature
+					 * group. */
+    Reserved		= 0x1FFF,	/* These bits are reserved and should be set to 0. */
+  };
+
   typedef struct
   {
     HBUINT16	ligActionIndex;	/* Index to the first ligActionTable entry
@@ -375,6 +386,10 @@ struct LigatureEntry<true>
     DEFINE_SIZE_STATIC (2);
   } EntryData;
 
+  template <typename Flags>
+  static inline bool performAction (Flags flags)
+  { return flags & PerformAction; };
+
   template <typename Entry, typename Flags>
   static inline unsigned int ligActionIndex (Entry &entry, Flags flags)
   { return entry->data.ligActionIndex; };
@@ -382,8 +397,23 @@ struct LigatureEntry<true>
 template <>
 struct LigatureEntry<false>
 {
+  enum Flags
+  {
+    SetComponent	= 0x8000,	/* Push this glyph onto the component stack for
+					 * eventual processing. */
+    DontAdvance		= 0x4000,	/* Leave the glyph pointer at this glyph for the
+					   next iteration. */
+    Offset		= 0x3FFF,	/* Byte offset from beginning of subtable to the
+					 * ligature action list. This value must be a
+					 * multiple of 4. */
+  };
+
   typedef void EntryData;
 
+  template <typename Flags>
+  static inline bool performAction (Flags flags)
+  { return flags & Offset; };
+
   template <typename Entry, typename Flags>
   static inline unsigned int ligActionIndex (Entry &entry, Flags flags)
   { return flags & 0x3FFF; };
@@ -395,21 +425,17 @@ struct LigatureSubtable
 {
   typedef typename Types::HBUINT HBUINT;
 
-  typedef typename LigatureEntry<Types::extended>::EntryData EntryData;
+  typedef LigatureEntry<Types::extended> LigatureEntryT;
+  typedef typename LigatureEntryT::EntryData EntryData;
+  typedef typename LigatureEntryT::Flags Flags;
 
   struct driver_context_t
   {
-    static const bool in_place = false;
-    enum Flags
+    enum
     {
-      SetComponent	= 0x8000,	/* Push this glyph onto the component stack for
-					 * eventual processing. */
-      DontAdvance	= 0x4000,	/* Leave the glyph pointer at this glyph for the
-					   next iteration. */
-      PerformAction	= 0x2000,	/* Use the ligActionIndex to process a ligature
-					 * group. */
-      Reserved		= 0x1FFF,	/* These bits are reserved and should be set to 0. */
+      DontAdvance	= LigatureEntry<Types::extended>::DontAdvance,
     };
+    static const bool in_place = false;
     enum LigActionFlags
     {
       LigActionLast	= 0x80000000,	/* This is the last action in the list. This also
@@ -434,7 +460,7 @@ struct LigatureSubtable
     inline bool is_actionable (StateTableDriver<Types, EntryData> *driver HB_UNUSED,
 			       const Entry<EntryData> *entry)
     {
-      return entry->flags & PerformAction;
+      return LigatureEntryT::performAction (entry->flags);
     }
     inline bool transition (StateTableDriver<Types, EntryData> *driver,
 			    const Entry<EntryData> *entry)
@@ -443,7 +469,7 @@ struct LigatureSubtable
       unsigned int flags = entry->flags;
 
       DEBUG_MSG (APPLY, nullptr, "Ligature transition at %d", buffer->idx);
-      if (flags & SetComponent)
+      if (flags & Flags::SetComponent)
       {
         if (unlikely (match_length >= ARRAY_LENGTH (match_positions)))
 	  return false;
@@ -456,11 +482,11 @@ struct LigatureSubtable
 	DEBUG_MSG (APPLY, nullptr, "Set component at %d", buffer->out_len);
       }
 
-      if (flags & PerformAction)
+      if (LigatureEntryT::performAction (flags))
       {
 	DEBUG_MSG (APPLY, nullptr, "Perform action with %d", match_length);
 	unsigned int end = buffer->out_len;
-	unsigned int action_idx = LigatureEntry<Types::extended>::ligActionIndex (entry, flags);
+	unsigned int action_idx = LigatureEntryT::ligActionIndex (entry, flags);
 	unsigned int action;
 	unsigned int ligature_idx = 0;
 
commit 431c6e496be56e441ee4b9b705f40a1246bdd0d6
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Oct 31 00:15:00 2018 -0700

    [mort] Some Ligature work

diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh
index c3a74835..cc83987d 100644
--- a/src/hb-aat-layout-morx-table.hh
+++ b/src/hb-aat-layout-morx-table.hh
@@ -359,19 +359,43 @@ struct ContextualSubtable
   DEFINE_SIZE_STATIC (20);
 };
 
-template <typename Types>
-struct LigatureSubtable
-{
-  typedef typename Types::HBUINT HBUINT;
 
-  struct EntryData
+template <bool extended>
+struct LigatureEntry;
+
+template <>
+struct LigatureEntry<true>
+{
+  typedef struct
   {
     HBUINT16	ligActionIndex;	/* Index to the first ligActionTable entry
 				 * for processing this group, if indicated
 				 * by the flags. */
     public:
     DEFINE_SIZE_STATIC (2);
-  };
+  } EntryData;
+
+  template <typename Entry, typename Flags>
+  static inline unsigned int ligActionIndex (Entry &entry, Flags flags)
+  { return entry->data.ligActionIndex; };
+};
+template <>
+struct LigatureEntry<false>
+{
+  typedef void EntryData;
+
+  template <typename Entry, typename Flags>
+  static inline unsigned int ligActionIndex (Entry &entry, Flags flags)
+  { return flags & 0x3FFF; };
+};
+
+
+template <typename Types>
+struct LigatureSubtable
+{
+  typedef typename Types::HBUINT HBUINT;
+
+  typedef typename LigatureEntry<Types::extended>::EntryData EntryData;
 
   struct driver_context_t
   {
@@ -436,7 +460,7 @@ struct LigatureSubtable
       {
 	DEBUG_MSG (APPLY, nullptr, "Perform action with %d", match_length);
 	unsigned int end = buffer->out_len;
-	unsigned int action_idx = entry->data.ligActionIndex;
+	unsigned int action_idx = LigatureEntry<Types::extended>::ligActionIndex (entry, flags);
 	unsigned int action;
 	unsigned int ligature_idx = 0;
 


More information about the HarfBuzz mailing list