diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 1f1f387d..dfd12275 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -7,6 +7,7 @@ #include "Constants.h" #include "FileSystemUtils.h" #include "Graphics.h" +#include "Localization.h" #include "UtilityClass.h" #include "XMLUtils.h" @@ -174,6 +175,7 @@ static void load_font(Font* f, const char* name) * font.txt takes priority over in the XML. * If neither exist, it's just ASCII. */ bool charset_loaded = false; + bool special_loaded = false; unsigned char* charmap = NULL; size_t length; if (FILESYSTEM_areAssetsInSameRealDir(name_png, name_txt)) @@ -259,6 +261,7 @@ static void load_font(Font* f, const char* name) } } } + special_loaded = true; } } @@ -266,11 +269,25 @@ static void load_font(Font* f, const char* name) { /* If we don't have font.txt and no tag either, * this font is 2.2-and-below-style plain ASCII. */ - for (uint8_t codepoint = 0x00; codepoint < 0x80; codepoint++) + for (uint32_t codepoint = 0x00; codepoint < 0x80; codepoint++) { add_glyphinfo(f, codepoint, codepoint); } } + + if (!special_loaded && f->glyph_w == 8 && f->glyph_h == 8) + { + /* If we don't have , and the font is 8x8, + * 0x00-0x1F will be less wide because that's how it has always been. */ + for (uint32_t codepoint = 0x00; codepoint < 0x20; codepoint++) + { + GlyphInfo* glyph = get_glyphinfo(f, codepoint); + if (glyph != NULL) + { + glyph->advance = 6; + } + } + } } void load_main(void) @@ -442,4 +459,63 @@ void print( } } +int print_wrap( + const uint32_t flags, + const int x, + int y, + const std::string& text, + const uint8_t r, + const uint8_t g, + const uint8_t b, + int linespacing /*= -1*/, + int maxwidth /*= -1*/ +) +{ + if (linespacing == -1) + { + linespacing = 10; + } + linespacing = SDL_max(linespacing, loc::get_langmeta()->font_h); + + if (maxwidth == -1) + { + maxwidth = 304; + } + + // TODO look through all the flags + + const char* str = text.c_str(); + // This could fit 64 non-BMP characters onscreen, should be plenty + char buffer[256]; + size_t start = 0; + + if (graphics.flipmode) + { + // Correct for the height of the resulting print. + size_t len = 0; + while (graphics.next_wrap(&start, &len, &str[start], maxwidth)) + { + y += linespacing; + } + y -= linespacing; + start = 0; + } + + while (graphics.next_wrap_s(buffer, sizeof(buffer), &start, str, maxwidth)) + { + print(flags, x, y, buffer, r, g, b); + + if (graphics.flipmode) + { + y -= linespacing; + } + else + { + y += linespacing; + } + } + + return y + linespacing; +} + } // namespace font diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index c9e91a93..6ebeb845 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -106,7 +106,23 @@ void destroy(void); int get_advance(const Font* f, uint32_t codepoint); // TODO de-api -void print(uint32_t flags, int x, int y, const std::string& text, uint8_t r, uint8_t g, uint8_t b); +void print( + uint32_t flags, + int x, + int y, + const std::string& text, + uint8_t r, uint8_t g, uint8_t b +); + +int print_wrap( + uint32_t flags, + int x, + int y, + const std::string& text, + uint8_t r, uint8_t g, uint8_t b, + int linespacing = -1, + int maxwidth = -1 +); } // namespace font diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 58282ca6..1162e188 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -443,7 +443,7 @@ bool Graphics::next_wrap_s( int Graphics::PrintWrap( const int x, int y, - std::string s, + const std::string& text, const int r, const int g, const int b, @@ -451,50 +451,11 @@ int Graphics::PrintWrap( int linespacing /*= -1*/, int maxwidth /*= -1*/ ) { - if (linespacing == -1) - { - linespacing = 10; - } - linespacing = SDL_max(linespacing, loc::get_langmeta()->font_h); - - if (maxwidth == -1) - { - maxwidth = 304; - } - - const char* str = s.c_str(); - /* Screen width is 320 pixels. The shortest a char can be is 6 pixels wide. - * 320 / 6 is 54, rounded up. 4 bytes per char. */ - char buffer[54*4 + 1]; - size_t start = 0; - - if (flipmode) - { - /* Correct for the height of the resulting print. */ - size_t len = 0; - while (next_wrap(&start, &len, &str[start], maxwidth)) - { - y += linespacing; - } - y -= linespacing; - start = 0; - } - - while (next_wrap_s(buffer, sizeof(buffer), &start, str, maxwidth)) - { - Print(x, y, buffer, r, g, b, cen); - - if (flipmode) - { - y -= linespacing; - } - else - { - y += linespacing; - } - } - - return y + linespacing; + // DEPRECATED + if (cen) + return font::print_wrap(PR_CEN, -1, y, text, r, g, b, linespacing /*= -1 */, maxwidth /*= -1 */); + else + return font::print_wrap(0, x, y, text, r, g, b, linespacing /*= -1 */, maxwidth /*= -1 */); } diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index af35e906..1f857c5d 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -210,7 +210,7 @@ public: bool next_wrap_s(char buffer[], size_t buffer_size, size_t* start, const char* str, int maxwidth); - int PrintWrap(int x, int y, std::string s, int r, int g, int b, bool cen = false, int linespacing = -1, int maxwidth = -1); + int PrintWrap(int x, int y, const std::string& s, int r, int g, int b, bool cen = false, int linespacing = -1, int maxwidth = -1); void bprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false);