Skip to content

Commit

Permalink
Fixes #138 - placing inline boxes (#163)
Browse files Browse the repository at this point in the history
When a inline box is placed at the beginning of the non-first line then
line breaking is wrong.

Lets have the following text:

```
Line1\nLine2
       |
       \- Inlinebox here
```

It produces the following items in layout:

[run, inlinebox, run]

But the line breaking occurs when the second run is processed. So
inlinebox ends on the previous line.
This PR fixes it by checking that current cluster_idx is mandatory break
and ends line before processing inline boxes
  • Loading branch information
spirali authored Nov 10, 2024
1 parent b10ba60 commit e8230d8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions parley/src/layout/line/greedy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ impl<'a, B: Brush> BreakLines<'a, B> {

match item.kind {
LayoutItemKind::InlineBox => {
// This fixes issue #138
// It fixes an inline box that starts at then beginning of a non-first line
// We need to check that current cluster_idx (a first cluster of the following run)
// does not contain mandatory break (it means that cluster_idx - 1 is \n)
// We have to process line breaking right now before processing inline boxes,
// otherwise line break will occur in processing of the following run, and it is
// too late and inline box will end on the previous line.
if !self.state.line.skip_mandatory_break
&& self
.layout
.data
.clusters
.get(self.state.cluster_idx)
.map(|c| c.info.boundary() == Boundary::Mandatory)
.unwrap_or(false)
{
self.state.prev_boundary = None;
self.state.line.items.end = self.state.item_idx;
self.state.line.clusters.end = self.state.cluster_idx;
self.state.line.skip_mandatory_break = true;
if try_commit_line!(BreakReason::Explicit) {
return self.start_new_line();
}
}
let inline_box = &self.layout.data.inline_boxes[item.index];

// Compute the x position of the content being currently processed
Expand Down

0 comments on commit e8230d8

Please sign in to comment.