mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
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:
@@ -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
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user