1 /** @file lvfontglyphcache.h
2 	@brief font glyph cache interface
3 
4 	CoolReader Engine
5 
6 	(c) Vadim Lopatin, 2000-2006
7 
8 	This source code is distributed under the terms of
9 	GNU General Public License.
10 
11 	See LICENSE file for details.
12 
13 */
14 
15 // This file contains copy of class LVFontLocalGlyphCache from cr3.2.31
16 
17 #ifndef __LV_FONTGLYPHCACHEA_H_INCLUDED__
18 #define __LV_FONTGLYPHCACHEA_H_INCLUDED__
19 
20 //#include <stdlib.h>
21 //#include "crsetup.h"
22 #include "lvtypes.h"
23 
24 
25 struct LVFontGlyphCacheItemA;
26 
27 class LVFontGlobalGlyphCacheA {
28 private:
29 	LVFontGlyphCacheItemA *head;
30 	LVFontGlyphCacheItemA *tail;
31 	int size;
32 	int max_size;
33 
34 	void removeNoLock(LVFontGlyphCacheItemA *item);
35 
36 	void putNoLock(LVFontGlyphCacheItemA *item);
37 
38 public:
LVFontGlobalGlyphCacheA(int maxSize)39 	LVFontGlobalGlyphCacheA(int maxSize)
40 			: head(NULL), tail(NULL), size(0), max_size(maxSize) {
41 	}
42 
~LVFontGlobalGlyphCacheA()43 	~LVFontGlobalGlyphCacheA() {
44 		clear();
45 	}
46 
47 	void put(LVFontGlyphCacheItemA *item);
48 
49 	void remove(LVFontGlyphCacheItemA *item);
50 
51 	void refresh(LVFontGlyphCacheItemA *item);
52 
53 	void clear();
54 
getSize()55     int getSize() { return size; }
56 };
57 
58 class LVFontLocalGlyphCacheA {
59 private:
60 	LVFontGlyphCacheItemA *head;
61 	LVFontGlyphCacheItemA *tail;
62 	LVFontGlobalGlyphCacheA *global_cache;
63 	//int size;
64 public:
LVFontLocalGlyphCacheA(LVFontGlobalGlyphCacheA * globalCache)65 	LVFontLocalGlyphCacheA(LVFontGlobalGlyphCacheA *globalCache)
66 			: head(NULL), tail(NULL), global_cache(globalCache) {}
67 
~LVFontLocalGlyphCacheA()68 	~LVFontLocalGlyphCacheA() {
69 		clear();
70 	}
71 
72 	void clear();
73 
74 	LVFontGlyphCacheItemA *getByChar(lChar32 ch);
75 #if USE_HARFBUZZ==1
76 	LVFontGlyphCacheItemA *getByIndex(lUInt32 index);
77 #endif
78 
79 	void put(LVFontGlyphCacheItemA *item);
80 
81 	void remove(LVFontGlyphCacheItemA *item);
82 };
83 
84 struct LVFontGlyphCacheItemA {
85 	LVFontGlyphCacheItemA *prev_global;
86 	LVFontGlyphCacheItemA *next_global;
87 	LVFontGlyphCacheItemA *prev_local;
88 	LVFontGlyphCacheItemA *next_local;
89 	LVFontLocalGlyphCacheA *local_cache;
90 	union {
91 		lChar32 ch;
92 #if USE_HARFBUZZ==1
93 		lUInt32 gindex;
94 #endif
95 	} data;
96 	lUInt16 bmp_width;
97 	lUInt16 bmp_height;
98 	lInt16 origin_x;
99 	lInt16 origin_y;
100 	lUInt16 advance;
101 	lUInt8 bmp[1];
102 
103 	//=======================================================================
getSizeLVFontGlyphCacheItemA104 	int getSize() {
105 		return sizeof(LVFontGlyphCacheItemA)
106 			   + (bmp_width * bmp_height - 1) * sizeof(lUInt8);
107 	}
108 
109 	static LVFontGlyphCacheItemA *newItem(LVFontLocalGlyphCacheA *local_cache, lChar32 data, int w, int h);
110 #if USE_HARFBUZZ==1
111 	static LVFontGlyphCacheItemA *newItem(LVFontLocalGlyphCacheA *local_cache, lUInt32 glyph_index, int w, int h);
112 #endif
113 
114 	static void freeItem(LVFontGlyphCacheItemA *item);
115 };
116 
117 #endif //__LV_FONTGLYPHCACHEA_H_INCLUDED__
118