gfxFontFeatures.cpp (1734B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "gfxFontFeatures.h" 7 #include "nsAtom.h" 8 #include "nsUnicharUtils.h" 9 #include "nsHashKeys.h" 10 11 using namespace mozilla; 12 13 gfxFontFeatureValueSet::gfxFontFeatureValueSet() : mFontFeatureValues(8) {} 14 15 Span<const uint32_t> gfxFontFeatureValueSet::GetFontFeatureValuesFor( 16 const nsACString& aFamily, uint32_t aVariantProperty, nsAtom* aName) const { 17 nsAutoCString family(aFamily); 18 ToLowerCase(family); 19 FeatureValueHashKey key(family, aVariantProperty, aName); 20 FeatureValueHashEntry* entry = mFontFeatureValues.GetEntry(key); 21 if (!entry) { 22 return {}; 23 } 24 NS_ASSERTION(entry->mValues.Length() > 0, 25 "null array of font feature values"); 26 return {entry->mValues}; 27 } 28 29 nsTArray<uint32_t>* gfxFontFeatureValueSet::AppendFeatureValueHashEntry( 30 const nsACString& aFamily, nsAtom* aName, uint32_t aAlternate) { 31 FeatureValueHashKey key(aFamily, aAlternate, aName); 32 FeatureValueHashEntry* entry = mFontFeatureValues.PutEntry(key); 33 entry->mKey = key; 34 return &entry->mValues; 35 } 36 37 bool gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals( 38 const KeyTypePointer aKey) const { 39 return aKey->mPropVal == mKey.mPropVal && aKey->mName == mKey.mName && 40 aKey->mFamily.Equals(mKey.mFamily); 41 } 42 43 PLDHashNumber gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey( 44 const KeyTypePointer aKey) { 45 return HashString(aKey->mFamily) + aKey->mName->hash() + 46 aKey->mPropVal * uint32_t(0xdeadbeef); 47 }