diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-14 17:32:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-14 18:07:18 +0200 |
| commit | 5e41672a91536c1f740bbc1630a6908adff57329 (patch) | |
| tree | 2f481ab7a205154b11deaf4925aa5a0f693d7f23 /src/layout | |
| parent | 7c0899b5373cdc4f1083a0a8515856207c431423 (diff) | |
Refactor and refine PDF exporter ♻
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/actions.rs | 8 | ||||
| -rw-r--r-- | src/layout/mod.rs | 15 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/layout/actions.rs b/src/layout/actions.rs index 3eb4fb7f..bbefbfc0 100644 --- a/src/layout/actions.rs +++ b/src/layout/actions.rs @@ -84,7 +84,7 @@ impl LayoutActionList { MoveAbsolute(pos) => self.next_pos = Some(self.origin + pos), DebugBox(pos, size) => self.actions.push(DebugBox(self.origin + pos, size)), - SetFont(index, size) if (index, size) != self.active_font => { + SetFont(index, size) => { self.next_font = Some((index, size)); } @@ -92,8 +92,12 @@ impl LayoutActionList { if let Some(target) = self.next_pos.take() { self.actions.push(MoveAbsolute(target)); } + if let Some((index, size)) = self.next_font.take() { - self.actions.push(SetFont(index, size)); + if (index, size) != self.active_font { + self.actions.push(SetFont(index, size)); + self.active_font = (index, size); + } } self.actions.push(action); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 14aa6417..abf140d6 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -76,6 +76,11 @@ impl MultiLayout { self.layouts.push(layout); } + /// The count of sublayouts. + pub fn count(&self) -> usize { + self.layouts.len() + } + /// Whether this layout contains any sublayouts. pub fn is_empty(&self) -> bool { self.layouts.is_empty() @@ -91,6 +96,16 @@ impl IntoIterator for MultiLayout { } } +impl<'a> IntoIterator for &'a MultiLayout { + type Item = &'a Layout; + type IntoIter = std::slice::Iter<'a, Layout>; + + fn into_iter(self) -> Self::IntoIter { + self.layouts.iter() + } +} + + /// The context for layouting. #[derive(Copy, Clone)] pub struct LayoutContext<'a, 'p> { |
