1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/graphite2/src/inc/FeatureMap.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,184 @@ 1.4 +/* GRAPHITE2 LICENSING 1.5 + 1.6 + Copyright 2010, SIL International 1.7 + All rights reserved. 1.8 + 1.9 + This library is free software; you can redistribute it and/or modify 1.10 + it under the terms of the GNU Lesser General Public License as published 1.11 + by the Free Software Foundation; either version 2.1 of License, or 1.12 + (at your option) any later version. 1.13 + 1.14 + This program is distributed in the hope that it will be useful, 1.15 + but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + Lesser General Public License for more details. 1.18 + 1.19 + You should also have received a copy of the GNU Lesser General Public 1.20 + License along with this library in the file named "LICENSE". 1.21 + If not, write to the Free Software Foundation, 51 Franklin Street, 1.22 + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the 1.23 + internet at http://www.fsf.org/licenses/lgpl.html. 1.24 + 1.25 +Alternatively, the contents of this file may be used under the terms of the 1.26 +Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public 1.27 +License, as published by the Free Software Foundation, either version 2 1.28 +of the License or (at your option) any later version. 1.29 +*/ 1.30 +#pragma once 1.31 +#include "inc/Main.h" 1.32 +#include "inc/FeatureVal.h" 1.33 + 1.34 +namespace graphite2 { 1.35 + 1.36 +// Forward declarations for implmentation types 1.37 +class FeatureMap; 1.38 +class Face; 1.39 + 1.40 + 1.41 +class FeatureSetting 1.42 +{ 1.43 +public: 1.44 + FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {}; 1.45 + uint16 label() const { return m_label; } 1.46 + int16 value() const { return m_value; } 1.47 + 1.48 + CLASS_NEW_DELETE; 1.49 +private: 1.50 + FeatureSetting(const FeatureSetting & fs) : m_label(fs.m_label), m_value(fs.m_value) {}; 1.51 + 1.52 + uint16 m_label; 1.53 + int16 m_value; 1.54 +}; 1.55 + 1.56 +class FeatureRef 1.57 +{ 1.58 + typedef uint32 chunk_t; 1.59 + static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8; 1.60 + 1.61 +public: 1.62 + FeatureRef() : m_nameValues(0) {} 1.63 + FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, 1.64 + uint32 name, uint16 uiName, uint16 flags, 1.65 + FeatureSetting *settings, uint16 num_set) throw(); 1.66 + ~FeatureRef() throw(); 1.67 + 1.68 + bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h 1.69 + void maskFeature(Features & pDest) const { 1.70 + if (m_index < pDest.size()) //defensive 1.71 + pDest[m_index] |= m_mask; 1.72 + } 1.73 + 1.74 + uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h 1.75 + 1.76 + uint32 getId() const { return m_id; } 1.77 + uint16 getNameId() const { return m_nameid; } 1.78 + uint16 getNumSettings() const { return m_numSet; } 1.79 + uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); } 1.80 + int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); } 1.81 + uint32 maxVal() const { return m_max; } 1.82 + const Face* getFace() const { return m_pFace;} 1.83 + const FeatureMap* getFeatureMap() const;// { return m_pFace;} 1.84 + 1.85 + CLASS_NEW_DELETE; 1.86 +private: 1.87 + FeatureRef(const FeatureRef & rhs); 1.88 + 1.89 + const Face * m_pFace; //not NULL 1.90 + FeatureSetting * m_nameValues; // array of name table ids for feature values 1.91 + chunk_t m_mask, // bit mask to get the value from the vector 1.92 + m_max; // max value the value can take 1.93 + uint32 m_id; // feature identifier/name 1.94 + uint16 m_nameid, // Name table id for feature name 1.95 + m_flags, // feature flags (unused at the moment but read from the font) 1.96 + m_numSet; // number of values (number of entries in m_nameValues) 1.97 + byte m_bits, // how many bits to shift the value into place 1.98 + m_index; // index into the array to find the ulong to mask 1.99 + 1.100 +private: //unimplemented 1.101 + FeatureRef& operator=(const FeatureRef&); 1.102 +}; 1.103 + 1.104 + 1.105 +class NameAndFeatureRef 1.106 +{ 1.107 + public: 1.108 + NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){} 1.109 + NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {} 1.110 + 1.111 + bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name 1.112 + { return m_name<rhs.m_name; } 1.113 + 1.114 + CLASS_NEW_DELETE 1.115 + 1.116 + uint32 m_name; 1.117 + const FeatureRef* m_pFRef; 1.118 +}; 1.119 + 1.120 +class FeatureMap 1.121 +{ 1.122 +public: 1.123 + FeatureMap() : m_numFeats(0), m_feats(NULL), m_pNamedFeats(NULL), 1.124 + m_defaultFeatures(NULL) {} 1.125 + ~FeatureMap() { delete [] m_feats; delete[] m_pNamedFeats; delete m_defaultFeatures; } 1.126 + 1.127 + bool readFeats(const Face & face); 1.128 + const FeatureRef *findFeatureRef(uint32 name) const; 1.129 + FeatureRef *feature(uint16 index) const { return m_feats + index; } 1.130 + //GrFeatureRef *featureRef(byte index) { return index < m_numFeats ? m_feats + index : NULL; } 1.131 + const FeatureRef *featureRef(byte index) const { return index < m_numFeats ? m_feats + index : NULL; } 1.132 + FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done. 1.133 + uint16 numFeats() const { return m_numFeats; }; 1.134 + CLASS_NEW_DELETE 1.135 +private: 1.136 +friend class SillMap; 1.137 + uint16 m_numFeats; 1.138 + 1.139 + FeatureRef *m_feats; 1.140 + NameAndFeatureRef* m_pNamedFeats; //owned 1.141 + FeatureVal* m_defaultFeatures; //owned 1.142 + 1.143 +private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures 1.144 + FeatureMap(const FeatureMap&); 1.145 + FeatureMap& operator=(const FeatureMap&); 1.146 +}; 1.147 + 1.148 + 1.149 +class SillMap 1.150 +{ 1.151 +private: 1.152 + class LangFeaturePair 1.153 + { 1.154 + LangFeaturePair(const LangFeaturePair &); 1.155 + LangFeaturePair & operator = (const LangFeaturePair &); 1.156 + 1.157 + public: 1.158 + LangFeaturePair() : m_lang(0), m_pFeatures(0) {} 1.159 + ~LangFeaturePair() { delete m_pFeatures; } 1.160 + 1.161 + uint32 m_lang; 1.162 + Features* m_pFeatures; //owns 1.163 + CLASS_NEW_DELETE 1.164 + }; 1.165 +public: 1.166 + SillMap() : m_langFeats(NULL), m_numLanguages(0) {} 1.167 + ~SillMap() { delete[] m_langFeats; } 1.168 + bool readFace(const Face & face); 1.169 + bool readSill(const Face & face); 1.170 + FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done. 1.171 + uint16 numLanguages() const { return m_numLanguages; }; 1.172 + uint32 getLangName(uint16 index) const { return (index < m_numLanguages)? m_langFeats[index].m_lang : 0; }; 1.173 + 1.174 + const FeatureMap & theFeatureMap() const { return m_FeatureMap; }; 1.175 +private: 1.176 + FeatureMap m_FeatureMap; //of face 1.177 + LangFeaturePair * m_langFeats; 1.178 + uint16 m_numLanguages; 1.179 + 1.180 +private: //defensive on m_langFeats 1.181 + SillMap(const SillMap&); 1.182 + SillMap& operator=(const SillMap&); 1.183 +}; 1.184 + 1.185 +} // namespace graphite2 1.186 + 1.187 +struct gr_feature_ref : public graphite2::FeatureRef {};