IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#57873 - 02/11/21 09:45 AM Change font size to fit in the page
phinix_mike Offline
OL Newbie

Registered: 02/11/21
Posts: 7
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()

Top
#57971 - 04/22/21 10:40 AM Re: Change font size to fit in the page [Re: phinix_mike]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
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()

_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#58160 - 09/30/21 11:49 AM Re: Change font size to fit in the page [Re: Jean-Cédric]
phinix_mike Offline
OL Newbie

Registered: 02/11/21
Posts: 7
Originally Posted By: Jean-Cédric
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()



Wooow.. that just killed me:)

I tried this but it made whole thing huge, tried to fix it but its just impossible.

My code above works ok, I decided to add some string length variable to actual data file so it changes styles when its too long and makes it all small font.

However, I have problem with wrapping.
BeginParagraph wrapping works but cuts all words that come to right edge.
I only want to cut words that are very long without space - my data has sometimes http links, which can be very long. Ideal would be to cut those that have like 5 "/", but I guess I just ask too much:)
Maybe I just add space after each slash...

Top