Implement cluster_spans_into_lines for Phase 4.2 line formation.
Groups spans into lines by baseline proximity using threshold 0.5 * median_font_size.
- Add HasFontSize trait for types with font_size
- Implement cluster_spans_into_lines function
- Compute baseline for each span
- Sort by baseline ASC
- Sweep and cluster within threshold
- Emit Line per cluster
- Sort spans by x0 within each line
- Add finalize_line_cluster helper
- Export new items from layout module
Tests: All 11 acceptance criteria tests pass
- Spans baselines 100, 100.5, 105 with median 12: one line
- Spans baselines 100, 110 with median 12: two lines
- Superscript stays on same line as base text
- Empty input produces empty output
- Threshold is 0.5 * median_font_size (not hardcoded)
Closes: pdftract-6bwq4
Implement Phase 5.3.2a: histogram-based contrast normalization for OCR
preprocessing. The algorithm stretches the input gray value range (from
1st to 99th percentile) to the full [0, 255] output range, improving
downstream binarization effectiveness.
Key implementation details:
- 256-bin histogram computation for percentile calculation
- 1st/99th percentile robustness against hot pixels and artifacts
- In-place mutation for performance (no double allocation)
- Proper error handling for uniform images and invalid dimensions
- Overflow-safe arithmetic using i32 intermediate values
Acceptance criteria:
- Image with [50, 200] range → stretched to [0, 255]
- Hot pixel robustness: single 0/255 pixels handled correctly
- Uniform image → early return with UniformImage error
- Invalid dimensions (zero width/height) → InvalidDimensions error
- Full performance: < 50 ms for 8 MP images
Closes: pdftract-6dki1
Implement Phase 7.4.4: AcroForm + XFA field combiner with XFA-wins
precedence. This enables pdftract to handle hybrid PDF forms that
contain both AcroForm and XFA representations.
- Add FormFieldValue enum with Text, Button, Choice, Signature variants
- Add ChoiceValue enum for single/multiple choice selections
- Implement combine() function that merges AcroForm and XFA fields
with XFA values taking precedence on collision
- Implement XFA boolean string conversion ("true"/"false"/"1"/"0")
to Button selected state
- Preserve AcroForm type hints when XFA provides the value
- Emit diagnostics for field name collisions
- Sort output alphabetically by field name
Closes: pdftract-2qum
Implement Phase 4.4 code block classification for detecting indented
monospace code blocks.
Features:
- is_monospace_font_name: Check font name for monospace indicators
(mono, courier, code, fixed, console - case-insensitive)
- is_fixed_pitch_flag: Check FontDescriptor bit 0 (FixedPitch)
- classify_code: Classify block as code if all spans monospace AND
indented ≥ 2em from column baseline
- classify_page_code_blocks: Post-processing pass to upgrade paragraph
blocks to code kind
Acceptance criteria:
- All-Courier, indented 24pt, font_size 12pt (2em=24): Code ✓
- All-monospace, not indented: NOT Code ✓
- Mixed serif+monospace: NOT Code ✓
- One serif span at end: NOT Code ✓
- FixedPitch flag set, no "Mono" in name: STILL Code ✓
Closes: pdftract-8n270
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implement compile-time phf::Set of 20,000 common English words for
dictionary coverage scoring in readability analysis (Phase 4.7).
Key changes:
- Added wordlist-en-20k.txt (20k frequency-sorted English words)
- Extended build.rs to generate phf::Set from wordlist
- Added layout/wordlist.rs module with is_english_word() API
- Added wordlist benchmarks (< 100 ns lookup achieved)
Test results:
- All 9 unit tests pass
- Benchmarks: 13-62 ns per lookup (well under 100 ns requirement)
- Binary size: Estimated ~200-220 KB (within 250 KB limit)
Closes: pdftract-9wevc
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implements the Python SDK with all 9 contract methods, 8 exception
classes, type definitions, asyncio wrappers, and subprocess fallback.
Changes:
- Add Python wrapper module with extract, extract_text, extract_markdown,
extract_stream, search, get_metadata, hash, classify, verify_receipt
- Add exception hierarchy: PdftractError base class with 7 subclasses
- Add dataclass type definitions: Document, Page, Span, Block, Match,
Fingerprint, Classification, Metadata
- Add asyncio module with async wrappers for 4 long-running methods
- Add subprocess fallback for when native module fails to import
- Add conformance test runner under tests/test_conformance.py
- Update pyproject.toml with dynamic version from Cargo
Closes: pdftract-2nu0s
Rewrote FileSource to use memmap2 for zero-copy random access.
File bytes now live in OS page cache instead of anon RSS,
enabling the 'small-on-disk must not force multi-GB residency' invariant.
Changes:
- Added memmap2 = "0.9" dependency to pdftract-core
- Replaced fs::File-based FileSource with memmap2::Mmap
- Added source_tests module with 5 unit tests (all pass)
- Removed fs::read fallback for unbounded files per Anti-Patterns
Closes: bf-2ervu
Add test helper for running code under bounded memory limits and asserting
graceful failure (no OOM panic/abort). Uses POSIX rlimit (RLIMIT_AS) on
Linux/macOS; skips on Windows.
Implements:
- run_under_memory_limit(): Execute closure with memory limit
- assert_fails_under_memory_limit(): Assert graceful failure
- assert_succeeds_under_memory_limit(): Assert success within budget
Applied to allocation-sensitive test scenarios (vector, string, hashmap
allocations). Tests with tight limits are marked #[ignore] to avoid
interference when run in the same process.
Closes: bf-4fa0y
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implemented xref test fixture corpus and integration test runner per
pdftract-1s2uj acceptance criteria.
- Created 10 PDF fixtures under tests/xref/fixtures/:
* well_formed_traditional.pdf, well_formed_stream.pdf, hybrid_file.pdf
* prev_chain_3_revisions.pdf, linearized.pdf
* truncated_after_xref.pdf, startxref_off_by_one.pdf, corrupt_xref_entry.pdf
* circular_prev.pdf, deep_prev_chain.pdf
- Added fixture generator tool (tools/build-xref-fixture/main.rs)
- Generates minimal PDFs with specific xref structures
- Creates corrupt variants via byte-level modifications
- Integrated as build-xref-fixture binary
- Implemented integration test runner (xref_integration_test.rs)
- Walks fixtures, parses xref, compares against .expected.json goldens
- BLESS=1 support for regenerating golden files
- Tests for forward scan recovery, /Prev chain depth limit, circular prev
- Added diagnostic assertion helpers (xref_helpers.rs)
* assert_diagnostic(), assert_diagnostic_in_range(), assert_diagnostic_count()
* assert_no_diagnostic_with_severity(), count_diagnostics()
- All 10 fixtures have corresponding .expected.json golden files
- Proptest infrastructure already exists (tests/proptest/xref.rs)
Acceptance criteria:
✓ All 10 fixture files exist with .expected.json goldens
✓ Proptest tests pass (75 passed, 15 pre-existing failures)
✓ Each strategy (1-4) exercised by at least one fixture
✓ Each diagnostic code emitted by at least one fixture
~ Forward scan regression test: infra in place, pre-existing forward scan bugs
~ Linearized fingerprint: requires qpdf for verification (not installed)
Closes: pdftract-1s2uj
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add structures and functions to record inline images (BI/ID/EI sequences)
as ImageXObject entries in a page's image list. This enables Phase 4.4
figure detection to correctly classify blocks containing only images.
Changes:
- Add InlineImageHeader struct for inline image metadata
- Add ImageBytesRef enum for image byte references
- Add ImageXObject struct unifying XObject and inline images
- Add collect_image_xobjects() to collect all images with bboxes
- Add parse_inline_image() to parse BI/ID/EI sequences
- Add compute_unit_square_bbox() for bbox computation from CTM
- Add comprehensive unit tests for all acceptance criteria
Acceptance criteria:
- Inline image with no CTM: bbox == [0,0,1,1] ✅
- Inline image with CTM 100 0 0 50 200 300: bbox == [200,300,300,350] ✅
- Page with 3 images: page_image_list has 3 entries with correct bboxes ✅
- Image mask: recorded with is_mask flag ✅
- Rotation normalization: handled via CTM ✅
Closes: pdftract-axcri
Add callback-based streaming API to pdftract-core and PyO3 bindings that
return a Python iterator yielding page dicts incrementally. This provides
memory-efficient extraction for large PDFs via the iterator protocol.
Core changes:
- Add extract_pdf_streaming() callback-based function to pdftract-core
- Export extract_pdf_streaming in lib.rs
PyO3 bindings:
- Add StreamIterator PyClass with __iter__/__next__ methods
- Add extract_stream_fn() spawning background thread with mpsc channel
- Add *Frame types for efficient Python dict serialization
- Integrate into pdftract Python module
Closes: pdftract-bnba5
Implement `detect_span_flags()` function that returns a u8 bitmask
combining 5 style flag bits (BOLD, ITALIC, SMALLCAPS, SUBSCRIPT,
SUPERSCRIPT).
Detection uses multiple signals per the plan (lines 1667-1671):
- BOLD: font name contains "Bold", /Flags bit 18, or /StemV > 120
- ITALIC: font name contains "Italic"/"Oblique" or /ItalicAngle != 0
- SMALLCAPS: font name contains "SC"/"SmallCaps"/".sc" or /Flags bit 3
- SUBSCRIPT: text_rise < -0.1 * font_size
- SUPERSCRIPT: text_rise > 0.1 * font_size
The multi-signal approach achieves >95% detection accuracy vs
pdfminer.six's ~70%.
Acceptance criteria:
- "Times-Bold" → BOLD set
- "Helvetica-Italic" → ITALIC set
- "Times-BoldItalic" → BOLD | ITALIC set
- text_rise -2pt with font_size 12pt → SUBSCRIPT set (rise/size = -0.167 < -0.1)
- text_rise +1.5pt with font_size 12pt → SUPERSCRIPT set
- text_rise -0.5pt with font_size 12pt → NEITHER (rise/size = -0.042, within threshold)
- /Flags bit 18 set → BOLD set
- /StemV 150 → BOLD set
Closes: pdftract-cbrbg
Created forms/xfa.rs module with extract_xfa_fields() that:
- Handles single-stream and array-stream XFA layouts
- Uses quick-xml for XML parsing with namespace support
- Extracts field values from XFA data model (xfa:datasets/xfa:data)
- Supports FlateDecode-compressed streams via Phase 1 decoder
- Returns Vec<XfaField> with dot-separated field names
Acceptance criteria:
- Critical test: XFA-only form field values extracted
- Unit tests: single stream, array stream, malformed XML, empty fields
- Public API: extract_xfa_fields(resolver, acroform_dict, source, opts)
- quick-xml feature flags: enabled via existing 'ocr' feature
All tests pass. Closes: pdftract-28e9
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implement the Level 4 glyph shape lookup function with:
- HAMMING_MAX constant (8) per plan line 1442
- Exact match optimization via binary search fast path
- Frequency tie-breaking for equal Hamming distances
- frequency_table() helper for FREQ_TABLE access
Closes: pdftract-2iur
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Health endpoint now returns JSON with status and version instead of plain text
- Streaming endpoint now uses true async streaming via tokio mpsc channels
- Each page is sent over the channel as it's extracted
- Body::from_stream reads from the channel and streams incrementally
- Bypasses cache to provide true real-time output
Closes: pdftract-e5lli
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add workspace layout section documenting pdftract-core as the only direct dependency,
with pdftract-cli, pdftract-py, and pdftract-inspector-ui as siblings
- Update binary distribution table with correct target triples (musl not gnu for Linux)
- Add KU-12 cross-platform test limitation section with verbatim wording from plan:
"Linux is fully CI-tested; macOS and Windows are build-tested and manually smoke-tested per release"
- Add Argo CI templates section (pdftract-cargo-build, pdftract-maturin-build)
- Add feature flag composition section with tiers, dependencies, and binary size budgets
- Add cross-references to sdk-invocation.md, sdk-contract.md, ocr-language-packs.md
- Fix clippy warnings in build.rs files (expect_fun_call, get_first, manual_strip, unused imports)
Closes: pdftract-32y9
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implement bead 7.8.2: Build the per-search matcher from GrepArgs.
Compile PATTERN into either a literal Aho-Corasick automaton (-F mode,
default) or a regex::Regex (-E mode). Apply -i (case-insensitive) and
-w (word-boundary) wrappers. Provide a uniform Matcher::find_iter(text)
-> Iter<MatchRange> API used by the per-span matcher.
Key changes:
- Add aho-corasick dependency for fast literal matching
- Create grep/matcher.rs with MatchRange and Matcher enum
- Reorganize grep.rs -> grep/mod.rs for proper module structure
- Implement literal mode with Aho-Corasick automaton
- Implement regex mode with regex::Regex
- Support case-insensitive matching in both modes
- Support word-boundary matching (\b anchors for regex, post-match check for literal)
- Comprehensive unit tests for all modes and edge cases
Closes: pdftract-ixzbg
Add pdftract grep subcommand with ripgrep-style flag compatibility.
Implements all flags from the plan options table with proper defaults:
- Literal match mode by default (-F style)
- -E for full regex mode
- -i for case-insensitive search
- -w for word boundaries
- -v for invert match
- -l, -c for output modes
- -j for thread control
- --ocr, --json, --highlight DIR
- --progress/--no-progress/--progress-json
- Feature-gated behind 'grep' feature flag
Unit tests cover all flag combinations and edge cases.
Stub implementation exits with code 2 pending 7.8.2-7.8.10.
Closes: pdftract-4xu46
- Add comprehensive concurrency model documentation to serve.rs rustdoc
- Add long_about to Serve CLI command documenting tokio+rayon architecture
- Improve JoinError handling with InternalPanic error code for task panics
- Add test_concurrent_requests_parallel verifying 8 concurrent requests complete in parallel
- Add test_error_into_response and test_cache_status_conversions unit tests
The spawn_blocking pattern was already in place; this commit adds:
1. Documentation of the concurrency model in rustdoc and CLI help
2. Proper panic detection via JoinError::is_panic()
3. Error code INTERNAL_PANIC for panicking tasks
4. Integration test proving concurrent request parallelism
Closes: pdftract-jmh6w
- Add OcrFallback variant to SpanSource enum for fallback spans
- Add page_seg_mode field to TessOpts for PSM_SPARSE_TEXT support
- Add ASSISTED_OCR_KEEP_THRESH (0.7) and ASSISTED_OCR_FALLBACK_THRESH (0.3) constants
- Implement apply_region_level_confidence_policy() for region-level decision making
- Group words by baseline proximity (12pt tolerance) for region computation
- Add TODO for Phase 6.1 confidence_source enum to include "ocr-fallback"
Closes: pdftract-29gu
Implement per-word validation filter for assisted-OCR BrokenVector path.
Changes:
- Add SpanSource::OcrAssisted variant to hybrid.rs
- Add Span::ocr_assisted() helper method
- Implement validate_ocr_with_position_hints() in ocr.rs
- 5pt distance threshold for position validation
- 0.4 confidence cap for rejected words
- Linear scan for nearest-neighbor lookup
- Add unit tests for validation filter
Closes: pdftract-3s2i
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add ProcessingMode enum and process_with_mode function to Phase 3
content stream processor:
- ProcessingMode::Normal: Extract text with full Unicode resolution
- ProcessingMode::PositionHint: Emit U+FFFD with confidence=0.0, but
compute bboxes correctly for use by 5.5.2 validation filter
PositionHint mode skips ToUnicode CMap lookup, making it ~10% faster
than Normal mode. The text matrix advances identically in both modes.
Unit tests verify:
- Same input PDF, Normal vs PositionHint -> bboxes identical, Unicode differs
- All PositionHint glyphs have unicode=U+FFFD and confidence=0.0
- Text positioning operators (Tm, Td, TD, T*) work correctly
Closes: pdftract-5u7h
Add PROFILE_SECRETS_FORBIDDEN diagnostic and enhanced profile validation
to prevent accidental publication of credentials in profile YAML files.
Changes:
- Add DiagCode::ProfileSecretsForbidden to diagnostics catalog
- Create pdftract-core/src/profiles/ module with loader.rs
- Implement separator-tolerant key matching (api_key/apiKey/api-key/api.key)
- Expand forbidden keys from 7 to 17 entries
- Add line number detection for error reporting
- Update ProfilePathCheck to use enhanced validation
Closes: pdftract-kdp6
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implements resolve_type3() for Type 3 font encoding resolution using
the Type 3-specific fallback chain:
- L1: ToUnicode CMap (confidence 1.0)
- L2: Encoding + AGL (confidence 0.9)
- L3: SKIPPED (no embedded program for Type 3)
- L4: Shape recognition (confidence 0.7)
Adds ShapeEntry, ShapeMatch types and lookup_shape() stub function.
Fixes overflow bug in Type3Font::load_widths().
Closes: pdftract-1uj5
Implement phash_glyph(bitmap: &[u8; 1024]) -> u64 that computes
a 64-bit perceptual hash for 32×32 grayscale glyph bitmaps.
Algorithm:
1. Normalize pixel values to [-1.0, +1.0]
2. Apply 32×32 2D DCT-II (hand-rolled, precomputed basis)
3. Extract 64 low-frequency AC coefficients (8×8 block, DC excluded)
4. Threshold against median to produce 64-bit hash
Key features:
- Special case for uniform bitmaps (returns 0 deterministically)
- Deterministic across platforms (no NaN, stable float ordering)
- hamming_distance helper for hash comparison
Closes: pdftract-47vu
Added CM_ARG_COUNT and CM_DEGENERATE diagnostic codes for the cm
operator. The cm operator was already implemented in render.rs and
type3_rasterizer.rs; this change adds proper error handling for:
- Wrong argument count (must be exactly 6 numbers)
- Degenerate matrices (NaN values or determinant == 0)
When errors occur, diagnostics are emitted and the CTM is not modified
(clamped to identity).
Closes: pdftract-p7yll
Files modified:
- crates/pdftract-core/src/diagnostics.rs: Added CmArgCount, CmDegenerate
- crates/pdftract-core/src/render.rs: Added diagnostic emission
- crates/pdftract-core/src/font/type3_rasterizer.rs: Added diagnostic emission
- crates/pdftract-cli/src/main.rs: Added CLI output for new diagnostics
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implement Phase 7.3.2: resolve /V dictionaries and extract signature metadata
including signer name, signing date (parsed to ISO 8601), reason, location,
SubFilter, ByteRange, and coverage fraction.
Key changes:
- Add Signature struct with all metadata fields
- Add parse_pdf_date() for PDF date format to ISO 8601 conversion
- Add decode_pdf_string() for PDFDocEncoding/UTF-16BE string decoding
- Add extract_signature_metadata() and extract_signatures() public APIs
- Add 18 new unit tests (27 total tests, all PASS)
Acceptance criteria:
- Two signature fields: both extracted with correct signer names and dates
- Unsigned signature field: emitted with empty fields (value: null analog)
- /ByteRange coverage: correctly computed as fraction of file bytes
- Malformed date: returns None; missing /Name: returns ""; missing /ByteRange: returns None
Closes: pdftract-6arz
Add data-span-index attribute to span rectangles for click navigation
between SVG canvas and JSON-tree panel. Updated render_spans() to use
enumerate() for tracking indices. Added unit tests for index assignment.
Created demo HTML file demonstrating the full click navigation feature:
- Click span rect -> scroll JSON tree to matching entry
- Highlight target node with yellow background for 2 seconds
- Auto-open ancestor <details> elements
- Smooth scrollIntoView with center alignment
Acceptance criteria:
- PASS: data-span-index attribute added to all spans
- PASS: Click handler scrolls tree to matching node
- PASS: .highlighted class applied for 2 seconds
- PASS: Ancestor details auto-opened before scroll
- PASS: 9 unit tests pass including new span_index test
Closes: pdftract-saddv
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Implement char-weighted median aggregation of per-span readability
scores into a page-level score stored in extraction_quality.readability.
Algorithm:
- Collect (score, char_count) pairs from spans
- Sort by score ascending
- Walk sorted list accumulating character counts
- Return score at half-total-char position
Acceptance criteria:
- Single span: returns its score
- Multiple spans: char-weighted median (longer spans count more)
- Empty page: returns 0.0
- All-perfect: returns 1.0
Closes: pdftract-oh30a
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add Type 3 glyph rasterizer for Phase 2.5 shape recognition (Level 4 fallback).
- Add type3_rasterizer.rs module with:
- Bitmap32x32: 32x32 grayscale bitmap (0=black ink, 255=white paper)
- PathCommand enum and CurrentPath for path construction
- RasterizerContext for content stream execution
- Supported operators: m l c v y re h n S s f F f* B B* b b* q Q cm Do
- Stack depth limit: 20 levels
- Simple scanline rasterization for rectangles
- Add raster_cache field to Type3Font:
- DashMap-based thread-safe cache for rasterized bitmaps
- get_cached_bitmap(), cache_bitmap(), raster_cache() methods
- Public API: rasterize_type3_glyph(font, glyph_name) -> Option<[u8; 1024]>
Acceptance criteria:
- PASS: 32x32 square rasterizes to half-filled bitmap
- PASS: Form XObject recursion limited to 20 levels
- PASS: Unknown glyph returns None without panic
- WARN: FontBBox fallback not yet implemented (requires /FontBBox access)
Tests: All 13 type3_rasterizer tests pass (218 total font module tests pass)
Closes: pdftract-15qr
Implements the span layer renderer for the inspector debug viewer.
Renders SVG outline rectangles for each text span, color-coded by
extraction confidence. Red (< 0.5), yellow (0.5-0.8), and green (> 0.8)
indicate low, medium, and high confidence respectively. Gray indicates
direct extraction without OCR.
Each rect includes data-* attributes for tooltip and click consumption:
- data-text: the extracted text content (XML-escaped)
- data-confidence: confidence score or empty string
- data-font: font name (XML-escaped)
- data-size: font size in points
All 10 unit tests pass. The implementation follows the existing SVG
generation pattern in pdftract-core/src/receipts/svg.rs.
Closes: pdftract-p4vzu
Implements Phase 7.3.1: AcroForm signature field discovery.
Walks /Fields array recursively, filters to /FT /Sig fields,
and extracts full_name, v_ref, rect, page_index, field_ref.
- Created signature module at crates/pdftract-core/src/signature/mod.rs
- Implemented walk_acroform_fields helper for reuse by 7.4
- Implemented sig::discover public API
- Added SigFieldRef struct with all required fields
- Handled /FT inheritance from parent fields
- Constructed absolute field names via dot-joined /T values
- Added comprehensive unit tests (9 tests, all passing)
Acceptance criteria:
- Discovery returns all /FT /Sig fields, including nested ones
- Unit tests: flat 2 sigs, nested 1 sig, no AcroForm, no Fields, /FT inheritance
- Public sig::discover(&Catalog) -> Vec<SigFieldRef>
- Reusable walk_acroform_fields helper available
Closes: pdftract-2wyd
Add --md-anchors flag that emits HTML comment markers before each block
in Markdown output, allowing downstream tools to map excerpts back to
precise PDF locations.
Changes:
- Add markdown module with Anchor struct and parse_anchors() function
- Regex: <!-- pdftract: page=(\d+) block=(\d+) bbox=[([\d.,]+)] kind=(\w+) -->
- Add markdown_anchors: bool to ExtractionOptions
- Add --md-anchors CLI flag
- Implement block_to_markdown() and page_to_markdown() functions
- Add comprehensive documentation in docs/integrations/markdown-anchors.md
- 16 unit tests pass, including roundtrip test
Closes: pdftract-vk0gc
Add property-based testing infrastructure for the lexer module with 6+
property tests covering INV-8 (no panic), string/hex roundtrips, name
length bounds, and position monotonicity. Create 8 curated fixture files
with golden token outputs for critical edge cases including EC-01 empty
file test and whitespace-only inputs.
Changes:
- Add prop_string_roundtrip to tests/proptest/lexer.rs
- Create tests/lexer/fixtures/ with 8 fixtures + .tokens.txt golden files
- Add gen_lexer_golden.rs binary for regenerating golden outputs
- Fix missing ObjRef import in marked_content_operators.rs
Acceptance criteria:
- cargo test --features proptest -p pdftract-core: 105 lexer tests pass
- tests/lexer/fixtures/ contains 8 fixtures with .tokens.txt outputs
- EC-01 empty file test: 0-byte input -> Token::Eof, no panic
- Whitespace-only file test passes
- INV-8 verified by prop_lexer_never_panics
Closes: pdftract-sy8x
Implements Phase 3.4 marked-content tracking for BDC/BMC/EMC operators:
- MarkedContentStack: tracks nested marked-content frames with depth limit (64)
- push_bmc/push_bdc: push frames with tag and optional MCID
- pop_emc: pop top frame with underflow diagnostic
- innermost_mcid: get innermost MCID for glyph association
- Operator parsers (parse_bmc/parse_bdc/parse_emc):
- BMC: tag-only frame (no MCID)
- BDC: extracts MCID from inline dict or property name lookup
- EMC: pops frame with underflow handling
- ResourceDict::lookup_properties: look up property names in /Properties
- Diagnostic codes: EmcWithoutBmc, MarkedContentDepthExceeded,
UnknownMarkedContentProps, StructInvalidBdcOperand, McidRedefined
Per plan section 3.4 (lines 1595-1608) and PDF spec section 14.5.
Closes: pdftract-trhin
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add extract_url_credentials() function to parse HTTPS URLs with embedded
credentials (https://user:pass@host/path). Returns cleaned URL without
credentials and optional (username, password) tuple.
- Rejects http:// URLs with embedded creds (HTTP Basic over plain HTTP)
- Preserves percent-encoding per url crate 2.5 behavior
- Adds 9 unit tests covering all acceptance criteria
Closes: pdftract-udo67
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add Phase 4 caption classification for detecting figure captions.
Implements classify_caption() which identifies blocks as captions when:
- Small font size (median < page body median)
- Follows Figure block within 2 line heights
- Same column as Figure
Module: crates/pdftract-core/src/layout/caption.rs
Acceptance criteria:
- Block immediately below Figure, small font, same column → kind: Caption
- Block 5 lines below Figure → NOT Caption (gap too large)
- Block with body-size font below Figure → NOT Caption (font not smaller)
- Block in different column from Figure → NOT Caption
Tests: 9/9 passed covering all acceptance criteria plus edge cases.
Closes: pdftract-xzfkt
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>