Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Adjusting text leading

edited January 2015 in General Posts: 277

Hi,

Is there a way to adjust text leading (space between lines) when drawing a large chuck of text?

Thanks!

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,520

    Is all of the text being displayed with 1 text statement and are you using textWrapWidth. If so I don't think there's a way to alter the spacing between lines.

  • Posts: 277

    Yes and yes. Thanks though! I'll try and think of something...

  • edited January 2015 Posts: 136

    maybe replacing every '\n' with '\n\n' using a for loop?

  • dave1707dave1707 Mod
    Posts: 7,520

    @Rodolphe You can always use a for loop and parse thru the text adding up each character and when it exceeds the linewidth you can "text" that line. By using individual "text" statements, you can vary the spacing of each "text" statement.

  • edited January 2015 Posts: 136

    string.gsub(yourstring, '\n','\n\n') would do it as well, but again, this only matters if you want it to essentially be twice as spaced.

  • dave1707dave1707 Mod
    Posts: 7,520

    @Rodolphe Here's a very simple example of altering line spacing. Slide the spacing parameter to alter the spacing. A lot of checking needs to be added so words won't be split, but this is just a quick example.


    function setup() parameter.integer("spacing",15,100) textMode(CORNER) str="qwer gubvyctvt yhuubvtrc ybnuji imiybyb exxewa vyyubun unubytvrv gybnuinim niunbytc rcrvtybun ybybyvtvtv tctvybniin innuyvrcrc tvh jn uubyby tv uui iytgtv u unu ybyyb yyvtvtv yy niinyb yy tvyb" end function draw() background(0) str1="" cnt=0 for z=1,string.len(str) do str1=str1..string.sub(str,z,z) w,h=textSize(str1) if w>200 then cnt=cnt+1 text(str1,100,HEIGHT-cnt*spacing) str1="" end end end
  • Posts: 277

    Ok, thanks a great start! Thanks a lot!

Sign In or Register to comment.