diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index 722c43db1..7390b956b 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -26,6 +26,8 @@ A93E6E5510420B57007D418B /* Lua.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; }; A93E6EED10420BA8007D418B /* love.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A3410420AC0007D418B /* love.cpp */; }; A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */; }; + A946D3BB117681BD005E1462 /* FontData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946D3BA117681BC005E1462 /* FontData.cpp */; }; + A946D3C611768D69005E1462 /* wrap_FontData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946D3C511768D69005E1462 /* wrap_FontData.cpp */; }; A946D67F104248DA002BF36C /* Reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69EA10420ABF007D418B /* Reference.cpp */; }; A946D680104248DA002BF36C /* Matrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E310420ABF007D418B /* Matrix.cpp */; }; A946D681104248DA002BF36C /* Object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E810420ABF007D418B /* Object.cpp */; }; @@ -576,6 +578,10 @@ A93E6E5310420B57007D418B /* Lua.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lua.framework; path = /Library/Frameworks/Lua.framework; sourceTree = ""; }; A946CE801172BCD6005E1462 /* wrap_EncodedImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_EncodedImageData.h; sourceTree = ""; }; A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_EncodedImageData.cpp; sourceTree = ""; }; + A946D3B9117681BC005E1462 /* FontData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontData.h; sourceTree = ""; }; + A946D3BA117681BC005E1462 /* FontData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontData.cpp; sourceTree = ""; }; + A946D3C411768D69005E1462 /* wrap_FontData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_FontData.h; sourceTree = ""; }; + A946D3C511768D69005E1462 /* wrap_FontData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_FontData.cpp; sourceTree = ""; }; A968F0C61083A07B00A895AA /* EnumMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumMap.h; sourceTree = ""; }; A968F0C71083A07C00A895AA /* StringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringMap.h; sourceTree = ""; }; A968F0CE1083A9A900A895AA /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = ""; }; @@ -928,6 +934,8 @@ A93E6A6F10420AC1007D418B /* font */ = { isa = PBXGroup; children = ( + A946D3BA117681BC005E1462 /* FontData.cpp */, + A946D3B9117681BC005E1462 /* FontData.h */, A93E6A7010420AC1007D418B /* freetype */, A93E6A7710420AC2007D418B /* GlyphData.cpp */, A93E6A7810420AC2007D418B /* GlyphData.h */, @@ -935,6 +943,8 @@ A93E6A7A10420AC2007D418B /* ImageRasterizer.h */, A93E6A7B10420AC2007D418B /* Rasterizer.cpp */, A93E6A7C10420AC2007D418B /* Rasterizer.h */, + A946D3C511768D69005E1462 /* wrap_FontData.cpp */, + A946D3C411768D69005E1462 /* wrap_FontData.h */, A93E6A7D10420AC2007D418B /* wrap_GlyphData.cpp */, A93E6A7E10420AC2007D418B /* wrap_GlyphData.h */, A93E6A7F10420AC2007D418B /* wrap_Rasterizer.cpp */, @@ -1656,6 +1666,8 @@ A986DEB5113249A800810279 /* Thread.cpp in Sources */, A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */, A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */, + A946D3BB117681BD005E1462 /* FontData.cpp in Sources */, + A946D3C611768D69005E1462 /* wrap_FontData.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/common/types.h b/src/common/types.h index 249c92d03..063135094 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -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; diff --git a/src/modules/font/FontData.cpp b/src/modules/font/FontData.cpp new file mode 100644 index 000000000..8b80881f4 --- /dev/null +++ b/src/modules/font/FontData.cpp @@ -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 \ No newline at end of file diff --git a/src/modules/font/FontData.h b/src/modules/font/FontData.h new file mode 100644 index 000000000..2f864cfee --- /dev/null +++ b/src/modules/font/FontData.h @@ -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 + +#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 \ No newline at end of file diff --git a/src/modules/font/freetype/TrueTypeRasterizer.cpp b/src/modules/font/freetype/TrueTypeRasterizer.cpp index 17ef510c8..43163cd63 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.cpp +++ b/src/modules/font/freetype/TrueTypeRasterizer.cpp @@ -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; diff --git a/src/modules/font/freetype/wrap_Font.cpp b/src/modules/font/freetype/wrap_Font.cpp index 681dc093a..884fe760b 100644 --- a/src/modules/font/freetype/wrap_Font.cpp +++ b/src/modules/font/freetype/wrap_Font.cpp @@ -20,6 +20,7 @@ #include "wrap_Font.h" +#include #include #include @@ -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); } diff --git a/src/modules/font/wrap_FontData.cpp b/src/modules/font/wrap_FontData.cpp new file mode 100644 index 000000000..75ba11eb1 --- /dev/null +++ b/src/modules/font/wrap_FontData.cpp @@ -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 + +namespace love +{ +namespace font +{ + FontData * luax_checkfontdata(lua_State * L, int idx) + { + return luax_checktype(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 diff --git a/src/modules/font/wrap_FontData.h b/src/modules/font/wrap_FontData.h new file mode 100644 index 000000000..a66ea7e49 --- /dev/null +++ b/src/modules/font/wrap_FontData.h @@ -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 + +#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 diff --git a/src/modules/font/wrap_GlyphData.cpp b/src/modules/font/wrap_GlyphData.cpp index 5e6188bb3..73c9aa462 100644 --- a/src/modules/font/wrap_GlyphData.cpp +++ b/src/modules/font/wrap_GlyphData.cpp @@ -40,5 +40,5 @@ namespace font return luax_register_type(L, "GlyphData", functions); } -} // sound +} // font } // love