mirror of
https://github.com/typst/typst
synced 2025-07-30 07:47:55 +08:00
Extract pdf texture into a method
This commit is contained in:
parent
4b733b5f8b
commit
9bacb89fc8
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3258,6 +3258,7 @@ dependencies = [
|
||||
"comemo",
|
||||
"ecow",
|
||||
"flate2",
|
||||
"hayro",
|
||||
"image",
|
||||
"ttf-parser",
|
||||
"typst-library",
|
||||
|
@ -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)?)
|
||||
}
|
||||
|
@ -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 }
|
||||
|
Loading…
x
Reference in New Issue
Block a user