font_cache.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef FONT_CACHE_H
00028 #define FONT_CACHE_H
00029 
00030 #include <stdio.h>
00031 #include <list>
00032 
00033 #ifdef _WIN32
00034 #include <unordered_map>
00035 #else
00036 #include <tr1/unordered_map>
00037 #endif
00038 
00039 #include <ft2build.h>
00040 #include FT_FREETYPE_H
00041 #include FT_GLYPH_H
00042 
00043 
00044 
00045 
00046 class FontCache
00047 {
00048 public:
00049     ~FontCache();
00050     static FontCache& instance()
00051     {
00052         static FontCache _instance;
00053         return _instance;
00054     }
00055 
00056 private:
00057 
00058     FontCache();
00059     FontCache(const FontCache&);
00060 
00061 public:
00062     void remove_smallest();
00063     void clear();
00064     FT_BitmapGlyph get_glyph(FT_Face face, const unsigned int hash_code, int ch);
00065 
00066 private:
00067     typedef unsigned int UINT32;
00068     typedef std::tr1::unordered_map<FT_UInt, FT_Glyph> GlyphTable;
00069     typedef GlyphTable::iterator        GlyphIter;
00070 
00071     typedef std::tr1::unordered_map<UINT32, GlyphTable> FontTable;
00072     typedef FontTable::iterator          FontIter;
00073     FontTable cache;
00074 
00075     typedef std::tr1::unordered_map<UINT32, UINT32> Code;
00076     typedef Code::iterator           CodeIter;
00077     Code codes;
00078 };
00079 
00080 #endif // FONT_CACHE_H