• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "hb-aat-layout-feat-table.hh"
37 
38 
add_feature(hb_tag_t tag,unsigned value)39 void hb_aat_map_builder_t::add_feature (hb_tag_t tag, unsigned value)
40 {
41   if (!face->table.feat->has_data ()) return;
42 
43   if (tag == HB_TAG ('a','a','l','t'))
44   {
45     if (!face->table.feat->exposes_feature (HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES))
46       return;
47     feature_info_t *info = features.push();
48     info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES;
49     info->setting = (hb_aat_layout_feature_selector_t) value;
50     info->seq = features.length;
51     info->is_exclusive = true;
52     return;
53   }
54 
55   const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag);
56   if (!mapping) return;
57 
58   const AAT::FeatureName* feature = &face->table.feat->get_feature (mapping->aatFeatureType);
59   if (!feature->has_data ())
60   {
61     /* Special case: Chain::compile_flags will fall back to the deprecated version of
62      * small-caps if necessary, so we need to check for that possibility.
63      * https://github.com/harfbuzz/harfbuzz/issues/2307 */
64     if (mapping->aatFeatureType == HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE &&
65 	mapping->selectorToEnable == HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS)
66     {
67       feature = &face->table.feat->get_feature (HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE);
68       if (!feature->has_data ()) return;
69     }
70     else return;
71   }
72 
73   feature_info_t *info = features.push();
74   info->type = mapping->aatFeatureType;
75   info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable;
76   info->seq = features.length;
77   info->is_exclusive = feature->is_exclusive ();
78 }
79 
80 void
compile(hb_aat_map_t & m)81 hb_aat_map_builder_t::compile (hb_aat_map_t  &m)
82 {
83   /* Sort features and merge duplicates */
84   if (features.length)
85   {
86     features.qsort ();
87     unsigned int j = 0;
88     for (unsigned int i = 1; i < features.length; i++)
89       if (features[i].type != features[j].type ||
90 	  /* Nonexclusive feature selectors come in even/odd pairs to turn a setting on/off
91 	   * respectively, so we mask out the low-order bit when checking for "duplicates"
92 	   * (selectors referring to the same feature setting) here. */
93 	  (!features[i].is_exclusive && ((features[i].setting & ~1) != (features[j].setting & ~1))))
94 	features[++j] = features[i];
95     features.shrink (j + 1);
96   }
97 
98   hb_aat_layout_compile_map (this, &m);
99 }
100 
101 
102 #endif
103