diff --git a/src/modules/font/Font.cpp b/src/modules/font/Font.cpp index a65eb1f9f..eab45e8d1 100644 --- a/src/modules/font/Font.cpp +++ b/src/modules/font/Font.cpp @@ -54,7 +54,7 @@ Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const return new BMFontRasterizer(fontdef, images); } -Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text) +Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text, int extraspacing) { std::vector glyphs; glyphs.reserve(text.size()); @@ -72,12 +72,12 @@ Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::st throw love::Exception("UTF-8 decoding error: %s", e.what()); } - return newImageRasterizer(data, &glyphs[0], (int) glyphs.size()); + return newImageRasterizer(data, &glyphs[0], (int) glyphs.size(), extraspacing); } -Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs) +Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing) { - return new ImageRasterizer(data, glyphs, numglyphs); + return new ImageRasterizer(data, glyphs, numglyphs, extraspacing); } GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text) diff --git a/src/modules/font/Font.h b/src/modules/font/Font.h index faaa412fc..81558776f 100644 --- a/src/modules/font/Font.h +++ b/src/modules/font/Font.h @@ -52,8 +52,8 @@ public: virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &images); - virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs); - virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length); + virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs, int extraspacing); + virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length, int extraspacing); virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph); virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph); diff --git a/src/modules/font/ImageRasterizer.cpp b/src/modules/font/ImageRasterizer.cpp index 99e43dcf7..18586748a 100644 --- a/src/modules/font/ImageRasterizer.cpp +++ b/src/modules/font/ImageRasterizer.cpp @@ -34,10 +34,11 @@ inline bool equal(const love::image::pixel &a, const love::image::pixel &b) return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a); } -ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs) +ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing) : imageData(data) , glyphs(glyphs) , numglyphs(numglyphs) + , extraSpacing(extraspacing) { load(); } @@ -60,7 +61,7 @@ GlyphData *ImageRasterizer::getGlyphData(uint32 glyph) const if (it != imageGlyphs.end()) { gm.width = it->second.width; - gm.advance = it->second.width; + gm.advance = it->second.width + extraSpacing; } gm.height = metrics.height; diff --git a/src/modules/font/ImageRasterizer.h b/src/modules/font/ImageRasterizer.h index 090efab75..a02116ad2 100644 --- a/src/modules/font/ImageRasterizer.h +++ b/src/modules/font/ImageRasterizer.h @@ -39,7 +39,7 @@ namespace font class ImageRasterizer : public Rasterizer { public: - ImageRasterizer(love::image::ImageData *imageData, uint32 *glyphs, int numglyphs); + ImageRasterizer(love::image::ImageData *imageData, uint32 *glyphs, int numglyphs, int extraspacing); virtual ~ImageRasterizer(); // Implement Rasterizer @@ -49,6 +49,14 @@ public: virtual bool hasGlyph(uint32 glyph) const; private: + + // Information about a glyph in the ImageData + struct ImageGlyphData + { + int x; + int width; + }; + // Load all the glyph positions into memory void load(); @@ -61,12 +69,7 @@ private: // Number of glyphs in the font int numglyphs; - // Information about a glyph in the ImageData - struct ImageGlyphData - { - int x; - int width; - }; + int extraSpacing; std::map imageGlyphs; diff --git a/src/modules/font/wrap_Font.cpp b/src/modules/font/wrap_Font.cpp index 391f76acc..103827870 100644 --- a/src/modules/font/wrap_Font.cpp +++ b/src/modules/font/wrap_Font.cpp @@ -162,8 +162,9 @@ int w_newImageRasterizer(lua_State *L) image::ImageData *d = luax_checktype(L, 1, IMAGE_IMAGE_DATA_ID); std::string glyphs = luax_checkstring(L, 2); + int extraspacing = luaL_optint(L, 3, 0); - luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs); }); + luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); }); luax_pushtype(L, FONT_RASTERIZER_ID, t); t->release(); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index d50916784..80367a3e7 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -339,9 +339,13 @@ int w_newImageFont(lua_State *L) // Convert to Rasterizer if necessary. if (!luax_istype(L, 1, FONT_RASTERIZER_ID)) { - luaL_checkstring(L, 2); - int idxs[] = {1, 2}; - luax_convobj(L, idxs, 2, "font", "newImageRasterizer"); + luaL_checktype(L, 2, LUA_TSTRING); + + std::vector idxs; + for (int i = 0; i < lua_gettop(L); i++) + idxs.push_back(i + 1); + + luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newImageRasterizer"); } love::font::Rasterizer *rasterizer = luax_checktype(L, 1, FONT_RASTERIZER_ID);