From 1118c0bcb2ce3ef8d5403dc58511ffa7eb98dfbb Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 9 Feb 2026 13:54:40 -0600 Subject: [PATCH] reduce resolution for generated svg for space savings --- src/ui/presenter.rs | 17 +++++++++-------- src/ui/text_svg.rs | 25 +++++++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 44b7ee1..2dd8d76 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -1118,14 +1118,15 @@ pub(crate) fn slide_view<'a>( BackgroundKind::Html => todo!(), }; if let Some(text) = &slide.text_svg - && let Some(handle) = &text.handle { - stack = stack.push( - image(handle) - .content_fit(ContentFit::ScaleDown) - .width(Length::Shrink) - .height(Length::Shrink), - ); - }; + && let Some(handle) = &text.handle + { + stack = stack.push( + image(handle) + .content_fit(ContentFit::Contain) + .width(Length::Fill) + .height(Length::Fill), + ); + }; Container::new(stack).center(Length::Fill).into() }) .into() diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 64e0043..e8f7a4f 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -263,7 +263,7 @@ impl TextSvg { self } - pub fn build(mut self) -> Self { + pub fn build(mut self, size: Size) -> Self { // debug!("starting..."); let mut path = dirs::data_local_dir().unwrap(); @@ -272,20 +272,25 @@ impl TextSvg { let mut final_svg = String::with_capacity(1024); - let size = Size::new(1920.0, 1080.0); - let font_size = f32::from(self.font.size); + let font_scale = size.height / 1080.0; + let font_size = f32::from(self.font.size) * font_scale; let total_lines = self.text.lines().count(); let half_lines = (total_lines / 2) as f32; let line_spacing = 10.0; let text_and_line_spacing = font_size + line_spacing; + let center_y = (size.width / 2.0).to_string(); + let x_width_padded = (size.width - 10.0).to_string(); + let (text_anchor, starting_y_position, text_x_position) = match self.alignment { TextAlignment::TopLeft => ("start", font_size, "10"), TextAlignment::TopCenter => { - ("middle", font_size, "990") + ("middle", font_size, center_y.as_str()) + } + TextAlignment::TopRight => { + ("end", font_size, x_width_padded.as_str()) } - TextAlignment::TopRight => ("end", font_size, "1910"), TextAlignment::MiddleLeft => { let middle_position = size.height / 2.0; let position = half_lines.mul_add( @@ -300,7 +305,7 @@ impl TextSvg { -text_and_line_spacing, middle_position, ); - ("middle", position, "990") + ("middle", position, center_y.as_str()) } TextAlignment::MiddleRight => { let middle_position = size.height / 2.0; @@ -308,7 +313,7 @@ impl TextSvg { -text_and_line_spacing, middle_position, ); - ("end", position, "1910") + ("end", position, x_width_padded.as_str()) } TextAlignment::BottomLeft => { let position = size.height @@ -320,13 +325,13 @@ impl TextSvg { let position = size.height - (total_lines as f32 * text_and_line_spacing); - ("middle", position, "990") + ("middle", position, center_y.as_str()) } TextAlignment::BottomRight => { let position = size.height - (total_lines as f32 * text_and_line_spacing); - ("end", position, "1910") + ("end", position, x_width_padded.as_str()) } }; @@ -481,7 +486,7 @@ pub fn text_svg_generator( .size(slide.font_size().try_into().unwrap()), ) .fontdb(Arc::clone(&fontdb)) - .build(); + .build(Size::new(1280.0, 720.0)); slide.text_svg = Some(text_svg); } }