IFont.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Fonts.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class JsonNode;
  13. class Point;
  14. VCMI_LIB_NAMESPACE_END
  15. struct SDL_Surface;
  16. struct SDL_Color;
  17. typedef struct _TTF_Font TTF_Font;
  18. class CBitmapFont;
  19. class CBitmapHanFont;
  20. class IFont
  21. {
  22. protected:
  23. /// Internal function to render font, see renderTextLeft
  24. virtual void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const = 0;
  25. public:
  26. virtual ~IFont()
  27. {}
  28. /// Returns height of font
  29. virtual size_t getLineHeight() const = 0;
  30. /// Returns width, in pixels of a character glyph. Pointer must contain at least characterSize valid bytes
  31. virtual size_t getGlyphWidth(const char * data) const = 0;
  32. /// Return width of the string
  33. virtual size_t getStringWidth(const std::string & data) const;
  34. /**
  35. * @param surface - destination to print text on
  36. * @param data - string to print
  37. * @param color - font color
  38. * @param pos - position of rendered font
  39. */
  40. /// pos = topleft corner of the text
  41. void renderTextLeft(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  42. /// pos = center of the text
  43. void renderTextRight(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  44. /// pos = bottomright corner of the text
  45. void renderTextCenter(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  46. /// pos = topleft corner of the text
  47. void renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  48. /// pos = center of the text
  49. void renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  50. /// pos = bottomright corner of the text
  51. void renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  52. };