1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Experiment reversing for latin words (and arabic numbers)

This commit is contained in:
Mathieu Schroeter 2022-09-27 00:13:59 +02:00
parent e4c73d03b0
commit cd74d4dbfc
No known key found for this signature in database
GPG Key ID: 8B9145A5FA9DA8A8

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <regex>
#include <SDL_ttf.h>
@ -126,6 +127,22 @@ public:
TTF_Font * GetFont () { return this->font; }
std::string ReverseLatinWords (const std::string & text)
{
std::regex re("([a-zA-Z0-9]+)");
std::string out;
std::string::const_iterator it = text.cbegin(), end = text.cend();
for (std::smatch match; std::regex_search(it, end, match, re); it = match[0].second)
{
out += match.prefix();
auto substr = match.str();
std::reverse(substr.begin (), substr.end ());
out += substr;
}
out.append(it, end);
return out;
}
void Draw (CPixmap * pPixmap, Point pos, std::string pText, Sint32 slope)
{
Uint32 format;
@ -137,6 +154,9 @@ public:
auto texText = this->cache.Get (pText);
if (!texText && isRTL)
pText = this->ReverseLatinWords (pText);
SDL_Texture * texOutline = texText ? texText->outline : nullptr;
SDL_Texture * texBase = texText ? texText->base : nullptr;
SDL_Texture * texOver = texText ? texText->over : nullptr;