platformFont.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _PLATFORM_H_
  23. #include "platform/platform.h"
  24. #endif
  25. #ifndef _PLATFORMFONT_H_
  26. #define _PLATFORMFONT_H_
  27. // Charsets for fonts
  28. // [tom, 7/27/2005] These are intended to map to their Win32 equivalents. This
  29. // enumeration may require changes to accommodate other platforms.
  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. extern const char *getCharSetName(const U32 charSet);
  53. class PlatformFont
  54. {
  55. public:
  56. struct CharInfo
  57. {
  58. S16 bitmapIndex; ///< @note -1 indicates character is NOT to be
  59. /// rendered, i.e., \n, \r, etc.
  60. U32 xOffset; ///< x offset into bitmap sheet
  61. U32 yOffset; ///< y offset into bitmap sheet
  62. U32 width; ///< width of character (pixels)
  63. U32 height; ///< height of character (pixels)
  64. S32 xOrigin;
  65. S32 yOrigin;
  66. S32 xIncrement;
  67. U8 *bitmapData; ///< temp storage for bitmap data
  68. };
  69. virtual ~PlatformFont() {}
  70. /// Is the specified character valid for rendering?
  71. virtual bool isValidChar(const UTF16 ch) const = 0;
  72. virtual bool isValidChar(const UTF8 *str) const = 0;
  73. virtual U32 getFontHeight() const = 0;
  74. virtual U32 getFontBaseLine() const = 0;
  75. virtual PlatformFont::CharInfo &getCharInfo(const UTF16 ch) const = 0;
  76. virtual PlatformFont::CharInfo &getCharInfo(const UTF8 *str) const = 0;
  77. /// This is just for createPlatformFont to call.
  78. ///
  79. /// @todo Rethink this so we don't have a private public.
  80. virtual bool create( const char *name, dsize_t size, U32 charset = TGE_ANSI_CHARSET ) = 0;
  81. static void enumeratePlatformFonts( Vector<StringTableEntry>& fonts, UTF16* fontFamily = NULL );
  82. };
  83. extern PlatformFont *createPlatformFont(const char *name, dsize_t size, U32 charset = TGE_ANSI_CHARSET);
  84. #endif // _PLATFORMFONT_H_