Ensure that actual_x is set when string fits inside available_width.

This commit is contained in:
Michael Drake 2013-03-20 22:07:22 +00:00
parent 918aa9d266
commit 91d05fc0f1
1 changed files with 28 additions and 35 deletions

View File

@ -245,11 +245,9 @@ bool nsfont_split(const plot_font_style_t *fstyle,
FIXED kern = 0; FIXED kern = 0;
int utf16charlen = 0; int utf16charlen = 0;
struct OutlineFont *ofont, *ufont = NULL; struct OutlineFont *ofont, *ufont = NULL;
uint32 tx=0,i=0; uint32 tx=0;
size_t len;
int utf8_pos = 0; int utf8_pos = 0;
int32 tempx = 0; int32 tempx = 0;
size_t coffset = 0;
ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size);
if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false;
@ -269,52 +267,47 @@ bool nsfont_split(const plot_font_style_t *fstyle,
tempx = ami_font_width_glyph(ofont, *utf16, utf16next, emwidth); tempx = ami_font_width_glyph(ofont, *utf16, utf16next, emwidth);
if(tempx == 0) if (tempx == 0) {
{ if (ufont == NULL)
if(ufont == NULL)
{
ufont = ami_open_outline_font(fstyle, *utf16); ufont = ami_open_outline_font(fstyle, *utf16);
}
if(ufont) if (ufont)
{ tempx = ami_font_width_glyph(ufont, *utf16,
tempx = ami_font_width_glyph(ufont, *utf16, utf16next, emwidth); utf16next, emwidth);
}
/* Check whether we have a space */
if (*(string + utf8_pos) == ' ') {
/* Got a space */
*actual_x = tx;
*char_offset = utf8_pos;
if (x < tx) {
/* Beyond available width,
* so don't look further */
return true;
} }
/*
if(tempx == 0)
{
tempx = ami_font_width_glyph(ofont, 0xfffd, utf16next, emwidth);
}
*/
} }
tx += tempx; tx += tempx;
if ((x < tx) && (coffset != 0)) { if ((x < tx) && (*char_offset != 0)) {
/* Reached available width, and a space has been found; split there. */ /* Reached available width, and a space was found;
break; * split there. */
return true;
} else if (*(string + utf8_pos) == ' ') {
*actual_x = tx;
coffset = utf8_pos;
if (x < tx) {
/* Out of space, so don't look further */
break;
}
} }
utf16 += utf16charlen; utf16 += utf16charlen;
utf8_pos = utf8_next(string, length, utf8_pos); utf8_pos = utf8_next(string, length, utf8_pos);
} }
free(outf16); free(outf16);
if(coffset == 0) { /* No spaces to split at, or everything fits */
*char_offset = length; assert(*char_offset == 0 || x >= tx);
*actual_x = tx;
} else { *char_offset = length;
*char_offset = coffset; *actual_x = tx;
}
return true; return true;
} }