Extension text

Discussion about writing code for Inkscape.
draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

Extension text

Postby draftman » Wed Oct 02, 2019 11:53 am

I need my extension to create a superscript.
I know SVG supports This, but I don't know how to write it in an extension.

Here's a sample of what I'm trying to do.
(var2 needs to be a superscript)

Code: Select all

                    leng = str (int(var1)) + str(var2)
                    t='rotate(%f,%f,%f) matrix(1,0,0,1,0,-%f)' % (deg,x,y,0)

                    self.addText(
                      self.group,
                      x,
                      y,
                      leng, transform = t )
               
    def addText(self,node,x,y,text,transform=None):
                FontSize = self.options.FontSize* self.unittouu('1px')
                new = inkex.etree.SubElement(node,inkex.addNS('text','svg'))
                s = {'text-align': 'center', 'vertical-align': 'bottom','text-anchor': 'middle',
                'font-size': FontSize, 'fill-opacity': '1.0', 'stroke': 'none',
                    'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000'}
                new.set('style', simplestyle.formatStyle(s))
                if not transform==None:
                  new.set('transform', str(transform))
                new.set('x', str(x))
                new.set('y', str(y))
                new.text = str(text)


Any help would be appreciated

Moini
Posts: 3333
Joined: Mon Oct 05, 2015 10:44 am

Re: Extension text

Postby Moini » Thu Oct 03, 2019 3:26 am

How to find out how to do it:
- create a file
- type a text
- mark letters
- use the superscript button
- save the file
- open the file in a text editor
- check the SVG code
- reproduce the SVG code with your extension by editing the SVG text element.

This results in inserting the following:

<tspan style="font-size:65%;baseline-shift:super">superscript text</tspan>

into the text.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

Re: Extension text

Postby draftman » Fri Oct 04, 2019 5:44 am

Thanks Moini,
I used the xlm editor in inkscape and realized baseline-shift was a style attribute. So I added "baseline-shift":"super", to the style and it works

draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

Re: Extension text

Postby draftman » Sun Oct 13, 2019 2:44 pm

Spoke too soon.
It only works if document properties/units = px and scale = 1.

Moini
Posts: 3333
Joined: Mon Oct 05, 2015 10:44 am

Re: Extension text

Postby Moini » Mon Oct 14, 2019 3:32 am

Then maybe check what it takes to look right under different circumstances?... (i.e. create SVG, and examine it)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

draftman
Posts: 39
Joined: Sun Jan 25, 2015 5:29 am

Re: Extension text

Postby draftman » Mon Oct 14, 2019 7:27 am

I decided to use ( 'font-size': Fontsize * .65,) and ( y-(Fontsize*.35)) instead.
This is stable and more flexible, but you have to start a new string every time you need a superscript.
It would be nice to keep it all in one string, but for what I'm using it for this works fine.

I read somewhere that document properties/scale is going to be eliminated in Inkscape 1.0.
Do you know if this is true?


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest