hb-ot-map-private.hh revision a8cf7b43fa795150ae3d42d64424bb6e0373d0b2
14924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009,2010  Red Hat, Inc.
3f860366456d9e59b139a940da6d89c3c4fb9e96eBehdad Esfahbod * Copyright © 2010,2011,2012  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
34f860366456d9e59b139a940da6d89c3c4fb9e96eBehdad Esfahbod#include "hb-ot-layout-private.hh"
354924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
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
70610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  struct pause_map_t {
71610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int num_lookups; /* Cumulative */
723e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod    pause_func_t callback;
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    }
113610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    assert (stage <= pauses[table_index].len);
114610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int start = stage ? pauses[table_index][stage - 1].num_lookups : 0;
115610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod    unsigned int end   = stage < pauses[table_index].len ? pauses[table_index][stage].num_lookups : 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 ();
12690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod    lookups[0].finish ();
12790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod    lookups[1].finish ();
128b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    pauses[0].finish ();
129b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    pauses[1].finish ();
1306a7ac79e26e85f6781186cf708a12825c0857324Behdad Esfahbod  }
1316a7ac79e26e85f6781186cf708a12825c0857324Behdad Esfahbod
132851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  public:
133851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  hb_tag_t chosen_script[2];
134851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  bool found_script[2];
13590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
136610e5e8f713bb2a68939b72cb2b801a7aaede4f9Behdad Esfahbod  private:
137b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
13890645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  HB_INTERNAL void add_lookups (hb_face_t    *face,
13990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod				unsigned int  table_index,
14090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod				unsigned int  feature_index,
141cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod				hb_mask_t     mask,
142a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod				bool          auto_zwj);
14390645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
14490645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_mask_t global_mask;
14590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
14690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_prealloced_array_t<feature_map_t, 8> features;
14790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_prealloced_array_t<lookup_map_t, 32> lookups[2]; /* GSUB/GPOS */
148b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  hb_prealloced_array_t<pause_map_t, 1> pauses[2]; /* GSUB/GPOS */
14990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod};
1504924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
151ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodenum hb_ot_map_feature_flags_t {
152ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  F_NONE		= 0x0000,
153ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  F_GLOBAL		= 0x0001,
154cfc507c5432e6327e8484b07b9e091212653bc92Behdad Esfahbod  F_HAS_FALLBACK	= 0x0002,
155a8cf7b43fa795150ae3d42d64424bb6e0373d0b2Behdad Esfahbod  F_MANUAL_ZWJ		= 0x0004
156ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod};
15741732f1fe3ce856d8bb95850635034537b6ba047Behdad Esfahbod/* Macro version for where const is desired. */
15841732f1fe3ce856d8bb95850635034537b6ba047Behdad Esfahbod#define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r)))
159ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
160ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator | (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
161ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t ((unsigned int) l | (unsigned int) r); }
162ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
163ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator & (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
164ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t ((unsigned int) l & (unsigned int) r); }
165ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t
166ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator ~ (hb_ot_map_feature_flags_t r)
167ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ return hb_ot_map_feature_flags_t (~(unsigned int) r); }
168ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t&
169ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator |= (hb_ot_map_feature_flags_t &l, hb_ot_map_feature_flags_t r)
170ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ l = l | r; return l; }
171ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodinline hb_ot_map_feature_flags_t&
172ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbodoperator &= (hb_ot_map_feature_flags_t& l, hb_ot_map_feature_flags_t r)
173ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod{ l = l & r; return l; }
174ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod
1754924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
176f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbodstruct hb_ot_map_builder_t
177f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod{
178f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  public:
179f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
1806fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  HB_INTERNAL hb_ot_map_builder_t (hb_face_t *face_,
1816fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod				   const hb_segment_properties_t *props_);
1828336186a52813b53e90b4399dc462d55750e2d37Behdad Esfahbod
183ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  HB_INTERNAL void add_feature (hb_tag_t tag, unsigned int value,
184ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod				hb_ot_map_feature_flags_t flags);
185f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
186e7ffcfafb1108801ac504f18f820e497226bf07fBehdad Esfahbod  inline void add_global_bool_feature (hb_tag_t tag)
187ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod  { add_feature (tag, 1, F_GLOBAL); }
188f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
1893e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  inline void add_gsub_pause (hb_ot_map_t::pause_func_t pause_func)
1903e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  { add_pause (0, pause_func); }
1913e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  inline void add_gpos_pause (hb_ot_map_t::pause_func_t pause_func)
1923e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  { add_pause (1, pause_func); }
193b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
1946fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  HB_INTERNAL void compile (struct hb_ot_map_t &m);
195f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
196f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  inline void finish (void) {
197f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    feature_infos.finish ();
198b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    pauses[0].finish ();
199b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    pauses[1].finish ();
200f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  }
201f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
202f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  private:
203f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
204f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  struct feature_info_t {
205f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    hb_tag_t tag;
206f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int seq; /* sequence#, used for stable sorting only */
207f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int max_value;
208ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod    hb_ot_map_feature_flags_t flags;
209f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    unsigned int default_value; /* for non-global features, what should the unset glyphs take */
210b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    unsigned int stage[2]; /* GSUB/GPOS */
211f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
212f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    static int cmp (const feature_info_t *a, const feature_info_t *b)
213f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod    { return (a->tag != b->tag) ?  (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); }
214f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod  };
215f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
216b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  struct pause_info_t {
217b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod    unsigned int stage;
2183e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod    hb_ot_map_t::pause_func_t callback;
219b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  };
220b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod
2213e38c0f2886c38d2f0a9d80a97a36edf2479d2c7Behdad Esfahbod  HB_INTERNAL void add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func);
222d8d0c480c85246a74d47dd5297019c7e39391ab0Behdad Esfahbod
2235ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod  public:
2245ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod
2256fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_face_t *face;
2266fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_segment_properties_t props;
2276fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod
2286fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  hb_tag_t chosen_script[2];
229851784f8372004e0a40b698c0cdc2d7db8629aa2Behdad Esfahbod  bool found_script[2];
2306fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod  unsigned int script_index[2], language_index[2];
2316fddf2d7397411bba8a23ac535e8b851495d3105Behdad Esfahbod
2325ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod  private:
2335ab3855f8106158ee7e68797e8c35e63e9216e5dBehdad Esfahbod
234b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  unsigned int current_stage[2]; /* GSUB/GPOS */
235b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  hb_prealloced_array_t<feature_info_t,16> feature_infos;
236b70c96dbe41d6512b80fe3d966a1942e1ef64a4bBehdad Esfahbod  hb_prealloced_array_t<pause_info_t, 1> pauses[2]; /* GSUB/GPOS */
237f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod};
238f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
239f6d7a9bb4c19e605f1f16d9ca40adefba138c37eBehdad Esfahbod
2404924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod
2414924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#endif /* HB_OT_MAP_PRIVATE_HH */
242