From 2ad1712eafa11f90a16f0d40e53e2646374762a7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 20 Dec 2015 19:25:09 -0500 Subject: [PATCH] Font:getWrap can now accept a colored text table in the same format as what's accepted by love.graphics.print. Resolves issue #1108. The returned table of strings still has no color information. --- src/modules/graphics/opengl/Font.cpp | 8 ++++---- src/modules/graphics/opengl/Font.h | 2 +- src/modules/graphics/opengl/wrap_Font.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index d98372eca..404bd85d3 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -901,13 +901,13 @@ void Font::getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::ve } } -void Font::getWrap(const std::string &text, float wraplimit, std::vector &lines, std::vector *linewidths) +void Font::getWrap(const std::vector &text, float wraplimit, std::vector &lines, std::vector *linewidths) { - ColoredCodepoints codepoints; - getCodepointsFromString(text, codepoints.cps); + ColoredCodepoints cps; + getCodepointsFromString(text, cps); std::vector codepointlines; - getWrap(codepoints, wraplimit, codepointlines, linewidths); + getWrap(cps, wraplimit, codepointlines, linewidths); std::string line; diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index 3f65d7772..df5fcd90e 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -160,7 +160,7 @@ public: * @param max_width Optional output of the maximum width * Returns a vector with the lines. **/ - void getWrap(const std::string &text, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); + void getWrap(const std::vector &text, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); void getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::vector &lines, std::vector *line_widths = nullptr); /** diff --git a/src/modules/graphics/opengl/wrap_Font.cpp b/src/modules/graphics/opengl/wrap_Font.cpp index d449925bb..b47dabde5 100644 --- a/src/modules/graphics/opengl/wrap_Font.cpp +++ b/src/modules/graphics/opengl/wrap_Font.cpp @@ -21,6 +21,7 @@ // LOVE #include "common/config.h" #include "wrap_Font.h" +#include "wrap_Text.h" // C++ #include @@ -56,13 +57,16 @@ int w_Font_getWidth(lua_State *L) int w_Font_getWrap(lua_State *L) { Font *t = luax_checkfont(L, 1); - const char *str = luaL_checkstring(L, 2); + + std::vector text; + luax_checkcoloredstring(L, 2, text); + float wrap = (float) luaL_checknumber(L, 3); int max_width = 0; std::vector lines; std::vector widths; - luax_catchexcept(L, [&]() { t->getWrap(str, wrap, lines, &widths); }); + luax_catchexcept(L, [&]() { t->getWrap(text, wrap, lines, &widths); }); for (int width : widths) max_width = std::max(max_width, width);