LCOV - code coverage report
Current view: directory - gfx/graphite2/src/inc - Face.h (source / functions) Found Hit Coverage
Test: app.info Lines: 22 0 0.0 %
Date: 2012-06-02 Functions: 18 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                 : 
      29                 : #include "inc/Main.h"
      30                 : #include "inc/GlyphFace.h"
      31                 : #include "inc/Silf.h"
      32                 : #include "inc/TtfUtil.h"
      33                 : #include "inc/Main.h"
      34                 : #include "graphite2/Font.h"
      35                 : #include "inc/FeatureMap.h"
      36                 : #include "inc/GlyphFaceCache.h"
      37                 : 
      38                 : #ifndef GRAPHITE2_NFILEFACE
      39                 : #include <cstdio>
      40                 : #include <cassert>
      41                 : #include "inc/TtfTypes.h"
      42                 : #endif      //!GRAPHITE2_NFILEFACE
      43                 : 
      44                 : namespace graphite2 {
      45                 : 
      46                 : class Segment;
      47                 : class FeatureVal;
      48                 : class NameTable;
      49                 : class Cmap;
      50                 : 
      51                 : using TtfUtil::Tag;
      52                 : 
      53                 : // These are the actual tags, as distinct from the consecutive IDs in TtfUtil.h
      54                 : 
      55                 : #ifndef GRAPHITE2_NFILEFACE
      56                 : class TableCacheItem
      57                 : {
      58                 : public:
      59                 :     TableCacheItem(char * theData, size_t theSize) : m_data(theData), m_size(theSize) {}
      60                 :     TableCacheItem() : m_data(0), m_size(0) {}
      61                 :     ~TableCacheItem()
      62                 :     {
      63                 :         if (m_size) free(m_data);
      64                 :     }
      65                 :     void set(char * theData, size_t theSize) { m_data = theData; m_size = theSize; }
      66                 :     const void * data() const { return m_data; }
      67                 :     size_t size() const { return m_size; }
      68                 : private:
      69                 :     char * m_data;
      70                 :     size_t m_size;
      71                 : };
      72                 : #endif      //!GRAPHITE2_NFILEFACE
      73                 : 
      74                 : 
      75                 : 
      76                 : 
      77                 : class FileFace
      78                 : {
      79                 : #ifndef GRAPHITE2_NFILEFACE
      80                 : public:
      81                 :     static const void *table_fn(const void* appFaceHandle, unsigned int name, size_t *len);
      82                 :   
      83                 :     FileFace(const char *filename);
      84                 :     ~FileFace();
      85                 : //    virtual const void *getTable(unsigned int name, size_t *len) const;
      86                 :     bool isValid() const { return m_pfile && m_pHeader && m_pTableDir; }
      87                 : 
      88                 :     CLASS_NEW_DELETE
      89                 : public:     //for local convenience    
      90                 :     FILE* m_pfile;
      91                 :     unsigned int m_lfile;
      92                 :     mutable TableCacheItem m_tables[18];
      93                 :     TtfUtil::Sfnt::OffsetSubTable* m_pHeader;
      94                 :     TtfUtil::Sfnt::OffsetSubTable::Entry* m_pTableDir;       //[] number of elements is determined by m_pHeader->num_tables
      95                 : #endif      //!GRAPHITE2_NFILEFACE
      96                 :    
      97                 : private:        //defensive
      98                 :     FileFace(const FileFace&);
      99                 :     FileFace& operator=(const FileFace&);
     100                 : };
     101                 : 
     102                 : class Face
     103                 : {
     104                 : public:
     105               0 :     const byte *getTable(const Tag name, size_t  * len = 0) const {
     106               0 :         size_t tbl_len=0;
     107               0 :         const byte * const tbl = reinterpret_cast<const byte *>((*m_getTable)(m_appFaceHandle, name, &tbl_len));
     108               0 :         if (len) *len = tbl_len;
     109               0 :         return TtfUtil::CheckTable(name, tbl, tbl_len) ? tbl : 0;
     110                 :     }
     111               0 :     float advance(unsigned short id) const { return m_pGlyphFaceCache->glyph(id)->theAdvance().x; }
     112                 :     const Silf *silf(int i) const { return ((i < m_numSilf) ? m_silfs + i : (const Silf *)NULL); }
     113                 :     virtual bool runGraphite(Segment *seg, const Silf *silf) const;
     114               0 :     uint16 findPseudo(uint32 uid) const { return (m_numSilf) ? m_silfs[0].findPseudo(uid) : 0; }
     115                 : 
     116                 : public:
     117               0 :     Face(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn getTable2) : 
     118                 :         m_appFaceHandle(appFaceHandle), m_getTable(getTable2), m_pGlyphFaceCache(NULL),
     119                 :         m_cmap(NULL), m_numSilf(0), m_silfs(NULL), m_pFileFace(NULL),
     120               0 :         m_pNames(NULL) {}
     121                 :     virtual ~Face();
     122                 : public:
     123               0 :     float getAdvance(unsigned short glyphid, float scale) const { return advance(glyphid) * scale; }
     124               0 :     const Rect &theBBoxTemporary(uint16 gid) const { return m_pGlyphFaceCache->glyph(gid)->theBBox(); }   //warning value may become invalid when another glyph is accessed
     125               0 :     unsigned short upem() const { return m_upem; }
     126               0 :     uint16 glyphAttr(uint16 gid, uint8 gattr) const { return m_pGlyphFaceCache->glyphAttr(gid, gattr); }
     127                 : 
     128                 : private:
     129                 :     friend class Font;
     130               0 :     unsigned short numGlyphs() const { return m_pGlyphFaceCache->m_nGlyphs; }
     131                 : 
     132                 : public:
     133                 :     bool readGlyphs(uint32 faceOptions);
     134                 :     bool readGraphite();
     135               0 :     bool readFeatures() { return m_Sill.readFace(*this); }
     136                 :     const Silf *chooseSilf(uint32 script) const;
     137               0 :     const SillMap& theSill() const { return m_Sill; }
     138               0 :     uint16 numFeatures() const { return m_Sill.m_FeatureMap.numFeats(); }
     139               0 :     const FeatureRef *featureById(uint32 id) const { return m_Sill.m_FeatureMap.findFeatureRef(id); }
     140               0 :     const FeatureRef *feature(uint16 index) const { return m_Sill.m_FeatureMap.feature(index); }
     141                 :     uint16 getGlyphMetric(uint16 gid, uint8 metric) const;
     142                 : 
     143               0 :     const GlyphFaceCache* getGlyphFaceCache() const { return m_pGlyphFaceCache; }      //never NULL
     144                 :     void takeFileFace(FileFace* pFileFace/*takes ownership*/);
     145               0 :     Cmap & cmap() const { return *m_cmap; };
     146                 :     NameTable * nameTable() const;
     147                 :     uint16 languageForLocale(const char * locale) const;
     148                 : 
     149               0 :     CLASS_NEW_DELETE
     150                 : private:
     151                 :     const void* m_appFaceHandle/*non-NULL*/;
     152                 :     gr_get_table_fn m_getTable;
     153                 :     uint16 m_ascent;
     154                 :     uint16 m_descent;
     155                 :     // unsigned short *m_glyphidx;     // index for each glyph id in the font
     156                 :     // unsigned short m_readglyphs;    // how many glyphs have we in m_glyphs?
     157                 :     // unsigned short m_capacity;      // how big is m_glyphs
     158                 :     mutable GlyphFaceCache* m_pGlyphFaceCache;      //owned - never NULL
     159                 :     mutable Cmap * m_cmap; // cmap cache if available
     160                 :     unsigned short m_upem;          // design units per em
     161                 : protected:
     162                 :     unsigned short m_numSilf;       // number of silf subtables in the silf table
     163                 :     Silf *m_silfs;                   // silf subtables.
     164                 : private:
     165                 :     SillMap m_Sill;
     166                 :     FileFace* m_pFileFace;      //owned
     167                 :     mutable NameTable* m_pNames;
     168                 :     
     169                 : private:        //defensive on m_pGlyphFaceCache, m_pFileFace and m_silfs
     170                 :     Face(const Face&);
     171                 :     Face& operator=(const Face&);
     172                 : };
     173                 : 
     174                 : } // namespace graphite2
     175                 : 
     176                 : struct gr_face : public graphite2::Face {};

Generated by: LCOV version 1.7