mirror of
https://github.com/typst/typst
synced 2025-08-15 23:48:32 +08:00
Reformat
This commit is contained in:
parent
c14eeae249
commit
ea021a29e3
@ -20,7 +20,10 @@ use typst::syntax::{FileId, Source, Span};
|
|||||||
use typst::WorldExt;
|
use typst::WorldExt;
|
||||||
use typst_pdf::{PdfOptions, Timestamp, Validator};
|
use typst_pdf::{PdfOptions, Timestamp, Validator};
|
||||||
|
|
||||||
use crate::args::{CompileArgs, CompileCommand, DiagnosticFormat, Input, Output, OutputFormat, PdfStandard, PdfVersion, WatchCommand};
|
use crate::args::{
|
||||||
|
CompileArgs, CompileCommand, DiagnosticFormat, Input, Output, OutputFormat,
|
||||||
|
PdfStandard, PdfVersion, WatchCommand,
|
||||||
|
};
|
||||||
#[cfg(feature = "http-server")]
|
#[cfg(feature = "http-server")]
|
||||||
use crate::server::HtmlServer;
|
use crate::server::HtmlServer;
|
||||||
use crate::timings::Timer;
|
use crate::timings::Timer;
|
||||||
@ -298,7 +301,7 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
|
|||||||
PdfStandard::A_3u => Validator::A_3u,
|
PdfStandard::A_3u => Validator::A_3u,
|
||||||
PdfStandard::A_4 => Validator::A_4,
|
PdfStandard::A_4 => Validator::A_4,
|
||||||
PdfStandard::A_4f => Validator::A_4f,
|
PdfStandard::A_4f => Validator::A_4f,
|
||||||
PdfStandard::A_4e => Validator::A_4e
|
PdfStandard::A_4e => Validator::A_4e,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -319,7 +322,7 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
|
|||||||
timestamp,
|
timestamp,
|
||||||
page_ranges: config.pages.clone(),
|
page_ranges: config.pages.clone(),
|
||||||
validator,
|
validator,
|
||||||
pdf_version
|
pdf_version,
|
||||||
};
|
};
|
||||||
let buffer = typst_pdf::pdf(document, &options)?;
|
let buffer = typst_pdf::pdf(document, &options)?;
|
||||||
config
|
config
|
||||||
|
@ -140,7 +140,14 @@ impl RasterImage {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self(Arc::new(Repr { data, format, is_rotated, dynamic: Arc::new(dynamic), icc, dpi })))
|
Ok(Self(Arc::new(Repr {
|
||||||
|
data,
|
||||||
|
format,
|
||||||
|
is_rotated,
|
||||||
|
dynamic: Arc::new(dynamic),
|
||||||
|
icc,
|
||||||
|
dpi,
|
||||||
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The raw image data.
|
/// The raw image data.
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
|
|
||||||
use krilla::annotation::Annotation;
|
use krilla::annotation::Annotation;
|
||||||
|
use krilla::configure::{Configuration, PdfVersion, ValidationError};
|
||||||
use krilla::destination::{NamedDestination, XyzDestination};
|
use krilla::destination::{NamedDestination, XyzDestination};
|
||||||
use krilla::error::KrillaError;
|
use krilla::error::KrillaError;
|
||||||
use krilla::page::PageLabel;
|
use krilla::page::PageLabel;
|
||||||
use krilla::path::PathBuilder;
|
use krilla::path::PathBuilder;
|
||||||
use krilla::surface::Surface;
|
use krilla::surface::Surface;
|
||||||
use krilla::{Document, PageSettings, SerializeSettings};
|
use krilla::{Document, PageSettings, SerializeSettings};
|
||||||
use krilla::configure::{Configuration, PdfVersion, ValidationError};
|
|
||||||
use typst_library::diag::{bail, SourceResult};
|
use typst_library::diag::{bail, SourceResult};
|
||||||
use typst_library::foundations::NativeElement;
|
use typst_library::foundations::NativeElement;
|
||||||
use typst_library::introspection::Location;
|
use typst_library::introspection::Location;
|
||||||
@ -319,7 +319,11 @@ pub(crate) fn handle_group(
|
|||||||
|
|
||||||
/// Finish a krilla document and handle export errors.
|
/// Finish a krilla document and handle export errors.
|
||||||
fn finish(document: Document, gc: GlobalContext) -> SourceResult<Vec<u8>> {
|
fn finish(document: Document, gc: GlobalContext) -> SourceResult<Vec<u8>> {
|
||||||
let validator: krilla::configure::Validator = gc.options.validator.map(|v| v.into()).unwrap_or(krilla::configure::Validator::None);
|
let validator: krilla::configure::Validator = gc
|
||||||
|
.options
|
||||||
|
.validator
|
||||||
|
.map(|v| v.into())
|
||||||
|
.unwrap_or(krilla::configure::Validator::None);
|
||||||
|
|
||||||
match document.finish() {
|
match document.finish() {
|
||||||
Ok(r) => Ok(r),
|
Ok(r) => Ok(r),
|
||||||
@ -334,10 +338,8 @@ fn finish(document: Document, gc: GlobalContext) -> SourceResult<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
KrillaError::ValidationError(ve) => {
|
KrillaError::ValidationError(ve) => {
|
||||||
// We can only produce 1 error, so just take the first one.
|
// We can only produce 1 error, so just take the first one.
|
||||||
let prefix = format!(
|
let prefix =
|
||||||
"validated export for {} failed:",
|
format!("validated export for {} failed:", validator.as_str());
|
||||||
validator.as_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
match &ve[0] {
|
match &ve[0] {
|
||||||
ValidationError::TooLongString => {
|
ValidationError::TooLongString => {
|
||||||
|
@ -8,7 +8,9 @@ use krilla::SvgSettings;
|
|||||||
use typst_library::diag::{bail, SourceResult};
|
use typst_library::diag::{bail, SourceResult};
|
||||||
use typst_library::foundations::Smart;
|
use typst_library::foundations::Smart;
|
||||||
use typst_library::layout::Size;
|
use typst_library::layout::Size;
|
||||||
use typst_library::visualize::{ExchangeFormat, Image, ImageKind, ImageScaling, RasterFormat, RasterImage};
|
use typst_library::visualize::{
|
||||||
|
ExchangeFormat, Image, ImageKind, ImageScaling, RasterFormat, RasterImage,
|
||||||
|
};
|
||||||
use typst_syntax::Span;
|
use typst_syntax::Span;
|
||||||
|
|
||||||
use crate::convert::{FrameContext, GlobalContext};
|
use crate::convert::{FrameContext, GlobalContext};
|
||||||
@ -43,10 +45,7 @@ pub(crate) fn handle_image(
|
|||||||
surface.draw_svg(
|
surface.draw_svg(
|
||||||
svg.tree(),
|
svg.tree(),
|
||||||
size.to_krilla(),
|
size.to_krilla(),
|
||||||
SvgSettings {
|
SvgSettings { embed_text: true, ..Default::default() },
|
||||||
embed_text: true,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,12 +158,16 @@ impl CustomImage for PdfImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[comemo::memoize]
|
#[comemo::memoize]
|
||||||
fn convert_raster(raster: RasterImage, interpolate: bool) -> Option<krilla::image::Image> {
|
fn convert_raster(
|
||||||
|
raster: RasterImage,
|
||||||
|
interpolate: bool,
|
||||||
|
) -> Option<krilla::image::Image> {
|
||||||
match raster.format() {
|
match raster.format() {
|
||||||
RasterFormat::Exchange(e) => match e {
|
RasterFormat::Exchange(e) => match e {
|
||||||
ExchangeFormat::Jpg => {
|
ExchangeFormat::Jpg => {
|
||||||
if !raster.is_rotated() {
|
if !raster.is_rotated() {
|
||||||
let image_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(raster.data().clone());
|
let image_data: Arc<dyn AsRef<[u8]> + Send + Sync> =
|
||||||
|
Arc::new(raster.data().clone());
|
||||||
krilla::image::Image::from_jpeg(image_data.into(), interpolate)
|
krilla::image::Image::from_jpeg(image_data.into(), interpolate)
|
||||||
} else {
|
} else {
|
||||||
// Can't embed original JPEG data if it had to be rotated.
|
// Can't embed original JPEG data if it had to be rotated.
|
||||||
@ -172,7 +175,9 @@ fn convert_raster(raster: RasterImage, interpolate: bool) -> Option<krilla::imag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => krilla::image::Image::from_custom(PdfImage::new(raster), interpolate),
|
_ => krilla::image::Image::from_custom(PdfImage::new(raster), interpolate),
|
||||||
|
},
|
||||||
|
RasterFormat::Pixel(_) => {
|
||||||
|
krilla::image::Image::from_custom(PdfImage::new(raster), interpolate)
|
||||||
}
|
}
|
||||||
RasterFormat::Pixel(_) => krilla::image::Image::from_custom(PdfImage::new(raster), interpolate)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,18 +79,16 @@ fn convert_font(
|
|||||||
if let Some(font) = gc.fonts_forward.get(&typst_font) {
|
if let Some(font) = gc.fonts_forward.get(&typst_font) {
|
||||||
Ok(font.clone())
|
Ok(font.clone())
|
||||||
} else {
|
} else {
|
||||||
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> = Arc::new(typst_font.data().clone());
|
let font_data: Arc<dyn AsRef<[u8]> + Send + Sync> =
|
||||||
let font = match krilla::font::Font::new(
|
Arc::new(typst_font.data().clone());
|
||||||
font_data.into(),
|
let font =
|
||||||
typst_font.index(),
|
match krilla::font::Font::new(font_data.into(), typst_font.index(), true) {
|
||||||
true,
|
None => {
|
||||||
) {
|
let font_str = display_font(&typst_font);
|
||||||
None => {
|
bail!(Span::detached(), "failed to process font {font_str}");
|
||||||
let font_str = display_font(&typst_font);
|
}
|
||||||
bail!(Span::detached(), "failed to process font {font_str}");
|
Some(f) => f,
|
||||||
}
|
};
|
||||||
Some(f) => f,
|
|
||||||
};
|
|
||||||
|
|
||||||
gc.fonts_forward.insert(typst_font.clone(), font.clone());
|
gc.fonts_forward.insert(typst_font.clone(), font.clone());
|
||||||
gc.fonts_backward.insert(font.clone(), typst_font.clone());
|
gc.fonts_backward.insert(font.clone(), typst_font.clone());
|
||||||
|
@ -6,7 +6,9 @@ use krilla::path as kp;
|
|||||||
use krilla::path::PathBuilder;
|
use krilla::path::PathBuilder;
|
||||||
use typst_library::layout::{Abs, Point, Size, Transform};
|
use typst_library::layout::{Abs, Point, Size, Transform};
|
||||||
use typst_library::text::Font;
|
use typst_library::text::Font;
|
||||||
use typst_library::visualize::{Color, ColorSpace, Curve, CurveItem, FillRule, LineCap, LineJoin};
|
use typst_library::visualize::{
|
||||||
|
Color, ColorSpace, Curve, CurveItem, FillRule, LineCap, LineJoin,
|
||||||
|
};
|
||||||
|
|
||||||
pub(crate) trait SizeExt {
|
pub(crate) trait SizeExt {
|
||||||
fn to_krilla(&self) -> kg::Size;
|
fn to_krilla(&self) -> kg::Size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user