LCOV - code coverage report
Current view: directory - gfx/graphite2/src/inc - FeatureMap.h (source / functions) Found Hit Coverage
Test: app.info Lines: 40 0 0.0 %
Date: 2012-06-02 Functions: 34 0 0.0 %

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

Generated by: LCOV version 1.7