Skip to content

Support Nested SVG #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged

Support Nested SVG #67

merged 1 commit into from
Feb 18, 2025

Conversation

swhitty
Copy link
Owner

@swhitty swhitty commented Feb 18, 2025

Adds support for nested <svg> including support for <use lookups from the parent space.

This sample SVG has been added for testing

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="360" height="450" stroke="black" fill-opacity="0.5">
   <defs>
      <polygon id="star" points="100,10 40,198 190,78, 10,78, 160,198" fill-rule="nonzero" />
   </defs>
	 
   <rect width="360" height="450" fill="snow" />

   <g transform="translate(170, 30) scale(800)" fill="orange">
      <polygon points="-0.1,0.01 -0.04,0.198 -0.190,0.078, -0.010,0.078, -0.160,0.198" stroke="black" stroke-width="0.002" fill-rule="nonzero" />
   </g>

   <svg x="180" y="28" width="165" height="165" viewBox="-0.2 0 0.2 0.2" >
      <polygon fill="green" points="-0.1,0.01 -0.04,0.198 -0.190,0.078, -0.010,0.078, -0.160,0.198" stroke-width="0.002" fill-rule="nonzero" />
   </svg>
	
   <g transform="rotate(28)" stroke="blue">
      <svg x="130" y="130" width="165" height="165" viewBox="-0.2 0 0.2 0.2">
         <polygon fill="red" fill-opacity="0.4" points="-0.1,0.01 -0.04,0.198 -0.190,0.078, -0.010,0.078, -0.160,0.198" stroke="currentColor" stroke-width="0.002" fill-rule="nonzero" />
      </svg>
   </g>
	
   <svg x="0" y="210" width="200" height="200">
      <use xlink:href="#star" fill="blue" stroke-width="2" transform="scale(0.85)" />
   </svg>
	
   <g transform="scale(0.85)">
      <svg x="200" y="240" width="200" height="200">
         <defs>
            <circle id="star" cx="100" cy="110" r="50" fill="purple" stroke-width="2" />
            <circle id="round" cx="100" cy="110" r="50" fill="purple" stroke-width="2" />
         </defs>
         <use xlink:href="#round" />
         <use xlink:href="#star" />
         <circle cx="100" cy="120" r="160" fill="none" stroke-width="2" />
      </svg>
   </g>
</svg>

nested-svg

With SwiftDraw outputting this PNG@2x

As reported in #66

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 65.21739% with 16 lines in your changes missing coverage. Please review.

Project coverage is 84.87%. Comparing base (3d021b8) to head (15e34dc).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
SwiftDraw/Parser.XML.Element.swift 10.00% 9 Missing ⚠️
SwiftDraw/LayerTree.Builder.swift 77.41% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #67      +/-   ##
==========================================
- Coverage   85.02%   84.87%   -0.16%     
==========================================
  Files          78       78              
  Lines        7191     7225      +34     
==========================================
+ Hits         6114     6132      +18     
- Misses       1077     1093      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@swhitty swhitty linked an issue Feb 18, 2025 that may be closed by this pull request
@swhitty swhitty merged commit dac2d26 into main Feb 18, 2025
16 of 19 checks passed
@swhitty swhitty deleted the nested-svg branch February 18, 2025 09:04
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.

Break in path
1 participant