mirror of
https://github.com/typst/typst
synced 2025-07-28 06:47:53 +08:00
More
This commit is contained in:
parent
627f5b9d4f
commit
7399513bfc
@ -471,6 +471,7 @@ display_possible_values!(DiagnosticFormat);
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)]
|
||||
pub enum Feature {
|
||||
Html,
|
||||
PdfEmbedding
|
||||
}
|
||||
|
||||
display_possible_values!(Feature);
|
||||
|
@ -117,6 +117,7 @@ impl SystemWorld {
|
||||
.iter()
|
||||
.map(|&feature| match feature {
|
||||
Feature::Html => typst::Feature::Html,
|
||||
Feature::PdfEmbedding => typst::Feature::PdfEmbedding
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -237,6 +237,7 @@ impl FromIterator<Feature> for Features {
|
||||
#[non_exhaustive]
|
||||
pub enum Feature {
|
||||
Html,
|
||||
PdfEmbedding
|
||||
}
|
||||
|
||||
/// A group of related standard library definitions.
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
mod raster;
|
||||
mod svg;
|
||||
mod pdf;
|
||||
|
||||
pub use self::raster::{
|
||||
ExchangeFormat, PixelEncoding, PixelFormat, RasterFormat, RasterImage,
|
||||
@ -468,11 +469,21 @@ impl ImageFormat {
|
||||
if is_svg(data) {
|
||||
return Some(Self::Vector(VectorFormat::Svg));
|
||||
}
|
||||
|
||||
if is_pdf(data) {
|
||||
return Some(Self::Vector(VectorFormat::Pdf))
|
||||
}
|
||||
|
||||
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.
|
||||
fn is_svg(data: &[u8]) -> bool {
|
||||
// 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 {
|
||||
/// The vector graphics format of the web.
|
||||
Svg,
|
||||
/// The PDF graphics format.
|
||||
Pdf,
|
||||
}
|
||||
|
||||
impl<R> From<R> for ImageFormat
|
||||
|
6
crates/typst-library/src/visualize/image/pdf.rs
Normal file
6
crates/typst-library/src/visualize/image/pdf.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
use crate::foundations::Bytes;
|
||||
|
||||
/// A PDF image.
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct PdfImage(Bytes);
|
Loading…
x
Reference in New Issue
Block a user