Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
6 #include "gfxFontFeatures.h"
7 #include "nsUnicharUtils.h"
8 #include "nsHashKeys.h"
10 using namespace mozilla;
12 gfxFontFeatureValueSet::gfxFontFeatureValueSet()
13 : mFontFeatureValues(10)
14 {
15 }
17 bool
18 gfxFontFeatureValueSet::GetFontFeatureValuesFor(const nsAString& aFamily,
19 uint32_t aVariantProperty,
20 const nsAString& aName,
21 nsTArray<uint32_t>& aValues)
22 {
23 nsAutoString family(aFamily), name(aName);
24 ToLowerCase(family);
25 ToLowerCase(name);
26 FeatureValueHashKey key(family, aVariantProperty, name);
28 aValues.Clear();
29 FeatureValueHashEntry *entry = mFontFeatureValues.GetEntry(key);
30 if (entry) {
31 NS_ASSERTION(entry->mValues.Length() > 0,
32 "null array of font feature values");
33 aValues.AppendElements(entry->mValues);
34 return true;
35 }
37 return false;
38 }
41 void
42 gfxFontFeatureValueSet::AddFontFeatureValues(const nsAString& aFamily,
43 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues)
44 {
45 nsAutoString family(aFamily);
46 ToLowerCase(family);
48 uint32_t i, numFeatureValues = aValues.Length();
49 for (i = 0; i < numFeatureValues; i++) {
50 const FeatureValues& fv = aValues.ElementAt(i);
51 uint32_t alternate = fv.alternate;
52 uint32_t j, numValues = fv.valuelist.Length();
53 for (j = 0; j < numValues; j++) {
54 const ValueList& v = fv.valuelist.ElementAt(j);
55 nsAutoString name(v.name);
56 ToLowerCase(name);
57 FeatureValueHashKey key(family, alternate, name);
58 FeatureValueHashEntry *entry = mFontFeatureValues.PutEntry(key);
59 entry->mKey = key;
60 entry->mValues = v.featureSelectors;
61 }
62 }
63 }
65 bool
66 gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals(
67 const KeyTypePointer aKey) const
68 {
69 return aKey->mPropVal == mKey.mPropVal &&
70 aKey->mFamily.Equals(mKey.mFamily) &&
71 aKey->mName.Equals(mKey.mName);
72 }
74 PLDHashNumber
75 gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey(
76 const KeyTypePointer aKey)
77 {
78 return HashString(aKey->mFamily) + HashString(aKey->mName) +
79 aKey->mPropVal * uint32_t(0xdeadbeef);
80 }