CBitmapFont.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 CBitmapFont : public IFont
  21. {
  22. static const size_t totalChars = 256;
  23. struct BitmapChar
  24. {
  25. si32 leftOffset;
  26. ui32 width;
  27. si32 rightOffset;
  28. ui8 *pixels; // pixels of this character, part of BitmapFont::data
  29. };
  30. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  31. const std::array<BitmapChar, totalChars> chars;
  32. const ui8 height;
  33. std::array<BitmapChar, totalChars> loadChars() const;
  34. void renderCharacter(SDL_Surface * surface, const BitmapChar & character, const SDL_Color & color, int &posX, int &posY) const;
  35. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  36. public:
  37. CBitmapFont(const std::string & filename);
  38. size_t getLineHeight() const override;
  39. size_t getGlyphWidth(const char * data) const override;
  40. friend class CBitmapHanFont;
  41. };