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.hh" |
30 | |
31 | #ifndef HB_NO_AAT_SHAPE |
32 | |
33 | #include "hb-aat-map.hh" |
34 | |
35 | #include "hb-aat-layout.hh" |
36 | |
37 | |
38 | void hb_aat_map_builder_t::add_feature (hb_tag_t tag, |
39 | unsigned int value) |
40 | { |
41 | if (tag == HB_TAG ('a','a','l','t')) |
42 | { |
43 | feature_info_t *info = features.push(); |
44 | info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES; |
45 | info->setting = (hb_aat_layout_feature_selector_t) value; |
46 | return; |
47 | } |
48 | |
49 | const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag); |
50 | if (!mapping) return; |
51 | |
52 | feature_info_t *info = features.push(); |
53 | info->type = mapping->aatFeatureType; |
54 | info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable; |
55 | } |
56 | |
57 | void |
58 | hb_aat_map_builder_t::compile (hb_aat_map_t &m) |
59 | { |
60 | /* Sort features and merge duplicates */ |
61 | if (features.length) |
62 | { |
63 | features.qsort (); |
64 | unsigned int j = 0; |
65 | for (unsigned int i = 1; i < features.length; i++) |
66 | if (features[i].type != features[j].type) |
67 | features[++j] = features[i]; |
68 | features.shrink (j + 1); |
69 | } |
70 | |
71 | hb_aat_layout_compile_map (this, &m); |
72 | } |
73 | |
74 | |
75 | #endif |
76 | |