gfx/graphite2/src/inc/GlyphFaceCache.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/graphite2/src/inc/GlyphFaceCache.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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 +
    1.32 +#include "inc/GlyphFace.h"
    1.33 +#include "graphite2/Font.h"
    1.34 +
    1.35 +namespace graphite2 {
    1.36 +
    1.37 +class Segment;
    1.38 +class Face;
    1.39 +class FeatureVal;
    1.40 +
    1.41 +
    1.42 +class GlyphFaceCacheHeader
    1.43 +{
    1.44 +public:
    1.45 +    bool initialize(const Face & face, const bool dumb_font);    //return result indicates success. Do not use if failed.
    1.46 +    unsigned short numGlyphs() const { return m_nGlyphs; }
    1.47 +    unsigned short numAttrs() const { return m_numAttrs; }
    1.48 +
    1.49 +private:
    1.50 +friend class Face;
    1.51 +friend class GlyphFace;
    1.52 +    const byte* m_pHead,
    1.53 +    		  * m_pHHea,
    1.54 +    		  * m_pHmtx,
    1.55 +    		  * m_pGlat,
    1.56 +    		  * m_pGloc,
    1.57 +    		  * m_pGlyf,
    1.58 +    		  * m_pLoca;
    1.59 +    size_t		m_lHmtx,
    1.60 +    			m_lGlat,
    1.61 +    			m_lGlyf,
    1.62 +    			m_lLoca;
    1.63 +
    1.64 +    uint32			m_fGlat;
    1.65 +    unsigned short 	m_numAttrs,					// number of glyph attributes per glyph
    1.66 +    				m_nGlyphsWithGraphics,		//i.e. boundary box and advance
    1.67 +    				m_nGlyphsWithAttributes,
    1.68 +    				m_nGlyphs;					// number of glyphs in the font. Max of the above 2.
    1.69 +    bool 			m_locFlagsUse32Bit;
    1.70 +};
    1.71 +
    1.72 +class GlyphFaceCache : public GlyphFaceCacheHeader
    1.73 +{
    1.74 +public:
    1.75 +    static GlyphFaceCache* makeCache(const GlyphFaceCacheHeader& hdr /*, EGlyphCacheStrategy requested */);
    1.76 +
    1.77 +    GlyphFaceCache(const GlyphFaceCacheHeader& hdr);
    1.78 +    ~GlyphFaceCache();
    1.79 +
    1.80 +    const GlyphFace *glyphSafe(unsigned short glyphid) const { return glyphid<numGlyphs()?glyph(glyphid):NULL; }
    1.81 +    uint16 glyphAttr(uint16 gid, uint8 gattr) const { if (gattr>=numAttrs()) return 0; const GlyphFace*p=glyphSafe(gid); return p?p->getAttr(gattr):0; }
    1.82 +
    1.83 +    void * operator new (size_t s, const GlyphFaceCacheHeader& hdr)
    1.84 +    {
    1.85 +        return malloc(s + sizeof(GlyphFace*)*hdr.numGlyphs());
    1.86 +    }
    1.87 +    // delete in case an exception is thrown in constructor
    1.88 +    void operator delete(void* p, const GlyphFaceCacheHeader& ) throw()
    1.89 +    {
    1.90 +        free(p);
    1.91 +    }
    1.92 +
    1.93 +    const GlyphFace *glyph(unsigned short glyphid) const;      //result may be changed by subsequent call with a different glyphid
    1.94 +    void loadAllGlyphs();
    1.95 +
    1.96 +    CLASS_NEW_DELETE
    1.97 +    
    1.98 +private:
    1.99 +    GlyphFace **glyphPtrDirect(unsigned short glyphid) const { return (GlyphFace **)((const char*)(this)+sizeof(GlyphFaceCache)+sizeof(GlyphFace*)*glyphid);}
   1.100 +
   1.101 +private:      //defensive
   1.102 +    GlyphFaceCache(const GlyphFaceCache&);
   1.103 +    GlyphFaceCache& operator=(const GlyphFaceCache&);
   1.104 +};
   1.105 +
   1.106 +} // namespace graphite2

mercurial