From ffaeda931697c97e1503d9c2610b115c838d7200 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 28 Oct 2026 01:06:48 +0000 Subject: [PATCH] Refactor pdf for strict Clippy checks --- crates/pdf/src/export.rs | 5 ++++- crates/pdf/src/exporter.rs | 7 ++++++- crates/pdf/src/exporter/draw.rs | 13 +++++++++---- crates/pdf/src/exporter/nav.rs | 5 ++++- crates/pdf/src/exporter/text.rs | 24 ++++++++++++++++-------- crates/pdf/src/glyphs.rs | 2 +- crates/pdf/src/metadata.rs | 2 +- crates/pdf/src/options.rs | 2 +- crates/pdf/src/paint.rs | 9 +++------ crates/pdf/src/picture.rs | 4 +++- crates/pdf/src/tags.rs | 2 +- 11 files changed, 49 insertions(+), 26 deletions(-) diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rs index 6d31b27276..a6f6abf81e 100644 --- a/crates/pdf/src/export.rs +++ b/crates/pdf/src/export.rs @@ -2,7 +2,10 @@ use super::exporter::Exporter; use super::metadata::metadata; use super::options::{PdfError, PdfOptions}; use super::paint::{clamp_side, ok}; -use super::*; +use super::{ + DocLayout, Document, HashMap, HashSet, KrillaError, LayoutCache, LayoutOptions, Page, PageSettings, Size, Transform, WriteError, Writer, krilla, + layout, write, +}; /// Lay out `doc` and write it as PDF. Without markup the layout is the final text: tracked /// deletions are left out, as in Word's "No Markup" view. With `comments` each page carries the diff --git a/crates/pdf/src/exporter.rs b/crates/pdf/src/exporter.rs index 6cf79baaa7..4d184f8663 100644 --- a/crates/pdf/src/exporter.rs +++ b/crates/pdf/src/exporter.rs @@ -4,7 +4,12 @@ use super::options::{PdfError, PdfOptions}; use super::paint::{append_path, fill, grown, norm, ok, paint_fill, pdf_line_cap, rect_path, shape_effects, shape_path}; use super::picture::{Vector, build_vector, load_image, paint_of, vector_picture}; use super::tags::{Role, TagEntry, figure_alt, graphic_alt, holds_picture}; -use super::*; +use super::{ + Annotation, Arc, Artifact, ArtifactType, ClKind, ContentTag, DisplayOptions, DocLayout, DocPath, Document, Draw, FaceRef, Fill, FillRule, Font, + GlyphId, HashMap, HashSet, Identifier, Image, InlineObject, ItemDisplay, KrillaGlyph, LineCap, LineEnd, LineJoin, LineStyle, LinkAnnotation, + Node, NonZeroU16, Outline, OutlineNode, Page, PathBuilder, Placed, Point, Rect, Rgb, ShapeKind, Size, SpanTag, StoryRef, Stroke, StrokeDash, + Surface, Tag, TagGroup, TagKind, TagTree, Target, Transform, WriteError, XyzDestination, krilla, rgb, write, +}; mod draw; mod nav; diff --git a/crates/pdf/src/exporter/draw.rs b/crates/pdf/src/exporter/draw.rs index 5d45b28c23..73b6d5e1a5 100644 --- a/crates/pdf/src/exporter/draw.rs +++ b/crates/pdf/src/exporter/draw.rs @@ -1,4 +1,8 @@ -use super::*; +use super::text::GlyphPaint; +use super::{ + Draw, Exporter, Fill, FillRule, LineCap, LineJoin, LineStyle, PathBuilder, Rect, Rgb, ShapeKind, Size, Stroke, StrokeDash, Surface, Transform, + append_path, fill, grown, krilla, norm, ok, paint_fill, pdf_line_cap, rect_path, rgb, shape_effects, shape_path, vector_picture, +}; impl Exporter<'_> { /// Paint one display item on the PDF surface in its current point-coordinate system. @@ -13,6 +17,7 @@ impl Exporter<'_> { } } Draw::Glyphs { face, size, glyphs, color, alpha, synth_bold, synth_italic, text, link, ranges, x_scale, .. } => { + let paint = GlyphPaint { color: *color, alpha: *alpha, bold: *synth_bold, italic: *synth_italic }; match glyphs.first().map(|g| g.1).filter(|_| x_scale.is_finite() && *x_scale > 0.0 && (x_scale - 1.0).abs() > 1e-4) { // Scaled letters (`w:w`): drawn stretched across from the run's start, their // positions brought back so the stretch puts each where the layout has it. @@ -20,10 +25,10 @@ impl Exporter<'_> { let k = *x_scale; let moved: Vec<(u32, f32, f32)> = glyphs.iter().map(|&(g, x, y)| (g, x0 + (x - x0) / k, y)).collect(); s.push_transform(&Transform::from_row(k, 0.0, 0.0, 1.0, x0 * (1.0 - k), 0.0)); - self.glyphs(s, face, *size, &moved, *color, *alpha, *synth_bold, *synth_italic, text, ranges); + self.glyphs(s, face, *size, &moved, paint, (text, ranges)); s.pop(); } - None => self.glyphs(s, face, *size, glyphs, *color, *alpha, *synth_bold, *synth_italic, text, ranges), + None => self.glyphs(s, face, *size, glyphs, paint, (text, ranges)), } if let Some(l) = link { self.link_rect(face, *size, glyphs, l); @@ -93,7 +98,7 @@ impl Exporter<'_> { let can_fill = *kind != ShapeKind::Line; let fx = effects.sanitized(); if !fx.is_empty() && (f.is_some() && can_fill || stroke.is_some()) { - shape_effects(s, *kind, *corner, rect, &fx, f.is_some() && can_fill, stroke.is_some(), *stroke_width); + shape_effects(s, (*kind, *corner), rect, &fx, (f.is_some() && can_fill, stroke.is_some(), *stroke_width)); } // Soft edges: the fill fades out toward the outline (which fades with it). if let (Some(rad), Some(c), true) = (fx.soft_edge, f.as_ref(), can_fill) { diff --git a/crates/pdf/src/exporter/nav.rs b/crates/pdf/src/exporter/nav.rs index e201590c93..1924748dfc 100644 --- a/crates/pdf/src/exporter/nav.rs +++ b/crates/pdf/src/exporter/nav.rs @@ -1,4 +1,7 @@ -use super::*; +use super::{ + Annotation, ClKind, DocPath, Exporter, Fit, HashMap, LineEnd, LinkAnnotation, Outline, OutlineNode, Placed, Point, StoryRef, Target, + XyzDestination, krilla, write, +}; impl Exporter<'_> { /// Where a bookmark is: (output page, x, y) — the page and line its start lands on, which diff --git a/crates/pdf/src/exporter/text.rs b/crates/pdf/src/exporter/text.rs index fff476667f..f41e17dbe0 100644 --- a/crates/pdf/src/exporter/text.rs +++ b/crates/pdf/src/exporter/text.rs @@ -1,4 +1,16 @@ -use super::*; +use super::{ + Exporter, FaceRef, Fill, FillRule, GlyphId, KrillaGlyph, Point, Rgb, Stroke, Surface, Transform, baseline, cluster_ends, fill, glyph_outlines, + left_to_right, norm, ok, paint_of, rgb, split_clusters, visual_order, +}; + +/// How a run of glyphs is painted: its colour, opacity and synthetic bold and italic. +#[derive(Clone, Copy)] +pub(super) struct GlyphPaint { + pub color: Rgb, + pub alpha: f32, + pub bold: bool, + pub italic: bool, +} impl Exporter<'_> { /// Unicode text for each glyph: (text, per-glyph byte range). Glyphs and the run's text are @@ -66,20 +78,16 @@ impl Exporter<'_> { (text.to_string(), ranges) } - #[allow(clippy::too_many_arguments)] pub(super) fn glyphs( &mut self, s: &mut Surface, face: &FaceRef, size: f32, glyphs: &[(u32, f32, f32)], - color: Rgb, - alpha: f32, - bold: bool, - italic: bool, - text: &str, - known: &[std::ops::Range], + style: GlyphPaint, + (text, known): (&str, &[std::ops::Range]), ) { + let GlyphPaint { color, alpha, bold, italic } = style; if !size.is_finite() || size <= 0.0 || size > 5000.0 { return; } diff --git a/crates/pdf/src/glyphs.rs b/crates/pdf/src/glyphs.rs index bad9a1b21a..be795047cd 100644 --- a/crates/pdf/src/glyphs.rs +++ b/crates/pdf/src/glyphs.rs @@ -1,5 +1,5 @@ use super::paint::append_path; -use super::*; +use super::{FaceRef, HashMap, Path, PathBuilder}; /// The outlines of `glyphs` (glyph id, pen position) at `size`, as one path in page coordinates. pub(crate) fn glyph_outlines(face: &FaceRef, size: f32, glyphs: &[(u32, f32, f32)]) -> Option { diff --git a/crates/pdf/src/metadata.rs b/crates/pdf/src/metadata.rs index 50933ad18d..31dc47e615 100644 --- a/crates/pdf/src/metadata.rs +++ b/crates/pdf/src/metadata.rs @@ -1,5 +1,5 @@ use super::options::PdfOptions; -use super::*; +use super::{DateTime, Document, Metadata}; pub(crate) fn metadata(doc: &Document, opts: &PdfOptions) -> Metadata { let c = &doc.core; diff --git a/crates/pdf/src/options.rs b/crates/pdf/src/options.rs index 3f3d850557..7300ce2101 100644 --- a/crates/pdf/src/options.rs +++ b/crates/pdf/src/options.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{NumeralMode, WriteError}; #[derive(Debug, Clone, PartialEq, thiserror::Error)] pub enum PdfError { diff --git a/crates/pdf/src/paint.rs b/crates/pdf/src/paint.rs index 54a0e1856a..cfa1139c5c 100644 --- a/crates/pdf/src/paint.rs +++ b/crates/pdf/src/paint.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Fill, FillRule, LineCap, NormalizedF32, Paint, Path, PathBuilder, Rect, Rgb, ShapeKind, Stroke, Surface, Transform, krilla, rgb}; /// Largest page side we write (200", the PDF limit). const MAX_SIDE: f32 = 14_400.0; @@ -89,13 +89,10 @@ pub(crate) fn grown(r: &Rect, g: f32, dx: f32, dy: f32) -> Rect { /// blur as the raster renderer, see [`wordcraft_doc::effects::bands`]). pub(crate) fn shape_effects( s: &mut Surface, - kind: ShapeKind, - corner: Option, + (kind, corner): (ShapeKind, Option), rect: &Rect, fx: &wordcraft_doc::effects::ShapeEffects, - filled: bool, - stroked: bool, - sw: f32, + (filled, stroked, sw): (bool, bool, f32), ) { let sw = if sw.is_finite() { sw.clamp(0.25, 200.0) } else { 0.75 }; let silhouette = |s: &mut Surface, c: Rgb, a: f32, g: f32, dx: f32, dy: f32| { diff --git a/crates/pdf/src/picture.rs b/crates/pdf/src/picture.rs index 0aaac38dc2..9be9f52250 100644 --- a/crates/pdf/src/picture.rs +++ b/crates/pdf/src/picture.rs @@ -1,6 +1,8 @@ use super::exporter::Exporter; use super::paint::{append_path, norm}; -use super::*; +use super::{ + Arc, Fill, FillRule, Image, LineCap, LineJoin, NormalizedF32, Path, PathBuilder, Picture, PlacedItem, Rect, Size, Stroke, Surface, Transform, rgb, +}; /// Largest picture side we embed (pixels). const MAX_IMAGE_SIDE: u32 = 30_000; diff --git a/crates/pdf/src/tags.rs b/crates/pdf/src/tags.rs index 8703b2bafa..f8186be42a 100644 --- a/crates/pdf/src/tags.rs +++ b/crates/pdf/src/tags.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{ArtifactType, Draw, GraphicKind, Node, TagKind}; /// A chart's or diagram's alt text: its own, else what it is ("chart", "diagram"). pub(crate) fn graphic_alt(alt: &str, kind: GraphicKind) -> &str {