Skip to content

Render SVG quadratic curves with equivalent cubic controls - #1835

Merged
blikblum merged 2 commits into
foliojs:masterfrom
nk-batman21:fix-svg-quadratic-curves
Oct 31, 2026
Merged

blikblum merged 2 commits into
foliojs:masterfrom
nk-batman21:fix-svg-quadratic-curves

Conversation

@nk-batman21

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix. Fixes #550.

SVG Q/q and T/t commands used PDF's v operator, which describes a cubic curve with its first control point at the current point. That changes the shape of a quadratic curve: the forward and reversed paths in #550 do not overlap.

Convert those commands to equivalent cubic controls using the current point already tracked by the SVG parser. Smooth quadratic commands reuse the same conversion and keep the preceding quadratic control point for reflection. This change is limited to SVG paths; the standalone quadraticCurveTo() API is unchanged.

The seven new path tests fail on the base and pass with the fix. The rendered forward and reverse paths from the issue now overlap.

  • Ran: yarn test:unit (533 tests), yarn lint, yarn build.
  • Ran: Prettier on the changed files.

Checklist:

  • Unit Tests
  • Documentation N/A (no API change)
  • Update CHANGELOG.md
  • Ready to be merged

@blikblum
blikblum merged commit 011f030 into foliojs:master Oct 31, 2026
3 checks passed
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.

Quadratic curve inaccuracy

2 participants