adding pdf rendering
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-15 09:29:27 -05:00
parent 6532666c56
commit ad14135ddf
6 changed files with 177 additions and 78 deletions

View file

@ -174,6 +174,7 @@ impl Presenter {
},
scroll_id: Id::unique(),
current_font: cosmic::font::default(),
pdf_viewer: PdfViewer::default(),
}
}
@ -206,7 +207,8 @@ impl Presenter {
Message::SlideChange(slide) => {
let slide_text = slide.text();
debug!(slide_text, "slide changed");
debug!("comparing background...");
let bg = slide.background().clone();
debug!(?bg, "comparing background...");
let backgrounds_match =
self.current_slide.background()
== slide.background();
@ -223,6 +225,11 @@ impl Presenter {
self.reset_video();
}
if slide.background().kind == BackgroundKind::Pdf {
self.pdf_viewer
.insert_pdf(&slide.background().path);
}
let offset = AbsoluteOffset {
x: {
if self.current_slide_index > 2 {
@ -404,6 +411,7 @@ impl Presenter {
slide_view(
&self.current_slide,
&self.video,
&self.pdf_viewer,
self.current_font,
false,
true,
@ -414,6 +422,7 @@ impl Presenter {
slide_view(
&self.current_slide,
&self.video,
&self.pdf_viewer,
self.current_font,
false,
false,
@ -450,6 +459,7 @@ impl Presenter {
let container = slide_view(
&slide,
&self.video,
&self.pdf_viewer,
font,
true,
false,
@ -636,7 +646,6 @@ impl Presenter {
fn reset_video(&mut self) {
match self.current_slide.background().kind {
BackgroundKind::Image => self.video = None,
BackgroundKind::Video => {
let path = &self.current_slide.background().path;
if path.exists() {
@ -660,6 +669,7 @@ impl Presenter {
self.video = None;
}
}
_ => self.video = None,
}
}
@ -712,6 +722,7 @@ fn scale_font(font_size: f32, width: f32) -> f32 {
pub(crate) fn slide_view<'a>(
slide: &'a Slide,
video: &'a Option<Video>,
pdf_viewer: &'a PdfViewer,
font: Font,
delegate: bool,
hide_mouse: bool,
@ -788,6 +799,18 @@ pub(crate) fn slide_view<'a>(
Container::new(Space::new(0, 0))
}
}
BackgroundKind::Pdf => Container::new(
if let Some(pdf) = pdf_viewer.view(slide.pdf_index())
{
pdf.map(|_| Message::None)
} else {
Space::new(0.0, 0.0).into()
},
)
.center_x(width)
.center_y(size.height)
.clip(true),
BackgroundKind::Html => todo!(),
};
let stack = stack!(
black,