Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* GRAPHITE2 LICENSING
3 Copyright 2010, SIL International
4 All rights reserved.
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.
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.
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.
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
29 #include "inc/GlyphFace.h"
30 #include "graphite2/Font.h"
32 namespace graphite2 {
34 class Segment;
35 class Face;
36 class FeatureVal;
39 class GlyphFaceCacheHeader
40 {
41 public:
42 bool initialize(const Face & face, const bool dumb_font); //return result indicates success. Do not use if failed.
43 unsigned short numGlyphs() const { return m_nGlyphs; }
44 unsigned short numAttrs() const { return m_numAttrs; }
46 private:
47 friend class Face;
48 friend class GlyphFace;
49 const byte* m_pHead,
50 * m_pHHea,
51 * m_pHmtx,
52 * m_pGlat,
53 * m_pGloc,
54 * m_pGlyf,
55 * m_pLoca;
56 size_t m_lHmtx,
57 m_lGlat,
58 m_lGlyf,
59 m_lLoca;
61 uint32 m_fGlat;
62 unsigned short m_numAttrs, // number of glyph attributes per glyph
63 m_nGlyphsWithGraphics, //i.e. boundary box and advance
64 m_nGlyphsWithAttributes,
65 m_nGlyphs; // number of glyphs in the font. Max of the above 2.
66 bool m_locFlagsUse32Bit;
67 };
69 class GlyphFaceCache : public GlyphFaceCacheHeader
70 {
71 public:
72 static GlyphFaceCache* makeCache(const GlyphFaceCacheHeader& hdr /*, EGlyphCacheStrategy requested */);
74 GlyphFaceCache(const GlyphFaceCacheHeader& hdr);
75 ~GlyphFaceCache();
77 const GlyphFace *glyphSafe(unsigned short glyphid) const { return glyphid<numGlyphs()?glyph(glyphid):NULL; }
78 uint16 glyphAttr(uint16 gid, uint8 gattr) const { if (gattr>=numAttrs()) return 0; const GlyphFace*p=glyphSafe(gid); return p?p->getAttr(gattr):0; }
80 void * operator new (size_t s, const GlyphFaceCacheHeader& hdr)
81 {
82 return malloc(s + sizeof(GlyphFace*)*hdr.numGlyphs());
83 }
84 // delete in case an exception is thrown in constructor
85 void operator delete(void* p, const GlyphFaceCacheHeader& ) throw()
86 {
87 free(p);
88 }
90 const GlyphFace *glyph(unsigned short glyphid) const; //result may be changed by subsequent call with a different glyphid
91 void loadAllGlyphs();
93 CLASS_NEW_DELETE
95 private:
96 GlyphFace **glyphPtrDirect(unsigned short glyphid) const { return (GlyphFace **)((const char*)(this)+sizeof(GlyphFaceCache)+sizeof(GlyphFace*)*glyphid);}
98 private: //defensive
99 GlyphFaceCache(const GlyphFaceCache&);
100 GlyphFaceCache& operator=(const GlyphFaceCache&);
101 };
103 } // namespace graphite2