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#include "wrap_GlyphData.h"
22
23namespace love
24{
25namespace font
26{
27
28GlyphData *luax_checkglyphdata(lua_State *L, int idx)
29{
30 return luax_checktype<GlyphData>(L, idx);
31}
32
33int w_GlyphData_clone(lua_State *L)
34{
35 GlyphData *t = luax_checkglyphdata(L, 1), *c = nullptr;
36 luax_catchexcept(L, [&](){ c = t->clone(); });
37 luax_pushtype(L, c);
38 c->release();
39 return 1;
40}
41
42int w_GlyphData_getWidth(lua_State *L)
43{
44 GlyphData *t = luax_checkglyphdata(L, 1);
45 lua_pushinteger(L, t->getWidth());
46 return 1;
47}
48
49int w_GlyphData_getHeight(lua_State *L)
50{
51 GlyphData *t = luax_checkglyphdata(L, 1);
52 lua_pushinteger(L, t->getHeight());
53 return 1;
54}
55
56int w_GlyphData_getDimensions(lua_State *L)
57{
58 GlyphData *t = luax_checkglyphdata(L, 1);
59 lua_pushinteger(L, t->getWidth());
60 lua_pushinteger(L, t->getHeight());
61 return 2;
62}
63
64int w_GlyphData_getGlyph(lua_State *L)
65{
66 GlyphData *t = luax_checkglyphdata(L, 1);
67 uint32 glyph = t->getGlyph();
68 lua_pushnumber(L, (lua_Number) glyph);
69 return 1;
70}
71
72int w_GlyphData_getGlyphString(lua_State *L)
73{
74 GlyphData *t = luax_checkglyphdata(L, 1);
75
76 luax_catchexcept(L, [&](){ luax_pushstring(L, t->getGlyphString()); });
77 return 1;
78}
79
80int w_GlyphData_getAdvance(lua_State *L)
81{
82 GlyphData *t = luax_checkglyphdata(L, 1);
83 lua_pushinteger(L, t->getAdvance());
84 return 1;
85}
86
87int w_GlyphData_getBearing(lua_State *L)
88{
89 GlyphData *t = luax_checkglyphdata(L, 1);
90 lua_pushinteger(L, t->getBearingX());
91 lua_pushinteger(L, t->getBearingY());
92 return 2;
93}
94
95int w_GlyphData_getBoundingBox(lua_State *L)
96{
97 GlyphData *t = luax_checkglyphdata(L, 1);
98
99 int minX = t->getMinX();
100 int minY = t->getMinY();
101 int maxX = t->getMaxX();
102 int maxY = t->getMaxY();
103
104 int width = maxX - minX;
105 int height = maxY - minY;
106
107 lua_pushinteger(L, minX);
108 lua_pushinteger(L, minY);
109 lua_pushinteger(L, width);
110 lua_pushinteger(L, height);
111
112 return 4;
113}
114
115int w_GlyphData_getFormat(lua_State *L)
116{
117 GlyphData *t = luax_checkglyphdata(L, 1);
118
119 const char *str;
120 if (!getConstant(t->getFormat(), str))
121 return luax_enumerror(L, "pixel format", str);
122
123 lua_pushstring(L, str);
124 return 1;
125}
126
127const luaL_Reg w_GlyphData_functions[] =
128{
129 { "clone", w_GlyphData_clone },
130 { "getWidth", w_GlyphData_getWidth },
131 { "getHeight", w_GlyphData_getHeight },
132 { "getDimensions", w_GlyphData_getDimensions },
133 { "getGlyph", w_GlyphData_getGlyph },
134 { "getGlyphString", w_GlyphData_getGlyphString },
135 { "getAdvance", w_GlyphData_getAdvance },
136 { "getBearing", w_GlyphData_getBearing },
137 { "getBoundingBox", w_GlyphData_getBoundingBox },
138 { "getFormat", w_GlyphData_getFormat },
139 { 0, 0 }
140};
141
142extern "C" int luaopen_glyphdata(lua_State *L)
143{
144 int ret = luax_register_type(L, &GlyphData::type, data::w_Data_functions, w_GlyphData_functions, nullptr);
145 love::data::luax_rundatawrapper(L, GlyphData::type);
146 return ret;
147}
148
149} // font
150} // love
151