platformFont.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORMFONT_H_
  23. #define _PLATFORMFONT_H_
  24. #ifndef _TORQUE_TYPES_H_
  25. #include "platform/types.h"
  26. #endif
  27. //-------------------------------------------------------------------------
  28. template <class T> class Vector;
  29. //-------------------------------------------------------------------------
  30. enum FontCharset
  31. {
  32. TGE_ANSI_CHARSET = 0,
  33. TGE_SYMBOL_CHARSET,
  34. TGE_SHIFTJIS_CHARSET,
  35. TGE_HANGEUL_CHARSET,
  36. TGE_HANGUL_CHARSET,
  37. TGE_GB2312_CHARSET,
  38. TGE_CHINESEBIG5_CHARSET,
  39. TGE_OEM_CHARSET,
  40. TGE_JOHAB_CHARSET,
  41. TGE_HEBREW_CHARSET,
  42. TGE_ARABIC_CHARSET,
  43. TGE_GREEK_CHARSET,
  44. TGE_TURKISH_CHARSET,
  45. TGE_VIETNAMESE_CHARSET,
  46. TGE_THAI_CHARSET,
  47. TGE_EASTEUROPE_CHARSET,
  48. TGE_RUSSIAN_CHARSET,
  49. TGE_MAC_CHARSET,
  50. TGE_BALTIC_CHARSET
  51. };
  52. //-------------------------------------------------------------------------
  53. const char *getFontCharSetName(const U32 charSet);
  54. //-------------------------------------------------------------------------
  55. class PlatformFont
  56. {
  57. public:
  58. struct CharInfo
  59. {
  60. S16 bitmapIndex; // Note: -1 indicates character is NOT to be rendered, i.e., \n, \r, etc.
  61. U32 xOffset; // x offset into bitmap sheet
  62. U32 yOffset; // y offset into bitmap sheet
  63. U32 width; // width of character (pixels)
  64. U32 height; // height of character (pixels)
  65. S32 xOrigin;
  66. S32 yOrigin;
  67. S32 xIncrement;
  68. U8 *bitmapData; // temp storage for bitmap data
  69. };
  70. PlatformFont() {}
  71. virtual ~PlatformFont() {}
  72. virtual bool isValidChar(const UTF16 ch) const = 0;
  73. virtual bool isValidChar(const UTF8 *str) const = 0;
  74. virtual U32 getFontHeight() const = 0;
  75. virtual U32 getFontBaseLine() const = 0;
  76. virtual PlatformFont::CharInfo &getCharInfo(const UTF16 ch) const = 0;
  77. virtual PlatformFont::CharInfo &getCharInfo(const UTF8 *str) const = 0;
  78. virtual bool create(const char *name, U32 size, U32 charset = TGE_ANSI_CHARSET) = 0;
  79. static void enumeratePlatformFonts( Vector<StringTableEntry>& fonts );
  80. };
  81. //-------------------------------------------------------------------------
  82. extern PlatformFont *createPlatformFont(const char *name, U32 size, U32 charset = TGE_ANSI_CHARSET);
  83. #endif // _PLATFORMFONT_H_