spakin / SimpInkScr

Simple Inkscape Scripting
https://inkscape.org/~pakin/%E2%98%85simple-inkscape-scripting
GNU General Public License v3.0
330 stars 32 forks source link

Is there a way to resize the backround/paper without also automatically resizing the shapes inside of the svg? #70

Closed yahhalo05 closed 1 year ago

yahhalo05 commented 1 year ago

I need to extend the paper or the "background" of the SVG.

The only way I know how to do this is with the following command:

svg_root.set('height', 150) svg_root.set('width', 150)

If you do this, it also resizes all shapes inside of the SVG. I want it to resize without resizing the shapes it contains, so only the "background". Is there a way to do that?

Ps: I am not sure if this is the right way to ask a question. If it is not, please correct me.

spakin commented 1 year ago

I don't believe it's actually resizing all the shapes, just your view of them. As confirmation, I created a 1000×1000 canvas and centered a 500×500 rectangle within it. In the SVG file I see

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   width="1000"
   height="1000"
   id="svg2"
   version="1.1"
   inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
   sodipodi:docname="junk.svg"
   viewBox="0 0 1000 1000"

and later,

    <rect
       style="fill:#5500d4;stroke:#000000;stroke-width:2;stop-color:#000000"
       id="rect416"
       width="500"
       height="500"
       x="250"
       y="250" />

After executing

svg_root.set('height', 150)
svg_root.set('width', 150)

with Simple Inkscape Scripting, the width and height are each 150, and the page and the rectangle look proportionally smaller. However, while the SVG now starts with

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   viewBox="0 0 1000 1000"
   sodipodi:docname="junk.svg"
   inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
   version="1.1"
   id="svg2"
   height="150"
   width="150"

the rectangle remains the same size:

    <rect
       style="fill:#5500d4;stroke:#000000;stroke-width:2;stop-color:#000000"
       id="rect416"
       width="500"
       height="500"
       x="250"
       y="250" />

This suggests that you need to alter the SVG view box in addition to the width and height. I believe that

svg_root.set('height', 150)
svg_root.set('width', 150)
svg_root.set('viewBox', "0 0 150 150")

will do what you want.

Ps: I am not sure if this is the right way to ask a question. If it is not, please correct me.

This is fine for now but suggests that I ought to enable GitHub Discussions to support future usage questions.