Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: [Win32] Ignore suitable breaking point if next line still doesn't fit #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 < (int)log_attribs.size() && (log_attribs[next_chars].fSoftBreak || log_attribs[next_chars].fWhiteSpace)) break;

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

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