CTrueTypeFont.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include <SDL_ttf.h>
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class JsonNode;
  15. VCMI_LIB_NAMESPACE_END
  16. class CBitmapFont;
  17. class CTrueTypeFont final : public IFont
  18. {
  19. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  20. const std::unique_ptr<TTF_Font, void (*)(TTF_Font*)> font;
  21. const bool blended;
  22. const bool outline;
  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. size_t getFontAscentScaled() const override;
  30. public:
  31. CTrueTypeFont(const JsonNode & fontConfig);
  32. ~CTrueTypeFont();
  33. bool canRepresentCharacter(const char * data) const override;
  34. size_t getLineHeightScaled() const override;
  35. size_t getGlyphWidthScaled(const char * data) const override;
  36. size_t getStringWidthScaled(const std::string & data) const override;
  37. };