|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | #include <LibGfx/Font/FontVariant.h>
|
| 8 | +#include <LibGfx/TextLayout.h> |
| 9 | +#include <LibWeb/CSS/Enums.h> |
8 | 10 | #include <LibWeb/Layout/BreakNode.h>
|
9 | 11 | #include <LibWeb/Layout/InlineFormattingContext.h>
|
10 | 12 | #include <LibWeb/Layout/InlineLevelIterator.h>
|
11 | 13 | #include <LibWeb/Layout/InlineNode.h>
|
12 | 14 | #include <LibWeb/Layout/ListItemMarkerBox.h>
|
13 | 15 | #include <LibWeb/Layout/ReplacedBox.h>
|
| 16 | +#include <LibWeb/PixelUnits.h> |
14 | 17 |
|
15 | 18 | namespace Web::Layout {
|
16 | 19 |
|
@@ -556,6 +559,39 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
|
556 | 559 |
|
557 | 560 | CSSPixels chunk_width = CSSPixels::nearest_value_for(glyph_run->width());
|
558 | 561 |
|
| 562 | + // FIXME: |
| 563 | + { |
| 564 | + auto glyph_run = Gfx::shape_text({ x, 0 }, letter_spacing.to_float(), chunk.view, chunk.font, text_type, shape_features); |
| 565 | + dbgln("Shaping current chunk: {}", chunk.view); |
| 566 | + |
| 567 | + CSSPixels chunk_width = CSSPixels::nearest_value_for(glyph_run->width()); |
| 568 | + if (text_node.computed_values().overflow_wrap() == CSS::OverflowWrap::BreakWord) { |
| 569 | + // while glyph_run.width > context->available_space() |
| 570 | + // reshape text with lesser chars |
| 571 | + // reset the text_node iterator back to characters removed from initial text_shape |
| 572 | + auto maybe_available_space = m_inline_formatting_context.available_space(); |
| 573 | + if (maybe_available_space.has_value()) { |
| 574 | + auto available_space = maybe_available_space.value(); |
| 575 | + auto removed_code_points_count = 0; |
| 576 | + auto new_chunk_view = chunk.view; |
| 577 | + dbgln("Chunk Width: {}, Available Width: {}", chunk_width.to_int(), available_space.width.to_px_or_zero().to_int()); |
| 578 | + |
| 579 | + // FIXME: Use binary search to find the number of characters to rewind to |
| 580 | + while (chunk_width + CSSPixels::from_raw(removed_code_points_count) > available_space.width.to_px_or_zero()) { |
| 581 | + new_chunk_view = new_chunk_view.unicode_substring_view(0, new_chunk_view.length() - 1); |
| 582 | + glyph_run = Gfx::shape_text({ x, 0 }, letter_spacing.to_float(), new_chunk_view, chunk.font, text_type, shape_features); |
| 583 | + dbgln("Shaped current chunk: {}", new_chunk_view); |
| 584 | + chunk_width = CSSPixels::nearest_value_for(glyph_run->width()); |
| 585 | + removed_code_points_count++; |
| 586 | + } |
| 587 | + |
| 588 | + // FIXME: Rewind the chunk_iterator back removed_code_points_count times. |
| 589 | + |
| 590 | + dbgln("Removed {} codepoints when Breaking Words", removed_code_points_count); |
| 591 | + } |
| 592 | + } |
| 593 | + } |
| 594 | + |
559 | 595 | // NOTE: We never consider `content: ""` to be collapsible whitespace.
|
560 | 596 | bool is_generated_empty_string = text_node.is_generated() && chunk.length == 0;
|
561 | 597 |
|
|
0 commit comments