Skip to content

Commit 399fe36

Browse files
authored
parley: elide overflowing lines (#9682)
* Try skipping lines where min_coord is > the max height * Use max_coord instead
1 parent 8d4d9e7 commit 399fe36

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

internal/core/textlayout/sharedparley.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn layout(text: &str, scale_factor: ScaleFactor, mut options: LayoutOptions) ->
274274
(None, _) | (Some(_), TextVerticalAlignment::Top) => PhysicalLength::new(0.0),
275275
};
276276

277-
Layout { inner: layout, y_offset, elision_info }
277+
Layout { inner: layout, y_offset, elision_info, max_physical_height }
278278
}
279279

280280
struct ElisionInfo {
@@ -285,6 +285,7 @@ struct ElisionInfo {
285285
struct Layout {
286286
inner: parley::Layout<Brush>,
287287
y_offset: PhysicalLength,
288+
max_physical_height: Option<PhysicalLength>,
288289
elision_info: Option<ElisionInfo>,
289290
}
290291

@@ -341,8 +342,20 @@ impl Layout {
341342
&mut dyn Iterator<Item = parley::layout::Glyph>,
342343
),
343344
) {
344-
for (line_index, line) in self.inner.lines().enumerate() {
345-
let last_line = line_index == self.inner.len() - 1;
345+
let mut lines = self
346+
.inner
347+
.lines()
348+
.take_while(|line| {
349+
let metrics = line.metrics();
350+
match self.max_physical_height {
351+
Some(max_physical_height) => max_physical_height.get() > metrics.max_coord,
352+
_ => true,
353+
}
354+
})
355+
.peekable();
356+
357+
while let Some(line) = lines.next() {
358+
let last_line = lines.peek().is_none();
346359
for item in line.items() {
347360
match item {
348361
parley::PositionedLayoutItem::GlyphRun(glyph_run) => {

0 commit comments

Comments
 (0)