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_RASTERIZER_H |
22 | #define LOVE_FONT_RASTERIZER_H |
23 | |
24 | // LOVE |
25 | #include "common/Object.h" |
26 | #include "common/int.h" |
27 | #include "GlyphData.h" |
28 | |
29 | namespace love |
30 | { |
31 | namespace font |
32 | { |
33 | |
34 | /** |
35 | * Holds the specific font metrics. |
36 | **/ |
37 | struct FontMetrics |
38 | { |
39 | int advance; |
40 | int ascent; |
41 | int descent; |
42 | int height; |
43 | }; |
44 | |
45 | /** |
46 | * Holds data for a font object. |
47 | **/ |
48 | class Rasterizer : public Object |
49 | { |
50 | public: |
51 | |
52 | enum DataType |
53 | { |
54 | DATA_TRUETYPE, |
55 | DATA_IMAGE, |
56 | }; |
57 | |
58 | static love::Type type; |
59 | |
60 | virtual ~Rasterizer(); |
61 | |
62 | /** |
63 | * Gets the max height of the glyphs. |
64 | **/ |
65 | virtual int getHeight() const; |
66 | |
67 | /** |
68 | * Gets the max advance of the glyphs. |
69 | **/ |
70 | virtual int getAdvance() const; |
71 | |
72 | /** |
73 | * Gets the max ascent (height above baseline) for the font. |
74 | **/ |
75 | virtual int getAscent() const; |
76 | |
77 | /** |
78 | * Gets the max descent (height below baseline) for the font. |
79 | **/ |
80 | virtual int getDescent() const; |
81 | |
82 | /** |
83 | * Gets the line height of the font. |
84 | **/ |
85 | virtual int getLineHeight() const = 0; |
86 | |
87 | /** |
88 | * Gets a specific glyph. |
89 | * @param glyph The (UNICODE) glyph codepoint to get data for. |
90 | **/ |
91 | virtual GlyphData *getGlyphData(uint32 glyph) const = 0; |
92 | |
93 | /** |
94 | * Gets a specific glyph. |
95 | * @param text The (UNICODE) glyph character to get the data for. |
96 | **/ |
97 | virtual GlyphData *getGlyphData(const std::string &text) const; |
98 | |
99 | /** |
100 | * Gets the number of glyphs the rasterizer has data for. |
101 | **/ |
102 | virtual int getGlyphCount() const = 0; |
103 | |
104 | /** |
105 | * Gets whether this Rasterizer has a specific glyph. |
106 | * @param glyph The (UNICODE) glyph codepoint. |
107 | **/ |
108 | virtual bool hasGlyph(uint32 glyph) const = 0; |
109 | |
110 | /** |
111 | * Gets whether this Rasterizer has all the glyphs in a string. |
112 | * @param text The (UTF-8) string. |
113 | **/ |
114 | virtual bool hasGlyphs(const std::string &text) const; |
115 | |
116 | /** |
117 | * Gets the amount of horizontal kerning between two glyphs. |
118 | **/ |
119 | virtual float getKerning(uint32 leftglyph, uint32 rightglyph) const; |
120 | |
121 | virtual DataType getDataType() const = 0; |
122 | |
123 | float getDPIScale() const; |
124 | |
125 | protected: |
126 | |
127 | FontMetrics metrics; |
128 | float dpiScale; |
129 | |
130 | }; // Rasterizer |
131 | |
132 | } // font |
133 | } // love |
134 | |
135 | #endif // LOVE_FONT_RASTERIZER_H |
136 | |