summaryrefslogtreecommitdiff
path: root/src/export
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-24 15:05:59 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-24 15:05:59 +0200
commitf1025071edfb787309a75d4bb68bec0c2bd906bb (patch)
treeb28d6cf05b8a8f29acbfb44093e3c9bface802b6 /src/export
parentb96b7b7ee12a5d1c8e8c24c95b58b7ca03cec44b (diff)
Tidy up
Diffstat (limited to 'src/export')
-rw-r--r--src/export/render.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/export/render.rs b/src/export/render.rs
index 02c10e61..ef0fc9f2 100644
--- a/src/export/render.rs
+++ b/src/export/render.rs
@@ -488,14 +488,18 @@ fn render_image(
let view_width = size.x.to_f32();
let view_height = size.y.to_f32();
- let aspect = (image.width() as f32) / (image.height() as f32);
- // For better-looking output, resize `image` to its final size before painting it to `canvas`.
- // See https://github.com/typst/typst/issues/1404#issuecomment-1598374652 for the math.
+ // For better-looking output, resize `image` to its final size before
+ // painting it to `canvas`. For the math, see:
+ // https://github.com/typst/typst/issues/1404#issuecomment-1598374652
let theta = f32::atan2(-ts.kx, ts.sx);
- // To avoid division by 0, choose the one of { sin, cos } that is further from 0.
+
+ // To avoid division by 0, choose the one of { sin, cos } that is
+ // further from 0.
let prefer_sin = theta.sin().abs() > std::f32::consts::FRAC_1_SQRT_2;
let scale_x =
f32::abs(if prefer_sin { ts.kx / theta.sin() } else { ts.sx / theta.cos() });
+
+ let aspect = (image.width() as f32) / (image.height() as f32);
let w = (scale_x * view_width.max(aspect * view_height)).ceil() as u32;
let h = ((w as f32) / aspect).ceil() as u32;