hb-ot-map-private.hh revision 2265be0a620bc76ab65f12fedde67791beb51314
14924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009,2010  Red Hat, Inc.
306a44e859328f5f1e2f6034e711b474116d22e22Behdad Esfahbod * Copyright © 2010,2011,2012,2013  Google, Inc.
44924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *
54924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
64924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *
74924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * Permission is hereby granted, without written agreement and without
84924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
94924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * software and its documentation for any purpose, provided that the
104924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * above copyright notice and the following two paragraphs appear in
114924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * all copies of this software.
124924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *
134924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
144924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
154924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
164924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
174924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * DAMAGE.
184924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *
194924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
204924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
214924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
224924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
234924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
244924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod *
254924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
264924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod * Google Author(s): Behdad Esfahbod
274924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod */
284924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
294924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#ifndef HB_OT_MAP_PRIVATE_HH
304924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#define HB_OT_MAP_PRIVATE_HH
314924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
32895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod#include "hb-buffer-private.hh"
334924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
344924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
352265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbodstruct hb_ot_shape_plan_t;
364924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
374924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbodstatic const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
384924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
3990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbodstruct hb_ot_map_t
4090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod{
4190645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  friend struct hb_ot_map_builder_t;
424924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
438f08c3275040870a645ef034a38d30c05c619f21Behdad Esfahbod  public:
444924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
45610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  struct feature_map_t {
46610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    hb_tag_t tag; /* should be first for our bsearch to work */
47610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int index[2]; /* GSUB/GPOS */
48610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int stage[2]; /* GSUB/GPOS */
49610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int shift;
50610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    hb_mask_t mask;
51610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    hb_mask_t _1_mask; /* mask for value=1, for quick access */
52cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod    unsigned int needs_fallback : 1;
53a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod    unsigned int auto_zwj : 1;
54610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
55610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    static int cmp (const feature_map_t *a, const feature_map_t *b)
56610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    { return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; }
57610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  };
58610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
59610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  struct lookup_map_t {
60cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod    unsigned short index;
61a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod    unsigned short auto_zwj : 1;
62610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    hb_mask_t mask;
63610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
64610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    static int cmp (const lookup_map_t *a, const lookup_map_t *b)
65610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; }
66610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  };
67610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
688bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod  typedef void (*pause_func_t) (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer);
69610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
708ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod  struct stage_map_t {
71893f57b32f01da3411b5596d59170bc340e9fa39Behdad Esfahbod    unsigned int last_lookup; /* Cumulative */
72893f57b32f01da3411b5596d59170bc340e9fa39Behdad Esfahbod    pause_func_t pause_func;
73610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  };
74610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
75610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
768336186a52813b53e90b4399dc462d55750e2d37Behdad Esfahbod  hb_ot_map_t (void) { memset (this, 0, sizeof (*this)); }
778336186a52813b53e90b4399dc462d55750e2d37Behdad Esfahbod
7839dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod  inline hb_mask_t get_global_mask (void) const { return global_mask; }
794924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
80f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod  inline hb_mask_t get_mask (hb_tag_t feature_tag, unsigned int *shift = NULL) const {
81f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod    const feature_map_t *map = features.bsearch (&feature_tag);
828f08c3275040870a645ef034a38d30c05c619f21Behdad Esfahbod    if (shift) *shift = map ? map->shift : 0;
838f08c3275040870a645ef034a38d30c05c619f21Behdad Esfahbod    return map ? map->mask : 0;
844924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod  }
854924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
86fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod  inline bool needs_fallback (hb_tag_t feature_tag) const {
87fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod    const feature_map_t *map = features.bsearch (&feature_tag);
88fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod    return map ? map->needs_fallback : false;
89fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod  }
90fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod
91f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod  inline hb_mask_t get_1_mask (hb_tag_t feature_tag) const {
92f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod    const feature_map_t *map = features.bsearch (&feature_tag);
9339dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod    return map ? map->_1_mask : 0;
9439dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod  }
9539dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod
96610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  inline unsigned int get_feature_index (unsigned int table_index, hb_tag_t feature_tag) const {
97f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod    const feature_map_t *map = features.bsearch (&feature_tag);
98f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod    return map ? map->index[table_index] : HB_OT_LAYOUT_NO_FEATURE_INDEX;
99f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod  }
100f055442716ec7543ed156d4789955b19c11a5255Behdad Esfahbod
101610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  inline unsigned int get_feature_stage (unsigned int table_index, hb_tag_t feature_tag) const {
102610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    const feature_map_t *map = features.bsearch (&feature_tag);
103610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    return map ? map->stage[table_index] : (unsigned int) -1;
104610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  }
105610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
106610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  inline void get_stage_lookups (unsigned int table_index, unsigned int stage,
107610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod				 const struct lookup_map_t **plookups, unsigned int *lookup_count) const {
108610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    if (unlikely (stage == (unsigned int) -1)) {
109610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod      *plookups = NULL;
110610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod      *lookup_count = 0;
111610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod      return;
112610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    }
1138ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod    assert (stage <= stages[table_index].len);
114893f57b32f01da3411b5596d59170bc340e9fa39Behdad Esfahbod    unsigned int start = stage ? stages[table_index][stage - 1].last_lookup : 0;
115893f57b32f01da3411b5596d59170bc340e9fa39Behdad Esfahbod    unsigned int end   = stage < stages[table_index].len ? stages[table_index][stage].last_lookup : lookups[table_index].len;
116610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    *plookups = &lookups[table_index][start];
117610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    *lookup_count = end - start;
118610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  }
119610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod
120f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod  HB_INTERNAL void collect_lookups (unsigned int table_index, hb_set_t *lookups) const;
1218bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod  HB_INTERNAL void substitute (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const;
1228bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod  HB_INTERNAL void position (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const;
1231827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod
1246a7ac79e26e85f6781186cf708a12825c0857324Behdad Esfahbod  inline void finish (void) {
12590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod    features.finish ();
1262265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    for (unsigned int table_index = 0; table_index < 2; table_index++)
1272265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    {
1282265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod      lookups[table_index].finish ();
1292265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod      stages[table_index].finish ();
1302265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    }
1316a7ac79e26e85f6781186cf708a12825c0857324Behdad Esfahbod  }
1326a7ac79e26e85f6781186cf708a12825c0857324Behdad Esfahbod
133851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  public:
134851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  hb_tag_t chosen_script[2];
135851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  bool found_script[2];
13690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
137610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  private:
138b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
13990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  HB_INTERNAL void add_lookups (hb_face_t    *face,
14090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod				unsigned int  table_index,
14190645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod				unsigned int  feature_index,
142cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod				hb_mask_t     mask,
143a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod				bool          auto_zwj);
14490645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
14590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_mask_t global_mask;
14690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
14790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_prealloced_array_t<feature_map_t, 8> features;
14890645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_prealloced_array_t<lookup_map_t, 32> lookups[2]; /* GSUB/GPOS */
1498ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod  hb_prealloced_array_t<stage_map_t, 1> stages[2]; /* GSUB/GPOS */
15090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod};
1514924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
152ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodenum hb_ot_map_feature_flags_t {
153ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  F_NONE		= 0x0000,
154ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  F_GLOBAL		= 0x0001,
155cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod  F_HAS_FALLBACK	= 0x0002,
156a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod  F_MANUAL_ZWJ		= 0x0004
157ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod};
15841732f1fe3ce856d8bb95850635034537b6ba047Behdad Esfahbod/* Macro version for where const is desired. */
15941732f1fe3ce856d8bb95850635034537b6ba047Behdad Esfahbod#define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r)))
160ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
161ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator | (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
162ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t ((unsigned int) l | (unsigned int) r); }
163ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
164ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator & (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
165ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t ((unsigned int) l & (unsigned int) r); }
166ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
167ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator ~ (hb_ot_map_feature_flags_t r)
168ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t (~(unsigned int) r); }
169ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t&
170ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator |= (hb_ot_map_feature_flags_t &l, hb_ot_map_feature_flags_t r)
171ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ l = l | r; return l; }
172ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t&
173ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator &= (hb_ot_map_feature_flags_t& l, hb_ot_map_feature_flags_t r)
174ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ l = l & r; return l; }
175ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod
1764924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
177f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbodstruct hb_ot_map_builder_t
178f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod{
179f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  public:
180f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
1816fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  HB_INTERNAL hb_ot_map_builder_t (hb_face_t *face_,
1826fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod				   const hb_segment_properties_t *props_);
1838336186a52813b53e90b4399dc462d55750e2d37Behdad Esfahbod
184ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  HB_INTERNAL void add_feature (hb_tag_t tag, unsigned int value,
185ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod				hb_ot_map_feature_flags_t flags);
186f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
187e7ffcfafb1108801ac504f18f820e497226bf07fBehdad Esfahbod  inline void add_global_bool_feature (hb_tag_t tag)
188ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  { add_feature (tag, 1, F_GLOBAL); }
189f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
1903e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  inline void add_gsub_pause (hb_ot_map_t::pause_func_t pause_func)
1913e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  { add_pause (0, pause_func); }
1923e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  inline void add_gpos_pause (hb_ot_map_t::pause_func_t pause_func)
1933e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  { add_pause (1, pause_func); }
194b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
1956fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  HB_INTERNAL void compile (struct hb_ot_map_t &m);
196f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
197f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  inline void finish (void) {
198f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    feature_infos.finish ();
1992265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    for (unsigned int table_index = 0; table_index < 2; table_index++)
2002265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    {
2012265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod      stages[table_index].finish ();
2022265be0a620bc76ab65f12fedde67791beb51314Behdad Esfahbod    }
203f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  }
204f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
205f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  private:
206f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
207f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  struct feature_info_t {
208f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    hb_tag_t tag;
209f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int seq; /* sequence#, used for stable sorting only */
210f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int max_value;
211ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod    hb_ot_map_feature_flags_t flags;
212f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int default_value; /* for non-global features, what should the unset glyphs take */
213b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    unsigned int stage[2]; /* GSUB/GPOS */
214f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
215f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    static int cmp (const feature_info_t *a, const feature_info_t *b)
216f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    { return (a->tag != b->tag) ?  (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); }
217f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  };
218f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
2198ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod  struct stage_info_t {
2208ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod    unsigned int index;
221893f57b32f01da3411b5596d59170bc340e9fa39Behdad Esfahbod    hb_ot_map_t::pause_func_t pause_func;
222b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  };
223b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
2243e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  HB_INTERNAL void add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func);
225d8d0c480c85246a74d47dd5297019c7e39391ab0Behdad Esfahbod
2265ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod  public:
2275ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod
2286fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_face_t *face;
2296fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_segment_properties_t props;
2306fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod
2316fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_tag_t chosen_script[2];
232851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  bool found_script[2];
2336fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  unsigned int script_index[2], language_index[2];
2346fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod
2355ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod  private:
2365ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod
237b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  unsigned int current_stage[2]; /* GSUB/GPOS */
238b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  hb_prealloced_array_t<feature_info_t,16> feature_infos;
2398ac3c9c0b6b8e76bce282825b9bb706c0c78c2a6Behdad Esfahbod  hb_prealloced_array_t<stage_info_t, 1> stages[2]; /* GSUB/GPOS */
240f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod};
241f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
242f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
2434924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
2444924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#endif /* HB_OT_MAP_PRIVATE_HH */
245