Basic FreeType renderer implementation.
[gdipp.git] / gdipp_server / glyph_cache.h
blob81cc6f36aa10074e3c4dd9fde6157c3f88f0ce93
1 #pragma once
3 #include "gdipp_lib/lru.h"
4 #include "gdipp_server/glyph_run.h"
6 namespace gdipp
9 class glyph_cache
11 public:
12 typedef uint128_t string_id_type;
13 typedef uint128_t char_id_type;
15 static string_id_type get_string_id(const wchar_t *string, unsigned int count, bool is_glyph_index);
16 static char_id_type get_char_id(uint128_t render_trait, FT_UInt index, bool is_glyph_index);
18 ~glyph_cache();
20 void initialize();
21 const FT_Glyph lookup_glyph(char_id_type char_id) const;
22 bool store_glyph(char_id_type char_id, const FT_Glyph glyph);
23 const glyph_run *lookup_glyph_run(uint128_t string_id, uint128_t render_trait) const;
24 bool store_glyph_run(uint128_t string_id, uint128_t render_trait, glyph_run *a_glyph_run);
26 private:
27 // std::map from render trait to glyph run
28 typedef std::map<uint128_t, glyph_run *> trait_to_run_map;
30 // std::map from character ID (including character index and render trait) to its glyph
31 std::map<char_id_type, const FT_Glyph> _glyph_store;
32 // std::map from string ID to glyph run
33 // use hierarchical design so that when LRU string is evicted, all associated glyph runs are erased
34 std::map<uint128_t, trait_to_run_map> _glyph_run_store;
36 // least recently used glyph runs, indexed by string ID
37 lru_list<uint128_t> _glyph_run_lru;