* Work back from the last character that did fit to either a space or the last
* character of a word, whichever is met first.
* If there was one or the first character didn't fit then
- * break the line before that character
- * and if this is a space then discard it.
+ * If the text is centred or right justified and that one character was a
+ * space then break the line before that character
+ * Otherwise break the line after that character
+ * and if the next character is a space then discard it.
* Suppose there was none (and the first character did fit).
* If Break Within Word is permitted
* break the word after the last character that fits (there must be
{
while (p > str && *(--p) != SPACE)
;
- word_fits = (p == str || *p == SPACE);
+ word_fits = (p != str || *p == SPACE);
}
/* If there was one or the first character didn't fit then */
if (word_fits)
{
int next_is_space;
-
+ /* break the line before/after that character */
+ if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE)
+ p++;
next_is_space = (p - str) < *len_str && *p == SPACE;
*len_str = p - str;
/* and if the next character is a space then discard it. */