font_cache.h

Go to the documentation of this file.
00001 /*
00002  * File Name: font_cache.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-common.
00007  *
00008  * uds-plugin-common is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-common is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
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 /// @brief Cached font glyphs.
00044 /// The class is designed to contain multiple font glyphs. For every font glyph, 
00045 /// The caller should provide a hash code.
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     /// @brief Constructors and destructors
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
Generated by  doxygen 1.6.2-20100208