This commit is contained in:
Laurenz Stampfl 2025-07-17 19:28:41 +02:00
parent 627f5b9d4f
commit 7399513bfc
5 changed files with 22 additions and 0 deletions

View File

@ -471,6 +471,7 @@ display_possible_values!(DiagnosticFormat);
#[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)] #[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)]
pub enum Feature { pub enum Feature {
Html, Html,
PdfEmbedding
} }
display_possible_values!(Feature); display_possible_values!(Feature);

View File

@ -117,6 +117,7 @@ impl SystemWorld {
.iter() .iter()
.map(|&feature| match feature { .map(|&feature| match feature {
Feature::Html => typst::Feature::Html, Feature::Html => typst::Feature::Html,
Feature::PdfEmbedding => typst::Feature::PdfEmbedding
}) })
.collect(); .collect();

View File

@ -237,6 +237,7 @@ impl FromIterator<Feature> for Features {
#[non_exhaustive] #[non_exhaustive]
pub enum Feature { pub enum Feature {
Html, Html,
PdfEmbedding
} }
/// A group of related standard library definitions. /// A group of related standard library definitions.

View File

@ -2,6 +2,7 @@
mod raster; mod raster;
mod svg; mod svg;
mod pdf;
pub use self::raster::{ pub use self::raster::{
ExchangeFormat, PixelEncoding, PixelFormat, RasterFormat, RasterImage, ExchangeFormat, PixelEncoding, PixelFormat, RasterFormat, RasterImage,
@ -468,11 +469,21 @@ impl ImageFormat {
if is_svg(data) { if is_svg(data) {
return Some(Self::Vector(VectorFormat::Svg)); return Some(Self::Vector(VectorFormat::Svg));
} }
if is_pdf(data) {
return Some(Self::Vector(VectorFormat::Pdf))
}
None None
} }
} }
/// Checks whether the data looks like a PDF file.
fn is_pdf(data: &[u8]) -> bool {
let head = &data[..data.len().min(2048)];
memchr::memmem::find(head, b"%PDF-").is_some()
}
/// Checks whether the data looks like an SVG or a compressed SVG. /// Checks whether the data looks like an SVG or a compressed SVG.
fn is_svg(data: &[u8]) -> bool { fn is_svg(data: &[u8]) -> bool {
// Check for the gzip magic bytes. This check is perhaps a bit too // Check for the gzip magic bytes. This check is perhaps a bit too
@ -493,6 +504,8 @@ fn is_svg(data: &[u8]) -> bool {
pub enum VectorFormat { pub enum VectorFormat {
/// The vector graphics format of the web. /// The vector graphics format of the web.
Svg, Svg,
/// The PDF graphics format.
Pdf,
} }
impl<R> From<R> for ImageFormat impl<R> From<R> for ImageFormat

View File

@ -0,0 +1,6 @@
use std::sync::Arc;
use crate::foundations::Bytes;
/// A PDF image.
#[derive(Clone, Hash)]
pub struct PdfImage(Bytes);