Moved the default Font logic from the graphics.lua script to the Graphics and Font module C++ code. Moved love.graphics.setNewFont from the graphics.lua script to the Graphics module Lua wrapper code. Moved the Vera.ttf data from the graphics.lua script to its own file inside the Font module.

This commit is contained in:
Alex Szpakowski
2015-01-31 01:10:38 -04:00
parent 72f98b9c8f
commit 665cdc4ae7
13 changed files with 5593 additions and 7471 deletions
+1
View File
@@ -45,6 +45,7 @@ public:
// Implements Module.
virtual ModuleType getModuleType() const { return M_FONT; }
virtual Rasterizer *newRasterizer(int size) = 0;
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;
File diff suppressed because it is too large Load Diff
+16 -1
View File
@@ -25,6 +25,8 @@
#include "libraries/utf8/utf8.h"
#include <string.h>
namespace love
{
namespace font
@@ -32,10 +34,13 @@ namespace font
namespace freetype
{
// Default TrueType font.
#include "font/Vera.ttf.h"
Font::Font()
{
if (FT_Init_FreeType(&library))
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed\n");
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed");
}
Font::~Font()
@@ -43,6 +48,16 @@ Font::~Font()
FT_Done_FreeType(library);
}
Rasterizer *Font::newRasterizer(int size)
{
StrongRef<filesystem::FileData> data(new filesystem::FileData(sizeof(Vera_ttf), "Vera.ttf"));
data->release();
memcpy(data->getData(), Vera_ttf, sizeof(Vera_ttf));
return new TrueTypeRasterizer(library, data.get(), size);
}
Rasterizer *Font::newRasterizer(Data *data, int size)
{
return new TrueTypeRasterizer(library, data, size);
+1
View File
@@ -52,6 +52,7 @@ public:
virtual ~Font();
// Implements Font
Rasterizer *newRasterizer(int size);
Rasterizer *newRasterizer(Data *data, int size);
Rasterizer *newRasterizer(love::image::ImageData *data, const std::string &text);
Rasterizer *newRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs);
+7 -3
View File
@@ -49,17 +49,21 @@ int w_newRasterizer(lua_State *L)
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))
else if (lua_type(L, 1) == LUA_TSTRING || 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);
int size = luaL_optint(L, 2, 12);
luax_catchexcept(L,
[&]() { t = instance()->newRasterizer(d, size); },
[&]() { d->release(); }
);
}
else
return luaL_argerror(L, 1, "expected ImageData, filename, or FileData");
{
// Default font (Vera.)
int size = luaL_optint(L, 1, 12);
luax_catchexcept(L, [&]() { t = instance()->newRasterizer(size); });
}
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
t->release();