Inkscape.org
Creating New Extensions Text span style
  1. #1
    DrQt DrQt @DrQt

    I’m generating flow text,

    on a single line, is a style around an arbitrary text selection possible?

     

    can I change letter_spacing on a single phrase in a line?

  2. #2
    inklinea inklinea @inklinea⛰️

    It's not possible to pass a text selection to the extension system ( i.e: text that you have highlighted using the mouse ). Just the parent text object.

    I checked in chat. 

    You can of course wrap any text you like in a <tspan> then style the tspan. 

    I don't have much experience with svg text. So I can't really advise on kerning etc.

    Don't forget that you can always use xpath to examine text elements and tspans etc.

  3. #3
    DrQt DrQt @DrQt

    I didn’t know about <tspan>, I will dig into that. Thanks for those tips. 

  4. #4
    DrQt DrQt @DrQt

    I didn’t know about <tspan>, I will dig into that. Thanks for those tips. 

  5. #5
    inklinea inklinea @inklinea⛰️

    When I get stuck I sometimes have the .svg file open in Geany, or Notepad++.

    Change something then save. Then look at the changes in the .svg. 

    I think flowed text makes extensive use of <tspan>.

    I also wrote an extension - which I did not post on inkscape.org, because I didn't like it  - https://gitlab.com/inklinea/textractor

  6. #6
    Scott Pakin Scott Pakin @pakin
    *

    Code sample to get you started:

    txt = inkex.TextElement(x='0', y='100')
    txt.set('xml:space', 'preserve')
    txt.text = 'This text is '
    txt.style = 'font-family: serif; font-size: 36pt'
    tspan1 = inkex.Tspan()
    tspan1.text = 'bold'
    tspan1.style = 'font-weight: bold'
    txt.append(tspan1)
    tspan2 = inkex.Tspan()
    tspan2.text = '!!!'
    txt.append(tspan2)
    
  7. #7
    DrQt DrQt @DrQt

    Thanks for that code example -- very helpful for hacking.

    Is there a newline command?

    I've been working with Flowtext, but it's overkill for what I need. 
    I'm a little confused about how I'm even successfully doing newlines there.

  8. #8
    Scott Pakin Scott Pakin @pakin
    DrQt

    Is there a newline command?

    Not as such.  Instead, you pass coordinates to inkex.Tspan as follows:

    txt = inkex.TextElement(x='0', y='100')
    txt.set('xml:space', 'preserve')
    txt.text = 'This text is '
    txt.style = 'font-family: serif; font-size: 36pt'
    tspan1 = inkex.Tspan()
    tspan1.text = 'bold'
    tspan1.style = 'font-weight: bold'
    txt.append(tspan1)
    tspan2 = inkex.Tspan(x='0', y='160')
    tspan2.text = 'and split across lines.'
    txt.append(tspan2)

    That is, you append Tspans to a Text object for both style changes and line breaks.

  9. #9
    DrQt DrQt @DrQt

    Ok!  Thank you for that clarification.