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
#58026 - 05/31/21 01:17 PM how to adjust font size
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 400
Loc: Home
Hi, can someone help my below "PressTalk After"code to check for an address block line by line, and if any given line length happened to be bigger then 4.0 then I need to reduce the font size for the whole address block until it fits in the box.

Some names are very long and we don't want to wrap it to the next line.
&Style font is set to font Arial_12 and we can go down to size 9!

define(&sText, string, '')
define(&fSize, measure, 12)

setstyleext(&Style1, &fSize, 0, [100], 100)
&sText := @(2,5,1,100) %this needs to read from line 2 to line 5

if(stringwidth(&sText) > 4.0)
&fSize := (4.0 / stringwidth(&sText)) * 12
setstyleext(&Style1, &fSize, 0, [100], 100)
endif()

show(&sText)

Thank You


Edited by Sami786 (05/31/21 01:19 PM)
_________________________
Peace

Top
#58027 - 06/01/21 05:36 AM Re: how to adjust font size [Re: Sami786]
MartinS Offline
OL Guru

Registered: 08/06/12
Posts: 142
Loc: Munich
You need two nested loops, the outer one goes through all the address lines and the inner one calculates the maximum font size possible for the current line to fit the address box width.
The lowest font size value of all lines is taken to be the final font size for the whole address.

The following code is doing that, please test and adjust where needed.
Just note it gets the appropriate font size by decreasing in steps of 0.5, you may decrease by lower value if useful.

define(&sText, string, '')
define(&fSize, measure, 12)
define(&minFontsize, integer, 9)
define(&fSizeMax, measure, 12)
define(&i, integer, 1)
define(&addressBoxWidth, measure, 2.0)

%first calculate the maximum font size allowed
For(&i, 2, 1, 5)
&sText := @(&i,1,100)
&fsize := 12
repeat
setstyleext(&Style1, &fSize, 0, [100], 100)
&fsize := &fsize - 0.5
until(or((stringwidth(&sText) <= &addressBoxWidth), (&fsize < 9.0)))
&fsize := &fsize + 0.5
if(&fsize < &fSizeMax)
&fSizeMax := &fsize
endif
EndFor()

%now print the address with maximum font size calculated above
setstyleext(&Style1, &fSizeMax, 0, [100], 100)
For(&i, 2, 1, 5)
&sText := @(&i,1,100)
show(&sText)
crlf()
endfor

Top
#58029 - 06/01/21 06:42 PM Re: how to adjust font size [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 400
Loc: Home
great, thank you
_________________________
Peace

Top