Fix: [Win32] Wrong multi-line text layout due to incorrect whitespace handling.

This commit is contained in:
Michael Lutz 2023-05-01 15:32:59 +02:00
parent 715234502c
commit 908be59699
1 changed files with 7 additions and 6 deletions

View File

@ -348,6 +348,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
/* If the text does not fit into the available width, find a suitable breaking point. */ /* If the text does not fit into the available width, find a suitable breaking point. */
int remaining_offset = (last_run - 1)->len; int remaining_offset = (last_run - 1)->len;
int whitespace_count = 0;
if (cur_width > max_width) { if (cur_width > max_width) {
std::vector<SCRIPT_LOGATTR> log_attribs; std::vector<SCRIPT_LOGATTR> log_attribs;
@ -380,10 +381,10 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
num_chars = last_cluster; num_chars = last_cluster;
} }
/* Include whitespace characters after the breaking point. */ /* Eat any whitespace characters before the breaking point. */
while (num_chars < (int)log_attribs.size() && log_attribs[num_chars].fWhiteSpace) { while (num_chars - 1 > this->cur_range_offset && log_attribs[num_chars - 1].fWhiteSpace) num_chars--;
num_chars++; /* Count whitespace after the breaking point. */
} while (num_chars + whitespace_count < (int)log_attribs.size() && log_attribs[num_chars + whitespace_count].fWhiteSpace) whitespace_count++;
/* Get last run that corresponds to the number of characters to show. */ /* Get last run that corresponds to the number of characters to show. */
for (std::vector<UniscribeRun>::iterator run = start_run; run != last_run; run++) { for (std::vector<UniscribeRun>::iterator run = start_run; run != last_run; run++) {
@ -432,9 +433,9 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
cur_pos += run.total_advance; cur_pos += run.total_advance;
} }
if (remaining_offset < (last_run - 1)->len) { if (remaining_offset + whitespace_count < (last_run - 1)->len) {
/* We didn't use up all of the last run, store remainder for the next line. */ /* We didn't use up all of the last run, store remainder for the next line. */
this->cur_range_offset = remaining_offset - 1; this->cur_range_offset = remaining_offset + whitespace_count - 1;
this->cur_range = last_run - 1; this->cur_range = last_run - 1;
assert(this->cur_range->len > this->cur_range_offset); assert(this->cur_range->len > this->cur_range_offset);
} else { } else {