Skip to content

feat: add SVG vector graphics support#16

Open
masoodkhanpatel wants to merge 1 commit into
gpdf-dev:mainfrom
masoodkhanpatel:f/svg-support
Open

feat: add SVG vector graphics support#16
masoodkhanpatel wants to merge 1 commit into
gpdf-dev:mainfrom
masoodkhanpatel:f/svg-support

Conversation

@masoodkhanpatel
Copy link
Copy Markdown

Closes #12

Summary

  • SVGs are rendered as true PDF vector graphics (Form XObjects), crisp at any scale — no rasterization
  • Auto-detected alongside JPEG/PNG; existing c.Image() API works unchanged
  • Supported elements: <path>, <rect>, <circle>, <ellipse>, <line>, <polyline>, <polygon>, <g> groups
  • Supported path commands: M/L/H/V/C/S/Q/T/A/Z (absolute and relative), arc-to-Bézier conversion
  • Supported styling: fill, stroke, stroke-width, opacity, fill-opacity, stroke-opacity, inline style attribute
  • Supported transforms: translate, scale, rotate, matrix, skewX, skewY
  • Color formats: named colors, #rrggbb, #rgb, rgb(), rgba()
  • Opacity via PDF ExtGState (ca/CA)
  • Deduplication: same SVG data reuses one Form XObject
  • New low-level API: pdf.Writer.RegisterFormXObject()

Checklist

  • Related issue linked (Closes SVG Image support #12)
  • go test ./... passes
  • go vet ./... clean
  • No new external dependencies
  • GoDoc comments on all new public APIs
  • Coverage above 80% threshold (85.7%)
  • Benchmarks not degraded (pre-existing broken dep in _benchmark is unrelated to this PR)

SVGs are rendered as true PDF vector graphics (Form XObjects) preserving
crisp quality at any scale — no rasterization. The existing `c.Image()`
API detects SVGs automatically alongside JPEG and PNG.

Supported elements: <path>, <rect> (with rounded corners), <circle>,
<ellipse>, <line>, <polyline>, <polygon>, <g> with transforms.
Path commands: M/L/H/V/C/S/Q/T/A/Z (absolute and relative), arcs
approximated with cubic Bézier curves. Colors: named, #rrggbb, #rgb,
rgb(), rgba(). Opacity via PDF ExtGState (ca/CA). Transforms: translate,
scale, rotate, matrix, skewX, skewY.

New low-level API: pdf.Writer.RegisterFormXObject().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

SVG Image support

2 participants