tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gfxFontFeatures.h (2852B)


      1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      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/. */
      6 
      7 #ifndef GFX_FONT_FEATURES_H
      8 #define GFX_FONT_FEATURES_H
      9 
     10 #include "nsAtom.h"
     11 #include "nsTHashtable.h"
     12 #include "nsTArray.h"
     13 #include "nsString.h"
     14 #include "mozilla/gfx/FontFeature.h"
     15 
     16 using gfxFontFeature = mozilla::gfx::FontFeature;
     17 
     18 class gfxFontFeatureValueSet final {
     19 public:
     20  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet)
     21 
     22  gfxFontFeatureValueSet();
     23 
     24  struct ValueList {
     25    ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
     26        : name(aName), featureSelectors(aSelectors.Clone()) {}
     27    nsString name;
     28    nsTArray<uint32_t> featureSelectors;
     29  };
     30 
     31  struct FeatureValues {
     32    uint32_t alternate;
     33    nsTArray<ValueList> valuelist;
     34  };
     35 
     36  mozilla::Span<const uint32_t> GetFontFeatureValuesFor(
     37      const nsACString& aFamily, uint32_t aVariantProperty,
     38      nsAtom* aName) const;
     39 
     40  // Appends a new hash entry with given key values and returns a pointer to
     41  // mValues array to fill. This should be filled first.
     42  nsTArray<uint32_t>* AppendFeatureValueHashEntry(const nsACString& aFamily,
     43                                                  nsAtom* aName,
     44                                                  uint32_t aAlternate);
     45 
     46 private:
     47  // Private destructor, to discourage deletion outside of Release():
     48  ~gfxFontFeatureValueSet() = default;
     49 
     50  struct FeatureValueHashKey {
     51    nsCString mFamily;
     52    uint32_t mPropVal;
     53    RefPtr<nsAtom> mName;
     54 
     55    FeatureValueHashKey() : mPropVal(0) {}
     56    FeatureValueHashKey(const nsACString& aFamily, uint32_t aPropVal,
     57                        nsAtom* aName)
     58        : mFamily(aFamily), mPropVal(aPropVal), mName(aName) {}
     59    FeatureValueHashKey(const FeatureValueHashKey& aKey) = default;
     60  };
     61 
     62  class FeatureValueHashEntry : public PLDHashEntryHdr {
     63   public:
     64    typedef const FeatureValueHashKey& KeyType;
     65    typedef const FeatureValueHashKey* KeyTypePointer;
     66 
     67    explicit FeatureValueHashEntry(KeyTypePointer aKey) {}
     68    FeatureValueHashEntry(FeatureValueHashEntry&& other)
     69        : PLDHashEntryHdr(std::move(other)),
     70          mKey(std::move(other.mKey)),
     71          mValues(std::move(other.mValues)) {
     72      NS_ERROR("Should not be called");
     73    }
     74    ~FeatureValueHashEntry() = default;
     75 
     76    bool KeyEquals(const KeyTypePointer aKey) const;
     77    static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
     78    static PLDHashNumber HashKey(const KeyTypePointer aKey);
     79    enum { ALLOW_MEMMOVE = true };
     80 
     81    FeatureValueHashKey mKey;
     82    nsTArray<uint32_t> mValues;
     83  };
     84 
     85  nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
     86 };
     87 
     88 #endif