1 #pragma once 2 3 #include "defines.h" 4 #include "glwrapper.h" 5 6 extern const VColour term_colours[NUM_TERM_COLOURS]; 7 8 class FontBuffer; 9 class formatted_string; 10 class GenericTexture; 11 12 class FontWrapper 13 { 14 public: 15 // Static creation functions. 16 // Implementation-specific files (e.g. fontwrapper-ft.cc) should 17 // contain their own version of this factory function. 18 static FontWrapper *create(); 19 ~FontWrapper()20 virtual ~FontWrapper() {} 21 22 // font loading 23 virtual bool load_font(const char *font_name, unsigned int font_size) = 0; 24 virtual bool configure_font() = 0; 25 26 // render just text 27 virtual void render_textblock(unsigned int x, unsigned int y, 28 char32_t *chars, uint8_t *colours, 29 unsigned int width, unsigned int height, 30 bool drop_shadow = false) = 0; 31 32 // render text + background box 33 virtual void render_tooltip(unsigned int x, unsigned int y, 34 const formatted_string &text, 35 const coord_def &min_pos, 36 const coord_def &max_pos) = 0; 37 38 virtual void render_string(unsigned int x, unsigned int y, 39 const formatted_string &text) = 0; 40 41 virtual void render_hover_string(unsigned int x, unsigned int y, 42 const formatted_string &text) = 0; 43 44 // FontBuffer helper functions 45 virtual void store(FontBuffer &buf, float &x, float &y, 46 const string &s, const VColour &c) = 0; 47 virtual void store(FontBuffer &buf, float &x, float &y, 48 const formatted_string &fs) = 0; 49 virtual void store(FontBuffer &buf, float &x, float &y, char32_t c, 50 const VColour &col) = 0; 51 virtual void store(FontBuffer &buf, float &x, float &y, char32_t c, 52 const VColour &fg_col, const VColour &bg_col) = 0; 53 54 virtual unsigned int char_width(bool logical=true) const = 0; 55 virtual unsigned int char_height(bool logical=true) const = 0; 56 virtual unsigned int max_width(int length, bool logical=true) const = 0; 57 virtual unsigned int max_height(int length, bool logical=true) const = 0; 58 59 virtual unsigned int string_width(const char *text, bool logical=true) = 0; 60 virtual unsigned int string_width(const formatted_string &str, bool logical=true) = 0; 61 virtual unsigned int string_height(const char *text, bool logical=true) const = 0; 62 virtual unsigned int string_height(const formatted_string &str, bool logical=true) const = 0; 63 64 // Try to split this string to fit in w x h pixel area. 65 virtual formatted_string split(const formatted_string &str, 66 unsigned int max_width, 67 unsigned int max_height) = 0; 68 69 virtual const GenericTexture *font_tex() const = 0; 70 }; 71