gfx/graphite2/src/inc/FeatureMap.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.

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms of the
michael@0 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
michael@0 24 License, as published by the Free Software Foundation, either version 2
michael@0 25 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 #pragma once
michael@0 28 #include "inc/Main.h"
michael@0 29 #include "inc/FeatureVal.h"
michael@0 30
michael@0 31 namespace graphite2 {
michael@0 32
michael@0 33 // Forward declarations for implmentation types
michael@0 34 class FeatureMap;
michael@0 35 class Face;
michael@0 36
michael@0 37
michael@0 38 class FeatureSetting
michael@0 39 {
michael@0 40 public:
michael@0 41 FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {};
michael@0 42 uint16 label() const { return m_label; }
michael@0 43 int16 value() const { return m_value; }
michael@0 44
michael@0 45 CLASS_NEW_DELETE;
michael@0 46 private:
michael@0 47 FeatureSetting(const FeatureSetting & fs) : m_label(fs.m_label), m_value(fs.m_value) {};
michael@0 48
michael@0 49 uint16 m_label;
michael@0 50 int16 m_value;
michael@0 51 };
michael@0 52
michael@0 53 class FeatureRef
michael@0 54 {
michael@0 55 typedef uint32 chunk_t;
michael@0 56 static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8;
michael@0 57
michael@0 58 public:
michael@0 59 FeatureRef() : m_nameValues(0) {}
michael@0 60 FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val,
michael@0 61 uint32 name, uint16 uiName, uint16 flags,
michael@0 62 FeatureSetting *settings, uint16 num_set) throw();
michael@0 63 ~FeatureRef() throw();
michael@0 64
michael@0 65 bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h
michael@0 66 void maskFeature(Features & pDest) const {
michael@0 67 if (m_index < pDest.size()) //defensive
michael@0 68 pDest[m_index] |= m_mask;
michael@0 69 }
michael@0 70
michael@0 71 uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h
michael@0 72
michael@0 73 uint32 getId() const { return m_id; }
michael@0 74 uint16 getNameId() const { return m_nameid; }
michael@0 75 uint16 getNumSettings() const { return m_numSet; }
michael@0 76 uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); }
michael@0 77 int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); }
michael@0 78 uint32 maxVal() const { return m_max; }
michael@0 79 const Face* getFace() const { return m_pFace;}
michael@0 80 const FeatureMap* getFeatureMap() const;// { return m_pFace;}
michael@0 81
michael@0 82 CLASS_NEW_DELETE;
michael@0 83 private:
michael@0 84 FeatureRef(const FeatureRef & rhs);
michael@0 85
michael@0 86 const Face * m_pFace; //not NULL
michael@0 87 FeatureSetting * m_nameValues; // array of name table ids for feature values
michael@0 88 chunk_t m_mask, // bit mask to get the value from the vector
michael@0 89 m_max; // max value the value can take
michael@0 90 uint32 m_id; // feature identifier/name
michael@0 91 uint16 m_nameid, // Name table id for feature name
michael@0 92 m_flags, // feature flags (unused at the moment but read from the font)
michael@0 93 m_numSet; // number of values (number of entries in m_nameValues)
michael@0 94 byte m_bits, // how many bits to shift the value into place
michael@0 95 m_index; // index into the array to find the ulong to mask
michael@0 96
michael@0 97 private: //unimplemented
michael@0 98 FeatureRef& operator=(const FeatureRef&);
michael@0 99 };
michael@0 100
michael@0 101
michael@0 102 class NameAndFeatureRef
michael@0 103 {
michael@0 104 public:
michael@0 105 NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){}
michael@0 106 NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {}
michael@0 107
michael@0 108 bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name
michael@0 109 { return m_name<rhs.m_name; }
michael@0 110
michael@0 111 CLASS_NEW_DELETE
michael@0 112
michael@0 113 uint32 m_name;
michael@0 114 const FeatureRef* m_pFRef;
michael@0 115 };
michael@0 116
michael@0 117 class FeatureMap
michael@0 118 {
michael@0 119 public:
michael@0 120 FeatureMap() : m_numFeats(0), m_feats(NULL), m_pNamedFeats(NULL),
michael@0 121 m_defaultFeatures(NULL) {}
michael@0 122 ~FeatureMap() { delete [] m_feats; delete[] m_pNamedFeats; delete m_defaultFeatures; }
michael@0 123
michael@0 124 bool readFeats(const Face & face);
michael@0 125 const FeatureRef *findFeatureRef(uint32 name) const;
michael@0 126 FeatureRef *feature(uint16 index) const { return m_feats + index; }
michael@0 127 //GrFeatureRef *featureRef(byte index) { return index < m_numFeats ? m_feats + index : NULL; }
michael@0 128 const FeatureRef *featureRef(byte index) const { return index < m_numFeats ? m_feats + index : NULL; }
michael@0 129 FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
michael@0 130 uint16 numFeats() const { return m_numFeats; };
michael@0 131 CLASS_NEW_DELETE
michael@0 132 private:
michael@0 133 friend class SillMap;
michael@0 134 uint16 m_numFeats;
michael@0 135
michael@0 136 FeatureRef *m_feats;
michael@0 137 NameAndFeatureRef* m_pNamedFeats; //owned
michael@0 138 FeatureVal* m_defaultFeatures; //owned
michael@0 139
michael@0 140 private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures
michael@0 141 FeatureMap(const FeatureMap&);
michael@0 142 FeatureMap& operator=(const FeatureMap&);
michael@0 143 };
michael@0 144
michael@0 145
michael@0 146 class SillMap
michael@0 147 {
michael@0 148 private:
michael@0 149 class LangFeaturePair
michael@0 150 {
michael@0 151 LangFeaturePair(const LangFeaturePair &);
michael@0 152 LangFeaturePair & operator = (const LangFeaturePair &);
michael@0 153
michael@0 154 public:
michael@0 155 LangFeaturePair() : m_lang(0), m_pFeatures(0) {}
michael@0 156 ~LangFeaturePair() { delete m_pFeatures; }
michael@0 157
michael@0 158 uint32 m_lang;
michael@0 159 Features* m_pFeatures; //owns
michael@0 160 CLASS_NEW_DELETE
michael@0 161 };
michael@0 162 public:
michael@0 163 SillMap() : m_langFeats(NULL), m_numLanguages(0) {}
michael@0 164 ~SillMap() { delete[] m_langFeats; }
michael@0 165 bool readFace(const Face & face);
michael@0 166 bool readSill(const Face & face);
michael@0 167 FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
michael@0 168 uint16 numLanguages() const { return m_numLanguages; };
michael@0 169 uint32 getLangName(uint16 index) const { return (index < m_numLanguages)? m_langFeats[index].m_lang : 0; };
michael@0 170
michael@0 171 const FeatureMap & theFeatureMap() const { return m_FeatureMap; };
michael@0 172 private:
michael@0 173 FeatureMap m_FeatureMap; //of face
michael@0 174 LangFeaturePair * m_langFeats;
michael@0 175 uint16 m_numLanguages;
michael@0 176
michael@0 177 private: //defensive on m_langFeats
michael@0 178 SillMap(const SillMap&);
michael@0 179 SillMap& operator=(const SillMap&);
michael@0 180 };
michael@0 181
michael@0 182 } // namespace graphite2
michael@0 183
michael@0 184 struct gr_feature_ref : public graphite2::FeatureRef {};

mercurial