Rasterizer.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright (c) 2006-2023 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. love::Type Rasterizer::type("Rasterizer", &Object::type);
  29. Rasterizer::~Rasterizer()
  30. {
  31. }
  32. int Rasterizer::getHeight() const
  33. {
  34. return metrics.height;
  35. }
  36. int Rasterizer::getAdvance() const
  37. {
  38. return metrics.advance;
  39. }
  40. int Rasterizer::getAscent() const
  41. {
  42. return metrics.ascent;
  43. }
  44. int Rasterizer::getDescent() const
  45. {
  46. return metrics.descent;
  47. }
  48. GlyphData *Rasterizer::getGlyphData(uint32 glyph) const
  49. {
  50. return getGlyphDataForIndex(getGlyphIndex(glyph));
  51. }
  52. GlyphData *Rasterizer::getGlyphData(const std::string &text) const
  53. {
  54. uint32 codepoint = 0;
  55. try
  56. {
  57. codepoint = utf8::peek_next(text.begin(), text.end());
  58. }
  59. catch (utf8::exception &e)
  60. {
  61. throw love::Exception("UTF-8 decoding error: %s", e.what());
  62. }
  63. return getGlyphData(codepoint);
  64. }
  65. bool Rasterizer::hasGlyphs(const std::string &text) const
  66. {
  67. if (text.size() == 0)
  68. return false;
  69. try
  70. {
  71. utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
  72. utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
  73. while (i != end)
  74. {
  75. uint32 codepoint = *i++;
  76. if (!hasGlyph(codepoint))
  77. return false;
  78. }
  79. }
  80. catch (utf8::exception &e)
  81. {
  82. throw love::Exception("UTF-8 decoding error: %s", e.what());
  83. }
  84. return true;
  85. }
  86. float Rasterizer::getKerning(uint32 /*leftglyph*/, uint32 /*rightglyph*/) const
  87. {
  88. return 0.0f;
  89. }
  90. float Rasterizer::getDPIScale() const
  91. {
  92. return dpiScale;
  93. }
  94. } // font
  95. } // love