EmscriptenFont.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. // Portions Copyright (c) 2014 James S Urquhart
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #ifndef _EMSCRIPTENFONT_H_
  24. #define _EMSCRIPTENFONT_H_
  25. #include "platform/platformFont.h"
  26. class EmscriptenFont : public PlatformFont
  27. {
  28. private:
  29. // Distance from drawing point to typographic baseline.
  30. // Think of the drawing point as the upper left corner of a text box.
  31. // NOTE: 'baseline' is synonymous with 'ascent' in Torque.
  32. U32 mBaseline;
  33. // Distance between lines.
  34. U32 mHeight;
  35. public:
  36. EmscriptenFont();
  37. virtual ~EmscriptenFont();
  38. /// Look up the requested font, cache style, layout, colorspace, and some metrics.
  39. virtual bool create( const char* name, U32 size, U32 charset = TGE_ANSI_CHARSET);
  40. /// Determine if the character requested is a drawable character, or if it should be ignored.
  41. virtual bool isValidChar( const UTF16 character) const;
  42. virtual bool isValidChar( const UTF8* str) const;
  43. /// Get some vertical data on the font at large. Useful for drawing multiline text, and sizing text boxes.
  44. virtual U32 getFontHeight() const { return mHeight; }
  45. virtual U32 getFontBaseLine() const { return mBaseline; }
  46. // Draw the character to a temporary bitmap, and fill the CharInfo with various text metrics.
  47. virtual PlatformFont::CharInfo &getCharInfo(const UTF16 character) const;
  48. virtual PlatformFont::CharInfo &getCharInfo(const UTF8 *str) const;
  49. };
  50. #endif