Skip to content
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

Loading SVGs does not carry over their stroke attributes #35

Closed
DerEchteFeuerpfeil opened this issue Oct 9, 2023 · 1 comment
Closed

Comments

@DerEchteFeuerpfeil
Copy link

Hey there, awesome project. I want to use the SVG normalizing capabilities and ran into issues. Precisely, I am running into the issue that all output has 3.0 stroke width and 0.3 stroke opacity.

I personally attribute this to the SVG loading from XML, where the attributes are read but not further used:

def from_xml(x: minidom.Element):
stroke = x.getAttribute('stroke')
dasharray = x.getAttribute('dasharray')
stroke_width = x.getAttribute('stroke-width')
fill = not x.hasAttribute("fill") or not x.getAttribute("fill") == "none"
filling = Filling.OUTLINE if not x.hasAttribute("filling") else int(x.getAttribute("filling"))
s = x.getAttribute('d')
return SVGPath.from_str(s, fill=fill, filling=filling)

But I am not sure at the moment. Is there a way to keep the original stroke attributes of the paths?

Dolphin example

The minimal reproducable code for this is the dolphin example from the README. This is the result of running that exact code for me:
image

This is the output when save_svg is called on the SVG object:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0.0 0.0 24.0 24.0" height="200px" width="200px">
<path fill="none" stroke="black" stroke-width="3.0" stroke-opacity="0.3"  filling="0" d="M19.29208755493164 17.08875274658203 C19.0003604888916 17.26874542236328 18.665618896484375 17.179052352905273 18.55558967590332 17.14957046508789 C18.351573944091797 17.09490394592285 18.108379364013672 16.993528366088867 17.767244338989258 16.820850372314453 C17.499290466308594 16.68522071838379 17.270736694335938 16.560340881347656 17.069175720214844 16.450275421142578 C16.672706604003906 16.2336368560791 16.386165618896484 16.07703971862793 16.097652435302734 15.999732971191406 C15.935028076171875 15.956157684326172 15.619440078735352 15.94711685180664 15.285219192504883 15.937570571899414 C14.764851570129395 15.922700881958008 14.117305755615234 15.904151916503906 13.528430938720703 15.746363639831543 C12.933895111083984 15.587058067321777 12.320493698120117 15.373151779174805 11.935758590698242 15.231826782226562 C11.673254013061523 15.68767261505127 11.144759178161621 16.413766860961914 10.282265663146973 16.803768157958984 C9.109655380249023 17.333890914916992 8.302614212036133 17.494300842285156 8.268816947937012 17.500858306884766 C8.062347412109375 17.54096031188965 7.855262756347656 17.435482025146484 7.766499996185303 17.244794845581055 C7.677706718444824 17.05422592163086 7.730056285858154 16.827720642089844 7.893519878387451 16.695514678955078 C7.898970603942871 16.69097137451172 8.561553955078125 16.140411376953125 8.747669219970703 15.371997833251953 C8.821741104125977 15.066312789916992 8.874481201171875 14.825379371643066 8.911786079406738 14.641104698181152 C8.265583992004395 14.657169342041016 7.140110015869141 14.778581619262695 6.415033340454102 15.380525588989258 C5.316692352294922 16.292226791381836 4.525607109069824 17.93700408935547 4.460894584655762 18.528764724731445 C4.393395900726318 19.145307540893555 4.404304504394531 19.148231506347656 4.685268878936768 19.223514556884766 C5.297435283660889 19.387544631958008 5.80500602722168 19.55040740966797 6.299775123596191 20.02096176147461 C6.737459182739258 20.43709945678711 6.937915325164795 20.81779670715332 6.959256172180176 20.859853744506836 C7.039971351623535 21.01830291748047 7.021628379821777 21.20917510986328 6.912227153778076 21.349294662475586 C6.80279541015625 21.489530563354492 6.6221160888671875 21.553672790527344 6.448828220367432 21.51381492614746 C6.28159761428833 21.47563934326172 5.769392967224121 21.38313865661621 5.416074752807617 21.413726806640625 C5.22844123840332 21.429994583129883 5.061683654785156 21.463172912597656 4.900393486022949 21.49528694152832 C4.642367362976074 21.546667098999023 4.398634433746338 21.595176696777344 4.139557838439941 21.557546615600586 C4.055301666259766 21.54533576965332 3.9701900482177734 21.527585983276367 3.8912200927734375 21.504844665527344 C3.741024971008301 21.695083618164062 3.5147924423217773 21.909183502197266 3.195315361022949 22.041549682617188 C2.9507532119750977 22.14292335510254 2.718639373779297 22.18368148803711 2.5138702392578125 22.219562530517578 C2.262392044067383 22.263721466064453 2.063711166381836 22.298583984375 1.8830337524414062 22.430408477783203 C1.4094963073730469 22.775928497314453 1.1621580123901367 23.22187042236328 1.1597576141357422 23.226350784301758 C1.0621509552001953 23.40476417541504 0.8579807281494141 23.498321533203125 0.65936279296875 23.454647064208984 C0.6524868011474609 23.453182220458984 0.6456165313720703 23.451465606689453 0.6388339996337891 23.449647903442383 C0.4506797790527344 23.39923095703125 0.31365299224853516 23.23536491394043 0.30036354064941406 23.0394287109375 C0.2943086624145508 22.951414108276367 0.2591733932495117 22.150197982788086 0.859130859375 21.15196990966797 C1.073622703552246 20.795122146606445 1.3351068496704102 20.50653839111328 1.587946891784668 20.227333068847656 C1.999312400817871 19.773265838623047 2.354580879211426 19.381141662597656 2.4059295654296875 18.797744750976562 C2.647205352783203 16.055723190307617 3.2495040893554688 13.935039520263672 4.195972919464111 12.49482250213623 C5.667790412902832 10.254865646362305 8.003429412841797 9.412933349609375 8.456668853759766 9.266988754272461 C8.681556701660156 9.19446849822998 8.883283615112305 9.131731033325195 9.052956581115723 9.080123901367188 C8.946891784667969 8.93655776977539 8.805723190307617 8.77777099609375 8.625152587890625 8.636550903320312 C8.214173316955566 8.315095901489258 8.03367805480957 8.208970069885254 7.9831109046936035 8.181642532348633 C7.979600429534912 8.180830001831055 7.976239204406738 8.17992877960205 7.972878932952881 8.179028511047363 C7.7803449630737305 8.127501487731934 7.666408061981201 7.960718631744385 7.660402774810791 7.757887363433838 C7.6541428565979 7.547279357910156 7.818886756896973 7.367133140563965 8.021797180175781 7.310590744018555 C8.060404777526855 7.299764633178711 8.981307983398438 7.050039291381836 10.031401634216309 7.331410884857178 C10.248095512390137 7.389473915100098 10.458047866821289 7.467029094696045 10.655391693115234 7.5619330406188965 C11.270244598388672 7.857690334320068 11.678993225097656 8.162938117980957 12.074275016784668 8.458067893981934 C12.460226058959961 8.746273040771484 12.824797630310059 9.018510818481445 13.399856567382812 9.310179710388184 C13.679200172424316 9.451892852783203 13.938959121704102 9.573063850402832 14.190105438232422 9.69028377532959 C15.054240226745605 10.093473434448242 15.800516128540039 10.44169807434082 16.81147003173828 11.353596687316895 C18.130874633789062 12.543868064880371 18.761526107788086 13.628332138061523 18.587364196777344 14.407089233398438 C18.550647735595703 14.571233749389648 18.508243560791016 14.715338706970215 18.46017074584961 14.839091300964355 C18.58405113220215 14.948943138122559 18.73365592956543 15.085912704467773 18.882488250732422 15.23284912109375 C19.488374710083008 15.83094310760498 19.706562042236328 16.21575927734375 19.635496139526367 16.56092643737793 C19.586000442504883 16.80108642578125 19.470491409301758 16.978622436523438 19.29208755493164 17.08875274658203 Z"></path></svg>```
@DerEchteFeuerpfeil
Copy link
Author

Solved it by passing it all the way down from

from_xml -> from_str -> from_commands

and in from_commands I just add it to the SVGPathGroup as it inherits from SVGPrimitive, which accepts these params

if stroke_width is not None:
    return SVGPathGroup(svg_paths, fill=fill, color=c, stroke_width=stroke_width)
else:
    return SVGPathGroup(svg_paths, fill=fill, color=c)

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

No branches or pull requests

1 participant