Change font size to fit in the page

Posted by: phinix_mike

Change font size to fit in the page - 02/11/21 09:45 AM

Hello,

I'm trying to make my variable text change its font size to fit in the box.

I have almost no knowledge of PressTalk, just started to learn it.

I have this little code for variable length text, that starts new line when finds double pipe.
Thing is, that text might be a bit long, so I need to make sure that it fits in the page.
Lets say default font size would be 12, then go down to make sure it all fits.

How can I do that?

Code:
define(&sMyString, string,@(15,1,9999))
search(&sMyString, '||')
beginparagraph(1,6.2,0, 'left',0.095)
 setstyle(&Style1)
 show(&sMyString)
 endparagraph()
 crlf(0.09)
endsearch()
beginparagraph(1,6.2,0, 'left',0.095)
show(&sMyString)
endparagraph()
Posted by: Jean-Cédric

Re: Change font size to fit in the page - 04/22/21 10:40 AM

That worked for me!!! wink

Code:
MoveTo(0,0)
MoveTo(&Width,&Height)
Define(&LocalVariable,string,@(1,1,200))
Set(&LocalVariable,@(1,1,200))
define(&i,measure,20)
define(&lineWidth,measure,0)
define(&widthFound,boolean,false)

Margin(0.0000,0.0000)

%Loop through your data text on each encounter of ||
search(&LocalVariable,'||')
    &widthFound := false
    %Loop until a proper font size is found
    repeat
          setstyleext(&style1,&i,0,[100],100)
          if(stringwidth(&LocalVariable) > &width)
             &i := &i - 0.1
          else()
             &widthFound := true
          endif()
    until(&widthFound)

    BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
           setstyleext(&style1,&i,0,[100],100)
           Show(&LocalVariable)
    EndParagraph()
endsearch()

%repeat one more time as the variable &LocalVariable still contains the rest of the text after the last ||
&widthFound := false
repeat
      setstyleext(&style1,&i,0,[100],100)
      if(stringwidth(&LocalVariable) > &width)
         &i := &i - 0.1
      else()
         &widthFound := true
      endif()
until(&widthFound)

BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
       setstyleext(&style1,&i,0,[100],100)
       Show(&LocalVariable)
EndParagraph()