CTrueTypeFont.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. void renderTextImpl(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const;
  30. size_t getFontAscentScaled() const override;
  31. public:
  32. CTrueTypeFont(const JsonNode & fontConfig);
  33. ~CTrueTypeFont();
  34. bool canRepresentCharacter(const char * data) const override;
  35. size_t getLineHeightScaled() const override;
  36. size_t getGlyphWidthScaled(const char * data) const override;
  37. size_t getStringWidthScaled(const std::string & data) const override;
  38. };