gfx/harfbuzz/src/hb-ot-map-private.hh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/harfbuzz/src/hb-ot-map-private.hh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,247 @@
     1.4 +/*
     1.5 + * Copyright © 2009,2010  Red Hat, Inc.
     1.6 + * Copyright © 2010,2011,2012,2013  Google, Inc.
     1.7 + *
     1.8 + *  This is part of HarfBuzz, a text shaping library.
     1.9 + *
    1.10 + * Permission is hereby granted, without written agreement and without
    1.11 + * license or royalty fees, to use, copy, modify, and distribute this
    1.12 + * software and its documentation for any purpose, provided that the
    1.13 + * above copyright notice and the following two paragraphs appear in
    1.14 + * all copies of this software.
    1.15 + *
    1.16 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
    1.17 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
    1.18 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
    1.19 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
    1.20 + * DAMAGE.
    1.21 + *
    1.22 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
    1.23 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    1.24 + * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
    1.25 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
    1.26 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    1.27 + *
    1.28 + * Red Hat Author(s): Behdad Esfahbod
    1.29 + * Google Author(s): Behdad Esfahbod
    1.30 + */
    1.31 +
    1.32 +#ifndef HB_OT_MAP_PRIVATE_HH
    1.33 +#define HB_OT_MAP_PRIVATE_HH
    1.34 +
    1.35 +#include "hb-buffer-private.hh"
    1.36 +
    1.37 +
    1.38 +struct hb_ot_shape_plan_t;
    1.39 +
    1.40 +static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
    1.41 +
    1.42 +struct hb_ot_map_t
    1.43 +{
    1.44 +  friend struct hb_ot_map_builder_t;
    1.45 +
    1.46 +  public:
    1.47 +
    1.48 +  struct feature_map_t {
    1.49 +    hb_tag_t tag; /* should be first for our bsearch to work */
    1.50 +    unsigned int index[2]; /* GSUB/GPOS */
    1.51 +    unsigned int stage[2]; /* GSUB/GPOS */
    1.52 +    unsigned int shift;
    1.53 +    hb_mask_t mask;
    1.54 +    hb_mask_t _1_mask; /* mask for value=1, for quick access */
    1.55 +    unsigned int needs_fallback : 1;
    1.56 +    unsigned int auto_zwj : 1;
    1.57 +
    1.58 +    static int cmp (const feature_map_t *a, const feature_map_t *b)
    1.59 +    { return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; }
    1.60 +  };
    1.61 +
    1.62 +  struct lookup_map_t {
    1.63 +    unsigned short index;
    1.64 +    unsigned short auto_zwj : 1;
    1.65 +    hb_mask_t mask;
    1.66 +
    1.67 +    static int cmp (const lookup_map_t *a, const lookup_map_t *b)
    1.68 +    { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; }
    1.69 +  };
    1.70 +
    1.71 +  typedef void (*pause_func_t) (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer);
    1.72 +
    1.73 +  struct stage_map_t {
    1.74 +    unsigned int last_lookup; /* Cumulative */
    1.75 +    pause_func_t pause_func;
    1.76 +  };
    1.77 +
    1.78 +
    1.79 +  hb_ot_map_t (void) { memset (this, 0, sizeof (*this)); }
    1.80 +
    1.81 +  inline hb_mask_t get_global_mask (void) const { return global_mask; }
    1.82 +
    1.83 +  inline hb_mask_t get_mask (hb_tag_t feature_tag, unsigned int *shift = NULL) const {
    1.84 +    const feature_map_t *map = features.bsearch (&feature_tag);
    1.85 +    if (shift) *shift = map ? map->shift : 0;
    1.86 +    return map ? map->mask : 0;
    1.87 +  }
    1.88 +
    1.89 +  inline bool needs_fallback (hb_tag_t feature_tag) const {
    1.90 +    const feature_map_t *map = features.bsearch (&feature_tag);
    1.91 +    return map ? map->needs_fallback : false;
    1.92 +  }
    1.93 +
    1.94 +  inline hb_mask_t get_1_mask (hb_tag_t feature_tag) const {
    1.95 +    const feature_map_t *map = features.bsearch (&feature_tag);
    1.96 +    return map ? map->_1_mask : 0;
    1.97 +  }
    1.98 +
    1.99 +  inline unsigned int get_feature_index (unsigned int table_index, hb_tag_t feature_tag) const {
   1.100 +    const feature_map_t *map = features.bsearch (&feature_tag);
   1.101 +    return map ? map->index[table_index] : HB_OT_LAYOUT_NO_FEATURE_INDEX;
   1.102 +  }
   1.103 +
   1.104 +  inline unsigned int get_feature_stage (unsigned int table_index, hb_tag_t feature_tag) const {
   1.105 +    const feature_map_t *map = features.bsearch (&feature_tag);
   1.106 +    return map ? map->stage[table_index] : (unsigned int) -1;
   1.107 +  }
   1.108 +
   1.109 +  inline void get_stage_lookups (unsigned int table_index, unsigned int stage,
   1.110 +				 const struct lookup_map_t **plookups, unsigned int *lookup_count) const {
   1.111 +    if (unlikely (stage == (unsigned int) -1)) {
   1.112 +      *plookups = NULL;
   1.113 +      *lookup_count = 0;
   1.114 +      return;
   1.115 +    }
   1.116 +    assert (stage <= stages[table_index].len);
   1.117 +    unsigned int start = stage ? stages[table_index][stage - 1].last_lookup : 0;
   1.118 +    unsigned int end   = stage < stages[table_index].len ? stages[table_index][stage].last_lookup : lookups[table_index].len;
   1.119 +    *plookups = &lookups[table_index][start];
   1.120 +    *lookup_count = end - start;
   1.121 +  }
   1.122 +
   1.123 +  HB_INTERNAL void collect_lookups (unsigned int table_index, hb_set_t *lookups) const;
   1.124 +  template <typename Proxy>
   1.125 +  HB_INTERNAL inline void apply (const Proxy &proxy,
   1.126 +				 const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const;
   1.127 +  HB_INTERNAL void substitute (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const;
   1.128 +  HB_INTERNAL void position (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const;
   1.129 +
   1.130 +  inline void finish (void) {
   1.131 +    features.finish ();
   1.132 +    for (unsigned int table_index = 0; table_index < 2; table_index++)
   1.133 +    {
   1.134 +      lookups[table_index].finish ();
   1.135 +      stages[table_index].finish ();
   1.136 +    }
   1.137 +  }
   1.138 +
   1.139 +  public:
   1.140 +  hb_tag_t chosen_script[2];
   1.141 +  bool found_script[2];
   1.142 +
   1.143 +  private:
   1.144 +
   1.145 +  HB_INTERNAL void add_lookups (hb_face_t    *face,
   1.146 +				unsigned int  table_index,
   1.147 +				unsigned int  feature_index,
   1.148 +				hb_mask_t     mask,
   1.149 +				bool          auto_zwj);
   1.150 +
   1.151 +  hb_mask_t global_mask;
   1.152 +
   1.153 +  hb_prealloced_array_t<feature_map_t, 8> features;
   1.154 +  hb_prealloced_array_t<lookup_map_t, 32> lookups[2]; /* GSUB/GPOS */
   1.155 +  hb_prealloced_array_t<stage_map_t, 4> stages[2]; /* GSUB/GPOS */
   1.156 +};
   1.157 +
   1.158 +enum hb_ot_map_feature_flags_t {
   1.159 +  F_NONE		= 0x0000,
   1.160 +  F_GLOBAL		= 0x0001,
   1.161 +  F_HAS_FALLBACK	= 0x0002,
   1.162 +  F_MANUAL_ZWJ		= 0x0004
   1.163 +};
   1.164 +/* Macro version for where const is desired. */
   1.165 +#define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r)))
   1.166 +inline hb_ot_map_feature_flags_t
   1.167 +operator | (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
   1.168 +{ return hb_ot_map_feature_flags_t ((unsigned int) l | (unsigned int) r); }
   1.169 +inline hb_ot_map_feature_flags_t
   1.170 +operator & (hb_ot_map_feature_flags_t l, hb_ot_map_feature_flags_t r)
   1.171 +{ return hb_ot_map_feature_flags_t ((unsigned int) l & (unsigned int) r); }
   1.172 +inline hb_ot_map_feature_flags_t
   1.173 +operator ~ (hb_ot_map_feature_flags_t r)
   1.174 +{ return hb_ot_map_feature_flags_t (~(unsigned int) r); }
   1.175 +inline hb_ot_map_feature_flags_t&
   1.176 +operator |= (hb_ot_map_feature_flags_t &l, hb_ot_map_feature_flags_t r)
   1.177 +{ l = l | r; return l; }
   1.178 +inline hb_ot_map_feature_flags_t&
   1.179 +operator &= (hb_ot_map_feature_flags_t& l, hb_ot_map_feature_flags_t r)
   1.180 +{ l = l & r; return l; }
   1.181 +
   1.182 +
   1.183 +struct hb_ot_map_builder_t
   1.184 +{
   1.185 +  public:
   1.186 +
   1.187 +  HB_INTERNAL hb_ot_map_builder_t (hb_face_t *face_,
   1.188 +				   const hb_segment_properties_t *props_);
   1.189 +
   1.190 +  HB_INTERNAL void add_feature (hb_tag_t tag, unsigned int value,
   1.191 +				hb_ot_map_feature_flags_t flags);
   1.192 +
   1.193 +  inline void add_global_bool_feature (hb_tag_t tag)
   1.194 +  { add_feature (tag, 1, F_GLOBAL); }
   1.195 +
   1.196 +  inline void add_gsub_pause (hb_ot_map_t::pause_func_t pause_func)
   1.197 +  { add_pause (0, pause_func); }
   1.198 +  inline void add_gpos_pause (hb_ot_map_t::pause_func_t pause_func)
   1.199 +  { add_pause (1, pause_func); }
   1.200 +
   1.201 +  HB_INTERNAL void compile (struct hb_ot_map_t &m);
   1.202 +
   1.203 +  inline void finish (void) {
   1.204 +    feature_infos.finish ();
   1.205 +    for (unsigned int table_index = 0; table_index < 2; table_index++)
   1.206 +    {
   1.207 +      stages[table_index].finish ();
   1.208 +    }
   1.209 +  }
   1.210 +
   1.211 +  private:
   1.212 +
   1.213 +  struct feature_info_t {
   1.214 +    hb_tag_t tag;
   1.215 +    unsigned int seq; /* sequence#, used for stable sorting only */
   1.216 +    unsigned int max_value;
   1.217 +    hb_ot_map_feature_flags_t flags;
   1.218 +    unsigned int default_value; /* for non-global features, what should the unset glyphs take */
   1.219 +    unsigned int stage[2]; /* GSUB/GPOS */
   1.220 +
   1.221 +    static int cmp (const feature_info_t *a, const feature_info_t *b)
   1.222 +    { return (a->tag != b->tag) ?  (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); }
   1.223 +  };
   1.224 +
   1.225 +  struct stage_info_t {
   1.226 +    unsigned int index;
   1.227 +    hb_ot_map_t::pause_func_t pause_func;
   1.228 +  };
   1.229 +
   1.230 +  HB_INTERNAL void add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func);
   1.231 +
   1.232 +  public:
   1.233 +
   1.234 +  hb_face_t *face;
   1.235 +  hb_segment_properties_t props;
   1.236 +
   1.237 +  hb_tag_t chosen_script[2];
   1.238 +  bool found_script[2];
   1.239 +  unsigned int script_index[2], language_index[2];
   1.240 +
   1.241 +  private:
   1.242 +
   1.243 +  unsigned int current_stage[2]; /* GSUB/GPOS */
   1.244 +  hb_prealloced_array_t<feature_info_t, 32> feature_infos;
   1.245 +  hb_prealloced_array_t<stage_info_t, 8> stages[2]; /* GSUB/GPOS */
   1.246 +};
   1.247 +
   1.248 +
   1.249 +
   1.250 +#endif /* HB_OT_MAP_PRIVATE_HH */

mercurial