diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-06-12 17:16:14 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-06-12 17:26:18 +0200 |
| commit | 6e3b1a2c80428d581d00b9d65e1c45401df2e210 (patch) | |
| tree | 34d4b1c200851aa77af66b737bfe445e2da11f44 /src/export | |
| parent | ed6550fdb08eae92bffab6b6b137b1e0eebf62c6 (diff) | |
Make all fields of `Frame` private
Diffstat (limited to 'src/export')
| -rw-r--r-- | src/export/pdf.rs | 18 | ||||
| -rw-r--r-- | src/export/render.rs | 12 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/export/pdf.rs b/src/export/pdf.rs index 4495bceb..cc84dbc3 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -611,19 +611,24 @@ impl<'a, 'b> PageExporter<'a, 'b> { } fn export(mut self, frame: &Frame) -> Page { + let size = frame.size(); + // Make the coordinate system start at the top-left. - self.bottom = frame.size.y.to_f32(); + self.bottom = size.y.to_f32(); self.transform(Transform { sx: Ratio::one(), ky: Ratio::zero(), kx: Ratio::zero(), sy: Ratio::new(-1.0), tx: Length::zero(), - ty: frame.size.y, + ty: size.y, }); + + // Encode the page into the content stream. self.write_frame(frame); + Page { - size: frame.size, + size, content: self.content, id: self.page_ref, links: self.links, @@ -648,7 +653,7 @@ impl<'a, 'b> PageExporter<'a, 'b> { } } - for &(pos, ref element) in &frame.elements { + for &(pos, ref element) in frame.elements() { let x = pos.x.to_f32(); let y = pos.y.to_f32(); match *element { @@ -669,8 +674,9 @@ impl<'a, 'b> PageExporter<'a, 'b> { self.transform(translation.pre_concat(group.transform)); if group.clips { - let w = group.frame.size.x.to_f32(); - let h = group.frame.size.y.to_f32(); + let size = group.frame.size(); + let w = size.x.to_f32(); + let h = size.y.to_f32(); self.content.move_to(0.0, 0.0); self.content.line_to(w, 0.0); self.content.line_to(w, h); diff --git a/src/export/render.rs b/src/export/render.rs index 9f088433..1387015b 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -23,8 +23,9 @@ use crate::Context; /// compilation so that fonts and images can be rendered and rendering artifacts /// can be cached. pub fn render(ctx: &Context, frame: &Frame, pixel_per_pt: f32) -> sk::Pixmap { - let pxw = (pixel_per_pt * frame.size.x.to_f32()).round().max(1.0) as u32; - let pxh = (pixel_per_pt * frame.size.y.to_f32()).round().max(1.0) as u32; + let size = frame.size(); + let pxw = (pixel_per_pt * size.x.to_f32()).round().max(1.0) as u32; + let pxh = (pixel_per_pt * size.y.to_f32()).round().max(1.0) as u32; let mut canvas = sk::Pixmap::new(pxw, pxh).unwrap(); canvas.fill(sk::Color::WHITE); @@ -43,7 +44,7 @@ fn render_frame( ctx: &Context, frame: &Frame, ) { - for (pos, element) in &frame.elements { + for (pos, element) in frame.elements() { let x = pos.x.to_f32(); let y = pos.y.to_f32(); let ts = ts.pre_translate(x, y); @@ -80,8 +81,9 @@ fn render_group( let mut mask = mask; let mut storage; if group.clips { - let w = group.frame.size.x.to_f32(); - let h = group.frame.size.y.to_f32(); + let size = group.frame.size(); + let w = size.x.to_f32(); + let h = size.y.to_f32(); if let Some(path) = sk::Rect::from_xywh(0.0, 0.0, w, h) .map(sk::PathBuilder::from_rect) .and_then(|path| path.transform(ts)) |
