Menu

#4 Use <defs> in SVG?

v1.0_(example)
wont-fix
nobody
None
5
2020-04-15
2020-04-13
zvezdochiot
No

Using <defs> for paths in SVG would allow to "merge" the same paths. Maybe this has already been implemented?</defs>

Discussion

  • Peter Selinger

    Peter Selinger - 2020-04-14

    Hi Zvezdochiot, thanks for the suggestion. It sounds like this functionality could be implemented by modifying the output of Potrace, rather than modifying Potrace itself. I am guessing that there already exist some programs for manipulating SVG images that could do this, or it would be easy to write such a program. As such, I probably will not add this as a feature to Potrace.

     
    👍
    1
    • zvezdochiot

      zvezdochiot - 2020-04-14

      Hi Peter, i do not know the programs you mentioned. Tell me?

      PS: At least replace:

      <path d="M{x0} {y0} ...
      

      to:

      <g transform="translate({x0},{y0})"><path d="M0 0 ...
      
       

      Last edit: zvezdochiot 2020-04-14
  • Peter Selinger

    Peter Selinger - 2020-04-14
    • status: open --> wont-fix
     
  • Peter Selinger

    Peter Selinger - 2020-04-14

    I don't know specific programs that do this either. But you could achieve replacing "<path d="M{x0} {y0} ..." by "<g transform="translate({x0},{y0})"><path d="M0 0 ..." with a relatively simple regular expression, such as

    sed 's/<path d="M\([0-9]*\) \([0-9]*\)/<g transform="translate(\1,\2)"><path d="M0 0/g'
    

    Just pipe the SVG output of Potrace through that command. You might have to add a few </g> tags as well, which can be done with a (more complicated) sed script, or an Awk script, or a Perl script, or any programming language.

    One of the design principles of Potrace is the old Unix philosophy "write programs that do only one thing and do it well". For example, Potrace also does not include code for reading many different image formats. See also the answer to the question "Why can't Potrace read PNG files?" in Section 3 of the FAQ. So rather than introducing many specialized features for producing specialized output for specialized people, Potrace produces output that is easy to parse and can be manipulated by other programs.

     
    👍
    1
  • zvezdochiot

    zvezdochiot - 2020-04-14

    Good. It remains now only to figure out how to transfer all the same path to defs.

     
  • zvezdochiot

    zvezdochiot - 2020-04-15

    The problem is solved by itself. Both potrace and rsvg-cairo produce PDF “from one object”, and not from several paths. PDF optimization by this method is not possible.

     

Log in to post a comment.