1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxFontFeatures.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 + 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef GFX_FONT_FEATURES_H 1.11 +#define GFX_FONT_FEATURES_H 1.12 + 1.13 +#include "nsTHashtable.h" 1.14 +#include "nsTArray.h" 1.15 +#include "nsString.h" 1.16 + 1.17 +// An OpenType feature tag and value pair 1.18 +struct gfxFontFeature { 1.19 + uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm 1.20 + uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters 1.21 + // to features that select among multiple alternatives 1.22 +}; 1.23 + 1.24 +inline bool 1.25 +operator<(const gfxFontFeature& a, const gfxFontFeature& b) 1.26 +{ 1.27 + return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue)); 1.28 +} 1.29 + 1.30 +inline bool 1.31 +operator==(const gfxFontFeature& a, const gfxFontFeature& b) 1.32 +{ 1.33 + return (a.mTag == b.mTag) && (a.mValue == b.mValue); 1.34 +} 1.35 + 1.36 +struct gfxAlternateValue { 1.37 + uint32_t alternate; // constants in gfxFontConstants.h 1.38 + nsString value; // string value to be looked up 1.39 +}; 1.40 + 1.41 +inline bool 1.42 +operator<(const gfxAlternateValue& a, const gfxAlternateValue& b) 1.43 +{ 1.44 + return (a.alternate < b.alternate) || 1.45 + ((a.alternate == b.alternate) && (a.value < b.value)); 1.46 +} 1.47 + 1.48 +inline bool 1.49 +operator==(const gfxAlternateValue& a, const gfxAlternateValue& b) 1.50 +{ 1.51 + return (a.alternate == b.alternate) && (a.value == b.value); 1.52 +} 1.53 + 1.54 +class gfxFontFeatureValueSet MOZ_FINAL { 1.55 +public: 1.56 + NS_INLINE_DECL_REFCOUNTING(gfxFontFeatureValueSet) 1.57 + 1.58 + gfxFontFeatureValueSet(); 1.59 + 1.60 + struct ValueList { 1.61 + ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors) 1.62 + : name(aName), featureSelectors(aSelectors) 1.63 + {} 1.64 + nsString name; 1.65 + nsTArray<uint32_t> featureSelectors; 1.66 + }; 1.67 + 1.68 + struct FeatureValues { 1.69 + uint32_t alternate; 1.70 + nsTArray<ValueList> valuelist; 1.71 + }; 1.72 + 1.73 + // returns true if found, false otherwise 1.74 + bool 1.75 + GetFontFeatureValuesFor(const nsAString& aFamily, 1.76 + uint32_t aVariantProperty, 1.77 + const nsAString& aName, 1.78 + nsTArray<uint32_t>& aValues); 1.79 + void 1.80 + AddFontFeatureValues(const nsAString& aFamily, 1.81 + const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues); 1.82 + 1.83 +private: 1.84 + // Private destructor, to discourage deletion outside of Release(): 1.85 + ~gfxFontFeatureValueSet() {} 1.86 + 1.87 + struct FeatureValueHashKey { 1.88 + nsString mFamily; 1.89 + uint32_t mPropVal; 1.90 + nsString mName; 1.91 + 1.92 + FeatureValueHashKey() 1.93 + : mPropVal(0) 1.94 + { } 1.95 + FeatureValueHashKey(const nsAString& aFamily, 1.96 + uint32_t aPropVal, 1.97 + const nsAString& aName) 1.98 + : mFamily(aFamily), mPropVal(aPropVal), mName(aName) 1.99 + { } 1.100 + FeatureValueHashKey(const FeatureValueHashKey& aKey) 1.101 + : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName) 1.102 + { } 1.103 + }; 1.104 + 1.105 + class FeatureValueHashEntry : public PLDHashEntryHdr { 1.106 + public: 1.107 + typedef const FeatureValueHashKey &KeyType; 1.108 + typedef const FeatureValueHashKey *KeyTypePointer; 1.109 + 1.110 + FeatureValueHashEntry(KeyTypePointer aKey) { } 1.111 + FeatureValueHashEntry(const FeatureValueHashEntry& toCopy) 1.112 + { 1.113 + NS_ERROR("Should not be called"); 1.114 + } 1.115 + ~FeatureValueHashEntry() { } 1.116 + 1.117 + bool KeyEquals(const KeyTypePointer aKey) const; 1.118 + static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } 1.119 + static PLDHashNumber HashKey(const KeyTypePointer aKey); 1.120 + enum { ALLOW_MEMMOVE = true }; 1.121 + 1.122 + FeatureValueHashKey mKey; 1.123 + nsTArray<uint32_t> mValues; 1.124 + }; 1.125 + 1.126 + nsTHashtable<FeatureValueHashEntry> mFontFeatureValues; 1.127 + }; 1.128 + 1.129 +#endif