Made font module officially properly exposed to Lua

This commit is contained in:
Bill Meltsner
2010-04-15 10:17:42 -04:00
parent e3a5aacd5a
commit 76dc50a419
8 changed files with 911 additions and 828 deletions
+57
View File
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2006-2010 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_FONT_FONT_H
#define LOVE_FONT_FONT_H
// LOVE
#include "FontData.h"
#include "Rasterizer.h"
#include <image/ImageData.h>
#include <common/Module.h>
// STD
#include <string>
namespace love
{
namespace font
{
class Font : public Module
{
public:
virtual Rasterizer * newRasterizer(Data * data, int size) = 0;
virtual Rasterizer * newRasterizer(love::image::ImageData * data, std::string glyphs) = 0;
virtual Rasterizer * newRasterizer(love::image::ImageData * data, unsigned short * glyphs, int length) = 0;
virtual GlyphData * newGlyphData(Rasterizer * r, unsigned short glyph) = 0;
virtual FontData * newFontData(Rasterizer * r) = 0;
// Implement Module
virtual const char * getName() const = 0;
}; // Font
} // font
} // love
#endif // LOVE_FONT_FONT_H
+5
View File
@@ -64,6 +64,11 @@ namespace freetype
{
return r->getGlyphData(glyph);
}
FontData * Font::newFontData(Rasterizer * r)
{
return new FontData(r);
}
const char * Font::getName() const
{
+7 -10
View File
@@ -22,9 +22,7 @@
#define LOVE_FONT_FREETYPE_FONT_H
// LOVE
#include <font/Rasterizer.h>
#include <image/ImageData.h>
#include <common/Module.h>
#include <font/Font.h>
// FreeType2
#ifdef LOVE_MACOSX
@@ -37,9 +35,6 @@
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>
// STD
#include <string>
namespace love
{
namespace font
@@ -47,7 +42,7 @@ namespace font
namespace freetype
{
class Font : public Module
class Font : public love::font::Font
{
private:
@@ -57,17 +52,19 @@ namespace freetype
public:
Font();
/**
* Destructor.
**/
virtual ~Font();
// Implements Font
Rasterizer * newRasterizer(Data * data, int size);
Rasterizer * newRasterizer(love::image::ImageData * data, std::string glyphs);
Rasterizer * newRasterizer(love::image::ImageData * data, unsigned short * glyphs, int length);
GlyphData * newGlyphData(Rasterizer * r, unsigned short glyph);
FontData * newFontData(Rasterizer * r);
// Implement Module
const char * getName() const;
+24 -4
View File
@@ -20,6 +20,8 @@
#include "wrap_Font.h"
#include "Font.h"
#include <font/wrap_FontData.h>
#include <font/wrap_GlyphData.h>
#include <font/wrap_Rasterizer.h>
@@ -36,10 +38,19 @@ namespace freetype
int w_newRasterizer(lua_State * L)
{
Data * d = luax_checkdata(L, 1);
int size = luaL_checkint(L, 2);
Rasterizer * t = instance->newRasterizer(d, size);
Rasterizer * t = NULL;
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);
}
luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
return 1;
}
@@ -53,11 +64,20 @@ namespace freetype
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
return 1;
}
int w_newFontData(lua_State * L)
{
Rasterizer * r = luax_checkrasterizer(L, 1);
FontData * f = instance->newFontData(r);
luax_newtype(L, "FontData", FONT_FONT_DATA_T, (void*)f);
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "newRasterizer", w_newRasterizer },
{ "newGlyphData", w_newGlyphData },
{ "newFontData", w_newFontData },
{ 0, 0 }
};
+2 -2
View File
@@ -23,8 +23,7 @@
// LOVE
#include <common/config.h>
#include "Font.h"
#include "wrap_Font.h"
#include <common/runtime.h>
namespace love
{
@@ -34,6 +33,7 @@ namespace freetype
{
int w_newRasterizer(lua_State * L);
int w_newGlyphData(lua_State * L);
int w_newFontData(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_font(lua_State * L);
} // freetype