| 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 | |
| 21 | // LOVE |
| 22 | #include "Rasterizer.h" |
| 23 | |
| 24 | // UTF-8 |
| 25 | #include "libraries/utf8/utf8.h" |
| 26 | |
| 27 | namespace love |
| 28 | { |
| 29 | namespace font |
| 30 | { |
| 31 | |
| 32 | love::Type Rasterizer::type("Rasterizer" , &Object::type); |
| 33 | |
| 34 | Rasterizer::~Rasterizer() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | int Rasterizer::getHeight() const |
| 39 | { |
| 40 | return metrics.height; |
| 41 | } |
| 42 | |
| 43 | int Rasterizer::getAdvance() const |
| 44 | { |
| 45 | return metrics.advance; |
| 46 | } |
| 47 | |
| 48 | int Rasterizer::getAscent() const |
| 49 | { |
| 50 | return metrics.ascent; |
| 51 | } |
| 52 | |
| 53 | int Rasterizer::getDescent() const |
| 54 | { |
| 55 | return metrics.descent; |
| 56 | } |
| 57 | |
| 58 | GlyphData *Rasterizer::getGlyphData(const std::string &text) const |
| 59 | { |
| 60 | uint32 codepoint = 0; |
| 61 | |
| 62 | try |
| 63 | { |
| 64 | codepoint = utf8::peek_next(text.begin(), text.end()); |
| 65 | } |
| 66 | catch (utf8::exception &e) |
| 67 | { |
| 68 | throw love::Exception("UTF-8 decoding error: %s" , e.what()); |
| 69 | } |
| 70 | |
| 71 | return getGlyphData(codepoint); |
| 72 | } |
| 73 | |
| 74 | bool Rasterizer::hasGlyphs(const std::string &text) const |
| 75 | { |
| 76 | if (text.size() == 0) |
| 77 | return false; |
| 78 | |
| 79 | try |
| 80 | { |
| 81 | utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end()); |
| 82 | utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end()); |
| 83 | |
| 84 | while (i != end) |
| 85 | { |
| 86 | uint32 codepoint = *i++; |
| 87 | |
| 88 | if (!hasGlyph(codepoint)) |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | catch (utf8::exception &e) |
| 93 | { |
| 94 | throw love::Exception("UTF-8 decoding error: %s" , e.what()); |
| 95 | } |
| 96 | |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | float Rasterizer::getKerning(uint32 /*leftglyph*/, uint32 /*rightglyph*/) const |
| 101 | { |
| 102 | return 0.0f; |
| 103 | } |
| 104 | |
| 105 | float Rasterizer::getDPIScale() const |
| 106 | { |
| 107 | return dpiScale; |
| 108 | } |
| 109 | |
| 110 | } // font |
| 111 | } // love |
| 112 | |