remove pdf module for inserting the handles as a slide field

This ensures that there isn't a need to duplicate tracking which index
we have and which one is currently active, instead we pre create all
the handles.
This commit is contained in:
Chris Cochrun 2025-09-15 11:00:38 -05:00
parent ad14135ddf
commit 191dd0255d
5 changed files with 65 additions and 189 deletions

View file

@ -1,6 +1,7 @@
use cosmic::widget::image::Handle;
use crisp::types::{Keyword, Symbol, Value};
use miette::{IntoDiagnostic, Result};
use mupdf::{Document, Page};
use mupdf::{Colorspace, Document, Matrix, Page};
use serde::{Deserialize, Serialize};
use sqlx::{
pool::PoolConnection, prelude::FromRow, query, sqlite::SqliteRow,
@ -131,13 +132,36 @@ impl ServiceTrait for Presentation {
let background = Background::try_from(self.path.clone())
.into_diagnostic()?;
debug!(?background);
let doc = Document::open(background.path.as_path())
let document = Document::open(background.path.as_path())
.into_diagnostic()?;
debug!(?doc);
let pages = doc.page_count().into_diagnostic()?;
debug!(?document);
let pages = document.pages().into_diagnostic()?;
debug!(?pages);
let pages: Vec<Handle> = pages
.filter_map(|page| {
let Some(page) = page.ok() else {
return None;
};
let matrix = Matrix::IDENTITY;
let colorspace = Colorspace::device_rgb();
let Ok(pixmap) = page
.to_pixmap(&matrix, &colorspace, true, true)
.into_diagnostic()
else {
error!("Can't turn this page into pixmap");
return None;
};
debug!(?pixmap);
Some(Handle::from_rgba(
pixmap.width(),
pixmap.height(),
pixmap.samples().to_vec(),
))
})
.collect();
let mut slides: Vec<Slide> = vec![];
for page in 0..pages {
for (index, page) in pages.into_iter().enumerate() {
let slide = SlideBuilder::new()
.background(
Background::try_from(self.path.clone())
@ -151,7 +175,8 @@ impl ServiceTrait for Presentation {
.video_loop(false)
.video_start_time(0.0)
.video_end_time(0.0)
.pdf_index(page as u32)
.pdf_index(index as u32)
.pdf_page(page)
.build()?;
slides.push(slide);
}

View file

@ -1,3 +1,4 @@
use cosmic::widget::image::Handle;
// use cosmic::dialog::ashpd::url::Url;
use crisp::types::{Keyword, Symbol, Value};
use iced_video_player::Video;
@ -34,6 +35,8 @@ pub struct Slide {
video_end_time: f32,
pdf_index: u32,
#[serde(skip)]
pdf_page: Option<Handle>,
#[serde(skip)]
pub text_svg: Option<TextSvg>,
}
@ -326,6 +329,10 @@ impl Slide {
self.audio.clone()
}
pub fn pdf_page(&self) -> Option<Handle> {
self.pdf_page.clone()
}
pub fn pdf_index(&self) -> u32 {
self.pdf_index
}
@ -547,6 +554,8 @@ pub struct SlideBuilder {
video_end_time: Option<f32>,
pdf_index: Option<u32>,
#[serde(skip)]
pdf_page: Option<Handle>,
#[serde(skip)]
text_svg: Option<TextSvg>,
}
@ -629,6 +638,11 @@ impl SlideBuilder {
self
}
pub(crate) fn pdf_page(mut self, pdf_page: Handle) -> Self {
let _ = self.pdf_page.insert(pdf_page);
self
}
pub(crate) fn pdf_index(
mut self,
pdf_index: impl Into<u32>,
@ -674,6 +688,7 @@ impl SlideBuilder {
video_end_time,
text_svg: self.text_svg,
pdf_index: self.pdf_index.unwrap_or_default(),
pdf_page: self.pdf_page,
..Default::default()
})
}