Added FontData class, preparing for overhauling love.graphics' Font class

This commit is contained in:
Bill Meltsner
2010-04-14 20:31:36 -04:00
parent 80bea88c9f
commit e5c3f3ae02
9 changed files with 252 additions and 26 deletions
+2
View File
@@ -39,6 +39,7 @@ namespace love
FILESYSTEM_FILE_DATA_ID,
// Font
FONT_FONT_DATA_ID,
FONT_GLYPH_DATA_ID,
FONT_RASTERIZER_ID,
@@ -102,6 +103,7 @@ namespace love
const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T;
const bits FILESYSTEM_FILE_DATA_T = (bits(1) << FILESYSTEM_FILE_DATA_ID) | DATA_T;
const bits FONT_FONT_DATA_T = (bits(1) << FONT_FONT_DATA_ID) | DATA_T;
const bits FONT_GLYPH_DATA_T = (bits(1) << FONT_GLYPH_DATA_ID) | DATA_T;
const bits FONT_RASTERIZER_T = (bits(1) << FONT_RASTERIZER_ID) | OBJECT_T;
+66
View File
@@ -0,0 +1,66 @@
/**
* 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.
**/
#include "FontData.h"
namespace love
{
namespace font
{
FontData::FontData(Rasterizer * raster)
: height(0)
{
data = new GlyphData *[MAX_CHARS];
for (unsigned int i = 0; i < MAX_CHARS; i++) {
data[i] = raster->getGlyphData(i);
int h = data[i]->getHeight();
if (h > height) height = h;
}
}
FontData::~FontData()
{
delete[] data;
}
void * FontData::getData() const
{
return (void *)data;
}
int FontData::getSize() const
{
return MAX_CHARS;
}
GlyphData * FontData::getGlyph(unsigned short glyph) const
{
return data[glyph];
}
int FontData::getHeight() const
{
return height;
}
} // font
} // love
+56
View File
@@ -0,0 +1,56 @@
/**
* 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_DATA_H
#define LOVE_FONT_FONT_DATA_H
// LOVE
#include <common/Data.h>
#include "GlyphData.h"
#include "Rasterizer.h"
namespace love
{
namespace font
{
class FontData : public Data
{
public:
FontData(Rasterizer * raster);
virtual ~FontData();
// Implements Data.
void * getData() const;
int getSize() const;
GlyphData * getGlyph(unsigned short glyph) const;
int getHeight() const;
static const unsigned int MAX_CHARS = 256;
private:
GlyphData ** data;
int height;
};
} // font
} // love
#endif // LOVE_FONT_FONT_DATA_H
@@ -1,21 +1,21 @@
/**
* 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.
/**
* 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.
**/
// LOVE
@@ -99,6 +99,9 @@ namespace freetype
dst[2*i] = dst[2*i+1] = bitmap.buffer[i];
}
}
// Having copied the data over, we can destroy the glyph
FT_Done_Glyph(ftglyph);
// Return data
return glyphData;
+9 -7
View File
@@ -20,6 +20,7 @@
#include "wrap_Font.h"
#include <font/wrap_FontData.h>
#include <font/wrap_GlyphData.h>
#include <font/wrap_Rasterizer.h>
@@ -61,6 +62,7 @@ namespace freetype
};
static const lua_CFunction types[] = {
luaopen_fontdata,
luaopen_glyphdata,
luaopen_rasterizer,
0
@@ -82,13 +84,13 @@ namespace freetype
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "font";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
WrappedModule w;
w.module = instance;
w.name = "font";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
+46
View File
@@ -0,0 +1,46 @@
/**
* 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.
**/
#include "wrap_FontData.h"
#include <common/wrap_Data.h>
namespace love
{
namespace font
{
FontData * luax_checkfontdata(lua_State * L, int idx)
{
return luax_checktype<FontData>(L, idx, "FontData", FONT_FONT_DATA_T);
}
static const luaL_Reg functions[] = {
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ 0, 0 }
};
int luaopen_fontdata(lua_State * L)
{
return luax_register_type(L, "FontData", functions);
}
} // font
} // love
+39
View File
@@ -0,0 +1,39 @@
/**
* 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_WRAP_FONT_DATA_H
#define LOVE_FONT_WRAP_FONT_DATA_H
// LOVE
#include <common/runtime.h>
#include "FontData.h"
namespace love
{
namespace font
{
FontData * luax_checkfontdata(lua_State * L, int idx);
int luaopen_fontdata(lua_State * L);
} // font
} // love
#endif // LOVE_FONT_WRAP_FONT_DATA_H
+1 -1
View File
@@ -40,5 +40,5 @@ namespace font
return luax_register_type(L, "GlyphData", functions);
}
} // sound
} // font
} // love