gfx/thebes/gfxFontFeatures.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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/. */
     7 #ifndef GFX_FONT_FEATURES_H
     8 #define GFX_FONT_FEATURES_H
    10 #include "nsTHashtable.h"
    11 #include "nsTArray.h"
    12 #include "nsString.h"
    14 // An OpenType feature tag and value pair
    15 struct gfxFontFeature {
    16     uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
    17     uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters
    18                      // to features that select among multiple alternatives
    19 };
    21 inline bool
    22 operator<(const gfxFontFeature& a, const gfxFontFeature& b)
    23 {
    24     return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
    25 }
    27 inline bool
    28 operator==(const gfxFontFeature& a, const gfxFontFeature& b)
    29 {
    30     return (a.mTag == b.mTag) && (a.mValue == b.mValue);
    31 }
    33 struct gfxAlternateValue {
    34     uint32_t           alternate;  // constants in gfxFontConstants.h
    35     nsString           value;      // string value to be looked up
    36 };
    38 inline bool
    39 operator<(const gfxAlternateValue& a, const gfxAlternateValue& b)
    40 {
    41     return (a.alternate < b.alternate) ||
    42         ((a.alternate == b.alternate) && (a.value < b.value));
    43 }
    45 inline bool
    46 operator==(const gfxAlternateValue& a, const gfxAlternateValue& b)
    47 {
    48     return (a.alternate == b.alternate) && (a.value == b.value);
    49 }
    51 class gfxFontFeatureValueSet MOZ_FINAL {
    52 public:
    53     NS_INLINE_DECL_REFCOUNTING(gfxFontFeatureValueSet)
    55     gfxFontFeatureValueSet();
    57     struct ValueList {
    58         ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
    59           : name(aName), featureSelectors(aSelectors)
    60         {}
    61         nsString             name;
    62         nsTArray<uint32_t>   featureSelectors;
    63     };
    65     struct FeatureValues {
    66         uint32_t             alternate;
    67         nsTArray<ValueList>  valuelist;
    68     };
    70     // returns true if found, false otherwise
    71     bool
    72     GetFontFeatureValuesFor(const nsAString& aFamily,
    73                             uint32_t aVariantProperty,
    74                             const nsAString& aName,
    75                             nsTArray<uint32_t>& aValues);
    76     void
    77     AddFontFeatureValues(const nsAString& aFamily,
    78                 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues);
    80 private:
    81     // Private destructor, to discourage deletion outside of Release():
    82     ~gfxFontFeatureValueSet() {}
    84     struct FeatureValueHashKey {
    85         nsString mFamily;
    86         uint32_t mPropVal;
    87         nsString mName;
    89         FeatureValueHashKey()
    90             : mPropVal(0)
    91         { }
    92         FeatureValueHashKey(const nsAString& aFamily,
    93                             uint32_t aPropVal,
    94                             const nsAString& aName)
    95             : mFamily(aFamily), mPropVal(aPropVal), mName(aName)
    96         { }
    97         FeatureValueHashKey(const FeatureValueHashKey& aKey)
    98             : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName)
    99         { }
   100     };
   102     class FeatureValueHashEntry : public PLDHashEntryHdr {
   103     public:
   104         typedef const FeatureValueHashKey &KeyType;
   105         typedef const FeatureValueHashKey *KeyTypePointer;
   107         FeatureValueHashEntry(KeyTypePointer aKey) { }
   108         FeatureValueHashEntry(const FeatureValueHashEntry& toCopy)
   109         {
   110             NS_ERROR("Should not be called");
   111         }
   112         ~FeatureValueHashEntry() { }
   114         bool KeyEquals(const KeyTypePointer aKey) const;
   115         static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
   116         static PLDHashNumber HashKey(const KeyTypePointer aKey);
   117         enum { ALLOW_MEMMOVE = true };
   119         FeatureValueHashKey mKey;
   120         nsTArray<uint32_t>  mValues;
   121     };
   123     nsTHashtable<FeatureValueHashEntry> mFontFeatureValues;
   124   };
   126 #endif

mercurial