1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* GRAPHITE2 LICENSING
Copyright 2010, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should also have received a copy of the GNU Lesser General Public
License along with this library in the file named "LICENSE".
If not, write to the Free Software Foundation, 51 Franklin Street,
Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
internet at http://www.fsf.org/licenses/lgpl.html.
Alternatively, the contents of this file may be used under the terms of the
Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
License, as published by the Free Software Foundation, either version 2
of the License or (at your option) any later version.
*/
#pragma once
#include "inc/GlyphFace.h"
#include "graphite2/Font.h"
namespace graphite2 {
class Segment;
class Face;
class FeatureVal;
class GlyphFaceCacheHeader
{
public:
bool initialize(const Face & face, const bool dumb_font); //return result indicates success. Do not use if failed.
unsigned short numGlyphs() const { return m_nGlyphs; }
unsigned short numAttrs() const { return m_numAttrs; }
private:
friend class Face;
friend class GlyphFace;
const byte* m_pHead,
* m_pHHea,
* m_pHmtx,
* m_pGlat,
* m_pGloc,
* m_pGlyf,
* m_pLoca;
size_t m_lHmtx,
m_lGlat,
m_lGlyf,
m_lLoca;
uint32 m_fGlat;
unsigned short m_numAttrs, // number of glyph attributes per glyph
m_nGlyphsWithGraphics, //i.e. boundary box and advance
m_nGlyphsWithAttributes,
m_nGlyphs; // number of glyphs in the font. Max of the above 2.
bool m_locFlagsUse32Bit;
};
class GlyphFaceCache : public GlyphFaceCacheHeader
{
public:
static GlyphFaceCache* makeCache(const GlyphFaceCacheHeader& hdr /*, EGlyphCacheStrategy requested */);
GlyphFaceCache(const GlyphFaceCacheHeader& hdr);
~GlyphFaceCache();
const GlyphFace *glyphSafe(unsigned short glyphid) const { return glyphid<numGlyphs()?glyph(glyphid):NULL; }
uint16 glyphAttr(uint16 gid, uint8 gattr) const { if (gattr>=numAttrs()) return 0; const GlyphFace*p=glyphSafe(gid); return p?p->getAttr(gattr):0; }
void * operator new (size_t s, const GlyphFaceCacheHeader& hdr)
{
return malloc(s + sizeof(GlyphFace*)*hdr.numGlyphs());
}
// delete in case an exception is thrown in constructor
void operator delete(void* p, const GlyphFaceCacheHeader& ) throw()
{
free(p);
}
const GlyphFace *glyph(unsigned short glyphid) const; //result may be changed by subsequent call with a different glyphid
void loadAllGlyphs();
CLASS_NEW_DELETE
private:
GlyphFace **glyphPtrDirect(unsigned short glyphid) const { return (GlyphFace **)((const char*)(this)+sizeof(GlyphFaceCache)+sizeof(GlyphFace*)*glyphid);}
private: //defensive
GlyphFaceCache(const GlyphFaceCache&);
GlyphFaceCache& operator=(const GlyphFaceCache&);
};
} // namespace graphite2
|