1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxFontFeatures.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "gfxFontFeatures.h" 1.10 +#include "nsUnicharUtils.h" 1.11 +#include "nsHashKeys.h" 1.12 + 1.13 +using namespace mozilla; 1.14 + 1.15 +gfxFontFeatureValueSet::gfxFontFeatureValueSet() 1.16 + : mFontFeatureValues(10) 1.17 +{ 1.18 +} 1.19 + 1.20 +bool 1.21 +gfxFontFeatureValueSet::GetFontFeatureValuesFor(const nsAString& aFamily, 1.22 + uint32_t aVariantProperty, 1.23 + const nsAString& aName, 1.24 + nsTArray<uint32_t>& aValues) 1.25 +{ 1.26 + nsAutoString family(aFamily), name(aName); 1.27 + ToLowerCase(family); 1.28 + ToLowerCase(name); 1.29 + FeatureValueHashKey key(family, aVariantProperty, name); 1.30 + 1.31 + aValues.Clear(); 1.32 + FeatureValueHashEntry *entry = mFontFeatureValues.GetEntry(key); 1.33 + if (entry) { 1.34 + NS_ASSERTION(entry->mValues.Length() > 0, 1.35 + "null array of font feature values"); 1.36 + aValues.AppendElements(entry->mValues); 1.37 + return true; 1.38 + } 1.39 + 1.40 + return false; 1.41 +} 1.42 + 1.43 + 1.44 +void 1.45 +gfxFontFeatureValueSet::AddFontFeatureValues(const nsAString& aFamily, 1.46 + const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues) 1.47 +{ 1.48 + nsAutoString family(aFamily); 1.49 + ToLowerCase(family); 1.50 + 1.51 + uint32_t i, numFeatureValues = aValues.Length(); 1.52 + for (i = 0; i < numFeatureValues; i++) { 1.53 + const FeatureValues& fv = aValues.ElementAt(i); 1.54 + uint32_t alternate = fv.alternate; 1.55 + uint32_t j, numValues = fv.valuelist.Length(); 1.56 + for (j = 0; j < numValues; j++) { 1.57 + const ValueList& v = fv.valuelist.ElementAt(j); 1.58 + nsAutoString name(v.name); 1.59 + ToLowerCase(name); 1.60 + FeatureValueHashKey key(family, alternate, name); 1.61 + FeatureValueHashEntry *entry = mFontFeatureValues.PutEntry(key); 1.62 + entry->mKey = key; 1.63 + entry->mValues = v.featureSelectors; 1.64 + } 1.65 + } 1.66 +} 1.67 + 1.68 +bool 1.69 +gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals( 1.70 + const KeyTypePointer aKey) const 1.71 +{ 1.72 + return aKey->mPropVal == mKey.mPropVal && 1.73 + aKey->mFamily.Equals(mKey.mFamily) && 1.74 + aKey->mName.Equals(mKey.mName); 1.75 +} 1.76 + 1.77 +PLDHashNumber 1.78 +gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey( 1.79 + const KeyTypePointer aKey) 1.80 +{ 1.81 + return HashString(aKey->mFamily) + HashString(aKey->mName) + 1.82 + aKey->mPropVal * uint32_t(0xdeadbeef); 1.83 +} 1.84 +