mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-12 00:44:27 -06:00
Refactor pdf for strict Clippy checks
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<usize>],
|
||||
style: GlyphPaint,
|
||||
(text, known): (&str, &[std::ops::Range<usize>]),
|
||||
) {
|
||||
let GlyphPaint { color, alpha, bold, italic } = style;
|
||||
if !size.is_finite() || size <= 0.0 || size > 5000.0 {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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<Path> {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{NumeralMode, WriteError};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
|
||||
pub enum PdfError {
|
||||
|
||||
@@ -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<u32>,
|
||||
(kind, corner): (ShapeKind, Option<u32>),
|
||||
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| {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user