Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 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 | |
Behdad Esfahbod | f4de0c7 | 2019-06-19 17:08:26 -0700 | [diff] [blame] | 29 | #include "hb.hh" |
| 30 | |
Behdad Esfahbod | 12092a4 | 2019-06-26 13:31:01 -0700 | [diff] [blame] | 31 | #ifndef HB_NO_AAT_SHAPE |
Behdad Esfahbod | f4de0c7 | 2019-06-19 17:08:26 -0700 | [diff] [blame] | 32 | |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 33 | #include "hb-aat-map.hh" |
| 34 | |
| 35 | #include "hb-aat-layout.hh" |
Jonathan Kew | b1c0b9d | 2020-04-02 14:39:13 +0100 | [diff] [blame] | 36 | #include "hb-aat-layout-feat-table.hh" |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 37 | |
| 38 | |
Ebrahim Byagowi | 89fa70f | 2020-04-03 00:05:40 +0430 | [diff] [blame] | 39 | void hb_aat_map_builder_t::add_feature (hb_tag_t tag, unsigned value) |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 40 | { |
Ebrahim Byagowi | 89fa70f | 2020-04-03 00:05:40 +0430 | [diff] [blame] | 41 | if (!face->table.feat->has_data ()) return; |
Jonathan Kew | b1c0b9d | 2020-04-02 14:39:13 +0100 | [diff] [blame] | 42 | |
Behdad Esfahbod | 52a00cd | 2018-10-31 19:05:53 -0700 | [diff] [blame] | 43 | if (tag == HB_TAG ('a','a','l','t')) |
| 44 | { |
Ebrahim Byagowi | 89fa70f | 2020-04-03 00:05:40 +0430 | [diff] [blame] | 45 | if (!face->table.feat->exposes_feature (HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES)) |
| 46 | return; |
Behdad Esfahbod | 52a00cd | 2018-10-31 19:05:53 -0700 | [diff] [blame] | 47 | feature_info_t *info = features.push(); |
Ebrahim Byagowi | 7a0471a | 2018-11-01 21:38:54 +0330 | [diff] [blame] | 48 | info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES; |
Ebrahim Byagowi | 54f4c17 | 2018-11-23 12:05:06 +0330 | [diff] [blame] | 49 | info->setting = (hb_aat_layout_feature_selector_t) value; |
Jonathan Kew | b027cb5 | 2020-03-30 18:47:22 +0100 | [diff] [blame] | 50 | info->seq = features.length; |
Jonathan Kew | 573b6bf | 2020-03-30 23:20:30 +0100 | [diff] [blame] | 51 | info->is_exclusive = true; |
Behdad Esfahbod | 52a00cd | 2018-10-31 19:05:53 -0700 | [diff] [blame] | 52 | return; |
| 53 | } |
| 54 | |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 55 | const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag); |
| 56 | if (!mapping) return; |
Jonathan Kew | 573b6bf | 2020-03-30 23:20:30 +0100 | [diff] [blame] | 57 | |
| 58 | const AAT::FeatureName* feature = &face->table.feat->get_feature (mapping->aatFeatureType); |
| 59 | if (!feature->has_data ()) |
Jonathan Kew | 1faf0ca | 2020-04-03 16:10:34 +0100 | [diff] [blame] | 60 | { |
Ebrahim Byagowi | 3737776 | 2020-04-03 20:03:20 +0430 | [diff] [blame] | 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. |
Ebrahim Byagowi | 75cae46 | 2020-04-03 20:04:16 +0430 | [diff] [blame] | 63 | * https://github.com/harfbuzz/harfbuzz/issues/2307 */ |
Jonathan Kew | 1faf0ca | 2020-04-03 16:10:34 +0100 | [diff] [blame] | 64 | if (mapping->aatFeatureType == HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE && |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 65 | mapping->selectorToEnable == HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS) |
Jonathan Kew | 1faf0ca | 2020-04-03 16:10:34 +0100 | [diff] [blame] | 66 | { |
Jonathan Kew | 573b6bf | 2020-03-30 23:20:30 +0100 | [diff] [blame] | 67 | feature = &face->table.feat->get_feature (HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE); |
| 68 | if (!feature->has_data ()) return; |
Jonathan Kew | 1faf0ca | 2020-04-03 16:10:34 +0100 | [diff] [blame] | 69 | } |
| 70 | else return; |
| 71 | } |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 72 | |
| 73 | feature_info_t *info = features.push(); |
| 74 | info->type = mapping->aatFeatureType; |
| 75 | info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable; |
Jonathan Kew | b027cb5 | 2020-03-30 18:47:22 +0100 | [diff] [blame] | 76 | info->seq = features.length; |
Jonathan Kew | 573b6bf | 2020-03-30 23:20:30 +0100 | [diff] [blame] | 77 | info->is_exclusive = feature->is_exclusive (); |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void |
Behdad Esfahbod | cc84287 | 2018-11-12 18:48:10 -0500 | [diff] [blame] | 81 | hb_aat_map_builder_t::compile (hb_aat_map_t &m) |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 82 | { |
| 83 | /* Sort features and merge duplicates */ |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 84 | if (features.length) |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 85 | { |
| 86 | features.qsort (); |
| 87 | unsigned int j = 0; |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 88 | for (unsigned int i = 1; i < features.length; i++) |
Jonathan Kew | 573b6bf | 2020-03-30 23:20:30 +0100 | [diff] [blame] | 89 | if (features[i].type != features[j].type || |
Ebrahim Byagowi | 2dda6dd | 2020-04-20 14:12:45 +0430 | [diff] [blame] | 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)))) |
Behdad Esfahbod | f33ad6d | 2018-10-23 14:31:51 -0700 | [diff] [blame] | 94 | features[++j] = features[i]; |
| 95 | features.shrink (j + 1); |
| 96 | } |
| 97 | |
| 98 | hb_aat_layout_compile_map (this, &m); |
| 99 | } |
Behdad Esfahbod | f4de0c7 | 2019-06-19 17:08:26 -0700 | [diff] [blame] | 100 | |
| 101 | |
| 102 | #endif |