Just yesterday, I wrote some code to manually word-wrap my strings so I'll just paste it here. Maybe it'll help you or someone. If it's not clear, just tell me.

P.S: This is written for unicode strings so you may need to change here and there.

First function finds where to split, it's called by the second one. UnT_WordWrap takes a string, splits it where it should be wrapped and fills a pre-allocated string array which it takes as the first argument.

Code:
short    const_null_uchar 			= 0x0;

int UnT_WrapSplit(STRING* arg_str, FONT* arg_font, var arg_width)
{
	if(arg_str == NULL || arg_font == NULL)
	{
		diag("\nUnT_WrapSplit: bad argument");
		return -1;
	}
	if(str_len(arg_str) < 1)
	{
		diag("\nUnT_WrapSplit: str_len(arg_str) < 1");
		return -1;
	}
	
	if(str_width(arg_str, arg_font) < arg_width) return str_len(arg_str);
	var chr = str_chr(arg_str, -str_len(arg_str) + 1, 0x20);
	if(chr == 0) 
	{
		STRING* temp_s = str_createw(&const_null_uchar);
		var temp_w = 0;
		chr = str_len(arg_str) - 1;
		do
		{
			str_cut(temp_s, arg_str, 0, chr);
			temp_w = str_width(temp_s, arg_font);
			chr -= 1;
		}while(temp_w > arg_width);
		ptr_remove(temp_s);
		return chr;
	}
	STRING* temp_s = str_cut(NULL, arg_str, 0, chr);
	var temp_v = UnT_WrapSplit(temp_s, arg_font, arg_width);
	ptr_remove(temp_s);
	return temp_v;
}

int UnT_WordWrap(STRING** out_str_array, int arg_arrayCapacity, STRING* arg_in_str, FONT* arg_font, var arg_width)
{
	if(out_str_array == NULL || arg_in_str == NULL || arg_font == NULL)
	{
		diag("\nUnT_WordWrap: bad argument");
		return -1;
	}
	
	var loc_str_len = str_len(arg_in_str);
	int loc_idx = 0;
	STRING* loc_temp_str = str_createw(&const_null_uchar);
	STRING* loc_temp_str_rest = str_createw(&const_null_uchar);
	str_cpy(loc_temp_str, arg_in_str);
	
	while(loc_idx < arg_arrayCapacity)
	{
		var end = UnT_WrapSplit(loc_temp_str, arg_font, arg_width);
		if(end < 1) break;
		str_cut(out_str_array[loc_idx], loc_temp_str, 0, end);
		str_trim(out_str_array[loc_idx]);
		str_cut(loc_temp_str_rest, loc_temp_str, end, 0);
		ptr_remove(loc_temp_str);
		loc_temp_str = loc_temp_str_rest;
		loc_idx++;
	}
	return loc_idx;
}


Last edited by Talemon; 12/12/12 08:03.