Imported Upstream version 2.6.4
[platform/upstream/harfbuzz.git] / src / hb-aat-layout-morx-table.hh
index 4a1d959..d8df579 100644 (file)
@@ -88,7 +88,7 @@ struct RearrangementSubtable
        start = buffer->idx;
 
       if (flags & MarkLast)
-       end = MIN (buffer->idx + 1, buffer->len);
+       end = hb_min (buffer->idx + 1, buffer->len);
 
       if ((flags & Verb) && start < end)
       {
@@ -117,14 +117,14 @@ struct RearrangementSubtable
        };
 
        unsigned int m = map[flags & Verb];
-       unsigned int l = MIN<unsigned int> (2, m >> 4);
-       unsigned int r = MIN<unsigned int> (2, m & 0x0F);
+       unsigned int l = hb_min (2u, m >> 4);
+       unsigned int r = hb_min (2u, m & 0x0F);
        bool reverse_l = 3 == (m >> 4);
        bool reverse_r = 3 == (m & 0x0F);
 
        if (end - start >= l + r)
        {
-         buffer->merge_clusters (start, MIN (buffer->idx + 1, buffer->len));
+         buffer->merge_clusters (start, hb_min (buffer->idx + 1, buffer->len));
          buffer->merge_clusters (start, end);
 
          hb_glyph_info_t *info = buffer->info;
@@ -226,7 +226,7 @@ struct ContextualSubtable
       hb_buffer_t *buffer = driver->buffer;
 
       if (buffer->idx == buffer->len && !mark_set)
-        return false;
+       return false;
 
       return entry.data.markIndex != 0xFFFF || entry.data.currentIndex != 0xFFFF;
     }
@@ -238,48 +238,48 @@ struct ContextualSubtable
       /* Looks like CoreText applies neither mark nor current substitution for
        * end-of-text if mark was not explicitly set. */
       if (buffer->idx == buffer->len && !mark_set)
-        return;
+       return;
 
-      const GlyphID *replacement;
+      const HBGlyphID *replacement;
 
       replacement = nullptr;
       if (Types::extended)
       {
        if (entry.data.markIndex != 0xFFFF)
        {
-         const Lookup<GlyphID> &lookup = subs[entry.data.markIndex];
+         const Lookup<HBGlyphID> &lookup = subs[entry.data.markIndex];
          replacement = lookup.get_value (buffer->info[mark].codepoint, driver->num_glyphs);
        }
       }
       else
       {
        unsigned int offset = entry.data.markIndex + buffer->info[mark].codepoint;
-       const UnsizedArrayOf<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) subs;
+       const UnsizedArrayOf<HBGlyphID> &subs_old = (const UnsizedArrayOf<HBGlyphID> &) subs;
        replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
        if (!replacement->sanitize (&c->sanitizer) || !*replacement)
          replacement = nullptr;
       }
       if (replacement)
       {
-       buffer->unsafe_to_break (mark, MIN (buffer->idx + 1, buffer->len));
+       buffer->unsafe_to_break (mark, hb_min (buffer->idx + 1, buffer->len));
        buffer->info[mark].codepoint = *replacement;
        ret = true;
       }
 
       replacement = nullptr;
-      unsigned int idx = MIN (buffer->idx, buffer->len - 1);
+      unsigned int idx = hb_min (buffer->idx, buffer->len - 1);
       if (Types::extended)
       {
        if (entry.data.currentIndex != 0xFFFF)
        {
-         const Lookup<GlyphID> &lookup = subs[entry.data.currentIndex];
+         const Lookup<HBGlyphID> &lookup = subs[entry.data.currentIndex];
          replacement = lookup.get_value (buffer->info[idx].codepoint, driver->num_glyphs);
        }
       }
       else
       {
        unsigned int offset = entry.data.currentIndex + buffer->info[idx].codepoint;
-       const UnsizedArrayOf<GlyphID> &subs_old = (const UnsizedArrayOf<GlyphID> &) subs;
+       const UnsizedArrayOf<HBGlyphID> &subs_old = (const UnsizedArrayOf<HBGlyphID> &) subs;
        replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
        if (!replacement->sanitize (&c->sanitizer) || !*replacement)
          replacement = nullptr;
@@ -304,7 +304,7 @@ struct ContextualSubtable
     bool mark_set;
     unsigned int mark;
     const ContextualSubtable *table;
-    const UnsizedOffsetListOf<Lookup<GlyphID>, HBUINT, false> &subs;
+    const UnsizedOffsetListOf<Lookup<HBGlyphID>, HBUINT, false> &subs;
   };
 
   bool apply (hb_aat_apply_context_t *c) const
@@ -337,9 +337,9 @@ struct ContextualSubtable
       const EntryData &data = entries[i].data;
 
       if (data.markIndex != 0xFFFF)
-       num_lookups = MAX<unsigned int> (num_lookups, 1 + data.markIndex);
+       num_lookups = hb_max (num_lookups, 1 + data.markIndex);
       if (data.currentIndex != 0xFFFF)
-       num_lookups = MAX<unsigned int> (num_lookups, 1 + data.currentIndex);
+       num_lookups = hb_max (num_lookups, 1 + data.currentIndex);
     }
 
     return_trace (substitutionTables.sanitize (c, this, num_lookups));
@@ -348,7 +348,7 @@ struct ContextualSubtable
   protected:
   StateTable<Types, EntryData>
                machine;
-  NNOffsetTo<UnsizedOffsetListOf<Lookup<GlyphID>, HBUINT, false>, HBUINT>
+  NNOffsetTo<UnsizedOffsetListOf<Lookup<HBGlyphID>, HBUINT, false>, HBUINT>
                substitutionTables;
   public:
   DEFINE_SIZE_STATIC (20);
@@ -488,7 +488,7 @@ struct LigatureSubtable
 
        unsigned int ligature_idx = 0;
        unsigned int action;
-        do
+       do
        {
          if (unlikely (!cursor))
          {
@@ -520,7 +520,7 @@ struct LigatureSubtable
          if (action & (LigActionStore | LigActionLast))
          {
            ligature_idx = Types::offsetToIndex (ligature_idx, table, ligature.arrayZ);
-           const GlyphID &ligatureData = ligature[ligature_idx];
+           const HBGlyphID &ligatureData = ligature[ligature_idx];
            if (unlikely (!ligatureData.sanitize (&c->sanitizer))) break;
            hb_codepoint_t lig = ligatureData;
 
@@ -554,7 +554,7 @@ struct LigatureSubtable
     const LigatureSubtable *table;
     const UnsizedArrayOf<HBUINT32> &ligAction;
     const UnsizedArrayOf<HBUINT16> &component;
-    const UnsizedArrayOf<GlyphID> &ligature;
+    const UnsizedArrayOf<HBGlyphID> &ligature;
     unsigned int match_length;
     unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
   };
@@ -586,7 +586,7 @@ struct LigatureSubtable
                ligAction;      /* Offset to the ligature action table. */
   NNOffsetTo<UnsizedArrayOf<HBUINT16>, HBUINT>
                component;      /* Offset to the component table. */
-  NNOffsetTo<UnsizedArrayOf<GlyphID>, HBUINT>
+  NNOffsetTo<UnsizedArrayOf<HBGlyphID>, HBUINT>
                ligature;       /* Offset to the actual ligature lists. */
   public:
   DEFINE_SIZE_STATIC (28);
@@ -606,7 +606,7 @@ struct NoncontextualSubtable
     unsigned int count = c->buffer->len;
     for (unsigned int i = 0; i < count; i++)
     {
-      const GlyphID *replacement = substitute.get_value (info[i].codepoint, num_glyphs);
+      const HBGlyphID *replacement = substitute.get_value (info[i].codepoint, num_glyphs);
       if (replacement)
       {
        info[i].codepoint = *replacement;
@@ -624,7 +624,7 @@ struct NoncontextualSubtable
   }
 
   protected:
-  Lookup<GlyphID>      substitute;
+  Lookup<HBGlyphID>    substitute;
   public:
   DEFINE_SIZE_MIN (2);
 };
@@ -726,7 +726,7 @@ struct InsertionSubtable
       {
        unsigned int count = (flags & MarkedInsertCount);
        unsigned int start = entry.data.markedInsertIndex;
-       const GlyphID *glyphs = &insertionAction[start];
+       const HBGlyphID *glyphs = &insertionAction[start];
        if (unlikely (!c->sanitizer.check_array (glyphs, count))) count = 0;
 
        bool before = flags & MarkedInsertBefore;
@@ -744,7 +744,7 @@ struct InsertionSubtable
 
        buffer->move_to (end + count);
 
-       buffer->unsafe_to_break_from_outbuffer (mark, MIN (buffer->idx + 1, buffer->len));
+       buffer->unsafe_to_break_from_outbuffer (mark, hb_min (buffer->idx + 1, buffer->len));
       }
 
       if (flags & SetMark)
@@ -754,7 +754,7 @@ struct InsertionSubtable
       {
        unsigned int count = (flags & CurrentInsertCount) >> 5;
        unsigned int start = entry.data.currentInsertIndex;
-       const GlyphID *glyphs = &insertionAction[start];
+       const HBGlyphID *glyphs = &insertionAction[start];
        if (unlikely (!c->sanitizer.check_array (glyphs, count))) count = 0;
 
        bool before = flags & CurrentInsertBefore;
@@ -793,7 +793,7 @@ struct InsertionSubtable
     private:
     hb_aat_apply_context_t *c;
     unsigned int mark;
-    const UnsizedArrayOf<GlyphID> &insertionAction;
+    const UnsizedArrayOf<HBGlyphID> &insertionAction;
   };
 
   bool apply (hb_aat_apply_context_t *c) const
@@ -819,7 +819,7 @@ struct InsertionSubtable
   protected:
   StateTable<Types, EntryData>
                machine;
-  NNOffsetTo<UnsizedArrayOf<GlyphID>, HBUINT>
+  NNOffsetTo<UnsizedArrayOf<HBGlyphID>, HBUINT>
                insertionAction;        /* Byte offset from stateHeader to the start of
                                         * the insertion glyph table. */
   public:
@@ -883,17 +883,17 @@ struct ChainSubtable
     Insertion          = 5
   };
 
-  template <typename context_t>
-  typename context_t::return_t dispatch (context_t *c) const
+  template <typename context_t, typename ...Ts>
+  typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
   {
     unsigned int subtable_type = get_type ();
     TRACE_DISPATCH (this, subtable_type);
     switch (subtable_type) {
-    case Rearrangement:                return_trace (c->dispatch (u.rearrangement));
-    case Contextual:           return_trace (c->dispatch (u.contextual));
-    case Ligature:             return_trace (c->dispatch (u.ligature));
-    case Noncontextual:                return_trace (c->dispatch (u.noncontextual));
-    case Insertion:            return_trace (c->dispatch (u.insertion));
+    case Rearrangement:                return_trace (c->dispatch (u.rearrangement, hb_forward<Ts> (ds)...));
+    case Contextual:           return_trace (c->dispatch (u.contextual, hb_forward<Ts> (ds)...));
+    case Ligature:             return_trace (c->dispatch (u.ligature, hb_forward<Ts> (ds)...));
+    case Noncontextual:                return_trace (c->dispatch (u.noncontextual, hb_forward<Ts> (ds)...));
+    case Insertion:            return_trace (c->dispatch (u.insertion, hb_forward<Ts> (ds)...));
     default:                   return_trace (c->default_return_value ());
     }
   }
@@ -969,19 +969,19 @@ struct Chain
   void apply (hb_aat_apply_context_t *c,
                     hb_mask_t flags) const
   {
-    const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types> > (featureZ.as_array (featureCount));
+    const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types>> (featureZ.as_array (featureCount));
     unsigned int count = subtableCount;
     for (unsigned int i = 0; i < count; i++)
     {
       bool reverse;
 
       if (!(subtable->subFeatureFlags & flags))
-        goto skip;
+       goto skip;
 
       if (!(subtable->get_coverage() & ChainSubtable<Types>::AllDirections) &&
          HB_DIRECTION_IS_VERTICAL (c->buffer->props.direction) !=
          bool (subtable->get_coverage() & ChainSubtable<Types>::Vertical))
-        goto skip;
+       goto skip;
 
       /* Buffer contents is always in logical direction.  Determine if
        * we need to reverse before applying this subtable.  We reverse
@@ -1016,22 +1016,22 @@ struct Chain
                HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction);
 
       if (!c->buffer->message (c->font, "start chain subtable %d", c->lookup_index))
-        goto skip;
+       goto skip;
 
       if (reverse)
-        c->buffer->reverse ();
+       c->buffer->reverse ();
 
       subtable->apply (c);
 
       if (reverse)
-        c->buffer->reverse ();
+       c->buffer->reverse ();
 
       (void) c->buffer->message (c->font, "end chain subtable %d", c->lookup_index);
 
       if (unlikely (!c->buffer->successful)) return;
 
     skip:
-      subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
+      subtable = &StructAfter<ChainSubtable<Types>> (*subtable);
       c->set_lookup_index (c->lookup_index + 1);
     }
   }
@@ -1049,13 +1049,13 @@ struct Chain
     if (!c->check_array (featureZ.arrayZ, featureCount))
       return_trace (false);
 
-    const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types> > (featureZ.as_array (featureCount));
+    const ChainSubtable<Types> *subtable = &StructAfter<ChainSubtable<Types>> (featureZ.as_array (featureCount));
     unsigned int count = subtableCount;
     for (unsigned int i = 0; i < count; i++)
     {
       if (!subtable->sanitize (c))
        return_trace (false);
-      subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
+      subtable = &StructAfter<ChainSubtable<Types>> (*subtable);
     }
 
     return_trace (true);
@@ -1080,10 +1080,10 @@ struct Chain
  * The 'mort'/'morx' Table
  */
 
-template <typename Types>
+template <typename Types, hb_tag_t TAG>
 struct mortmorx
 {
-  static constexpr hb_tag_t tableTag = HB_AAT_TAG_morx;
+  static constexpr hb_tag_t tableTag = TAG;
 
   bool has_data () const { return version != 0; }
 
@@ -1095,7 +1095,7 @@ struct mortmorx
     for (unsigned int i = 0; i < count; i++)
     {
       map->chain_flags.push (chain->compile_flags (mapper));
-      chain = &StructAfter<Chain<Types> > (*chain);
+      chain = &StructAfter<Chain<Types>> (*chain);
     }
   }
 
@@ -1109,7 +1109,7 @@ struct mortmorx
     {
       chain->apply (c, c->plan->aat_map.chain_flags[i]);
       if (unlikely (!c->buffer->successful)) return;
-      chain = &StructAfter<Chain<Types> > (*chain);
+      chain = &StructAfter<Chain<Types>> (*chain);
     }
   }
 
@@ -1125,7 +1125,7 @@ struct mortmorx
     {
       if (!chain->sanitize (c, version))
        return_trace (false);
-      chain = &StructAfter<Chain<Types> > (*chain);
+      chain = &StructAfter<Chain<Types>> (*chain);
     }
 
     return_trace (true);
@@ -1143,14 +1143,8 @@ struct mortmorx
   DEFINE_SIZE_MIN (8);
 };
 
-struct morx : mortmorx<ExtendedTypes>
-{
-  static constexpr hb_tag_t tableTag = HB_AAT_TAG_morx;
-};
-struct mort : mortmorx<ObsoleteTypes>
-{
-  static constexpr hb_tag_t tableTag = HB_AAT_TAG_mort;
-};
+struct morx : mortmorx<ExtendedTypes, HB_AAT_TAG_morx> {};
+struct mort : mortmorx<ObsoleteTypes, HB_AAT_TAG_mort> {};
 
 
 } /* namespace AAT */