Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/thebes/gfxFontFeatures.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#include "gfxFontFeatures.h"
7
#include "nsUnicharUtils.h"
8
#include "nsHashKeys.h"
9
10
using namespace mozilla;
11
12
gfxFontFeatureValueSet::gfxFontFeatureValueSet()
13
    : mFontFeatureValues(8)
14
0
{
15
0
}
16
17
bool
18
gfxFontFeatureValueSet::GetFontFeatureValuesFor(const nsACString& aFamily,
19
                                                uint32_t aVariantProperty,
20
                                                const nsAString& aName,
21
                                                nsTArray<uint32_t>& aValues)
22
0
{
23
0
    nsAutoCString family(aFamily);
24
0
    ToLowerCase(family);
25
0
    FeatureValueHashKey key(family, aVariantProperty, aName);
26
0
27
0
    aValues.Clear();
28
0
    FeatureValueHashEntry *entry = mFontFeatureValues.GetEntry(key);
29
0
    if (entry) {
30
0
        NS_ASSERTION(entry->mValues.Length() > 0,
31
0
                     "null array of font feature values");
32
0
        aValues.AppendElements(entry->mValues);
33
0
        return true;
34
0
    }
35
0
36
0
    return false;
37
0
}
38
39
40
void
41
gfxFontFeatureValueSet::AddFontFeatureValues(const nsACString& aFamily,
42
                 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues)
43
0
{
44
0
    nsAutoCString family(aFamily);
45
0
    ToLowerCase(family);
46
0
47
0
    uint32_t i, numFeatureValues = aValues.Length();
48
0
    for (i = 0; i < numFeatureValues; i++) {
49
0
        const FeatureValues& fv = aValues.ElementAt(i);
50
0
        uint32_t alternate = fv.alternate;
51
0
        uint32_t j, numValues = fv.valuelist.Length();
52
0
        for (j = 0; j < numValues; j++) {
53
0
            const ValueList& v = fv.valuelist.ElementAt(j);
54
0
            auto* array = AppendFeatureValueHashEntry(family, v.name, alternate);
55
0
            *array = v.featureSelectors;
56
0
        }
57
0
    }
58
0
}
59
60
61
nsTArray<uint32_t>*
62
gfxFontFeatureValueSet::AppendFeatureValueHashEntry(const nsACString& aFamily,
63
                                                    const nsAString& aName,
64
                                                    uint32_t aAlternate)
65
0
{
66
0
    FeatureValueHashKey key(aFamily, aAlternate, aName);
67
0
    FeatureValueHashEntry *entry = mFontFeatureValues.PutEntry(key);
68
0
    entry->mKey = key;
69
0
    return &entry->mValues;
70
0
}
71
72
bool
73
gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals(
74
                                               const KeyTypePointer aKey) const
75
0
{
76
0
    return aKey->mPropVal == mKey.mPropVal &&
77
0
           aKey->mFamily.Equals(mKey.mFamily) &&
78
0
           aKey->mName.Equals(mKey.mName);
79
0
}
80
81
PLDHashNumber
82
gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey(
83
                                                     const KeyTypePointer aKey)
84
0
{
85
0
    return HashString(aKey->mFamily) + HashString(aKey->mName) +
86
0
           aKey->mPropVal * uint32_t(0xdeadbeef);
87
0
}
88