IFont.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * IFont.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 Point;
  13. class ColorRGBA;
  14. VCMI_LIB_NAMESPACE_END
  15. struct SDL_Surface;
  16. class IFont : boost::noncopyable
  17. {
  18. protected:
  19. int getScalingFactor() const;
  20. public:
  21. virtual ~IFont()
  22. {}
  23. /// Returns height of font
  24. virtual size_t getLineHeightScaled() const = 0;
  25. /// Returns width, in pixels of a character glyph. Pointer must contain at least characterSize valid bytes
  26. virtual size_t getGlyphWidthScaled(const char * data) const = 0;
  27. /// Return width of the string
  28. virtual size_t getStringWidthScaled(const std::string & data) const;
  29. /// Returns distance from top of the font glyphs to baseline
  30. virtual size_t getFontAscentScaled() const = 0;
  31. /// Returns height of font
  32. size_t getLineHeight() const;
  33. /// Returns width, in pixels of a character glyph. Pointer must contain at least characterSize valid bytes
  34. size_t getGlyphWidth(const char * data) const;
  35. /// Return width of the string
  36. size_t getStringWidth(const std::string & data) const;
  37. /// Returns distance from top of the font glyphs to baseline
  38. size_t getFontAscent() const;
  39. /// Internal function to render font, see renderTextLeft
  40. virtual void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const = 0;
  41. virtual bool canRepresentCharacter(const char * data) const = 0;
  42. /**
  43. * @param surface - destination to print text on
  44. * @param data - string to print
  45. * @param color - font color
  46. * @param pos - position of rendered font
  47. */
  48. /// pos = topleft corner of the text
  49. void renderTextLeft(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const;
  50. /// pos = center of the text
  51. void renderTextRight(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const;
  52. /// pos = bottomright corner of the text
  53. void renderTextCenter(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const;
  54. /// pos = topleft corner of the text
  55. void renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const;
  56. /// pos = center of the text
  57. void renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const;
  58. /// pos = bottomright corner of the text
  59. void renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const;
  60. };