Skip to content

Normalize SF Symbol variant paths for interpolation compatibility#123

Open
rursache wants to merge 1 commit intoswhitty:mainfrom
rursache:fix/57-sfsymbol-interpolation
Open

Normalize SF Symbol variant paths for interpolation compatibility#123
rursache wants to merge 1 commit intoswhitty:mainfrom
rursache:fix/57-sfsymbol-interpolation

Conversation

@rursache
Copy link

Summary

  • Fixes "the provided variants are not interpolatable" error when generating SF Symbols with separate weight variant SVGs
  • Root cause: source SVGs (e.g. from Apple's CoreSVG) can have incompatible path structures between weights - one variant may have a cubic curve (rounded corner) where another has a line (sharp corner), producing different segment counts
  • Adds two-phase path normalization after variant generation:
    1. Segment count alignment: inserts degenerate zero-length cubics in shorter variants to match the longest
    2. Type promotion: promotes L (line) to degenerate C (cubic) where types differ at the same position

Example (from the reported issue):

Before fix:

  • Ultralight Path 1: 27 segments (14 cubics)
  • Regular Path 1: 26 segments (13 cubics)
  • Black Path 1: 26 segments (13 cubics)

After fix:

  • All variants: 27 segments (14 cubics) with matching command sequences

Test plan

  • Added testNormalizeSegments_PromotesLineToCubic - verifies L→C promotion
  • Added testNormalizeSegments_InsertsDegenerate - verifies alignment with extra segments
  • Added testNormalizeSegments_AlreadyMatching - verifies no-op when paths match
  • Added testCommandType and testPromoteToCubic unit tests for helpers
  • Verified with reporter's photo.error SVGs - all 3 variants produce matching segment sequences
  • All 193+ tests pass, existing key.svg symbol test unaffected

Closes #57

When generating SF Symbols with separate weight variants (ultralight,
regular, black), the source SVGs can have incompatible path structures -
different segment counts or types (e.g. a cubic curve in one weight
where another has a straight line). SF Symbols requires identical
path structures across all variants for interpolation.

This fix adds a two-phase normalization after variant paths are generated:

1. Segment count alignment: When one variant has an extra segment
   (e.g. a rounded corner as cubic where others have a sharp corner),
   degenerate zero-length cubic segments are inserted in the shorter
   variants to match the longest.

2. Type promotion: When variants have the same number of segments but
   different types at a position (line vs cubic), lines are promoted
   to degenerate cubic curves with control points along the line.

Closes swhitty#57
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.

the provided variants are not interpolatable

1 participant