CTrueTypeFont.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * CTrueTypeFont.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. #include "../render/IFont.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class JsonNode;
  14. VCMI_LIB_NAMESPACE_END
  15. class CBitmapFont;
  16. using TTF_Font = struct _TTF_Font;
  17. class CTrueTypeFont final : public IFont
  18. {
  19. std::unique_ptr<CBitmapFont> fallbackFont;
  20. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  21. const std::unique_ptr<TTF_Font, void (*)(TTF_Font*)> font;
  22. const bool blended;
  23. const bool dropShadow;
  24. std::pair<std::unique_ptr<ui8[]>, ui64> loadData(const JsonNode & config);
  25. TTF_Font * loadFont(const JsonNode & config);
  26. int getPointSize(const JsonNode & config) const;
  27. int getFontStyle(const JsonNode & config) const;
  28. void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override;
  29. public:
  30. CTrueTypeFont(const JsonNode & fontConfig);
  31. ~CTrueTypeFont();
  32. size_t getLineHeight() const override;
  33. size_t getGlyphWidth(const char * data) const override;
  34. size_t getStringWidth(const std::string & data) const override;
  35. };