Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / gfx / thebes / gfxFontFeatures.h
blob24ece02d36a8a39d0fb2041f472ac7cae067f1a1
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef GFX_FONT_FEATURES_H
8 #define GFX_FONT_FEATURES_H
10 #include "nsAtom.h"
11 #include "nsTHashtable.h"
12 #include "nsTArray.h"
13 #include "nsString.h"
15 // An OpenType feature tag and value pair
16 struct gfxFontFeature {
17 uint32_t
18 mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
19 uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters
20 // to features that select among multiple alternatives
23 inline bool operator<(const gfxFontFeature& a, const gfxFontFeature& b) {
24 return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
27 inline bool operator==(const gfxFontFeature& a, const gfxFontFeature& b) {
28 return (a.mTag == b.mTag) && (a.mValue == b.mValue);
31 class nsAtom;
33 class gfxFontFeatureValueSet final {
34 public:
35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet)
37 gfxFontFeatureValueSet();
39 struct ValueList {
40 ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
41 : name(aName), featureSelectors(aSelectors.Clone()) {}
42 nsString name;
43 nsTArray<uint32_t> featureSelectors;
46 struct FeatureValues {
47 uint32_t alternate;
48 nsTArray<ValueList> valuelist;
51 mozilla::Span<const uint32_t> GetFontFeatureValuesFor(
52 const nsACString& aFamily, uint32_t aVariantProperty,
53 nsAtom* aName) const;
55 // Appends a new hash entry with given key values and returns a pointer to
56 // mValues array to fill. This should be filled first.
57 nsTArray<uint32_t>* AppendFeatureValueHashEntry(const nsACString& aFamily,
58 nsAtom* aName,
59 uint32_t aAlternate);
61 private:
62 // Private destructor, to discourage deletion outside of Release():
63 ~gfxFontFeatureValueSet() = default;
65 struct FeatureValueHashKey {
66 nsCString mFamily;
67 uint32_t mPropVal;
68 RefPtr<nsAtom> mName;
70 FeatureValueHashKey() : mPropVal(0) {}
71 FeatureValueHashKey(const nsACString& aFamily, uint32_t aPropVal,
72 nsAtom* aName)
73 : mFamily(aFamily), mPropVal(aPropVal), mName(aName) {}
74 FeatureValueHashKey(const FeatureValueHashKey& aKey) = default;
77 class FeatureValueHashEntry : public PLDHashEntryHdr {
78 public:
79 typedef const FeatureValueHashKey& KeyType;
80 typedef const FeatureValueHashKey* KeyTypePointer;
82 explicit FeatureValueHashEntry(KeyTypePointer aKey) {}
83 FeatureValueHashEntry(FeatureValueHashEntry&& other)
84 : PLDHashEntryHdr(std::move(other)),
85 mKey(std::move(other.mKey)),
86 mValues(std::move(other.mValues)) {
87 NS_ERROR("Should not be called");
89 ~FeatureValueHashEntry() = default;
91 bool KeyEquals(const KeyTypePointer aKey) const;
92 static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
93 static PLDHashNumber HashKey(const KeyTypePointer aKey);
94 enum { ALLOW_MEMMOVE = true };
96 FeatureValueHashKey mKey;
97 nsTArray<uint32_t> mValues;
100 nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
103 #endif