CBitmapHanFont.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * CBitmapHanFont.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. /// supports multi-byte characters for such languages like Chinese
  17. class CBitmapHanFont final : public IFont
  18. {
  19. std::unique_ptr<CBitmapFont> fallback;
  20. // data, directly copied from file
  21. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  22. // size of the font. Not available in file but needed for proper rendering
  23. const size_t size;
  24. size_t getCharacterDataOffset(size_t index) const;
  25. size_t getCharacterIndex(ui8 first, ui8 second) const;
  26. void renderCharacter(SDL_Surface * surface, int characterIndex, const ColorRGBA & color, int &posX, int &posY) const;
  27. void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override;
  28. public:
  29. CBitmapHanFont(const JsonNode & config);
  30. size_t getLineHeight() const override;
  31. size_t getGlyphWidth(const char * data) const override;
  32. };