Skip to content

Store annotation geometry as f32 pdf-graphics types - #564

Merged
Velli20 merged 1 commit into
mainfrom
annotation-f32-geometry
Oct 11, 2026
Merged

Velli20 merged 1 commit into
mainfrom
annotation-f32-geometry

Conversation

@Velli20

@Velli20 Velli20 commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Summary

Annotation Core kept its geometry in f64 while the renderer and viewport work in f32, so every projection narrowed rectangles, points, and quads back to f32. pdf-graphics also carried f64 copies of the Rect, Point, Quad, and Polyline methods only for this crate.

  • Annotation geometry is read from the PDF as f32: rectangles, points, quads, polylines, line endpoints, difference rectangles, border widths and dashes, and font sizes. Opacity, border-effect intensity, action duration, and destination coordinates stay f64.
  • pdf-graphics: the f64 geometry methods are folded into the f32 impls (Rect::union/translate/clamp_translation, Point::is_finite/translate, Quad::bounds/is_convex, Polyline::vertex_bounds/squiggle), and the narrowing helpers are removed. Rect::is_valid now also rejects rectangles whose width or height overflows. Size and Transform gain the optional serde and TypeScript derives.
  • /RD difference rectangles and the BoxAnnotation/FreeTextStyle insets derived from them are Rects.
  • AnnotationEntry exposes bounds, origin, size, and transform as Vec<Rect>, Point, Size, and Transform. css_matrix composes with Transform::post_concatenated instead of multiplying the matrices by hand.
  • SourceAnnotation::contents stays; it supplies the text of text notes, free text, popups, and the projection text fallback.

Browser contract

annotation_contract.ts is regenerated: difference_rect, insets, and the entry's bounds, origin, size, and transform are now objects instead of number tuples. The JS that read entry.size by index now uses width and height.

Test plan

  • cargo check --workspace --all-targets, cargo fmt --check
  • cargo clippy --all --workspace, excluding pdf-conformance
  • cargo test -p pdf-graphics -p pdf-annotation-core -p pdf-web -p pdf-document
  • cargo xtask annotation-types --check
  • cargo xtask web-canvas --profile debug
  • Not run locally: the pdf-conformance tests, because their Skia build downloads a prebuilt binary. The crate compiles.
  • Not checked: annotation placement and sizing in a browser.

🤖 Generated with Claude Code

Annotation Core kept its geometry in f64 while the renderer and viewport
work in f32, so every projection narrowed rectangles, points, and quads
back to f32 and pdf-graphics carried f64 copies of the Rect, Point, Quad,
and Polyline methods only for this crate.

Annotation geometry is now read from the PDF as f32: rectangles, points,
quads, polylines, line endpoints, difference rectangles, border widths and
dashes, and font sizes. Opacity, border-effect intensity, action duration,
and destination coordinates stay f64. The f64 geometry methods are folded
into the f32 impls and the narrowing helpers are gone.

Difference rectangles and the insets derived from them are Rects, and
AnnotationEntry exposes its bounds, origin, size, and transform as Rect,
Point, Size, and Transform instead of bare arrays. The browser contract
and the JS that reads the entry size follow the new shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Conformance reads

Documents that Safe-PDF reads differently from the base commit, compared with PDFium. A read
regresses when Safe-PDF fails to open a document it opened before, crashes or times out, or
counts a different number of pages than PDFium.

pdf.js corpus

1008 documents compared with 0d1303f: 2 read worse, 0 read better.

Regressions

Document Base This pull request
issue17190_1 read, 1 page timeout: time limit exceeded (stage safe-read)
issue19517 read, 1 page timeout: time limit exceeded (stage safe-read)

840 documents of the PDFium corpus read as on 0d1303f.

Details are in the job summaries of the workflow run. Rerun a case locally with
cargo conformance run --corpus <corpus> --read-only --case <id>.

@Velli20
Velli20 merged commit 2dab801 into main Oct 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant