revisada i actualitzada la classe Text per a donar suport a utf-8

This commit is contained in:
2026-03-22 12:47:32 +01:00
parent 5e013a8414
commit d0ed49d192
12 changed files with 861 additions and 128 deletions

View File

@@ -60,17 +60,21 @@ void Title::initMarquee() {
letters_.clear();
long_text_ = Locale::get()->get("title.marquee");
// Pre-calcular anchos de caracteres para eficiencia
for (size_t i = 0; i < long_text_.length(); ++i) {
// Pre-calcular anchos de caracteres para eficiencia (iteración por codepoints UTF-8)
size_t pos = 0;
while (pos < long_text_.size()) {
uint32_t cp = Text::nextCodepoint(long_text_, pos);
Glyph l;
l.letter = long_text_[i]; // char directo, no substring
l.x = MARQUEE_START_X; // Usar constante
l.width = marquee_text_->length(std::string(1, long_text_[i])); // Pre-calcular ancho
l.codepoint = cp;
l.x = MARQUEE_START_X;
l.width = static_cast<float>(marquee_text_->glyphWidth(cp, 1)); // Pre-calcular ancho con kerning
l.enabled = false;
letters_.push_back(l);
}
letters_[0].enabled = true;
if (!letters_.empty()) {
letters_[0].enabled = true;
}
first_active_letter_ = 0;
last_active_letter_ = 0;
}
@@ -224,9 +228,9 @@ void Title::renderMarquee() {
const auto& letter = letters_[i];
if (letter.enabled) {
marquee_text_->writeColored(
static_cast<int>(letter.x), // Conversión explícita float→int
static_cast<int>(MARQUEE_Y), // Usar constante
std::string(1, letter.letter), // Convertir char a string
static_cast<int>(letter.x), // Conversión explícita float→int
static_cast<int>(MARQUEE_Y), // Usar constante
Text::codepointToUtf8(letter.codepoint), // Convertir codepoint a string UTF-8
static_cast<Uint8>(PaletteColor::MAGENTA));
}
}