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 "nsTHashtable.h"
14 // An OpenType feature tag and value pair
15 struct gfxFontFeature
{
17 mTag
; // see http://www.microsoft.com/typography/otspec/featuretags.htm
18 uint32_t mValue
; // 0 = off, 1 = on, larger values may be used as parameters
19 // to features that select among multiple alternatives
22 inline bool operator<(const gfxFontFeature
& a
, const gfxFontFeature
& b
) {
23 return (a
.mTag
< b
.mTag
) || ((a
.mTag
== b
.mTag
) && (a
.mValue
< b
.mValue
));
26 inline bool operator==(const gfxFontFeature
& a
, const gfxFontFeature
& b
) {
27 return (a
.mTag
== b
.mTag
) && (a
.mValue
== b
.mValue
);
30 struct gfxAlternateValue
{
31 uint32_t alternate
; // constants in gfxFontConstants.h
32 nsString value
; // string value to be looked up
35 inline bool operator<(const gfxAlternateValue
& a
, const gfxAlternateValue
& b
) {
36 return (a
.alternate
< b
.alternate
) ||
37 ((a
.alternate
== b
.alternate
) && (a
.value
< b
.value
));
40 inline bool operator==(const gfxAlternateValue
& a
, const gfxAlternateValue
& b
) {
41 return (a
.alternate
== b
.alternate
) && (a
.value
== b
.value
);
44 class gfxFontFeatureValueSet final
{
46 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet
)
48 gfxFontFeatureValueSet();
51 ValueList(const nsAString
& aName
, const nsTArray
<uint32_t>& aSelectors
)
52 : name(aName
), featureSelectors(aSelectors
) {}
54 nsTArray
<uint32_t> featureSelectors
;
57 struct FeatureValues
{
59 nsTArray
<ValueList
> valuelist
;
62 // returns true if found, false otherwise
63 bool GetFontFeatureValuesFor(const nsACString
& aFamily
,
64 uint32_t aVariantProperty
,
65 const nsAString
& aName
,
66 nsTArray
<uint32_t>& aValues
);
67 void AddFontFeatureValues(
68 const nsACString
& aFamily
,
69 const nsTArray
<gfxFontFeatureValueSet::FeatureValues
>& aValues
);
71 // Appends a new hash entry with given key values and returns a pointer to
72 // mValues array to fill. This should be filled first.
73 nsTArray
<uint32_t>* AppendFeatureValueHashEntry(const nsACString
& aFamily
,
74 const nsAString
& aName
,
78 // Private destructor, to discourage deletion outside of Release():
79 ~gfxFontFeatureValueSet() {}
81 struct FeatureValueHashKey
{
86 FeatureValueHashKey() : mPropVal(0) {}
87 FeatureValueHashKey(const nsACString
& aFamily
, uint32_t aPropVal
,
88 const nsAString
& aName
)
89 : mFamily(aFamily
), mPropVal(aPropVal
), mName(aName
) {}
90 FeatureValueHashKey(const FeatureValueHashKey
& aKey
)
91 : mFamily(aKey
.mFamily
), mPropVal(aKey
.mPropVal
), mName(aKey
.mName
) {}
94 class FeatureValueHashEntry
: public PLDHashEntryHdr
{
96 typedef const FeatureValueHashKey
& KeyType
;
97 typedef const FeatureValueHashKey
* KeyTypePointer
;
99 explicit FeatureValueHashEntry(KeyTypePointer aKey
) {}
100 FeatureValueHashEntry(FeatureValueHashEntry
&& other
)
101 : PLDHashEntryHdr(std::move(other
)),
102 mKey(std::move(other
.mKey
)),
103 mValues(std::move(other
.mValues
)) {
104 NS_ERROR("Should not be called");
106 ~FeatureValueHashEntry() {}
108 bool KeyEquals(const KeyTypePointer aKey
) const;
109 static KeyTypePointer
KeyToPointer(KeyType aKey
) { return &aKey
; }
110 static PLDHashNumber
HashKey(const KeyTypePointer aKey
);
111 enum { ALLOW_MEMMOVE
= true };
113 FeatureValueHashKey mKey
;
114 nsTArray
<uint32_t> mValues
;
117 nsTHashtable
<FeatureValueHashEntry
> mFontFeatureValues
;