diff options
| author | Andy Barcia RodrÃguez <40731413+AndyBarcia@users.noreply.github.com> | 2023-06-26 13:41:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-26 13:41:51 +0200 |
| commit | 5ee41e57e821fbbfaafc9cc2ad3f682112258fc4 (patch) | |
| tree | 52309feaa41c96ff9d722a2fea43d0c423e6c48a /library/src | |
| parent | 33803b16148ec064ccabc9bffd4a9383b969e23e (diff) | |
Fix underline bug. (#1567)
Diffstat (limited to 'library/src')
| -rw-r--r-- | library/src/text/deco.rs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index 8b8ce7fd..9ec4ca32 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -292,7 +292,7 @@ pub(super) fn decorate( let gap_padding = 0.08 * text.size; let min_width = 0.162 * text.size; - let mut start = pos.x - deco.extent; + let start = pos.x - deco.extent; let end = pos.x + (width + 2.0 * deco.extent); let mut push_segment = |from: Abs, to: Abs| { @@ -346,29 +346,23 @@ pub(super) fn decorate( } } + // Add start and end points, taking padding into account. + intersections.push(start - gap_padding); + intersections.push(end + gap_padding); // When emitting the decorative line segments, we move from left to // right. The intersections are not necessarily in this order, yet. intersections.sort(); - for gap in intersections.chunks_exact(2) { - let l = gap[0] - gap_padding; - let r = gap[1] + gap_padding; + for edge in intersections.windows(2) { + let l = edge[0]; + let r = edge[1]; - if start >= end { - break; - } - - if start >= l { - start = r; + // If we are too close, don't draw the segment + if r - l < gap_padding { continue; + } else { + push_segment(l + gap_padding, r - gap_padding); } - - push_segment(start, l); - start = r; - } - - if start < end { - push_segment(start, end); } } |
