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
11 #include "nsTHashtable.h"
15 // An OpenType feature tag and value pair
16 struct gfxFontFeature
{
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
);
33 class gfxFontFeatureValueSet final
{
35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet
)
37 gfxFontFeatureValueSet();
40 ValueList(const nsAString
& aName
, const nsTArray
<uint32_t>& aSelectors
)
41 : name(aName
), featureSelectors(aSelectors
.Clone()) {}
43 nsTArray
<uint32_t> featureSelectors
;
46 struct FeatureValues
{
48 nsTArray
<ValueList
> valuelist
;
51 mozilla::Span
<const uint32_t> GetFontFeatureValuesFor(
52 const nsACString
& aFamily
, uint32_t aVariantProperty
,
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
,
62 // Private destructor, to discourage deletion outside of Release():
63 ~gfxFontFeatureValueSet() = default;
65 struct FeatureValueHashKey
{
70 FeatureValueHashKey() : mPropVal(0) {}
71 FeatureValueHashKey(const nsACString
& aFamily
, uint32_t aPropVal
,
73 : mFamily(aFamily
), mPropVal(aPropVal
), mName(aName
) {}
74 FeatureValueHashKey(const FeatureValueHashKey
& aKey
) = default;
77 class FeatureValueHashEntry
: public PLDHashEntryHdr
{
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
;