macCarbFont.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <ApplicationServices/ApplicationServices.h>
  23. #include "platform/platformFont.h"
  24. class MacCarbFont : public PlatformFont
  25. {
  26. private:
  27. // Caches style, layout and colorspace data to speed up character drawing.
  28. // TODO: style colors
  29. ATSUStyle mStyle;
  30. ATSUTextLayout mLayout;
  31. CGColorSpaceRef mColorSpace;
  32. // Cache the baseline and height for the getter methods below.
  33. U32 mHeight; // distance between lines
  34. U32 mBaseline; // distance from drawing point to typographic baseline,
  35. // think of the drawing point as the upper left corner of a text box.
  36. // note: 'baseline' is synonymous with 'ascent' in Torque.
  37. // Cache the size and name requested in create()
  38. U32 mSize;
  39. StringTableEntry mName;
  40. public:
  41. MacCarbFont();
  42. virtual ~MacCarbFont();
  43. /// Look up the requested font, cache style, layout, colorspace, and some metrics.
  44. virtual bool create( const char* name, U32 size, U32 charset = TGE_ANSI_CHARSET);
  45. /// Determine if the character requested is a drawable character, or if it should be ignored.
  46. virtual bool isValidChar( const UTF16 ch) const;
  47. virtual bool isValidChar( const UTF8 *str) const;
  48. /// Get some vertical data on the font at large. Useful for drawing multiline text, and sizing text boxes.
  49. virtual U32 getFontHeight() const;
  50. virtual U32 getFontBaseLine() const;
  51. // Draw the character to a temporary bitmap, and fill the CharInfo with various text metrics.
  52. virtual PlatformFont::CharInfo &getCharInfo(const UTF16 ch) const;
  53. virtual PlatformFont::CharInfo &getCharInfo(const UTF8 *str) const;
  54. };
  55. inline U32 MacCarbFont::getFontHeight() const
  56. {
  57. return mHeight;
  58. }
  59. inline U32 MacCarbFont::getFontBaseLine() const
  60. {
  61. return mBaseline;
  62. }