Fix: #121 Print utf8 until invalid character.

This commit is contained in:
QC 2015-02-02 16:44:08 +01:00
parent e42a60f87a
commit 3a98c71fa1
1 changed files with 9 additions and 3 deletions

View File

@ -156,12 +156,18 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
void textbox_text ( textbox *tb, char *text )
{
g_free ( tb->text );
if ( g_utf8_validate ( text, -1, NULL ) ) {
const gchar *last_pointer = NULL;
if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
tb->text = g_strdup ( text );
}
else {
tb->text = g_strdup ( "Invalid UTF-8 string." );
if ( last_pointer != NULL ) {
// Copy string up to invalid character.
tb->text = g_strndup ( text, ( last_pointer - text ) );
}
else {
tb->text = g_strdup ( "Invalid UTF-8 string." );
}
}
pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );