Extract pdf texture into a method

This commit is contained in:
Laurenz Stampfl 2025-07-19 23:52:27 +02:00
parent 4b733b5f8b
commit 9bacb89fc8
3 changed files with 58 additions and 53 deletions

1
Cargo.lock generated
View File

@ -3258,6 +3258,7 @@ dependencies = [
"comemo",
"ecow",
"flate2",
"hayro",
"image",
"ttf-parser",
"typst-library",

View File

@ -7,7 +7,7 @@ use tiny_skia::IntSize;
use typst_library::foundations::Smart;
use typst_library::layout::Size;
use typst_library::text::{FontBook, FontStretch, FontStyle, FontVariant, FontWeight};
use typst_library::visualize::{Image, ImageKind, ImageScaling};
use typst_library::visualize::{Image, ImageKind, ImageScaling, PdfImage};
use crate::{AbsExt, State};
@ -101,7 +101,13 @@ fn build_texture(image: &Image, w: u32, h: u32) -> Option<Arc<sk::Pixmap>> {
texture
}
ImageKind::Pdf(pdf) => {
ImageKind::Pdf(pdf) => build_pdf_texture(pdf, w, h)?,
};
Some(Arc::new(texture))
}
fn build_pdf_texture(pdf: &PdfImage, w: u32, h: u32) -> Option<sk::Pixmap> {
let sf = pdf.standard_fonts().clone();
let select_standard_font = move |font: StandardFont| -> Option<FontData> {
@ -149,11 +155,8 @@ fn build_texture(image: &Image, w: u32, h: u32) -> Option<Arc<sk::Pixmap>> {
width: Some(w as u16),
height: Some(h as u16),
};
let hayro_pix = hayro::render(page, &interpreter_settings, &render_settings);
sk::Pixmap::from_vec(hayro_pix.take_u8(), IntSize::from_wh(w, h)?)?
}
};
Some(Arc::new(texture))
sk::Pixmap::from_vec(hayro_pix.take_u8(), IntSize::from_wh(w, h)?)
}

View File

@ -21,6 +21,7 @@ base64 = { workspace = true }
comemo = { workspace = true }
ecow = { workspace = true }
flate2 = { workspace = true }
hayro = { workspace = true }
image = { workspace = true }
ttf-parser = { workspace = true }
xmlparser = { workspace = true }