Save bitmaps as PNG
[lsnes.git] / include / library / customfont.hpp
blob99fd0a490eb80b0278714dc890222baee37d9e01
1 #ifndef _library__customfont__hpp__included__
2 #define _library__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 premultiplied_color hl) const;
22 void render(framebuffer<true>& fb, int32_t x, int32_t y, premultiplied_color fg, premultiplied_color bg,
23 premultiplied_color hl) const;
26 struct custom_font
28 public:
29 custom_font();
30 custom_font(const std::string& file);
31 void add(const std::u32string& key, const font_glyph_data& glyph) throw(std::bad_alloc);
32 std::u32string best_ligature_match(const std::u32string& codepoints, size_t start) const
33 throw(std::bad_alloc);
34 const font_glyph_data& lookup_glyph(const std::u32string& key) const throw();
35 unsigned get_rowadvance() const throw() { return rowadvance; }
36 private:
37 std::map<std::u32string, font_glyph_data> glyphs;
38 unsigned rowadvance;
41 #endif