spakin / SimpInkScr

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

"Styles" for text #62

Closed Pojio91 closed 1 year ago

Pojio91 commented 1 year ago

Hello and thank for this wonderfull extension. I am trying to add spacing between my letters in text created by the method "text()". I can do it manually by using the "spacing between letters" inside inkscape's text tab, but I would love to automate this.

I have tried several keywords, but can't seem to find the right one.

Do you by any chance know the keyword to add spacing between letters? Is there a way to find the documented keywords used for the method "text()"?

thanks a bunch!

spakin commented 1 year ago

A handy feature of Simple Inkscape Scripting is that you manually can draw an image in Inkscape then go to FileSave a Copy…, select Simple Inkscape Scripting script (*.py) as the file type, and provide the name of a Python file to save to. Inspect the resulting file, and you'll see how to reproduce the current image using a Simple Inkscape Scripting script.

In the case of adding spacing between letters, you'll find you need the letter-spacing style. Here's an example of specifying letterspacing within a Simple Inkscape Scripting script:

x, y = width/2, height/2

text('ANYONE WHO WOULD LETTERSPACE BLACKLETTER WOULD STEAL SHEEP.',
     (x, y - 12*pt),
     font_family='Bitstream Vera Serif, Times New Roman, serif',
     font_size='12pt',
     text_anchor='middle')

text('ANYONE WHO WOULD LETTERSPACE BLACKLETTER WOULD STEAL SHEEP.',
     (x, y + 12*pt),
     font_family='Bitstream Vera Serif, Times New Roman, serif',
     font_size='12pt',
     text_anchor='middle',
     letter_spacing='1.75pt')

Note that hyphens in SVG attributes (e.g., in letter-spacing) have to be replaced with underscores in Simple Inkscape Scripting (e.g., letter_spacing) to make them valid Python identifiers.

Pojio91 commented 1 year ago

Thank you so much the prompt and thorough answer!