afegida logica de continues
fix: el text no centrava correctament en horitzontal
This commit is contained in:
@@ -195,8 +195,8 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
// Altura de un carácter escalado (necesario para ajustar Y)
|
||||
const float char_height_scaled = char_height * escala;
|
||||
|
||||
// Posición actual del centro del carácter (ajustada desde esquina superior
|
||||
// izquierda)
|
||||
// Posición X del borde izquierdo del carácter actual
|
||||
// (se ajustará +char_width/2 para obtener el centro al renderizar)
|
||||
float current_x = posicio.x;
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
@@ -220,9 +220,9 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
auto it = chars_.find(c);
|
||||
if (it != chars_.end()) {
|
||||
// Renderizar carácter
|
||||
// Ajustar Y para que posicio represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de la altura)
|
||||
Punt char_pos = {current_x, posicio.y + char_height_scaled / 2.0f};
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Punt char_pos = {current_x + char_width_scaled / 2.0f, posicio.y + char_height_scaled / 2.0f};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0f, escala, true, 1.0f, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
@@ -244,16 +244,23 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
|
||||
const float char_width_scaled = char_width * escala;
|
||||
const float spacing_scaled = spacing * escala;
|
||||
|
||||
// Ancho total = (número de caracteres × char_width) + (espacios entre
|
||||
// caracteres)
|
||||
float width = text.length() * char_width_scaled;
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
unsigned char c = static_cast<unsigned char>(text[i]);
|
||||
|
||||
// Añadir spacing entre caracteres (n-1 espacios para n caracteres)
|
||||
if (text.length() > 1) {
|
||||
width += (text.length() - 1) * spacing_scaled;
|
||||
// Detectar copyright UTF-8 (0xC2 0xA9) - igual que render()
|
||||
if (c == 0xC2 && i + 1 < text.length() &&
|
||||
static_cast<unsigned char>(text[i + 1]) == 0xA9) {
|
||||
visual_chars++; // Un caràcter visual (©)
|
||||
i++; // Saltar el següent byte
|
||||
} else {
|
||||
visual_chars++; // Caràcter normal
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
// Ancho total = todos los caracteres VISUALES + spacing entre ellos
|
||||
return visual_chars * char_width_scaled + (visual_chars - 1) * spacing_scaled;
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float escala) const {
|
||||
|
||||
Reference in New Issue
Block a user