michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxFontFeatures.h" michael@0: #include "nsUnicharUtils.h" michael@0: #include "nsHashKeys.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: gfxFontFeatureValueSet::gfxFontFeatureValueSet() michael@0: : mFontFeatureValues(10) michael@0: { michael@0: } michael@0: michael@0: bool michael@0: gfxFontFeatureValueSet::GetFontFeatureValuesFor(const nsAString& aFamily, michael@0: uint32_t aVariantProperty, michael@0: const nsAString& aName, michael@0: nsTArray& aValues) michael@0: { michael@0: nsAutoString family(aFamily), name(aName); michael@0: ToLowerCase(family); michael@0: ToLowerCase(name); michael@0: FeatureValueHashKey key(family, aVariantProperty, name); michael@0: michael@0: aValues.Clear(); michael@0: FeatureValueHashEntry *entry = mFontFeatureValues.GetEntry(key); michael@0: if (entry) { michael@0: NS_ASSERTION(entry->mValues.Length() > 0, michael@0: "null array of font feature values"); michael@0: aValues.AppendElements(entry->mValues); michael@0: return true; michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: michael@0: void michael@0: gfxFontFeatureValueSet::AddFontFeatureValues(const nsAString& aFamily, michael@0: const nsTArray& aValues) michael@0: { michael@0: nsAutoString family(aFamily); michael@0: ToLowerCase(family); michael@0: michael@0: uint32_t i, numFeatureValues = aValues.Length(); michael@0: for (i = 0; i < numFeatureValues; i++) { michael@0: const FeatureValues& fv = aValues.ElementAt(i); michael@0: uint32_t alternate = fv.alternate; michael@0: uint32_t j, numValues = fv.valuelist.Length(); michael@0: for (j = 0; j < numValues; j++) { michael@0: const ValueList& v = fv.valuelist.ElementAt(j); michael@0: nsAutoString name(v.name); michael@0: ToLowerCase(name); michael@0: FeatureValueHashKey key(family, alternate, name); michael@0: FeatureValueHashEntry *entry = mFontFeatureValues.PutEntry(key); michael@0: entry->mKey = key; michael@0: entry->mValues = v.featureSelectors; michael@0: } michael@0: } michael@0: } michael@0: michael@0: bool michael@0: gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals( michael@0: const KeyTypePointer aKey) const michael@0: { michael@0: return aKey->mPropVal == mKey.mPropVal && michael@0: aKey->mFamily.Equals(mKey.mFamily) && michael@0: aKey->mName.Equals(mKey.mName); michael@0: } michael@0: michael@0: PLDHashNumber michael@0: gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey( michael@0: const KeyTypePointer aKey) michael@0: { michael@0: return HashString(aKey->mFamily) + HashString(aKey->mName) + michael@0: aKey->mPropVal * uint32_t(0xdeadbeef); michael@0: } michael@0: