From 362fc6ae45ddce2cc9948988251d2027b34b9e6e Mon Sep 17 00:00:00 2001 From: Holger Schemel <holger.schemel@virtion.de> Date: Wed, 30 Oct 2024 23:45:28 +0100 Subject: [PATCH] fixed checking and setting parameters for getting wrapped text --- src/libgame/text.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libgame/text.c b/src/libgame/text.c index 4fbd48ee..2281a31d 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -575,24 +575,28 @@ static struct WrappedTextInfo *GetWrappedText(char *text_buffer, int base_font_n if (text_buffer == NULL || *text_buffer == '\0') return NULL; - // if number of characters where to cut line not defined, set to default line size - if (cut_length == -1) - cut_length = line_length; - - // if pixel width where to cut line not defined, set from number of characters - if (cut_width == -1) - cut_width = cut_length * font_width; - // if pixel width of line buffer not defined, set from maximum line size if (line_width == -1) line_width = line_length * font_width; + else + line_length = line_width / font_width; // if pixel height of line buffer not defined, set from maximum number of lines if (max_height == -1) max_height = max_lines * line_height; + else + max_lines = max_height / line_height; + + // limit line buffer length to maximum output line size + line_length = MIN(line_length, MAX_OUTPUT_LINESIZE); - // update line buffer length from line width and font width - line_length = MIN(line_width / font_width, MAX_OUTPUT_LINESIZE); + // if number of characters where to cut line not defined, set to default line size + if (cut_length == -1) + cut_length = line_length; + + // if pixel width where to cut line not defined, set from number of characters + if (cut_width == -1) + cut_width = cut_length * font_width; wrapped_text = checked_calloc(sizeof(struct WrappedTextInfo)); wrapped_text->line_width = line_width; -- 2.34.1