| 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 | #ifndef LOVE_FONT_GLYPH_DATA_H |
| 22 | #define LOVE_FONT_GLYPH_DATA_H |
| 23 | |
| 24 | // LOVE |
| 25 | #include "common/config.h" |
| 26 | #include "common/Data.h" |
| 27 | #include "common/Exception.h" |
| 28 | #include "common/StringMap.h" |
| 29 | #include "common/int.h" |
| 30 | #include "common/pixelformat.h" |
| 31 | |
| 32 | // stdlib |
| 33 | #include <string> |
| 34 | |
| 35 | namespace love |
| 36 | { |
| 37 | namespace font |
| 38 | { |
| 39 | |
| 40 | /** |
| 41 | * Holds the specific glyph data. |
| 42 | **/ |
| 43 | struct GlyphMetrics |
| 44 | { |
| 45 | int height; |
| 46 | int width; |
| 47 | int advance; |
| 48 | int bearingX; |
| 49 | int bearingY; |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * Holds data for a specic glyph object. |
| 54 | **/ |
| 55 | class GlyphData : public Data |
| 56 | { |
| 57 | public: |
| 58 | |
| 59 | static love::Type type; |
| 60 | |
| 61 | GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, PixelFormat f); |
| 62 | GlyphData(const GlyphData &c); |
| 63 | virtual ~GlyphData(); |
| 64 | |
| 65 | // Implements Data. |
| 66 | GlyphData *clone() const; |
| 67 | void *getData() const; |
| 68 | size_t getSize() const; |
| 69 | |
| 70 | /** |
| 71 | * Gets the data starting at a specific pixel in the glyph. |
| 72 | **/ |
| 73 | void *getData(int x, int y) const; |
| 74 | |
| 75 | /** |
| 76 | * Gets the size in bytes of each pixel in the glyph. |
| 77 | **/ |
| 78 | size_t getPixelSize() const; |
| 79 | |
| 80 | /** |
| 81 | * Gets the height of the glyph. |
| 82 | **/ |
| 83 | virtual int getHeight() const; |
| 84 | |
| 85 | /** |
| 86 | * Gets the width of the glyph. |
| 87 | **/ |
| 88 | virtual int getWidth() const; |
| 89 | |
| 90 | /** |
| 91 | * Gets the glyph codepoint itself. |
| 92 | **/ |
| 93 | uint32 getGlyph() const; |
| 94 | |
| 95 | /** |
| 96 | * Gets the glyph as a UTF-8 string (instead of a UTF-8 code point.) |
| 97 | **/ |
| 98 | std::string getGlyphString() const; |
| 99 | |
| 100 | /** |
| 101 | * Gets the advance (the space the glyph takes up) of the glyph. |
| 102 | **/ |
| 103 | int getAdvance() const; |
| 104 | |
| 105 | /** |
| 106 | * Gets bearing (the spacing from origin) along the x-axis of the glyph. |
| 107 | **/ |
| 108 | int getBearingX() const; |
| 109 | |
| 110 | /** |
| 111 | * Gets bearing (the spacing from origin) along the y-axis of the glyph. |
| 112 | **/ |
| 113 | int getBearingY() const; |
| 114 | |
| 115 | /** |
| 116 | * Gets the min x value of the glyph. |
| 117 | **/ |
| 118 | int getMinX() const; |
| 119 | |
| 120 | /** |
| 121 | * Gets the min y value of the glyph. |
| 122 | **/ |
| 123 | int getMinY() const; |
| 124 | |
| 125 | /** |
| 126 | * Gets the max x value of the glyph. |
| 127 | **/ |
| 128 | int getMaxX() const; |
| 129 | |
| 130 | /** |
| 131 | * Gets the max y value of the glyph. |
| 132 | **/ |
| 133 | int getMaxY() const; |
| 134 | |
| 135 | /** |
| 136 | * Gets the format of the glyph data. |
| 137 | **/ |
| 138 | PixelFormat getFormat() const; |
| 139 | |
| 140 | private: |
| 141 | |
| 142 | // The glyph codepoint itself. |
| 143 | uint32 glyph; |
| 144 | |
| 145 | // Glyph metrics. |
| 146 | GlyphMetrics metrics; |
| 147 | |
| 148 | // Glyph texture data. |
| 149 | uint8 *data; |
| 150 | |
| 151 | // The format the data's in. |
| 152 | PixelFormat format; |
| 153 | |
| 154 | }; // GlyphData |
| 155 | |
| 156 | } // font |
| 157 | } // love |
| 158 | |
| 159 | #endif // LOVE_FONT_GLYPH_DATA_H |
| 160 | |