michael@0: /* GRAPHITE2 LICENSING michael@0: michael@0: Copyright 2010, SIL International michael@0: All rights reserved. michael@0: michael@0: This library is free software; you can redistribute it and/or modify michael@0: it under the terms of the GNU Lesser General Public License as published michael@0: by the Free Software Foundation; either version 2.1 of License, or michael@0: (at your option) any later version. michael@0: michael@0: This program is distributed in the hope that it will be useful, michael@0: but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: Lesser General Public License for more details. michael@0: michael@0: You should also have received a copy of the GNU Lesser General Public michael@0: License along with this library in the file named "LICENSE". michael@0: If not, write to the Free Software Foundation, 51 Franklin Street, michael@0: Suite 500, Boston, MA 02110-1335, USA or visit their web page on the michael@0: internet at http://www.fsf.org/licenses/lgpl.html. michael@0: michael@0: Alternatively, the contents of this file may be used under the terms of the michael@0: Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public michael@0: License, as published by the Free Software Foundation, either version 2 michael@0: of the License or (at your option) any later version. michael@0: */ michael@0: #pragma once michael@0: #include "inc/Main.h" michael@0: #include "inc/FeatureVal.h" michael@0: michael@0: namespace graphite2 { michael@0: michael@0: // Forward declarations for implmentation types michael@0: class FeatureMap; michael@0: class Face; michael@0: michael@0: michael@0: class FeatureSetting michael@0: { michael@0: public: michael@0: FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {}; michael@0: uint16 label() const { return m_label; } michael@0: int16 value() const { return m_value; } michael@0: michael@0: CLASS_NEW_DELETE; michael@0: private: michael@0: FeatureSetting(const FeatureSetting & fs) : m_label(fs.m_label), m_value(fs.m_value) {}; michael@0: michael@0: uint16 m_label; michael@0: int16 m_value; michael@0: }; michael@0: michael@0: class FeatureRef michael@0: { michael@0: typedef uint32 chunk_t; michael@0: static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8; michael@0: michael@0: public: michael@0: FeatureRef() : m_nameValues(0) {} michael@0: FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, michael@0: uint32 name, uint16 uiName, uint16 flags, michael@0: FeatureSetting *settings, uint16 num_set) throw(); michael@0: ~FeatureRef() throw(); michael@0: michael@0: bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h michael@0: void maskFeature(Features & pDest) const { michael@0: if (m_index < pDest.size()) //defensive michael@0: pDest[m_index] |= m_mask; michael@0: } michael@0: michael@0: uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h michael@0: michael@0: uint32 getId() const { return m_id; } michael@0: uint16 getNameId() const { return m_nameid; } michael@0: uint16 getNumSettings() const { return m_numSet; } michael@0: uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); } michael@0: int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); } michael@0: uint32 maxVal() const { return m_max; } michael@0: const Face* getFace() const { return m_pFace;} michael@0: const FeatureMap* getFeatureMap() const;// { return m_pFace;} michael@0: michael@0: CLASS_NEW_DELETE; michael@0: private: michael@0: FeatureRef(const FeatureRef & rhs); michael@0: michael@0: const Face * m_pFace; //not NULL michael@0: FeatureSetting * m_nameValues; // array of name table ids for feature values michael@0: chunk_t m_mask, // bit mask to get the value from the vector michael@0: m_max; // max value the value can take michael@0: uint32 m_id; // feature identifier/name michael@0: uint16 m_nameid, // Name table id for feature name michael@0: m_flags, // feature flags (unused at the moment but read from the font) michael@0: m_numSet; // number of values (number of entries in m_nameValues) michael@0: byte m_bits, // how many bits to shift the value into place michael@0: m_index; // index into the array to find the ulong to mask michael@0: michael@0: private: //unimplemented michael@0: FeatureRef& operator=(const FeatureRef&); michael@0: }; michael@0: michael@0: michael@0: class NameAndFeatureRef michael@0: { michael@0: public: michael@0: NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){} michael@0: NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {} michael@0: michael@0: bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name michael@0: { return m_name