Make compatible with new nsfont_split expectations. Only splits on spaces.

This commit is contained in:
Michael Drake 2013-02-10 18:26:59 +00:00
parent db8ec60fc0
commit 3148f8a6c3
2 changed files with 36 additions and 15 deletions

View File

@ -497,15 +497,22 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
* *
* \param fstyle style for this text * \param fstyle style for this text
* \param string UTF-8 string to measure * \param string UTF-8 string to measure
* \param length length of string * \param length length of string, in bytes
* \param x width available * \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 * \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported * \return true on success, false on error and error reported
* *
* On exit, [char_offset == 0 || * On exit, char_offset indicates first character after split point.
* string[char_offset] == ' ' || *
* char_offset == length] * 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, static bool nsfont_split(const plot_font_style_t *fstyle,
@ -532,10 +539,9 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
} }
*actual_x += glyph->advance.x >> 16; *actual_x += glyph->advance.x >> 16;
if (*actual_x > x) { if (*actual_x > x && last_space_idx != 0) {
/* string has exceeded available width return previous /* string has exceeded available width and we've
* space * found a space; return previous space */
*/
*actual_x = last_space_x; *actual_x = last_space_x;
*char_offset = last_space_idx; *char_offset = last_space_idx;
return true; return true;

View File

@ -121,20 +121,28 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
} }
/** /**
* Find where to split a string to make it fit a width. * Find where to split a string to make it fit a width.
* *
* \param fstyle style for this text * \param fstyle style for this text
* \param string UTF-8 string to measure * \param string UTF-8 string to measure
* \param length length of string * \param length length of string, in bytes
* \param x width available * \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 * \param actual_x updated to x coordinate of character closest to x
* \return true on success, false on error and error reported * \return true on success, false on error and error reported
* *
* On exit, [char_offset == 0 || * On exit, char_offset indicates first character after split point.
* string[char_offset] == ' ' || *
* char_offset == length] * 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, static bool nsfont_split(const plot_font_style_t *fstyle,
@ -143,7 +151,7 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
{ {
const struct fb_font_desc* fb_font = fb_get_font(fstyle); const struct fb_font_desc* fb_font = fb_get_font(fstyle);
*char_offset = x / fb_font->width; int c_off = *char_offset = x / fb_font->width;
if (*char_offset > length) { if (*char_offset > length) {
*char_offset = length; *char_offset = length;
} else { } else {
@ -152,6 +160,13 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
break; break;
(*char_offset)--; (*char_offset)--;
} }
if (*char_offset == 0) {
*char_offset = c_off;
while (*char_offset < length &&
string[*char_offset] != ' ') {
(*char_offset)++;
}
}
} }
*actual_x = *char_offset * fb_font->width; *actual_x = *char_offset * fb_font->width;
return true; return true;