Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / pdf / src / main / rust / SPEC_COVERAGE.md

SPEC_COVERAGE.md24.6 KiBRenderedCodeRaw
1# Spec coverage matrix (ISO 32000-1)
2
3A per-feature inventory of what this renderer implements, what it deliberately ignores,
4and — for each gap — how likely it is to appear in a real document and how visible its
5absence would be.
6
7The point of this document is that an **unimplemented** feature never shows up in code
8review, because there is no code to review. It produces the same user-visible symptom as
9a bug ("things that should be there are not rendered") while looking clean from the
10inside. So the inventory is exhaustive even where the answer is boring.
11
12## How to read this
13
14| Status | Meaning |
15| --- | --- |
16| **full** | Implemented to spec, to the fidelity the flat-primitive wire format allows. |
17| **partial** | Implemented, with a named limitation. The limitation is always stated. |
18| **ignored** | Recognised and deliberately given no effect, with the reason stated. Not an oversight. |
19| **missing** | Not implemented. Triaged below. |
20
21"Ignored" is a real answer, not a euphemism. Round 2 removed an overprint approximation
22because simulating it was **worse** than ignoring it: `white MULTIPLY dst == dst` turned
23white knockout rectangles into no-ops and let content that was meant to be covered
24reappear. Where a partial simulation would change the common case in order to improve the
25rare one, this renderer ignores the feature and says so.
26
27Triage columns are a judgement about real-world producers (Acrobat/Distiller, Illustrator,
28InDesign, Word, LaTeX, Ghostscript, scanner firmware), not about the spec. A feature no
29real producer emits is not worth implementing however cleanly it is specified.
30
31---
32
33## 1. Content-stream operators (Annex A, Table A.1)
34
35**All 73 operators in Table A.1 are recognised.** There is no operator that falls through
36to the catch-all arm, so there is no case where the interpreter silently skips a construct
37it does not know about. The dispatch is the single `match op.operator.as_str()` in
38`src/interpret.rs`.
39
40`ID` is not listed separately: `lopdf` delivers an inline image as one `BI` operation whose
41operand is the whole stream, so `BI`/`ID`/`EI` are one unit here (`EI` is matched as a
42no-op for streams that emit it separately).
43
44### Graphics state
45
46| Op | Status | Note |
47| --- | --- | --- |
48| `q` `Q` | full | Bounded by `MAX_GRAPHICS_STACK_HARD`; overflow is counted so an unmatched `Q` cannot pop a frame it does not own. |
49| `cm` | full | Non-finite results rejected, since a poisoned CTM makes whole regions vanish. |
50| `w` `J` `j` `M` `d` | full | |
51| `i` | full | Feeds `bezier_steps_for_flatness` (§10.6.2). |
52| `gs` | **partial** | Table 58 subset — see §2. |
53| `ri` | ignored | §8.6.5.8. See `/RI` in §2. |
54
55### Path construction and painting
56
57| Op | Status | Note |
58| --- | --- | --- |
59| `m` `l` `c` `v` `y` `h` `re` | full | `l`/`c` with no current point are no-ops per §8.5.2.1 rather than fabricating a subpath. |
60| `S` `s` `f` `F` `f*` `B` `B*` `b` `b*` `n` | full | Including pattern fills/strokes and soft-mask bracketing. |
61| `W` `W*` | full | One `ClipPush` per operator, carrying the full path (beziers retained) so holes survive. |
62| `sh` | full | Shading types 1-7 all real. Every content stream that can host one now seeds its clip extent — see §7 item 1 for why that was load-bearing, and for the single documented remainder (Type 3 CharProcs). |
63
64### Colour
65
66| Op | Status | Note |
67| --- | --- | --- |
68| `CS` `cs` | full | Selecting a space resets the colour to its initial value (§8.6.8). |
69| `SC` `sc` `SCN` `scn` | full | Including `/Pattern` with an underlying base space for uncoloured (`/PaintType 2`) patterns. |
70| `G` `g` `RG` `rg` `K` `k` | full | |
71
72### Text
73
74| Op | Status | Note |
75| --- | --- | --- |
76| `BT` `ET` | full | `ET` commits an accumulated text clip. |
77| `Tc` `Tw` `Tz` `TL` `Ts` `Tf` | full | |
78| `Tr` | **partial** | Modes 0-3 full. Clip modes 4-7 build the clip from substitute-glyph records, so **Type 3 glyphs and glyphs with no recoverable Unicode contribute nothing to it**. See §7. |
79| `Td` `TD` `Tm` `T*` | full | |
80| `Tj` `TJ` `'` `"` | full | Vertical writing mode (`/W2`, `/DW2`) honoured on the advance and the position vector. |
81
82### XObjects, images, marked and compatibility
83
84| Op | Status | Note |
85| --- | --- | --- |
86| `Do` | full | Image and Form subtypes. `/Subtype /PS` is correctly ignored (§8.8.2 says a reader shall ignore PostScript XObjects). Form `/BBox` clip, `/Matrix`, `/Group`, and `/OC` all honoured. Recursion bounded at depth 10. The form recursion is gated on the surrounding BDC bracket's hidden flag (§8.11.2) — see §7 item 0. |
87| `BI` … `EI` | full | With a lenient re-tokenizer, because `lopdf` wraps inline-image parsing in a nom `cut(...)` and one unparseable image used to blank the whole stream. |
88| `BMC` `BDC` `EMC` | full | Optional content, with inherited hiding (§8.11.4.5) and 1:1 nesting. Every construct that can paint is gated on the hidden flag: paths, images, `sh`, patterns, text (via render mode 3, so hidden text stays searchable), Type 3 CharProcs (same), soft-mask brackets, and the form recursion. |
89| `MP` `DP` | ignored | Marked-content *points*: no matching `EMC`, so correctly excluded from the stack. |
90| `BX` `EX` | ignored | Correct by construction. §7.8.2 requires unrecognised operators inside a compatibility section to be ignored along with their operands; every unrecognised operator is already ignored everywhere, and `lopdf` groups operands with their operator, so the operands go too. |
91| `d0` `d1` | **partial** | Recognised and treated as no-ops, which is right for the width/bbox declaration itself. **Not enforced:** §9.6.5 says a `d1` glyph is a shape only and colour operators inside it *shall be ignored*. Here they take effect. See §7. |
92
93---
94
95## 2. ExtGState parameters (§8.4.5, Table 58)
96
97Implemented in the `"gs"` arm of `src/interpret.rs`. All 26 keys accounted for.
98
99| Key | Status | Spec | Real-world likelihood | Visibility if absent |
100| --- | --- | --- | --- | --- |
101| `/LW` | full | 8.4.3.2 | common | — |
102| `/LC` | full | 8.4.3.3 | common | — |
103| `/LJ` | full | 8.4.3.4 | common | — |
104| `/ML` | full | 8.4.3.5 | common | — |
105| `/D` | full | 8.4.3.6 | common | — |
106| `/FL` | **full (added this round)** | 8.4.5 / 10.6.2 | uncommon | low — visibly faceted large curves |
107| `/Font` | **full (added this round)** | 8.4.5 / 9.3.1 | rare | high — text at the wrong place, spacing and encoding. Two documented limits: the registration bypasses the font cache, and an *inherited* selection does not resolve inside a nested stream (as is already true of an inherited `Tf` resource name). |
108| `/BM` | full | 11.3.5 | very common | — |
109| `/SMask` | full | 11.6.5 | very common | — |
110| `/CA` | full | 11.6.4.4 | very common | — |
111| `/ca` | full | 11.6.4.4 | very common | - |
112| `/RI` | ignored | 8.6.5.8 | common (as `/RelativeColorimetric`) | none |
113| `/OP` `/op` `/OPM` | ignored | 8.6.7 | common in print PDFs | none on an RGB device; **simulating it is actively harmful** |
114| `/TR` `/TR2` | ignored | 10.4 | rare non-identity | see below |
115| `/HT` | ignored | 10.5 | uncommon | none |
116| `/BG` `/BG2` | ignored | 10.3 | uncommon | none |
117| `/UCR` `/UCR2` | ignored | 10.3 | uncommon | none |
118| `/SM` | ignored | 10.6.3 | common | none |
119| `/SA` | ignored | 10.6 | common | very low |
120| `/TK` | ignored | 9.3.8 | rare | very low |
121| `/AIS` | ignored | 11.6.4.3 | rare | low |
122
123### Why `/TR` and `/TR2` are ignored
124
125This was the leading suspicion going into this round, so it is worth stating the reasoning
126rather than the conclusion.
127
128`/TR` is real and it does apply to **all** painting, not only to soft masks. But it sits in
129Clause 10, *Rendering*, alongside halftones, black generation and undercolour removal, and
130§10.4 defines it as operating on the **device colour components after conversion into the
131device colour space**. It is press calibration: the mechanism by which a document
132compensates for a specific output device's tone response. It is not a description of what
133the page looks like.
134
135Three things follow.
136
1371. Our device colour space is 8-bit sRGB assembled from whatever space the document used.
138 A curve authored to linearise a CMYK press applied to those components is not "more
139 correct" — it is a different wrong answer.
1402. Honouring it would have to be all-or-nothing, and it cannot be. Fill, stroke and text
141 colours are computed in Rust and could be remapped through a LUT. A `DCTDecode` image is
142 handed to the renderer as **JPEG bytes** and cannot be. So an inverting `/TR` — the one
143 case where `/TR` is dramatic rather than subtle — would invert the vector artwork and
144 leave every photograph alone. A uniformly wrong page is better than a half-inverted one.
145 This is round 2's overprint lesson applied verbatim.
1463. Non-identity `/TR` is rare in the wild. The overwhelmingly common occurrences are
147 `/TR /Identity` and `/TR2 /Default`, which are no-ops by definition.
148
149**The half of transfer functions that genuinely matters is implemented.** §11.6.5.2's soft
150mask `/TR` is a completely different parameter: it maps the *mask value*, not device
151colour, it is device-**in**dependent, and an inverting one (`{ 1 exch sub }`, or Type 2 with
152`/C0 [1] /C1 [0]`) is the standard idiom for "mask out where the group is bright" — so
153ignoring it hides exactly the wrong half of the content. That one is parsed
154(`functions::read_transfer_lut`), sampled to a 256-entry LUT, carried on the wire as
155`SoftMaskTransfer` (tag 13) and applied by the renderer. Note the asymmetry: the same key
156name in two dictionaries, one ignorable and one not.
157
158### Why `/HT` is ignored
159
160Deliberately, not accidentally. A halftone screen exists to represent continuous tone on a
161**bilevel** device by trading spatial resolution for tonal resolution. The output here is
1628-bit-per-channel antialiased RGB, which represents the requested tone directly. Applying a
163screen could only throw tonal resolution away. Same reasoning covers `/BG`, `/BG2`, `/UCR`
164and `/UCR2`, which are defined only for the DeviceGray → DeviceCMYK conversion that never
165happens here.
166
167---
168
169## 3. Colour spaces (§8.6, Table 61)
170
171| Space | Status | Note |
172| --- | --- | --- |
173| DeviceGray, DeviceRGB, DeviceCMYK | full | Plus the `/G` `/RGB` `/CMYK` inline abbreviations. |
174| CalGray, CalRGB | full | White point, gamma, matrix. |
175| Lab | full | White point and `/Range`. |
176| ICCBased | **partial** | Resolved through `/Alternate`, or by `/N` when absent. There is no ICC transform engine; this is what every non-colour-managed viewer does and the deviation is small for the sRGB-like profiles that dominate. |
177| Indexed | full | Any base space, `/Hival`, lookup as string or stream. |
178| Separation | full | Tint transform through any function type. |
179| DeviceN | full | As Separation, n-component. |
180| Pattern | full | With and without an underlying base space. |
181| `/DefaultRGB` `/DefaultGray` `/DefaultCMYK` | **missing** | §8.6.5.6 resource-level substitution of a CIE-based space for a device space. Likelihood: rare. Visibility: none — ignoring them means using the device space directly, which is what viewers do anyway. Not worth implementing. |
182
183## 4. Shadings (§8.7.4.5)
184
185| Type | Status |
186| --- | --- |
187| 1 function-based | full |
188| 2 axial | full — `/Domain`, both `/Extend` flags, `/Background`, `/BBox` |
189| 3 radial | full — including the non-negative-radius constraint and both `/Extend` flags |
190| 4 free-form Gouraud triangle mesh | full |
191| 5 lattice-form Gouraud mesh | full — `/VerticesPerRow` |
192| 6 Coons patch mesh | full |
193| 7 tensor-product patch mesh | full — including the 4 interior control points |
194
195`/Function` on types 4-7 (colour as a single parametric value through a function rather
196than as direct components, §8.7.4.5.5) is handled. `/AntiAlias` (Table 78) is ignored;
197the spec itself calls it a hint that may be disregarded.
198
199## 5. Functions (§7.10)
200
201| Type | Status |
202| --- | --- |
203| 0 sampled | full — n-D multilinear interpolation, all of Table 39's `/BitsPerSample` values, `/Encode`, `/Decode` |
204| 2 exponential | full — with `/Range`-implied output arity when `/C0`/`/C1` are absent |
205| 3 stitching | full |
206| 4 PostScript calculator | full — the entire operator set of Table 42 |
207
208Array-of-functions is supported everywhere a `/Function` may be an array.
209
210## 6. Filters (§7.4) and fonts (§9.5-9.7)
211
212All ten filters are recognised, with abbreviations: `ASCIIHexDecode`, `ASCII85Decode`,
213`LZWDecode`, `FlateDecode` (both with `/Predictor`), `RunLengthDecode`, `CCITTFaxDecode`,
214`DCTDecode`, `JPXDecode` (decoded in-process via the `openjp2` port, not passed through),
215`JBIG2Decode`, `Crypt`.
216
217Font types: Type1, MMType1, TrueType, Type3, and Type0 over CIDFontType0/CIDFontType2 are
218all real. Embedded programs are rendered as true outlines from `/FontFile` (Type 1
219eexec), `/FontFile2` (TrueType/OpenType) and `/FontFile3` (bare CFF and OpenType-CFF);
220substitute typefaces are the fallback, not the primary path. The standard 14 fall back to
221AFM metrics. The documented exception is the compiled code→CID tables of the predefined
222CJK CMaps.
223
224---
225
226## 7. Triage: what is actually left
227
228Ordered by (likelihood × visibility), which is the only ordering worth having.
229
2300. **A form XObject inside a disabled optional-content group painted anyway — FIXED.**
231 The single highest-impact gap found across all rounds, and the strongest candidate for
232 the original "renders things that shouldn't even be there" report. `oc_stack` is a local
233 in `interpret_content_seeded` that no nested stream inherits. The `Do` arm gated its
234 Image branch, its `/BBox` `ClipPush` and its `GroupPush` on the hidden flag — but not the
235 recursive interpret call. So `/OC1 BDC /Fm0 Do EMC` with OC1 switched OFF painted the
236 form's ENTIRE contents, and painted them UNCLIPPED, because the clip that would have
237 bounded them was suppressed by the very flag the recursion ignored. §8.11.2: content in
238 a disabled optional-content group shall not be drawn.
239
240 Round 1 fixed the BMC/BDC/EMC balance and round 2 fixed the text operators; `Do` was
241 missed by both, and by two full review passes, because there is no wrong-looking code to
242 review — the gate is simply absent. The XObject's own `/OC` key (§8.11.3.3) was always
243 handled; only the surrounding bracket state was lost.
244
245 Fixed by gating the recursion rather than threading the flag into it: a hidden form is
246 skipped whole, which is both cheaper and impossible to get half-right. `text_only`
247 deliberately still descends, because that caller is `search::build_index` and the policy
248 set in the `Tj` arm is that a hidden layer is hidden, not absent — its text stays
249 searchable. Covered by `a_form_xobject_in_a_disabled_oc_group_paints_nothing`, which
250 asserts both directions and pins the fixture with an ON-layer control.
251
252 Every other recursion site was audited for the same omission and all are already gated:
253 tiling-pattern cells and pattern strokes (behind the painting arms' hidden check),
254 soft-mask groups (same), Type 3 CharProcs (via render mode 3 in `show_string_type3`).
255 Annotation appearance streams are not inside page-content brackets at all and carry
256 their own `/OC` (§12.5.3), so `oc_stack` does not apply to them.
257
2580b. **Group alpha was silently dropped whenever a soft mask was active — FIXED.**
259 §11.6.6 resets the alpha constants to 1.0 on entering a transparency group, because
260 `/ca` applies ONCE to the group's composited result. That reset is gated on
261 `pushed_group`, and round 2 had made the group push and the soft-mask bracket mutually
262 exclusive — so a form carrying both `/ca` < 1 and an `/SMask` applied `ca` to every
263 element inside instead, over-darkening wherever that content overlapped itself. Exactly
264 the failure the comment two lines above the reset warns about.
265
266 Fixed by making the two non-exclusive. `sm_start` is captured above the push, so
267 `wrap_with_soft_mask` inserts `SoftMaskPush` outside the group: the group composites
268 (applying `ca` once) inside the masked layer, then the mask applies to that result, which
269 is the §11.6.5.1 order. Covered by
270 `group_alpha_resets_even_when_a_soft_mask_is_active`, whose fixture uses two OVERLAPPING
271 fills because overlap is the only shape that can witness the bug.
272
273 The reset stays gated on `pushed_group`, so when `MAX_PRIMITIVES` or the group-depth cap
274 demotes the push, `ca` is still applied per element. That is deliberate, not a residual:
275 with no composite to apply it to once, resetting anyway would drop `ca` entirely and
276 paint the form fully opaque — wrong for all content, where per-element is wrong only
277 where content overlaps itself. Round 2's overprint lesson again.
278
2791. **`sh` in a nested content stream — FIXED in round 3, everywhere including the one
280 documented remaining case.** §8.7.4.1 requires `sh` to cover the whole clip region, so `rasterize_shading`
281 refuses to invent an extent and paints *nothing* when given neither a shading `/BBox` nor
282 a clip extent. That extent is a separate ARGUMENT and is not the `ClipPush` primitive — a
283 clip bounds the shading at render time, the extent is what lets it produce a raster at
284 all. Only the page-level caller seeded it; every nested stream reached the interpreter
285 through `interpret_content`, which passes `None`. A gradient drawn with `sh` inside a form
286 XObject was therefore invisible.
287
288 Now seeded from the box each stream is clipped to: form XObjects (§8.10.1), soft-mask
289 groups (§11.6.5.2), tiling-pattern cells including both malformed-pattern fallbacks
290 (§8.7.3.1), and annotation appearance streams (§12.5.5, fixed by `residuals`).
291
292 One of these was worse than "invisible gradient" and worth calling out, because it shows
293 how a missing seed can corrupt a DECISION rather than just an output. The periodic-raster
294 path rasterizes a pattern cell once and repeats it as a bitmap, but only if the cell
295 consists solely of fills and strokes. Unseeded, a cell whose content was `sh` produced no
296 Image primitive at all, so the cell *looked* like pure fills/strokes, the periodic path
297 was taken, and the gradient was silently dropped from every tile. Seeded, the Image
298 appears, the gate correctly rejects it, and the per-tile path paints it.
299
300 **Remaining, deliberately:** Type 3 glyph CharProcs (`draw.rs`). Unlike every case above
301 there is no correct box to seed from — §9.6.4.2 permits an all-zero `/FontBBox`, in which
302 case no assumptions may be made about glyph extent, and §9.6.5 does not clip a CharProc to
303 it. Inventing one would be the guess `rasterize_shading` exists to refuse. A CharProc
304 containing `sh` is also close to unheard of; real Type 3 glyphs are image masks or simple
305 fills.
306
307 Worth remembering as a pattern: the comment on that early return in `images.rs` asserts
308 the `None` arm "should be unreachable in practice" because the page device box is seeded.
309 It was accurate about the caller it considered and silently wrong about five others. A
310 claim of unreachability is only as good as its enumeration of callers.
3112. **ExtGState `/Font` — FIXED in round 3.** Total-text-degradation failure when present,
312 though rarely present.
3133. **ExtGState `/FL` — FIXED in round 3.** The one Table 58 key that had full plumbing
314 (`bezier_steps_for_flatness`) and no parser.
3154. **`/Interpolate` on images — built, never wired.** `images::image_should_interpolate`
316 computes the right answer and nothing calls it, so every image is bilinearly smoothed on
317 magnification, including bilevel art: a magnified QR code, barcode or scanned fax gets a
318 grey ramp and a translucent fringe instead of hard black and white (§8.9.5.1 Table 89).
319 Blocked on the wire format — `wire.rs` reserves a v11 `u8 interpolate` in the Image arm
320 and the Kotlin parser already has the `isV11` gate, so this needs a `Prim::Image` field,
321 a `WIRE_VERSION` bump and a Kotlin constant bump **atomically**. Cross-language; not
322 landed here.
3235. **Text clip (`Tr` 4-7) from Type 3 glyphs and from glyphs with no recoverable Unicode.**
324 The clip is accumulated on the Kotlin side from substitute-glyph text records, and those
325 two cases emit none, so the clip ends up under-constrained: content that should show
326 through letterforms floods the whole area instead. Note the failure direction — the
327 renderer guards with `if (hasTextClip)`, so an empty accumulator is a no-op rather than
328 a blackout, which is the safe way round. Fixing it means clipping to `Fill` contours on
329 the Kotlin side; cross-language, and niche.
3306. **`d1` colour suppression (§9.6.5).** A `d1` Type 3 glyph is a shape only and colour
331 operators inside it shall be ignored; here they take effect. Worst case is a glyph whose
332 CharProc sets white and paints invisibly where a conforming reader would use the current
333 fill colour. Real Type 3 producers (dvips, Metafont, TeX bitmap fonts) emit `d1` followed
334 by an image mask and no colour operators, so this is close to unreachable in practice.
335 Deliberately not fixed: threading a "colour is locked" flag through `interpret_content`
336 changes a signature used by four files this round's ownership splits across, for a case
337 no producer generates.
3387. **`/DefaultRGB` / `/DefaultGray` / `/DefaultCMYK` (§8.6.5.6).** Not worth implementing;
339 see §3.
340
341Everything else in Clause 10 is ignored on purpose, and §2 says why for each key.
342
343## 8. Dead-code verdicts
344
345Three warnings survived earlier rounds. The distinction that matters is *leftover* versus
346*built and never wired up* — the second is a real bug. Established by comparing
347`cargo check --lib` against `cargo check --profile test --lib`: an item that warns in the
348first but not the second is read **only by tests**.
349
350| Item | Verdict |
351| --- | --- |
352| `images::image_should_interpolate` | **Built and never wired up — a real gap.** Its own doc comment names the handoff and `wire.rs` reserves the field for it. Blocked on wire.rs + Kotlin; see §7 item 4. |
353| `images::shading_device_size` | **Superseded leftover — delete.** `rasterize_shading`'s own `auto_size()` closure does the same job from the device-space clip bbox, which is the right quantity; `shading_device_size` uses the unit-square→device matrix, which is not. Every caller passes `size == 0`, so `auto_size()` always wins. Its only reference is its own test. |
354| `FontInfo::base_font` | **Diagnostic field, not unfinished work.** Its only reader is a `println!` in `debug_ishi_test`. The parts of the base font name that matter downstream are already distilled into `style.bold`/`style.italic` and `family` at parse time and shipped in the v8 `fontFlags` byte. Using the raw string for exact-family substitution would need a per-primitive wire string that nobody has started. Keep and annotate, or delete. |
355
356Note these three no longer surface under `cargo check --all-targets`, which compiles the
357tests and so sees the test-only readers. The verdicts above stand; reproduce them with
358`cargo check --lib`. `shading_device_size`'s verdict has since been actioned: it is gone
359from the tree, and a grep for it now returns nothing. The other two are unchanged.
360
361## 9. Memory, which is a coverage question too
362
363A feature that aborts the process is not implemented either. `bench` measured peak heap on
364a 400_000-rect page at 533 MiB, of which 415 MiB is the `Vec<Operation>` materialised in
365full before interpretation starts, against 32 MiB of primitives at the `MAX_PRIMITIVES`
366cap. So `MAX_PRIMITIVES` does not bound page memory in any meaningful way.
367
368`MAX_CONTENT_OPS` was lowered 1_000_000 -> 660_000 as a deliberate cap rather than a
369streaming refactor: a defensible bound now beats a half-finished refactor, and truncating
370the tail of a page beats an uncatchable process abort that loses the whole document. At
371`bench`'s 544 B/op that cuts the admitted worst case from ~519 MiB to ~342 MiB while
372discarding no primitive the old value could have produced, because every operator above
373~660_000 could only be read after `MAX_PRIMITIVES` had already stopped emitting.
374
375Two things learned in the process are worth recording here rather than only in the code.
376First, `MAX_CONTENT_OPS >= 2 * MAX_PRIMITIVES` is necessary but not sufficient: it is stated
377for the densest shape (`re f`, 2 operators per prim), and a page also spends operators on
378colour, `q`/`Q`, `cm` and clip setup, so setting the cap to exactly 2x leaves
379`MAX_PRIMITIVES` unreachable and quietly disarms the truncation test. Second, a cap here
380cannot bind on the path that matters without help: `content::MAX_OPERATIONS` ties the
381lenient recovery tokenizer to it, but the strict `lopdf` parse materialises the vector in
382full before `take` is applied, so a well-formed heavy page — the one `bench` measured — is
383unaffected until `content.rs` truncates and shrinks after the parse.
384
385The measurement table and the full reasoning live on the `MAX_CONTENT_OPS` and
386`MAX_PRIMITIVES` doc comments in `src/graphics_state.rs`, kept next to the numbers so they
387cannot drift apart from them.