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
#37550 - 10/19/11 04:39 AM Text centering in text box with wrapping
Tyran van Zyl
Unregistered


Hi Guys

I am trying to achieve something trivial but setting it up is not proving too simple.

I am using XML Data to populate various text boxes, I would like to vertically and horizontally center the text, and the only way to do this is by disabling Word Wrap, the problem is often the data is too long for the box (which needs to be fixed width) so I would like the data to wrap onto a second line, keeping the entire string centered in the text box.

Does anyone have a sample of Press Talk of this working for me to adapt to my text boxes?

Regards,


Edited by Tyran van Zyl (10/19/11 04:39 AM)

Top
#37551 - 10/19/11 09:46 AM Re: Text centering in text box with wrapping [Re: ]
Claude_FP Offline
OL Newbie

Registered: 07/19/11
Posts: 2
Loc: Laval, QC
Hi Tyran:

Can the height of the box vary? The trick here is ti use the stringwidth function to determine how many line are needed. As an example, if the print line is 4nches long and the available width is 2.5 inches you will need 2 lines to display the text.

You have to determine the maximun number of lines that you want to fit in the box to determine how the text will be displayed. in the example above, if the print line is over 5 inches , you would have to display on 3 lines, or reduce the font size to fit the text on 2 lines.

Once the number of lines is determined, use this number to determine the height of the first line . The following example works with any sized box

Hope this helps,

Code:
MoveTo(0,0)
SetLineWidth(0.0070)
SetStrokeColor([100])
SetFillColor([0])
LineTo(&width,0.0000)
LineTo(&width,&height)
LineTo(0.0000,&height)
LineTo(0.0000,0.0000)
ClosePath()
Stroke()
define(&i_,integer,1)
define(&sMyText,string,'The quick brown fox jumps over the lazy dog')
define(&iPrintLines,integer,1)
define(&mQuietZone,measure,&width*0.2)
define(&StringToShow,string,'')
&iPrintLines:=Floattoint(stringwidth(&sMyText)/(&width-&mQuietZone))+1

MoveTo(&Width,&Height)
Margin((&Width/2),(&Height/inttofloat(&iPrintLines))-0.0833)
SetStyle(&Verdana)
search(&sMyText,' ')
  if(stringwidth(&StringToShow+&sMyText)<(&width-&mQuietZone))
    &StringToShow:=&StringToShow+' '+&sMyText
  else()
    Crlf(0.1667)
    ShowCenter(&StringToShow)
    &StringToShow:=&sMyText
  endif()
endsearch()

    Crlf(0.1667)
    ShowCenter(&StringToShow+' '+&sMyText)

Top
#37593 - 10/25/11 09:21 AM Re: Text centering in text box with wrapping [Re: Claude_FP]
Tyran van Zyl
Unregistered


That worked.

Perfect, thanks

Top