sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
866 stars 124 forks source link

Can't Load SVGs Without Specified Colors? #176

Closed calvinsomething closed 2 months ago

calvinsomething commented 2 months ago

I am working with SVGs created in Adobe Illustrator, and it seems like if they only contain black there is no explicit styling for fill/stroke/etc. colors. After calling Document::loadFromFile with such files, an empty unique_ptr is returned.

Is this an issue or is there a way to load these files? librsvg can open these files.

sammycage commented 2 months ago

@calvinsomething could you please share the SVG file you're encountering problems with?

calvinsomething commented 2 months ago

I had to remove most of the contents because it's a company file, but this is the idea:

<?xml version="1.0" encoding="UTF-8"?>
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 864 553.89375">
  <g>
    <g>
      <g>
        <path d="m81.72734,33.36132c8.83043-1.70247,13.24967-2.52637,22.09515-4.12044.9068.73926,1.73539,1.40332,2.48757,1.99088.33625.30111.6861.58659,1.04953.85742.02531.02116.07552.05273.11661.09505.05257.05371.11661.13411.19441.19759.23323.19076.47948.37891.73867.5651.725.59342,1.54155,1.26139,2.44948,2.00423v17.95214c-1.37456,1.60937-2.59214,3.03776-3.65469,4.28483-.98541,1.15592-2.11266,2.47949-3.38159,3.97233-4.53936.81803-6.8081,1.23405-11.34347,2.08073v21.20214c-4.30246.80306-6.4528,1.21094-10.75168,2.03971v-53.12173Zm18.36469,17.75813v-10.48535c-3.04607.55566-4.56873.83626-7.61301,1.40462v10.48502c3.04428-.56803,4.56694-.84896,7.61301-1.4043Z"/>
      </g>
    </g>
  </g>
</svg>

SCRPX1900059-01

calvinsomething commented 2 months ago

Hmm, so it looks like the parsePaint call for "fill" should default to black if there isn't a value.

sammycage commented 2 months ago

The file you provided renders perfectly fine with the library.

hello svg

calvinsomething commented 2 months ago

Uh oh... thank you... maybe something else is wrong then.

sammycage commented 2 months ago

Hmm, so it looks like the parsePaint call for "fill" should default to black if there isn't a value.

I am well aware of that. Thank you for your input. The Document::loadFromFile function only returns an empty unique_ptr when there is a parser error or if the file is missing. If you continue to experience issues, please let me know, and I'll be happy to assist further.

calvinsomething commented 2 months ago

The bug had nothing to do with this library, I apologize for opening this issue and appreciate the help.