Inkscape.org
Beginners' Questions export to html with preset code (lineTo)
  1. #1
    stefan_claudiu stefan_claudiu @stefan_claudiu

    How do I export to html with changed code from default ctx to something I decide? Is there a tutorial that shows the things you need for html export?

  2. #2
    Polygon Polygon @Polygonβš–πŸŒΆ

    Is this an Inkscape related question?

  3. #3
    stefan_claudiu stefan_claudiu @stefan_claudiu

    Yes, I use Inkscape to create so called slingon nodes and then export it to html to use it in html canvas. There I receive javascript code for canvas that spares me from writing the coordinates (lineTo). However, the variable that is added in front of lineTo is ctx by default and I need to name it differently.

  4. #4
    stefan_claudiu stefan_claudiu @stefan_claudiu

    Correction: lineTo is html for the canvas.

  5. #5
    stefan_claudiu stefan_claudiu @stefan_claudiu

    A temporary solution is to use Visual Studio (which is free), paste the code in a new page, mark the ctx column with double click, right click the marked column and choose Change all Occurrences. If you can't use Visual Studio, you could do something similar in Excel, Open Office, spreadsheets or Google sheets by saving the file in Inkscape as XML and import it there.

  6. #6
    inklinea inklinea @inklinea⛰️

    At your own risk: 

    Yes, make a backup copy of:

    /usr/share/inkscape/extensions/ink2canvas_lib/canvas.py   ( Linux ) 

    or 

    C:\Program Files\Inkscape\share\inkscape\extensions\ink2canvas_lib\canvas.py  ( Windows )

    Make sure the backup is *not* in the Inkscape core extensions folder, the Inkscape user extensions folder or any of their subfolders.
    If the copy is in any of these folders it might break HTML5 export.

    Then in the original canvas.py

    Change: 

    def line_to(self, x, y):
            self.write("ctx.lineTo(%f, %f);" % (x, y))

            
    To:

    def line_to(self, x, y):
            self.write("sausages.lineTo(%f, %f);" % (x, y))

            

    Then when using File>Save A Copy ( choose HTML5 Canvas *.html )

    In the exported HTML5 file you should then have:

    ctx.bezierCurveTo(120.334050, 113.754250, 120.667750, 114.455520, 121.554740, 117.626500);
    ctx.bezierCurveTo(121.972190, 118.788680, 122.389640, 119.950860, 122.807100, 121.113040);
    sausages.lineTo(125.942600, 122.575360);
    sausages.lineTo(125.942600, 122.575360);
    ctx.bezierCurveTo(125.517910, 121.419670, 125.093230, 120.263970, 124.668550, 119.108270);
    ctx.bezierCurveTo(124.336980, 117.904770, 123.939710, 116.717460, 123.673830, 115.497760);

  7. #7
    stefan_claudiu stefan_claudiu @stefan_claudiu

    Doesn't that replace the name of the variable with another name until you edit the file? I'm looking for a solution in inkscape because I'm going to have many different objects that each need different variable names.

  8. #8
    inklinea inklinea @inklinea⛰️
    *

    In that case you probably need to write an extension yourself. 

    I would advise using https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/data-*

    To add custom data- attributes to objects. 

    Then modify canvas.py to use the data- attributes

     

Inkscape Inkscape.org Inkscape Forum Beginners' Questions export to html with preset code (lineTo)