From e7e5211eb930e7b5517838fe895250fc934f029e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Feb 2013 18:32:08 +0000 Subject: Update for new nsfont_split expectations. Untested, but code similar to framebuffer. --- monkey/font.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'monkey') diff --git a/monkey/font.c b/monkey/font.c index 759c3e935..7f390a49b 100644 --- a/monkey/font.c +++ b/monkey/font.c @@ -59,23 +59,29 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle, * * \param fstyle style for this text * \param string UTF-8 string to measure - * \param length length of string + * \param length length of string, in bytes * \param x width available - * \param char_offset updated to offset in string of actual_x, [0..length] + * \param char_offset updated to offset in string of actual_x, [1..length] * \param actual_x updated to x coordinate of character closest to x * \return true on success, false on error and error reported * - * On exit, [char_offset == 0 || - * string[char_offset] == ' ' || - * char_offset == length] + * On exit, char_offset indicates first character after split point. + * + * Note: char_offset of 0 should never be returned. + * + * Returns: + * char_offset giving split point closest to x, where actual_x <= x + * else + * char_offset giving split point closest to x, where actual_x > x + * + * Returning char_offset == length means no split possible */ static bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - - *char_offset = x / (fstyle->size / FONT_SIZE_SCALE); + int c_off = *char_offset = x / (fstyle->size / FONT_SIZE_SCALE); if (*char_offset > length) { *char_offset = length; } else { @@ -84,6 +90,12 @@ static bool nsfont_split(const plot_font_style_t *fstyle, break; (*char_offset)--; } + if (*char_offset == 0) { + *char_offset = c_off; + while (*char_offset < length && string[*char_offset] != ' ') { + (*char_offset)++; + } + } } *actual_x = *char_offset * (fstyle->size / FONT_SIZE_SCALE); return true; -- cgit v1.2.3