2013-05-08 15:42:44 +03:00
|
|
|
#ifndef _library__customfont__hpp__included__
|
|
|
|
#define _library__customfont__hpp__included__
|
2013-02-01 21:52:27 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <map>
|
|
|
|
#include "framebuffer.hpp"
|
|
|
|
|
|
|
|
struct font_glyph_data
|
|
|
|
{
|
|
|
|
font_glyph_data();
|
|
|
|
font_glyph_data(std::istream& s);
|
|
|
|
unsigned width;
|
|
|
|
unsigned height;
|
|
|
|
unsigned stride;
|
|
|
|
std::vector<uint32_t> glyph; //Bitpacked, element breaks between rows.
|
2013-12-19 06:57:22 +02:00
|
|
|
void render(framebuffer::fb<false>& fb, int32_t x, int32_t y, framebuffer::color fg, framebuffer::color bg,
|
|
|
|
framebuffer::color hl) const;
|
|
|
|
void render(framebuffer::fb<true>& fb, int32_t x, int32_t y, framebuffer::color fg, framebuffer::color bg,
|
|
|
|
framebuffer::color hl) const;
|
2013-02-01 21:52:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct custom_font
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
custom_font();
|
|
|
|
custom_font(const std::string& file);
|
2013-12-19 06:57:22 +02:00
|
|
|
custom_font(struct framebuffer::font& bfont);
|
2013-03-25 00:29:48 +02:00
|
|
|
void add(const std::u32string& key, const font_glyph_data& glyph) throw(std::bad_alloc);
|
|
|
|
std::u32string best_ligature_match(const std::u32string& codepoints, size_t start) const
|
2013-02-01 21:52:27 +02:00
|
|
|
throw(std::bad_alloc);
|
2013-03-25 00:29:48 +02:00
|
|
|
const font_glyph_data& lookup_glyph(const std::u32string& key) const throw();
|
2013-02-01 21:52:27 +02:00
|
|
|
unsigned get_rowadvance() const throw() { return rowadvance; }
|
|
|
|
private:
|
2013-03-25 00:29:48 +02:00
|
|
|
std::map<std::u32string, font_glyph_data> glyphs;
|
2013-02-01 21:52:27 +02:00
|
|
|
unsigned rowadvance;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|