Reformat + clippy

This commit is contained in:
Laurenz Stampfl 2024-12-17 20:09:32 +01:00
parent cc35c8f6af
commit 42519403d5
6 changed files with 20 additions and 15 deletions

View File

@ -1,5 +1,6 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use krilla::annotation::Annotation;
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;
@ -8,7 +9,6 @@ use krilla::surface::Surface;
use krilla::validation::ValidationError; use krilla::validation::ValidationError;
use krilla::version::PdfVersion; use krilla::version::PdfVersion;
use krilla::{Document, PageSettings, SerializeSettings}; use krilla::{Document, PageSettings, SerializeSettings};
use krilla::annotation::Annotation;
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;
@ -48,7 +48,11 @@ pub fn convert(
}; };
let mut document = Document::new_with(settings); 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)?; 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; let mut skipped_pages = 0;
for (i, typst_page) in gc.document.pages.iter().enumerate() { for (i, typst_page) in gc.document.pages.iter().enumerate() {
if gc.options if gc
.options
.page_ranges .page_ranges
.as_ref() .as_ref()
.is_some_and(|ranges| !ranges.includes_page_index(i)) .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(); let span = gc.image_spans.get(&i).unwrap();
bail!(*span, "failed to process image"); 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(); let mut locs_to_names = HashMap::new();
// Find all headings that have a label and are the first among other // Find all headings that have a label and are the first among other

View File

@ -1,7 +1,7 @@
//! Exporting Typst documents to PDF. //! Exporting Typst documents to PDF.
mod image;
mod convert; mod convert;
mod image;
mod link; mod link;
mod metadata; mod metadata;
mod outline; mod outline;

View File

@ -50,7 +50,7 @@ pub(crate) fn convert_stroke(
line_join: stroke.join.to_krilla(), line_join: stroke.join.to_krilla(),
line_cap: stroke.cap.to_krilla(), line_cap: stroke.cap.to_krilla(),
opacity: NormalizedF32::new(opacity as f32 / 255.0).unwrap(), 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),
}) })
} }

View File

@ -19,7 +19,7 @@ pub(crate) fn handle_shape(
if let Some(paint) = &shape.fill { if let Some(paint) = &shape.fill {
let fill = paint::convert_fill( let fill = paint::convert_fill(
gc, gc,
&paint, paint,
shape.fill_rule, shape.fill_rule,
false, false,
surface, surface,

View File

@ -40,7 +40,7 @@ pub(crate) fn handle_text(
surface.fill_glyphs( surface.fill_glyphs(
krilla::geom::Point::from_xy(0.0, 0.0), krilla::geom::Point::from_xy(0.0, 0.0),
fill, fill,
&glyphs, glyphs,
font.clone(), font.clone(),
text, text,
size.to_f32(), size.to_f32(),
@ -58,7 +58,7 @@ pub(crate) fn handle_text(
surface.stroke_glyphs( surface.stroke_glyphs(
krilla::geom::Point::from_xy(0.0, 0.0), krilla::geom::Point::from_xy(0.0, 0.0),
stroke, stroke,
&glyphs, glyphs,
font, font,
text, text,
size.to_f32(), size.to_f32(),

View File

@ -106,10 +106,7 @@ impl ColorExt for Color {
/// Convert a color into a krilla RGB color and an alpha value. /// Convert a color into a krilla RGB color and an alpha value.
fn to_krilla_rgb(&self) -> (kr::Color, u8) { fn to_krilla_rgb(&self) -> (kr::Color, u8) {
let components = self.to_space(ColorSpace::Srgb).to_vec4_u8(); let components = self.to_space(ColorSpace::Srgb).to_vec4_u8();
( (kr::Color::new(components[0], components[1], components[2]), components[3])
kr::Color::new(components[0], components[1], components[2]).into(),
components[3],
)
} }
} }
@ -117,7 +114,7 @@ impl ColorExt for Color {
pub(crate) fn display_font(font: &Font) -> String { pub(crate) fn display_font(font: &Font) -> String {
let font_family = &font.info().family; let font_family = &font.info().family;
let font_variant = font.info().variant; let font_variant = font.info().variant;
format!("{} ({:?})", font_family, font_variant) format!("{font_family} ({font_variant:?})")
} }
/// Build a typst path using a path builder. /// Build a typst path using a path builder.