Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/thebes/gfxFontFeatures.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef GFX_FONT_FEATURES_H
8
#define GFX_FONT_FEATURES_H
9
10
#include "nsTHashtable.h"
11
#include "nsTArray.h"
12
#include "nsString.h"
13
14
// An OpenType feature tag and value pair
15
struct gfxFontFeature {
16
    uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
17
    uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters
18
                     // to features that select among multiple alternatives
19
};
20
21
inline bool
22
operator<(const gfxFontFeature& a, const gfxFontFeature& b)
23
{
24
    return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
25
}
26
27
inline bool
28
operator==(const gfxFontFeature& a, const gfxFontFeature& b)
29
{
30
    return (a.mTag == b.mTag) && (a.mValue == b.mValue);
31
}
32
33
struct gfxAlternateValue {
34
    uint32_t           alternate;  // constants in gfxFontConstants.h
35
    nsString           value;      // string value to be looked up
36
};
37
38
inline bool
39
operator<(const gfxAlternateValue& a, const gfxAlternateValue& b)
40
{
41
    return (a.alternate < b.alternate) ||
42
        ((a.alternate == b.alternate) && (a.value < b.value));
43
}
44
45
inline bool
46
operator==(const gfxAlternateValue& a, const gfxAlternateValue& b)
47
{
48
    return (a.alternate == b.alternate) && (a.value == b.value);
49
}
50
51
class gfxFontFeatureValueSet final {
52
public:
53
    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet)
54
55
    gfxFontFeatureValueSet();
56
57
    struct ValueList {
58
        ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
59
          : name(aName), featureSelectors(aSelectors)
60
        {}
61
        nsString             name;
62
        nsTArray<uint32_t>   featureSelectors;
63
    };
64
65
    struct FeatureValues {
66
        uint32_t             alternate;
67
        nsTArray<ValueList>  valuelist;
68
    };
69
70
    // returns true if found, false otherwise
71
    bool
72
    GetFontFeatureValuesFor(const nsACString& aFamily,
73
                            uint32_t aVariantProperty,
74
                            const nsAString& aName,
75
                            nsTArray<uint32_t>& aValues);
76
    void
77
    AddFontFeatureValues(const nsACString& aFamily,
78
                const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues);
79
80
    // Appends a new hash entry with given key values and returns a pointer to
81
    // mValues array to fill. This should be filled first.
82
    nsTArray<uint32_t>*
83
    AppendFeatureValueHashEntry(const nsACString& aFamily,
84
                                const nsAString& aName,
85
                                uint32_t aAlternate);
86
87
private:
88
    // Private destructor, to discourage deletion outside of Release():
89
    ~gfxFontFeatureValueSet() {}
90
91
    struct FeatureValueHashKey {
92
        nsCString mFamily;
93
        uint32_t mPropVal;
94
        nsString mName;
95
96
        FeatureValueHashKey()
97
            : mPropVal(0)
98
0
        { }
99
        FeatureValueHashKey(const nsACString& aFamily,
100
                            uint32_t aPropVal,
101
                            const nsAString& aName)
102
            : mFamily(aFamily), mPropVal(aPropVal), mName(aName)
103
0
        { }
104
        FeatureValueHashKey(const FeatureValueHashKey& aKey)
105
            : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName)
106
        { }
107
    };
108
109
    class FeatureValueHashEntry : public PLDHashEntryHdr {
110
    public:
111
        typedef const FeatureValueHashKey &KeyType;
112
        typedef const FeatureValueHashKey *KeyTypePointer;
113
114
0
        explicit FeatureValueHashEntry(KeyTypePointer aKey) { }
115
        FeatureValueHashEntry(FeatureValueHashEntry&& other)
116
            : PLDHashEntryHdr(std::move(other))
117
            , mKey(std::move(other.mKey))
118
            , mValues(std::move(other.mValues))
119
        {
120
            NS_ERROR("Should not be called");
121
        }
122
0
        ~FeatureValueHashEntry() { }
123
124
        bool KeyEquals(const KeyTypePointer aKey) const;
125
0
        static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
126
        static PLDHashNumber HashKey(const KeyTypePointer aKey);
127
        enum { ALLOW_MEMMOVE = true };
128
129
        FeatureValueHashKey mKey;
130
        nsTArray<uint32_t>  mValues;
131
    };
132
133
    nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
134
  };
135
136
#endif