2
0

FontChain.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * FontChain.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 FontChain final : public IFont
  16. {
  17. struct TextChunk
  18. {
  19. const IFont * font;
  20. std::string text;
  21. };
  22. std::vector<TextChunk> splitTextToChunks(const std::string & data) const;
  23. std::vector<std::unique_ptr<IFont>> chain;
  24. void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override;
  25. size_t getFontAscentScaled() const override;
  26. bool bitmapFontsPrioritized(const std::string & bitmapFontName) const;
  27. public:
  28. FontChain() = default;
  29. void addTrueTypeFont(const JsonNode & trueTypeConfig, bool begin);
  30. void addBitmapFont(const std::string & bitmapFilename);
  31. size_t getLineHeightScaled() const override;
  32. size_t getGlyphWidthScaled(const char * data) const override;
  33. size_t getStringWidthScaled(const std::string & data) const override;
  34. bool canRepresentCharacter(const char * data) const override;
  35. };