From 42519403d5955d8e10dd804c8e64afe59163897c Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Tue, 17 Dec 2024 20:09:32 +0100 Subject: [PATCH] Reformat + clippy --- crates/typst-pdf/src/convert.rs | 18 +++++++++++++----- crates/typst-pdf/src/lib.rs | 2 +- crates/typst-pdf/src/paint.rs | 2 +- crates/typst-pdf/src/shape.rs | 2 +- crates/typst-pdf/src/text.rs | 4 ++-- crates/typst-pdf/src/util.rs | 7 ++----- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/typst-pdf/src/convert.rs b/crates/typst-pdf/src/convert.rs index 6b43b704a..dead2b702 100644 --- a/crates/typst-pdf/src/convert.rs +++ b/crates/typst-pdf/src/convert.rs @@ -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> { let span = gc.image_spans.get(&i).unwrap(); bail!(*span, "failed to process image"); } - } + }, } } -fn collect_named_destinations(document: &PagedDocument, options: &PdfOptions) -> HashMap { +fn collect_named_destinations( + document: &PagedDocument, + options: &PdfOptions, +) -> HashMap { let mut locs_to_names = HashMap::new(); // Find all headings that have a label and are the first among other diff --git a/crates/typst-pdf/src/lib.rs b/crates/typst-pdf/src/lib.rs index 3929d06ab..575a8739e 100644 --- a/crates/typst-pdf/src/lib.rs +++ b/crates/typst-pdf/src/lib.rs @@ -1,7 +1,7 @@ //! Exporting Typst documents to PDF. -mod image; mod convert; +mod image; mod link; mod metadata; mod outline; diff --git a/crates/typst-pdf/src/paint.rs b/crates/typst-pdf/src/paint.rs index b090daa4d..cce6e98be 100644 --- a/crates/typst-pdf/src/paint.rs +++ b/crates/typst-pdf/src/paint.rs @@ -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), }) } diff --git a/crates/typst-pdf/src/shape.rs b/crates/typst-pdf/src/shape.rs index 500ff240c..e2b8afa21 100644 --- a/crates/typst-pdf/src/shape.rs +++ b/crates/typst-pdf/src/shape.rs @@ -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, diff --git a/crates/typst-pdf/src/text.rs b/crates/typst-pdf/src/text.rs index f9815875c..7e242f1d2 100644 --- a/crates/typst-pdf/src/text.rs +++ b/crates/typst-pdf/src/text.rs @@ -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(), diff --git a/crates/typst-pdf/src/util.rs b/crates/typst-pdf/src/util.rs index cb89034cf..a98227dbd 100644 --- a/crates/typst-pdf/src/util.rs +++ b/crates/typst-pdf/src/util.rs @@ -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.