Skip to content

Commit

Permalink
Change: [Win32] Ignore suitable breaking point if next line still doe…
Browse files Browse the repository at this point in the history
…sn't fit
  • Loading branch information
glx22 committed Jan 13, 2024
1 parent b3f31a6 commit e1f8bd5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/os/windows/string_uniscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
int num_chars = this->cur_range_offset;
int start_offs = this->cur_range_offset;
int last_cluster = this->cur_range_offset + 1;
for (std::vector<UniscribeRun>::iterator r = start_run; r != last_run; r++) {
for (std::vector<UniscribeRun>::iterator r = start_run; r != this->ranges.end(); r++) {
log_attribs.resize(r->pos - start_run->pos + r->len);
if (FAILED(ScriptBreak(this->text_buffer + r->pos + start_offs, r->len - start_offs, &r->sa, &log_attribs[r->pos - start_run->pos + start_offs]))) return nullptr;

if (r >= last_run) continue;

std::vector<int> dx(r->len);
ScriptGetLogicalWidths(&r->sa, r->len, (int)r->glyphs.size(), &r->advances[0], &r->char_to_glyph[0], &r->vis_attribs[0], &dx[0]);

Expand All @@ -378,6 +380,26 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
if (num_chars == this->cur_range_offset) {
/* Didn't find any suitable word break point, just break on the last cluster boundary. */
num_chars = last_cluster;
} else {
/* If next line does not fit into the available width, ignore the found suitable breaking point. */
int next_width = 0;
int next_chars = 0;
start_offs = this->cur_range_offset;
for (std::vector<UniscribeRun>::iterator r = start_run; r != this->ranges.end(); r++) {
std::vector<int> dx(r->len);
ScriptGetLogicalWidths(&r->sa, r->len, (int)r->glyphs.size(), &r->advances[0], &r->char_to_glyph[0], &r->vis_attribs[0], &dx[0]);

/* Get width of next line until suitable breaking point. */
for (int c = start_offs; c < r->len && next_width <= max_width; c++, next_chars++) {
if (next_chars <= num_chars) continue;
if (log_attribs[next_chars].fSoftBreak || log_attribs[next_chars].fWhiteSpace) break;
next_width += dx[c];
}
if (next_chars < log_attribs.size() && (log_attribs[next_chars].fSoftBreak || log_attribs[next_chars].fWhiteSpace)) break;

Check warning on line 398 in src/os/windows/string_uniscribe.cpp

View workflow job for this annotation

GitHub Actions / MinGW (x86_64)

comparison of integer expressions of different signedness: 'int' and 'std::vector<tag_SCRIPT_LOGATTR>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]

Check warning on line 398 in src/os/windows/string_uniscribe.cpp

View workflow job for this annotation

GitHub Actions / Windows (windows-latest / x86)

'<': signed/unsigned mismatch

Check warning on line 398 in src/os/windows/string_uniscribe.cpp

View workflow job for this annotation

GitHub Actions / MinGW (i686)

comparison of integer expressions of different signedness: 'int' and 'std::vector<tag_SCRIPT_LOGATTR>::size_type' {aka 'unsigned int'} [-Wsign-compare]

Check warning on line 398 in src/os/windows/string_uniscribe.cpp

View workflow job for this annotation

GitHub Actions / Windows (windows-2019 / x86)

'<': signed/unsigned mismatch

start_offs = 0;
}
if (next_width > max_width) num_chars = last_cluster;
}

/* Eat any whitespace characters before the breaking point. */
Expand Down

0 comments on commit e1f8bd5

Please sign in to comment.