Skip to content

Commit

Permalink
Convert style conversion in a method
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 20, 2024
1 parent ae95c49 commit 74cff35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 5 additions & 10 deletions parley/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::style::*;
use super::FontContext;

#[cfg(feature = "std")]
use super::layout::{Decoration, Layout, Style};
use super::layout::Layout;

use swash::shape::ShapeContext;
use swash::text::cluster::CharInfo;
Expand Down Expand Up @@ -146,15 +146,10 @@ impl<'a, B: Brush, T: TextSource> RangedBuilder<'a, B, T> {
}

// Copy the visual styles into the layout
layout.data.styles.extend(lcx.styles.iter().map(|s| {
let s = &s.style;
Style {
brush: s.brush.clone(),
underline: s.underline.into_layout_decoration(&s.brush),
strikethrough: s.strikethrough.into_layout_decoration(&s.brush),
line_height: s.line_height,
}
}));
layout
.data
.styles
.extend(lcx.styles.iter().map(|s| s.style.as_layout_style()));

// Sort the inline boxes as subsequent code assumes that they are in text index order.
// Note: It's important that this is a stable sort to allow users to control the order of contiguous inline boxes
Expand Down
9 changes: 9 additions & 0 deletions parley/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ impl<B: Brush> ResolvedStyle<B> {
LetterSpacing(value) => nearly_eq(self.letter_spacing, *value),
}
}

pub(crate) fn as_layout_style(&self) -> layout::Style<B> {
layout::Style {
brush: self.brush.clone(),
underline: self.underline.as_layout_decoration(&self.brush),
strikethrough: self.strikethrough.as_layout_decoration(&self.brush),
line_height: self.line_height,
}
}
}

/// Underline or strikethrough decoration.
Expand Down

0 comments on commit 74cff35

Please sign in to comment.