2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-04-26 10:22:24 +04:00
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GFX_FONT_FEATURES_H
|
|
|
|
#define GFX_FONT_FEATURES_H
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2012-04-26 10:22:24 +04:00
|
|
|
// An OpenType feature tag and value pair
|
|
|
|
struct gfxFontFeature {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
|
|
|
|
uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters
|
2012-04-26 10:22:24 +04:00
|
|
|
// to features that select among multiple alternatives
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator<(const gfxFontFeature& a, const gfxFontFeature& b) {
|
|
|
|
return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator==(const gfxFontFeature& a, const gfxFontFeature& b) {
|
|
|
|
return (a.mTag == b.mTag) && (a.mValue == b.mValue);
|
|
|
|
}
|
|
|
|
|
2019-08-22 03:24:44 +03:00
|
|
|
class nsAtom;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class gfxFontFeatureValueSet final {
|
2013-05-20 06:59:20 +04:00
|
|
|
public:
|
2017-08-24 04:05:53 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
gfxFontFeatureValueSet();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
struct ValueList {
|
|
|
|
ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
|
2020-05-05 13:56:14 +03:00
|
|
|
: name(aName), featureSelectors(aSelectors.Clone()) {}
|
2013-05-20 06:59:20 +04:00
|
|
|
nsString name;
|
|
|
|
nsTArray<uint32_t> featureSelectors;
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
struct FeatureValues {
|
|
|
|
uint32_t alternate;
|
|
|
|
nsTArray<ValueList> valuelist;
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-08-22 03:24:47 +03:00
|
|
|
mozilla::Span<const uint32_t> GetFontFeatureValuesFor(
|
|
|
|
const nsACString& aFamily, uint32_t aVariantProperty,
|
|
|
|
nsAtom* aName) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-24 04:05:53 +03:00
|
|
|
// Appends a new hash entry with given key values and returns a pointer to
|
|
|
|
// mValues array to fill. This should be filled first.
|
2018-09-12 22:34:57 +03:00
|
|
|
nsTArray<uint32_t>* AppendFeatureValueHashEntry(const nsACString& aFamily,
|
2019-08-22 03:24:44 +03:00
|
|
|
nsAtom* aName,
|
2017-08-24 04:05:53 +03:00
|
|
|
uint32_t aAlternate);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2020-03-04 18:39:20 +03:00
|
|
|
~gfxFontFeatureValueSet() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
struct FeatureValueHashKey {
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mFamily;
|
2013-05-20 06:59:20 +04:00
|
|
|
uint32_t mPropVal;
|
2019-08-22 03:24:44 +03:00
|
|
|
RefPtr<nsAtom> mName;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
FeatureValueHashKey() : mPropVal(0) {}
|
2018-09-12 22:34:57 +03:00
|
|
|
FeatureValueHashKey(const nsACString& aFamily, uint32_t aPropVal,
|
2019-08-22 03:24:44 +03:00
|
|
|
nsAtom* aName)
|
2013-05-20 06:59:20 +04:00
|
|
|
: mFamily(aFamily), mPropVal(aPropVal), mName(aName) {}
|
2020-03-04 18:39:20 +03:00
|
|
|
FeatureValueHashKey(const FeatureValueHashKey& aKey) = default;
|
2013-05-20 06:59:20 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
class FeatureValueHashEntry : public PLDHashEntryHdr {
|
|
|
|
public:
|
|
|
|
typedef const FeatureValueHashKey& KeyType;
|
|
|
|
typedef const FeatureValueHashKey* KeyTypePointer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 01:58:40 +04:00
|
|
|
explicit FeatureValueHashEntry(KeyTypePointer aKey) {}
|
Bug 1415980 - make hash keys movable and not copyable; r=erahm
Everything that goes in a PLDHashtable (and its derivatives, like
nsTHashtable) needs to inherit from PLDHashEntryHdr. But through a lack
of enforcement, copy constructors for these derived classes didn't
explicitly invoke the copy constructor for PLDHashEntryHdr (and the
compiler didn't invoke the copy constructor for us). Instead,
PLDHashTable explicitly copied around the bits that the copy constructor
would have.
The current setup has two problems:
1) Derived classes should be using move construction, not copy
construction, since anything that's shuffling hash table keys/entries
around will be using move construction.
2) Derived classes should take responsibility for transferring bits of
superclass state around, and not rely on something else to handle that.
The second point is not a huge problem for PLDHashTable (PLDHashTable
only has to copy PLDHashEntryHdr's bits in a single place), but future
hash table implementations that might move entries around more
aggressively would have to insert compensation code all over the
place. Additionally, if moving entries is implemented via memcpy (which
is quite common), PLDHashTable copying around bits *again* is
inefficient.
Let's fix all these problems in one go, by:
1) Explicitly declaring the set of constructors that PLDHashEntryHdr
implements (and does not implement). In particular, the copy
constructor is deleted, so any derived classes that attempt to make
themselves copyable will be detected at compile time: the compiler
will complain that the superclass type is not copyable.
This change on its own will result in many compiler errors, so...
2) Change any derived classes to implement move constructors instead of
copy constructors. Note that some of these move constructors are,
strictly speaking, unnecessary, since the relevant classes are moved
via memcpy in nsTHashtable and its derivatives.
2018-09-20 18:20:36 +03:00
|
|
|
FeatureValueHashEntry(FeatureValueHashEntry&& other)
|
|
|
|
: PLDHashEntryHdr(std::move(other)),
|
|
|
|
mKey(std::move(other.mKey)),
|
|
|
|
mValues(std::move(other.mValues)) {
|
2013-05-20 06:59:20 +04:00
|
|
|
NS_ERROR("Should not be called");
|
|
|
|
}
|
2020-03-04 18:39:20 +03:00
|
|
|
~FeatureValueHashEntry() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey);
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
FeatureValueHashKey mKey;
|
|
|
|
nsTArray<uint32_t> mValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2012-04-26 10:22:24 +04:00
|
|
|
#endif
|