diff options
Diffstat (limited to 'src/export/render.rs')
| -rw-r--r-- | src/export/render.rs | 12 |
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; |
