mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 20:20:25 +02:00
updated to latest mobile-common (0cf55b7da58e), removed libtiff, libpng, libmng, devil, jasper, jpeg-8d, added libturbo-jpeg
This commit is contained in:
@@ -40,6 +40,11 @@ class Font : public Module
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Font() {}
|
||||
|
||||
// Implements Module.
|
||||
virtual ModuleType getModuleType() const { return M_FONT; }
|
||||
|
||||
virtual Rasterizer *newRasterizer(Data *data, int size) = 0;
|
||||
virtual Rasterizer *newRasterizer(love::image::ImageData *data, const std::string &glyphs) = 0;
|
||||
virtual Rasterizer *newRasterizer(love::image::ImageData *data, uint32 *glyphs, int length) = 0;
|
||||
|
||||
@@ -39,13 +39,11 @@ ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, i
|
||||
, glyphs(glyphs)
|
||||
, numglyphs(numglyphs)
|
||||
{
|
||||
imageData->retain();
|
||||
load();
|
||||
}
|
||||
|
||||
ImageRasterizer::~ImageRasterizer()
|
||||
{
|
||||
imageData->release();
|
||||
}
|
||||
|
||||
int ImageRasterizer::getLineHeight() const
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
void load();
|
||||
|
||||
// The image data
|
||||
love::image::ImageData *imageData;
|
||||
Object::StrongRef<love::image::ImageData> imageData;
|
||||
|
||||
// The glyphs in the font
|
||||
uint32 *glyphs;
|
||||
|
||||
@@ -51,14 +51,11 @@ TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size)
|
||||
metrics.ascent = s.ascender >> 6;
|
||||
metrics.descent = s.descender >> 6;
|
||||
metrics.height = s.height >> 6;
|
||||
|
||||
data->retain();
|
||||
}
|
||||
|
||||
TrueTypeRasterizer::~TrueTypeRasterizer()
|
||||
{
|
||||
FT_Done_Face(face);
|
||||
data->release();
|
||||
}
|
||||
|
||||
int TrueTypeRasterizer::getLineHeight() const
|
||||
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
FT_Face face;
|
||||
|
||||
// File data
|
||||
Data *data;
|
||||
Object::StrongRef<Data> data;
|
||||
}; // FreetypeRasterizer
|
||||
|
||||
} // freetype
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "font/wrap_GlyphData.h"
|
||||
#include "font/wrap_Rasterizer.h"
|
||||
|
||||
#include "filesystem/wrap_Filesystem.h"
|
||||
|
||||
#include "TrueTypeRasterizer.h"
|
||||
|
||||
namespace love
|
||||
@@ -34,55 +36,55 @@ namespace font
|
||||
namespace freetype
|
||||
{
|
||||
|
||||
static Font *instance = 0;
|
||||
#define instance() (Module::getInstance<Font>(Module::M_FONT))
|
||||
|
||||
int w_newRasterizer(lua_State *L)
|
||||
{
|
||||
// Convert to FileData, if necessary.
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
luax_convobj(L, 1, "filesystem", "newFileData");
|
||||
Rasterizer *t = nullptr;
|
||||
|
||||
Rasterizer *t = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
t = instance->newRasterizer(d, glyphs);
|
||||
}
|
||||
else if (luax_istype(L, 1, DATA_T))
|
||||
{
|
||||
Data *d = luax_checkdata(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
t = instance->newRasterizer(d, size);
|
||||
}
|
||||
)
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
luax_catchexcept(L, [&](){ t = instance()->newRasterizer(d, glyphs); });
|
||||
}
|
||||
else if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
{
|
||||
love::filesystem::FileData *d = love::filesystem::luax_getfiledata(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newRasterizer(d, size); },
|
||||
[&]() { d->release(); }
|
||||
);
|
||||
}
|
||||
else
|
||||
return luaL_argerror(L, 1, "expected ImageData, filename, or FileData");
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newGlyphData(lua_State *L)
|
||||
{
|
||||
Rasterizer *r = luax_checkrasterizer(L, 1);
|
||||
GlyphData *t = 0;
|
||||
GlyphData *t = nullptr;
|
||||
|
||||
// newGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
std::string glyph = luax_checkstring(L, 2);
|
||||
|
||||
EXCEPT_GUARD(t = instance->newGlyphData(r, glyph);)
|
||||
luax_catchexcept(L, [&](){ t = instance()->newGlyphData(r, glyph); });
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 g = (uint32) luaL_checknumber(L, 2);
|
||||
t = instance->newGlyphData(r, g);
|
||||
t = instance()->newGlyphData(r, g);
|
||||
}
|
||||
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -103,9 +105,10 @@ static const lua_CFunction types[] =
|
||||
|
||||
extern "C" int luaopen_love_font(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
Font *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new Font();)
|
||||
luax_catchexcept(L, [&](){ instance = new Font(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -64,7 +64,7 @@ int w_GlyphData_getGlyphString(lua_State *L)
|
||||
{
|
||||
GlyphData *t = luax_checkglyphdata(L, 1);
|
||||
|
||||
EXCEPT_GUARD(luax_pushstring(L, t->getGlyphString());)
|
||||
luax_catchexcept(L, [&](){ luax_pushstring(L, t->getGlyphString()); });
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
Rasterizer *t = luax_checkrasterizer(L, 1);
|
||||
GlyphData *g = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
luax_catchexcept(L, [&]() {
|
||||
// getGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
@@ -84,9 +84,10 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
uint32 glyph = (uint32) luaL_checknumber(L, 2);
|
||||
g = t->getGlyphData(glyph);
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
|
||||
g->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
|
||||
int count = lua_gettop(L) - 1;
|
||||
count = count < 1 ? 1 : count;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
luax_catchexcept(L, [&]() {
|
||||
for (int i = 2; i < count + 2; i++)
|
||||
{
|
||||
if (lua_type(L, i) == LUA_TSTRING)
|
||||
@@ -117,7 +118,7 @@ int w_Rasterizer_hasGlyphs(lua_State *L)
|
||||
if (!hasglyph)
|
||||
break;
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
luax_pushboolean(L, hasglyph);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user