MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / NextLine

Method NextLine

src/gfx_layout_icu.cpp:404–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404std::unique_ptr<const ICUParagraphLayout::Line> ICUParagraphLayout::NextLine(int max_width)
405{
406 std::vector<ICURun>::iterator start_run = this->current_run;
407 std::vector<ICURun>::iterator last_run = this->current_run;
408
409 if (start_run == this->runs.end()) return nullptr;
410
411 int cur_width = 0;
412
413 /* Add remaining width of the first run if it is a broken run. */
414 if (this->partial_offset > 0) {
415 if ((start_run->level & 1) == 0) {
416 for (size_t i = this->partial_offset; i < start_run->advance.size(); i++) {
417 cur_width += start_run->advance[i];
418 }
419 } else {
420 for (int i = 0; i < this->partial_offset; i++) {
421 cur_width += start_run->advance[i];
422 }
423 }
424 last_run++;
425 }
426
427 /* Gather runs until the line is full. */
428 while (last_run != this->runs.end() && cur_width < max_width) {
429 cur_width += last_run->total_advance;
430 last_run++;
431 }
432
433 /* If the text does not fit into the available width, find a suitable breaking point. */
434 int new_partial_length = 0;
435 if (cur_width > max_width) {
436 /* Create a break-iterator to find a good place to break lines. */
437 auto break_iterator = ICUParagraphLayoutFactory::GetBreakIterator();
438 break_iterator->setText(icu::UnicodeString(this->buff, this->buff_length));
439
440 auto overflow_run = last_run - 1;
441
442 /* Find the last glyph that fits. */
443 size_t index;
444 if ((overflow_run->level & 1) == 0) {
445 /* LTR */
446 for (index = overflow_run->glyphs.size(); index > 0; /* nothing */) {
447 --index;
448 cur_width -= overflow_run->advance[index];
449 if (cur_width <= max_width) break;
450 }
451 } else {
452 /* RTL */
453 for (index = 0; index < overflow_run->glyphs.size(); index++) {
454 cur_width -= overflow_run->advance[index];
455 if (cur_width <= max_width) break;
456 }
457 }
458
459 /* Find the character that matches; this is the start of the cluster. */
460 auto char_pos = overflow_run->glyph_to_char[index];
461

Callers 1

LayouterMethod · 0.45

Calls 5

push_backMethod · 0.80
ShapeMethod · 0.80
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected