Path: blob/master/src/java.desktop/share/native/libharfbuzz/hb-aat-map.cc
41152 views
/*1* Copyright © 2009,2010 Red Hat, Inc.2* Copyright © 2010,2011,2013 Google, Inc.3*4* This is part of HarfBuzz, a text shaping library.5*6* Permission is hereby granted, without written agreement and without7* license or royalty fees, to use, copy, modify, and distribute this8* software and its documentation for any purpose, provided that the9* above copyright notice and the following two paragraphs appear in10* all copies of this software.11*12* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR13* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES14* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN15* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH16* DAMAGE.17*18* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,19* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND20* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS21* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO22* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.23*24* Red Hat Author(s): Behdad Esfahbod25* Google Author(s): Behdad Esfahbod26*/2728#include "hb.hh"2930#ifndef HB_NO_AAT_SHAPE3132#include "hb-aat-map.hh"3334#include "hb-aat-layout.hh"35#include "hb-aat-layout-feat-table.hh"363738void hb_aat_map_builder_t::add_feature (hb_tag_t tag, unsigned value)39{40if (!face->table.feat->has_data ()) return;4142if (tag == HB_TAG ('a','a','l','t'))43{44if (!face->table.feat->exposes_feature (HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES))45return;46feature_info_t *info = features.push();47info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES;48info->setting = (hb_aat_layout_feature_selector_t) value;49info->seq = features.length;50info->is_exclusive = true;51return;52}5354const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag);55if (!mapping) return;5657const AAT::FeatureName* feature = &face->table.feat->get_feature (mapping->aatFeatureType);58if (!feature->has_data ())59{60/* Special case: Chain::compile_flags will fall back to the deprecated version of61* small-caps if necessary, so we need to check for that possibility.62* https://github.com/harfbuzz/harfbuzz/issues/2307 */63if (mapping->aatFeatureType == HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE &&64mapping->selectorToEnable == HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS)65{66feature = &face->table.feat->get_feature (HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE);67if (!feature->has_data ()) return;68}69else return;70}7172feature_info_t *info = features.push();73info->type = mapping->aatFeatureType;74info->setting = value ? mapping->selectorToEnable : mapping->selectorToDisable;75info->seq = features.length;76info->is_exclusive = feature->is_exclusive ();77}7879void80hb_aat_map_builder_t::compile (hb_aat_map_t &m)81{82/* Sort features and merge duplicates */83if (features.length)84{85features.qsort ();86unsigned int j = 0;87for (unsigned int i = 1; i < features.length; i++)88if (features[i].type != features[j].type ||89/* Nonexclusive feature selectors come in even/odd pairs to turn a setting on/off90* respectively, so we mask out the low-order bit when checking for "duplicates"91* (selectors referring to the same feature setting) here. */92(!features[i].is_exclusive && ((features[i].setting & ~1) != (features[j].setting & ~1))))93features[++j] = features[i];94features.shrink (j + 1);95}9697hb_aat_layout_compile_map (this, &m);98}99100101#endif102103104