diff --git a/crates/pdftract-core/src/graphics_state.rs b/crates/pdftract-core/src/graphics_state.rs index d9e10a8..96f2028 100644 --- a/crates/pdftract-core/src/graphics_state.rs +++ b/crates/pdftract-core/src/graphics_state.rs @@ -980,7 +980,8 @@ mod tests { #[test] fn test_color_device_rgb_clamped() { let color = Color::DeviceRGB([1.5, -0.5, 0.5]); - assert_eq!(color.to_css_hex(), Some("#ff8080".into())); + // R: 1.5 -> 1.0 -> ff, G: -0.5 -> 0.0 -> 00, B: 0.5 -> 0.5 -> 80 + assert_eq!(color.to_css_hex(), Some("#ff0080".into())); } // Tests for matrix operations diff --git a/crates/pdftract-core/src/layout/readability.rs b/crates/pdftract-core/src/layout/readability.rs index 952016d..ac0b2d4 100644 --- a/crates/pdftract-core/src/layout/readability.rs +++ b/crates/pdftract-core/src/layout/readability.rs @@ -153,7 +153,7 @@ mod tests { } impl ScoredSpan for TestSpan { - fn text(&self) -> Cow { + fn text(&self) -> Cow<'_, str> { Cow::Borrowed(&self.text) } diff --git a/crates/pdftract-core/src/page_class.rs b/crates/pdftract-core/src/page_class.rs index 6347bd2..ba3ad2d 100644 --- a/crates/pdftract-core/src/page_class.rs +++ b/crates/pdftract-core/src/page_class.rs @@ -309,7 +309,7 @@ mod page_classification_tests { fn test_page_classification_debug_assert_fires_on_invalid_confidence() { // Unit test: debug_assert fires on confidence = 1.5 in dev build // This test only runs in debug builds where debug_assert! is active - PageClassification::new(PageClass::Vector, 1.5, None); + let _ = PageClassification::new(PageClass::Vector, 1.5, None); } #[test] diff --git a/notes/pdftract-tuky.md b/notes/pdftract-tuky.md new file mode 100644 index 0000000..31d8160 --- /dev/null +++ b/notes/pdftract-tuky.md @@ -0,0 +1,78 @@ +# Verification Note: pdftract-tuky (Phase 3.1: Graphics State Machine coordinator) + +## Summary + +All 8 children of the Phase 3.1 Graphics State Machine coordinator are closed. This coordinator delivers the complete graphics state infrastructure consumed by all other Phase 3 operations. + +## Acceptance Criteria Status + +### 1. All 8 children closed ✅ + +All children verified closed: +- pdftract-1jlpy: Page /Rotate normalization (commit 606e162) +- pdftract-1os1: q/Q stack with depth limit 64 (closed) +- pdftract-1vxh: BT/ET text object lifecycle (closed) +- pdftract-44f6: GraphicsState struct + Color enum (closed) +- pdftract-4dmp: Text state operators (Tc Tw Tz TL Ts Tr) (closed) +- pdftract-4ubed: Color operators (rg RG k K cs scn) (closed) +- pdftract-4x0y: Font binding (Tf) + text positioning operators (Td TD Tm T*) (closed) +- pdftract-p7yll: CTM operator (cm) (closed) + +### 2. q/Q 64 levels deep succeeds; 65th level emits GSTATE_STACK_OVERFLOW ✅ + +Verified by tests in `src/graphics_state/stack.rs`: +- `test_64_nested_q_calls_succeed`: Pushes 64 times, all succeed +- `test_gstate_stack_depth_limit`: 65th push fails and emits diagnostic +- `test_max_depth_is_64`: Verifies stack limit + +### 3. Td chain accumulates correctly ✅ + +Verified by `test_td_chain` in `src/graphics_state/state.rs`: +```rust +// BT 100 200 Td 50 0 Td ET should yield translation (150, 200) +state.begin_text(); +state.move_text(100.0, 200.0); +state.move_text(50.0, 0.0); +// Result: (150, 200) ✅ +``` + +### 4. Tm followed by Td: Td is relative to previous text_line_matrix ✅ + +Implementation in `src/graphics_state/state.rs`: +- `set_text_matrix`: Sets both text_matrix and text_line_matrix +- `move_text`: Updates text_line_matrix first, then copies to text_matrix + +This matches ISO 32000-1 Table 108 specification. + +### 5. /Rotate 90 normalization ✅ + +Child bead pdftract-1jlpy (commit 606e162) implements page rotation normalization. The implementation: +- Handles /Rotate 0/90/180/270 degrees +- Applies inverse rotation matrix to all glyph bboxes after content stream execution +- Emits INVALID_ROTATE diagnostic for illegal rotation values + +### 6. Color operators tracked ✅ + +Verified by tests in `crates/pdftract-core/src/graphics_state.rs`: +- `test_set_fill_gray`, `test_set_fill_rgb`, `test_set_fill_cmyk` +- `test_set_stroke_gray`, `test_set_stroke_rgb`, `test_set_stroke_cmyk` +- `test_color_space_component_count` +- `test_set_fill_color_space`, `test_set_stroke_color_space` +- `test_set_fill_color_named_spot` + +## Test Results + +All 72 graphics_state tests pass: +``` +Summary [ 0.049s] 72 tests run: 72 passed, 2612 skipped +``` + +## Changes Made + +Fixed one incorrect test expectation in `crates/pdftract-core/src/graphics_state.rs`: +- `test_color_device_rgb_clamped`: Corrected expected value from "#ff8080" to "#ff0080" + (The G value -0.5 should clamp to 0.0, not 0.5) + +## Coordinator Status + +The Phase 3.1 Graphics State Machine is complete and ready for consumption by Phase 3.2-3.5.