mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
count leading whitespace in wordwrap
This commit is contained in:
parent
769fff8d67
commit
1bafa350b6
@ -137,7 +137,13 @@ wordwrap_to(const string &text, float wordwrap_width,
|
|||||||
size_t p = 0;
|
size_t p = 0;
|
||||||
|
|
||||||
// Preserve any initial whitespace and newlines.
|
// Preserve any initial whitespace and newlines.
|
||||||
|
float initial_width = 0.0;
|
||||||
while (p < text.length() && isspace(text[p])) {
|
while (p < text.length() && isspace(text[p])) {
|
||||||
|
if (text[p] == '\n') {
|
||||||
|
initial_width = 0.0;
|
||||||
|
} else {
|
||||||
|
initial_width += calc_width(text[p]);
|
||||||
|
}
|
||||||
output_text += text[p];
|
output_text += text[p];
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
@ -153,7 +159,7 @@ wordwrap_to(const string &text, float wordwrap_width,
|
|||||||
bool any_spaces = false;
|
bool any_spaces = false;
|
||||||
bool overflow = false;
|
bool overflow = false;
|
||||||
|
|
||||||
float width = 0.0;
|
float width = initial_width;
|
||||||
while (q < text.length() && text[q] != '\n') {
|
while (q < text.length() && text[q] != '\n') {
|
||||||
if (isspace(text[q])) {
|
if (isspace(text[q])) {
|
||||||
any_spaces = true;
|
any_spaces = true;
|
||||||
@ -191,7 +197,8 @@ wordwrap_to(const string &text, float wordwrap_width,
|
|||||||
|
|
||||||
if (next_start == p) {
|
if (next_start == p) {
|
||||||
// No characters got in at all. This could only happen if the
|
// No characters got in at all. This could only happen if the
|
||||||
// wordwrap width is narrower than a single character.
|
// wordwrap width is narrower than a single character, or if we
|
||||||
|
// have a substantial number of leading spaces in a line.
|
||||||
q++;
|
q++;
|
||||||
next_start++;
|
next_start++;
|
||||||
while (next_start < text.length() && isblank(text[next_start])) {
|
while (next_start < text.length() && isblank(text[next_start])) {
|
||||||
@ -220,7 +227,13 @@ wordwrap_to(const string &text, float wordwrap_width,
|
|||||||
p = next_start;
|
p = next_start;
|
||||||
|
|
||||||
// Preserve any initial whitespace and newlines.
|
// Preserve any initial whitespace and newlines.
|
||||||
|
initial_width = 0.0;
|
||||||
while (p < text.length() && isspace(text[p])) {
|
while (p < text.length() && isspace(text[p])) {
|
||||||
|
if (text[p] == '\n') {
|
||||||
|
initial_width = 0.0;
|
||||||
|
} else {
|
||||||
|
initial_width += calc_width(text[p]);
|
||||||
|
}
|
||||||
output_text += text[p];
|
output_text += text[p];
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user