michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_FONT_FEATURES_H michael@0: #define GFX_FONT_FEATURES_H michael@0: michael@0: #include "nsTHashtable.h" michael@0: #include "nsTArray.h" michael@0: #include "nsString.h" michael@0: michael@0: // An OpenType feature tag and value pair michael@0: struct gfxFontFeature { michael@0: uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm michael@0: uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters michael@0: // to features that select among multiple alternatives michael@0: }; michael@0: michael@0: inline bool michael@0: operator<(const gfxFontFeature& a, const gfxFontFeature& b) michael@0: { michael@0: return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue)); michael@0: } michael@0: michael@0: inline bool michael@0: operator==(const gfxFontFeature& a, const gfxFontFeature& b) michael@0: { michael@0: return (a.mTag == b.mTag) && (a.mValue == b.mValue); michael@0: } michael@0: michael@0: struct gfxAlternateValue { michael@0: uint32_t alternate; // constants in gfxFontConstants.h michael@0: nsString value; // string value to be looked up michael@0: }; michael@0: michael@0: inline bool michael@0: operator<(const gfxAlternateValue& a, const gfxAlternateValue& b) michael@0: { michael@0: return (a.alternate < b.alternate) || michael@0: ((a.alternate == b.alternate) && (a.value < b.value)); michael@0: } michael@0: michael@0: inline bool michael@0: operator==(const gfxAlternateValue& a, const gfxAlternateValue& b) michael@0: { michael@0: return (a.alternate == b.alternate) && (a.value == b.value); michael@0: } michael@0: michael@0: class gfxFontFeatureValueSet MOZ_FINAL { michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(gfxFontFeatureValueSet) michael@0: michael@0: gfxFontFeatureValueSet(); michael@0: michael@0: struct ValueList { michael@0: ValueList(const nsAString& aName, const nsTArray& aSelectors) michael@0: : name(aName), featureSelectors(aSelectors) michael@0: {} michael@0: nsString name; michael@0: nsTArray featureSelectors; michael@0: }; michael@0: michael@0: struct FeatureValues { michael@0: uint32_t alternate; michael@0: nsTArray valuelist; michael@0: }; michael@0: michael@0: // returns true if found, false otherwise michael@0: bool michael@0: GetFontFeatureValuesFor(const nsAString& aFamily, michael@0: uint32_t aVariantProperty, michael@0: const nsAString& aName, michael@0: nsTArray& aValues); michael@0: void michael@0: AddFontFeatureValues(const nsAString& aFamily, michael@0: const nsTArray& aValues); michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~gfxFontFeatureValueSet() {} michael@0: michael@0: struct FeatureValueHashKey { michael@0: nsString mFamily; michael@0: uint32_t mPropVal; michael@0: nsString mName; michael@0: michael@0: FeatureValueHashKey() michael@0: : mPropVal(0) michael@0: { } michael@0: FeatureValueHashKey(const nsAString& aFamily, michael@0: uint32_t aPropVal, michael@0: const nsAString& aName) michael@0: : mFamily(aFamily), mPropVal(aPropVal), mName(aName) michael@0: { } michael@0: FeatureValueHashKey(const FeatureValueHashKey& aKey) michael@0: : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName) michael@0: { } michael@0: }; michael@0: michael@0: class FeatureValueHashEntry : public PLDHashEntryHdr { michael@0: public: michael@0: typedef const FeatureValueHashKey &KeyType; michael@0: typedef const FeatureValueHashKey *KeyTypePointer; michael@0: michael@0: FeatureValueHashEntry(KeyTypePointer aKey) { } michael@0: FeatureValueHashEntry(const FeatureValueHashEntry& toCopy) michael@0: { michael@0: NS_ERROR("Should not be called"); michael@0: } michael@0: ~FeatureValueHashEntry() { } michael@0: michael@0: bool KeyEquals(const KeyTypePointer aKey) const; michael@0: static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } michael@0: static PLDHashNumber HashKey(const KeyTypePointer aKey); michael@0: enum { ALLOW_MEMMOVE = true }; michael@0: michael@0: FeatureValueHashKey mKey; michael@0: nsTArray mValues; michael@0: }; michael@0: michael@0: nsTHashtable mFontFeatureValues; michael@0: }; michael@0: michael@0: #endif