Skip to content

feat: add vector graphics extraction with path verbs, CTM, and opacity support#72

Merged
kolkov merged 2 commits into
mainfrom
feat/vector-graphics-extraction
May 7, 2026
Merged

feat: add vector graphics extraction with path verbs, CTM, and opacity support#72
kolkov merged 2 commits into
mainfrom
feat/vector-graphics-extraction

Conversation

@kolkov

@kolkov kolkov commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Document.GetVectorGraphics(), GetVectorGraphicsWithError(), and GetVectorGraphicsForPage() for extracting vector paths from parsed PDFs
  • Path verb + coordinates model (MoveTo, LineTo, CubicTo, QuadTo, Close) compatible with gogpu/gg and the gg-pdf bridge
  • New VectorParser separate from existing GraphicsParser — all table detection functionality untouched
  • Full graphics state: q/Q save/restore stack, CTM tracking via cm, ExtGState opacity (/CA, /ca)
  • All paint modes: stroke (S/s), fill (f/F/f*), fill+stroke (B/B*/b/b*)
  • Cubic bezier curves (c, v, y operators), rectangle expansion to path segments
  • CMYK → RGB conversion for K/k operators
  • Line cap, line join, miter limit extraction

Closes #66

Test plan

  • go fmt ./... clean
  • go vet ./... clean
  • go test ./... — 23 packages, all passing
  • golangci-lint run — no new issues
  • 50+ unit tests: all PathVerb/PaintMode values, state stack, all painting operators, all color operators, CTM, bezier variants, rectangle expansion
  • 14 integration tests: Creator API → build PDF in memory → extract vector graphics → verify paths/colors/paint modes
  • Existing GraphicsParser table detection tests still pass
  • No breaking changes to existing API
  • CHANGELOG, README updated

kolkov added 2 commits May 7, 2026 20:32
…y support

Implements issue #66 Phase 1: core vector path extraction from PDF content streams.

- New VectorParser (internal/extractor) with full graphics state stack (q/Q),
  CTM tracking (cm), fill path capture, curve operators (c/v/y), and all
  painting operators (S/f/F/B/B*/s/b/b*/f*/n)
- VectorPath domain type using verb+coords pattern compatible with gogpu/gg
- PathVerb (MoveTo/LineTo/CubicTo/QuadTo/Close) and PaintMode enums
- CMYK to RGB conversion (K/k operators), grayscale (G/g), ExtGState opacity
- Public API: Document.GetVectorGraphics, GetVectorGraphicsWithError,
  GetVectorGraphicsForPage (0-based page index)
- 50+ unit tests (operator dispatch, CTM, state stack, CMYK, clamp, colors)
- 14 integration tests (Creator round-trip, verb/coords consistency, fill/stroke
  detection, cubic bezier verification, color range validation)
@kolkov kolkov merged commit 7857295 into main May 7, 2026
7 checks passed
@kolkov kolkov deleted the feat/vector-graphics-extraction branch May 7, 2026 17:36
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.28099% with 139 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/extractor/vector_parser.go 65.15% 128 Missing and 3 partials ⚠️
vector_graphics.go 86.66% 5 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

Feature Request: Vector graphics extraction from existing PDFs

1 participant