mirror of
https://github.com/typst/typst
synced 2025-06-08 05:06:24 +08:00
Reformat + clippy
This commit is contained in:
parent
cc35c8f6af
commit
42519403d5
@ -1,5 +1,6 @@
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
|
||||
use krilla::annotation::Annotation;
|
||||
use krilla::destination::{NamedDestination, XyzDestination};
|
||||
use krilla::error::KrillaError;
|
||||
use krilla::page::PageLabel;
|
||||
@ -8,7 +9,6 @@ use krilla::surface::Surface;
|
||||
use krilla::validation::ValidationError;
|
||||
use krilla::version::PdfVersion;
|
||||
use krilla::{Document, PageSettings, SerializeSettings};
|
||||
use krilla::annotation::Annotation;
|
||||
use typst_library::diag::{bail, SourceResult};
|
||||
use typst_library::foundations::NativeElement;
|
||||
use typst_library::introspection::Location;
|
||||
@ -48,7 +48,11 @@ pub fn convert(
|
||||
};
|
||||
|
||||
let mut document = Document::new_with(settings);
|
||||
let mut gc = GlobalContext::new(&typst_document, options, collect_named_destinations(typst_document, options));
|
||||
let mut gc = GlobalContext::new(
|
||||
typst_document,
|
||||
options,
|
||||
collect_named_destinations(typst_document, options),
|
||||
);
|
||||
|
||||
convert_pages(&mut gc, &mut document)?;
|
||||
|
||||
@ -62,7 +66,8 @@ fn convert_pages(gc: &mut GlobalContext, document: &mut Document) -> SourceResul
|
||||
let mut skipped_pages = 0;
|
||||
|
||||
for (i, typst_page) in gc.document.pages.iter().enumerate() {
|
||||
if gc.options
|
||||
if gc
|
||||
.options
|
||||
.page_ranges
|
||||
.as_ref()
|
||||
.is_some_and(|ranges| !ranges.includes_page_index(i))
|
||||
@ -436,11 +441,14 @@ fn finish(document: Document, gc: GlobalContext) -> SourceResult<Vec<u8>> {
|
||||
let span = gc.image_spans.get(&i).unwrap();
|
||||
bail!(*span, "failed to process image");
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_named_destinations(document: &PagedDocument, options: &PdfOptions) -> HashMap<Location, NamedDestination> {
|
||||
fn collect_named_destinations(
|
||||
document: &PagedDocument,
|
||||
options: &PdfOptions,
|
||||
) -> HashMap<Location, NamedDestination> {
|
||||
let mut locs_to_names = HashMap::new();
|
||||
|
||||
// Find all headings that have a label and are the first among other
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Exporting Typst documents to PDF.
|
||||
|
||||
mod image;
|
||||
mod convert;
|
||||
mod image;
|
||||
mod link;
|
||||
mod metadata;
|
||||
mod outline;
|
||||
|
@ -50,7 +50,7 @@ pub(crate) fn convert_stroke(
|
||||
line_join: stroke.join.to_krilla(),
|
||||
line_cap: stroke.cap.to_krilla(),
|
||||
opacity: NormalizedF32::new(opacity as f32 / 255.0).unwrap(),
|
||||
dash: stroke.dash.as_ref().map(|d| convert_dash(d)),
|
||||
dash: stroke.dash.as_ref().map(convert_dash),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ pub(crate) fn handle_shape(
|
||||
if let Some(paint) = &shape.fill {
|
||||
let fill = paint::convert_fill(
|
||||
gc,
|
||||
&paint,
|
||||
paint,
|
||||
shape.fill_rule,
|
||||
false,
|
||||
surface,
|
||||
|
@ -40,7 +40,7 @@ pub(crate) fn handle_text(
|
||||
surface.fill_glyphs(
|
||||
krilla::geom::Point::from_xy(0.0, 0.0),
|
||||
fill,
|
||||
&glyphs,
|
||||
glyphs,
|
||||
font.clone(),
|
||||
text,
|
||||
size.to_f32(),
|
||||
@ -58,7 +58,7 @@ pub(crate) fn handle_text(
|
||||
surface.stroke_glyphs(
|
||||
krilla::geom::Point::from_xy(0.0, 0.0),
|
||||
stroke,
|
||||
&glyphs,
|
||||
glyphs,
|
||||
font,
|
||||
text,
|
||||
size.to_f32(),
|
||||
|
@ -106,10 +106,7 @@ impl ColorExt for Color {
|
||||
/// Convert a color into a krilla RGB color and an alpha value.
|
||||
fn to_krilla_rgb(&self) -> (kr::Color, u8) {
|
||||
let components = self.to_space(ColorSpace::Srgb).to_vec4_u8();
|
||||
(
|
||||
kr::Color::new(components[0], components[1], components[2]).into(),
|
||||
components[3],
|
||||
)
|
||||
(kr::Color::new(components[0], components[1], components[2]), components[3])
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +114,7 @@ impl ColorExt for Color {
|
||||
pub(crate) fn display_font(font: &Font) -> String {
|
||||
let font_family = &font.info().family;
|
||||
let font_variant = font.info().variant;
|
||||
format!("{} ({:?})", font_family, font_variant)
|
||||
format!("{font_family} ({font_variant:?})")
|
||||
}
|
||||
|
||||
/// Build a typst path using a path builder.
|
||||
|
Loading…
x
Reference in New Issue
Block a user