Rasterizer.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright (c) 2006-2015 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "Rasterizer.h"
  22. // UTF-8
  23. #include "libraries/utf8/utf8.h"
  24. namespace love
  25. {
  26. namespace font
  27. {
  28. Rasterizer::~Rasterizer()
  29. {
  30. }
  31. int Rasterizer::getHeight() const
  32. {
  33. return metrics.height;
  34. }
  35. int Rasterizer::getAdvance() const
  36. {
  37. return metrics.advance;
  38. }
  39. int Rasterizer::getAscent() const
  40. {
  41. return metrics.ascent;
  42. }
  43. int Rasterizer::getDescent() const
  44. {
  45. return metrics.descent;
  46. }
  47. GlyphData *Rasterizer::getGlyphData(const std::string &text) const
  48. {
  49. uint32 codepoint = 0;
  50. try
  51. {
  52. codepoint = utf8::peek_next(text.begin(), text.end());
  53. }
  54. catch (utf8::exception &e)
  55. {
  56. throw love::Exception("UTF-8 decoding error: %s", e.what());
  57. }
  58. return getGlyphData(codepoint);
  59. }
  60. bool Rasterizer::hasGlyphs(const std::string &text) const
  61. {
  62. if (text.size() == 0)
  63. return false;
  64. try
  65. {
  66. utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
  67. utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
  68. while (i != end)
  69. {
  70. uint32 codepoint = *i++;
  71. if (!hasGlyph(codepoint))
  72. return false;
  73. }
  74. }
  75. catch (utf8::exception &e)
  76. {
  77. throw love::Exception("UTF-8 decoding error: %s", e.what());
  78. }
  79. return true;
  80. }
  81. } // font
  82. } // love