Use std::u32string instead of std::vector<uint32_t> for UTF-32 strings
[lsnes.git] / include / library / customfont.hpp
blob5f700f88ce9ba88c11fc52255b21f2397f4619f6
1 #ifndef _customfont__hpp__included__
2 #define _customfont__hpp__included__
4 #include <vector>
5 #include <cstdint>
6 #include <cstdlib>
7 #include <iostream>
8 #include <stdexcept>
9 #include <map>
10 #include "framebuffer.hpp"
12 struct font_glyph_data
14 font_glyph_data();
15 font_glyph_data(std::istream& s);
16 unsigned width;
17 unsigned height;
18 unsigned stride;
19 std::vector<uint32_t> glyph; //Bitpacked, element breaks between rows.
20 void render(framebuffer<false>& fb, int32_t x, int32_t y, premultiplied_color fg, premultiplied_color bg)
21 const;
22 void render(framebuffer<true>& fb, int32_t x, int32_t y, premultiplied_color fg, premultiplied_color bg) const;
25 struct custom_font
27 public:
28 custom_font();
29 custom_font(const std::string& file);
30 void add(const std::u32string& key, const font_glyph_data& glyph) throw(std::bad_alloc);
31 std::u32string best_ligature_match(const std::u32string& codepoints, size_t start) const
32 throw(std::bad_alloc);
33 const font_glyph_data& lookup_glyph(const std::u32string& key) const throw();
34 unsigned get_rowadvance() const throw() { return rowadvance; }
35 private:
36 std::map<std::u32string, font_glyph_data> glyphs;
37 unsigned rowadvance;
40 #endif