Skip to content

feat(svg): SvgPath.parse - full SVG path grammar to native PathNode curves#172

Merged
DemchaAV merged 2 commits into
developfrom
feat/svg-path-import
Jun 12, 2026
Merged

feat(svg): SvgPath.parse - full SVG path grammar to native PathNode curves#172
DemchaAV merged 2 commits into
developfrom
feat/svg-path-import

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

What

The SVG milestone the path workstream was building toward: SvgPath.parse(d) (+ viewBox overload) in the new document.svg package lowers the complete SVG 1.1 path grammar into normalized, y-flipped DocumentPathSegments, and PathBuilder.svg(svgPath) drops them straight into addPath(...) — any icon's d string renders as native PDF curves.

  • Grammar: absolute/relative M L H V C S Q T A Z, implicit repetition (moveto→lineto chains), exact quadratic→cubic elevation, S/T control-point reflection, elliptical arcs via the W3C endpoint-to-center algorithm (radii correction, ≤90° cubic slices), single-character arc flags (a1 1 0 011 1 parses).
  • Normalization against the viewBox (icon workflow, keeps designed padding) or the tight bounding box; SVG y-down flips to our y-up; fills keep SVG's default non-zero winding.
  • Syntax errors are IllegalArgumentExceptions carrying the character position.
  • Scanner/state machine extracted into package-private SvgPathParser pre-commit (500-line rule); every branch is driven through the public-API tests.

Verification

  • 14 SvgPathTest cases: triangle/relative/H-V/implicit-lineto, exact quad elevation values, S/T reflection coordinates, quarter-arc κ≈0.5523 check, 270°→3 slices, zero-radius arc→line, compact flags, golden Material heart end-to-end (all coordinates inside the unit box), flat-path degeneracy, six error contracts.
  • PathBuilderTest.svgBridgeAppendsParsedSegments.
  • Example renders the Material heart at 72pt via the DSL — regenerated vector-path.pdf preview eyeballed: orientation correct, curves smooth, single page.
  • API hygiene green (new package ships package-info); full gate ./mvnw verify -pl .1276 tests, 0 failures, BUILD SUCCESS.

…urves

New document.svg package: SvgPath.parse(d) / parse(d, viewBox) lowers the complete SVG 1.1 path grammar (absolute/relative M L H V C S Q T A Z, implicit repetition, exact quadratic-to-cubic elevation, S/T control reflection, elliptical arcs via the W3C endpoint-to-center algorithm in <=90-degree cubic slices, single-char arc flags) into normalized, y-flipped DocumentPathSegments; PathBuilder.svg(svgPath) drops them into addPath(...). Scanner/state machine lives in package-private SvgPathParser (extracted pre-commit to keep SvgPath under the 500-line rule; every branch driven through SvgPathTest). 14 parser tests incl. golden Material-heart icon, kappa check on a quarter arc, 270-degree slice count, compact flags, position-carrying syntax errors; svg-bridge builder test. Example ships the Material heart rendered at 72pt (page grew to 660pt, preview stays single-page). Full gate: 1276 tests, BUILD SUCCESS.
@DemchaAV DemchaAV merged commit fe67b3f into develop Jun 12, 2026
11 checks passed
@DemchaAV DemchaAV deleted the feat/svg-path-import branch June 12, 2026 14:16
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.

1 participant