gfxFontFeatures.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef GFX_FONT_FEATURES_H
  6. #define GFX_FONT_FEATURES_H
  7. #include "nsTHashtable.h"
  8. #include "nsTArray.h"
  9. #include "nsString.h"
  10. // An OpenType feature tag and value pair
  11. struct gfxFontFeature {
  12. uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
  13. uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters
  14. // to features that select among multiple alternatives
  15. };
  16. inline bool
  17. operator<(const gfxFontFeature& a, const gfxFontFeature& b)
  18. {
  19. return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
  20. }
  21. inline bool
  22. operator==(const gfxFontFeature& a, const gfxFontFeature& b)
  23. {
  24. return (a.mTag == b.mTag) && (a.mValue == b.mValue);
  25. }
  26. struct gfxAlternateValue {
  27. uint32_t alternate; // constants in gfxFontConstants.h
  28. nsString value; // string value to be looked up
  29. };
  30. inline bool
  31. operator<(const gfxAlternateValue& a, const gfxAlternateValue& b)
  32. {
  33. return (a.alternate < b.alternate) ||
  34. ((a.alternate == b.alternate) && (a.value < b.value));
  35. }
  36. inline bool
  37. operator==(const gfxAlternateValue& a, const gfxAlternateValue& b)
  38. {
  39. return (a.alternate == b.alternate) && (a.value == b.value);
  40. }
  41. class gfxFontFeatureValueSet final {
  42. public:
  43. NS_INLINE_DECL_REFCOUNTING(gfxFontFeatureValueSet)
  44. gfxFontFeatureValueSet();
  45. struct ValueList {
  46. ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
  47. : name(aName), featureSelectors(aSelectors)
  48. {}
  49. nsString name;
  50. nsTArray<uint32_t> featureSelectors;
  51. };
  52. struct FeatureValues {
  53. uint32_t alternate;
  54. nsTArray<ValueList> valuelist;
  55. };
  56. // returns true if found, false otherwise
  57. bool
  58. GetFontFeatureValuesFor(const nsAString& aFamily,
  59. uint32_t aVariantProperty,
  60. const nsAString& aName,
  61. nsTArray<uint32_t>& aValues);
  62. void
  63. AddFontFeatureValues(const nsAString& aFamily,
  64. const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues);
  65. private:
  66. // Private destructor, to discourage deletion outside of Release():
  67. ~gfxFontFeatureValueSet() {}
  68. struct FeatureValueHashKey {
  69. nsString mFamily;
  70. uint32_t mPropVal;
  71. nsString mName;
  72. FeatureValueHashKey()
  73. : mPropVal(0)
  74. { }
  75. FeatureValueHashKey(const nsAString& aFamily,
  76. uint32_t aPropVal,
  77. const nsAString& aName)
  78. : mFamily(aFamily), mPropVal(aPropVal), mName(aName)
  79. { }
  80. FeatureValueHashKey(const FeatureValueHashKey& aKey)
  81. : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName)
  82. { }
  83. };
  84. class FeatureValueHashEntry : public PLDHashEntryHdr {
  85. public:
  86. typedef const FeatureValueHashKey &KeyType;
  87. typedef const FeatureValueHashKey *KeyTypePointer;
  88. explicit FeatureValueHashEntry(KeyTypePointer aKey) { }
  89. FeatureValueHashEntry(const FeatureValueHashEntry& toCopy)
  90. {
  91. NS_ERROR("Should not be called");
  92. }
  93. ~FeatureValueHashEntry() { }
  94. bool KeyEquals(const KeyTypePointer aKey) const;
  95. static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
  96. static PLDHashNumber HashKey(const KeyTypePointer aKey);
  97. enum { ALLOW_MEMMOVE = true };
  98. FeatureValueHashKey mKey;
  99. nsTArray<uint32_t> mValues;
  100. };
  101. nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
  102. };
  103. #endif