Result of WordWrap
Posted: Mon Dec 13, 2021 2:02 pm
For optimal space allocation with texts displayed in multiple columns I try to adjust the column width dynamically. For this it would be useful to know if WordWrap was successful or not.
Since I didn't find anything in the manual, I tried to test if the resulting layer after a possible wrap is smaller than the space provided. But the result is not optimal, because this test is not only negative if the wrapped text happens to have exactly this width, but also the width of the rightmost space character is counted.
I could now get the width of a space character and try around with it, but before I do that I want to ask if there is a return value somewhere that indicates if a wrap worked or if text was truncated.
To understand how the wrapping works I used this program:
Ralf
Since I didn't find anything in the manual, I tried to test if the resulting layer after a possible wrap is smaller than the space provided. But the result is not optimal, because this test is not only negative if the wrapped text happens to have exactly this width, but also the width of the rightmost space character is counted.
I could now get the width of a space character and try around with it, but before I do that I want to ask if there is a return value somewhere that indicates if a wrap worked or if text was truncated.
To understand how the wrapping works I used this program:
Code: Select all
@DISPLAY {Width = 650, Height = 400, Color = $555555, Layers = True}
StartPath(1)
MoveTo(1, 0, 0)
LineTo(1, 0, 50)
ClosePath(1)
xpos=0
ypos=10
brushid=PathToBrush(Nil, {{ID=1, Color=#WHITE}})
DisplayBrush(brushid, xpos, ypos, {Name="whiteLine"})
brushid=PathToBrush(Nil, {{ID=1, Color=#RED}})
DisplayBrush(brushid, xpos, ypos+50, {Name="redLine"})
fsize=40
xpos=10
ypos=30
maxwidth=500
SetFont(#SERIF, fsize)
SetFontColor("$FFAA22")
SetFontStyle(#BORDER, "$997744", 1)
text$="Dieser Text dient zum Testen der Umbruchfunktion"
TextOut(xpos1, ypos, text$, {Name="Txt1", Transparency=0})
layerwidth=GetAttribute(#LAYER, "Txt1", #ATTRWIDTH)
Wait(1,#SECONDS)
For maxwidth=550 To 100 Step -1
SetLayerStyle("whiteLine", {X=maxwidth})
SetLayerStyle("Txt1", {WordWrap=maxwidth})
layerwidth=GetAttribute(#LAYER, "Txt1", #ATTRWIDTH)
SetLayerStyle("redLine", {X=layerwidth})
DebugPrint("maxwidth: ",maxwidth," layerwidth: ",layerwidth, " diff: ",maxwidth-layerwidth)
Wait(1)
If maxwidth-layerwidth=0 Then Wait(1,#SECONDS)
Next
Wait(20,#SECONDS)