1 /* 2 * Copyright © 2009,2010 Red Hat, Inc. 3 * Copyright © 2010,2011,2013 Google, Inc. 4 * 5 * This is part of HarfBuzz, a text shaping library. 6 * 7 * Permission is hereby granted, without written agreement and without 8 * license or royalty fees, to use, copy, modify, and distribute this 9 * software and its documentation for any purpose, provided that the 10 * above copyright notice and the following two paragraphs appear in 11 * all copies of this software. 12 * 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * DAMAGE. 18 * 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 * 25 * Red Hat Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #include "hb-aat-map.hh" 30 31 #include "hb-aat-layout.hh" 32 33 34 void hb_aat_map_builder_t::add_feature (hb_tag_t tag, 35 unsigned int value) 36 { 37 if (tag == HB_TAG ('a','a','l','t')) 38 { 39 feature_info_t *info = features.push(); 40 info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES; 41 info->setting = (hb_aat_layout_feature_selector_t) value; 42 return; 43 } 44 45 const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag); 46 if (!mapping) return; 47 48 feature_info_t *info = features.push(); 49 info->type = mapping->aatFeatureType; 50 info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable; 51 } 52 53 void 54 hb_aat_map_builder_t::compile (hb_aat_map_t &m) 55 { 56 /* Sort features and merge duplicates */ 57 if (features.length) 58 { 59 features.qsort (); 60 unsigned int j = 0; 61 for (unsigned int i = 1; i < features.length; i++) 62 if (features[i].type != features[j].type) 63 features[++j] = features[i]; 64 features.shrink (j + 1); 65 } 66 67 hb_aat_layout_compile_map (this, &m); 68 }