Repository navigation
Dispatch content stream operators by matching on PdfOperatorVariant - #594
Merged
Velli20 merged 1 commit intoOct 21, 2026
Merged
Conversation
The operator backend traits (twelve per-category traits plus the PdfOperatorBackend supertrait) had one production implementor, PdfCanvas, and a test-only recorder that rebuilt a near-copy of PdfOperatorVariant. Nothing was generic over a single category trait, so the layer only added indirection over an enum that already describes every operator. PdfCanvas now dispatches through apply_operator, and its handlers are inherent methods. Tests check the parsed operators directly instead of replaying them through the recorder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #593 (both touch the canvas XObject/graphics-state handlers and
variants.rs). Retarget tomainonce #593 merges.Why
pdf_operator_backend.rsdefined twelve per-category operator traits plus thePdfOperatorBackendsupertrait. In practice:PdfCanvaswas the only production implementor; the other was a test-onlyRecordingBackend.RecordingBackendturned each parsedPdfOperatorVariantintoRecordedOperation, a near-copy of the same enum.PdfOperatorVariantis already a closed, data-only description of every operator, so the trait layer only added indirection.What
pdf_operator_backend.rs,recording_pdf_operator_backend.rs,PdfOperatorVariant::callandBeginMarkedContentWithProps::call.BeginMarkedContentWithPropsnow exposestag()andproperties()instead.PdfCanvas::apply_operatorincanvas_operator_dispatch.rs. Thecanvas_*_ops.rsandshading.rstrait impls are nowpub(crate)inherent methods.q/Qcallsave/restoredirectly.BX/EXandd0/d1share one no-op arm.mark_point*handlers are gone.AGENTS.md.Verification
cargo fmt --check,cargo clippy --all --workspaceandcargo check --no-default-featuresare clean.cargo test --workspacepasses, excludingpdf-graphics-skiaandpdf-conformance, which need a Skia download that wasn't available locally.cargo check --target wasm32-unknown-unknown -p web-canvas-examplepasses.text_recordingbench, shipped profile, 5 runs alternating with the previous commit: −0.5% to +0.9% per case, within noise.🤖 Generated with Claude Code