I have been learning how to script with python a few hours and looking at the svg codes for about the same time, so I admit I'm a bit clueless.
I want to create an extension that scales text depending on it's virtical position on the canvas using a simple algorithm
Here is my code so far:
Code: Select all
#!/usr/bin/python
import sys, copy
sys.path.append('C:\Program Files\Inkscape\share\extensions')
import inkex, simpletransform, simplepath, math
from math import cos, fabs
class GlobeStretcher(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def effect(self):
if self.selected:
for id, node in self.selected.iteritems():
if node.tag == inkex.addNS('text','svg'):
y = node.get('y')
scale = 'scale(' + str((1/cos(fabs(y-90)))) + ', ' + str(1) + ')'
transform = simpletransform.parseTransform(scale)
simpletransform.applyTransformToNode(transform, node)
effect = GlobeStretcher()
effect.affect()
At the moment it doesn't work, I get:
Traceback (most recent call last):
File "stretcher.py", line 24, in <module>
effect.affect()
File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 215, in affect
self.effect()
File "stretcher.py", line 19, in effect
scale = 'scale(' + str((1/cos(fabs(y-90)))) + ', ' + str(1) + ')'
TypeError: unsupported operand type(s) for -: 'str' and 'int'
The intention is that the extension scales text horizontally depending on their position relative to 90mm from the bottom of the page. I suspect I have more than one thing wrong in the code.
Could someone please give me some idea about how to do this - I know I'm missing something in the code.
As an almost non-coder, I must say it is a little difficult for complete beginners to learn how to code extensions using the help pages. Please don't take it as a criticism, I know many people do great work on inkscape, I just wonder if there might be the argument for having a forum section for coding or extensions as I'm sure I'm not alone in attempting to write extensions with limited coding skills.