CBitmapHanFont.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Fonts.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class JsonNode;
  13. class Point;
  14. VCMI_LIB_NAMESPACE_END
  15. struct SDL_Surface;
  16. struct SDL_Color;
  17. typedef struct _TTF_Font TTF_Font;
  18. class CBitmapFont;
  19. class CBitmapHanFont;
  20. /// supports multi-byte characters for such languages like Chinese
  21. class CBitmapHanFont : public IFont
  22. {
  23. std::unique_ptr<CBitmapFont> fallback;
  24. // data, directly copied from file
  25. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  26. // size of the font. Not available in file but needed for proper rendering
  27. const size_t size;
  28. size_t getCharacterDataOffset(size_t index) const;
  29. size_t getCharacterIndex(ui8 first, ui8 second) const;
  30. void renderCharacter(SDL_Surface * surface, int characterIndex, const SDL_Color & color, int &posX, int &posY) const;
  31. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  32. public:
  33. CBitmapHanFont(const JsonNode & config);
  34. size_t getLineHeight() const override;
  35. size_t getGlyphWidth(const char * data) const override;
  36. };
  37. class CTrueTypeFont : public IFont
  38. {
  39. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  40. const std::unique_ptr<TTF_Font, void (*)(TTF_Font*)> font;
  41. const bool blended;
  42. std::pair<std::unique_ptr<ui8[]>, ui64> loadData(const JsonNode & config);
  43. TTF_Font * loadFont(const JsonNode & config);
  44. int getFontStyle(const JsonNode & config);
  45. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  46. public:
  47. CTrueTypeFont(const JsonNode & fontConfig);
  48. size_t getLineHeight() const override;
  49. size_t getGlyphWidth(const char * data) const override;
  50. size_t getStringWidth(const std::string & data) const override;
  51. };