equal
deleted
inserted
replaced
294 w += GetCharacterWidth(size, c); |
294 w += GetCharacterWidth(size, c); |
295 |
295 |
296 if (w >= maxw) { |
296 if (w >= maxw) { |
297 /* string got too big... insert dotdotdot */ |
297 /* string got too big... insert dotdotdot */ |
298 ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
298 ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
299 ddd_pos[3] = 0; |
299 ddd_pos[3] = '\0'; |
300 return ddd_w; |
300 return ddd_w; |
301 } |
301 } |
302 } else { |
302 } else { |
303 if (c == SCC_SETX) str++; |
303 if (c == SCC_SETX) str++; |
304 else if (c == SCC_SETXY) str += 2; |
304 else if (c == SCC_SETXY) str += 2; |
438 int w = 0; |
438 int w = 0; |
439 |
439 |
440 for (;;) { |
440 for (;;) { |
441 WChar c = Utf8Consume((const char **)&str); |
441 WChar c = Utf8Consume((const char **)&str); |
442 /* whitespace is where we will insert the line-break */ |
442 /* whitespace is where we will insert the line-break */ |
443 if (c == ' ') last_space = str; |
443 if (IsWhitespace(c)) last_space = str; |
444 |
444 |
445 if (IsPrintable(c)) { |
445 if (IsPrintable(c)) { |
446 w += GetCharacterWidth(size, c); |
446 w += GetCharacterWidth(size, c); |
447 /* string is longer than maximum width so we need to decide what to |
447 /* string is longer than maximum width so we need to decide what to |
448 * do. We can do two things: |
448 * do. We can do two things: |
449 * 1. If no whitespace was found at all up until now (on this line) then |
449 * 1. If no whitespace was found at all up until now (on this line) then |
450 * we will truncate the string and bail out. |
450 * we will truncate the string and bail out. |
451 * 2. In all other cases force a linebreak at the last seen whitespace */ |
451 * 2. In all other cases force a linebreak at the last seen whitespace */ |
452 if (w > maxw) { |
452 if (w > maxw) { |
453 if (last_space == NULL) { |
453 if (last_space == NULL) { |
454 str[-1] = '\0'; |
454 *Utf8PrevChar(str) = '\0'; |
455 return num + (size << 16); |
455 return num + (size << 16); |
456 } |
456 } |
457 str = last_space; |
457 str = last_space; |
458 break; |
458 break; |
459 } |
459 } |
467 case '\n': goto end_of_inner_loop; |
467 case '\n': goto end_of_inner_loop; |
468 } |
468 } |
469 } |
469 } |
470 } |
470 } |
471 end_of_inner_loop: |
471 end_of_inner_loop: |
472 /* string didn't fit on line, so 'dummy' terminate and increase linecount */ |
472 /* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate |
|
473 * and increase linecount. We use Utf8PrevChar() as also non 1 char long |
|
474 * whitespace seperators are supported */ |
473 num++; |
475 num++; |
474 str[-1] = '\0'; |
476 char *s = Utf8PrevChar(str); |
|
477 *s++ = '\0'; |
|
478 |
|
479 /* In which case (see above) we will shift remainder to left and close the gap */ |
|
480 if (str - s >= 1) { |
|
481 for (; str[-1] != '\0';) *s++ = *str++; |
|
482 } |
475 } |
483 } |
476 } |
484 } |
477 |
485 |
478 /** Draw a given string with the centre around the given x coordinates |
486 /** Draw a given string with the centre around the given x coordinates |
479 * @param x Centre the string around this pixel width |
487 * @param x Centre the string around this pixel width |