Result of WordWrap

Discuss any general programming issues here
Post Reply
Flinx
Posts: 188
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Result of WordWrap

Post by Flinx »

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:

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 Umbruch­funktion"
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)
Ralf
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Result of WordWrap

Post by airsoftsoftwair »

Hollywood internally generates a wordwrapping table which indicates after which words the function has wrapped the line, e.g. the table "2,4,6" for the text "This is just a little word wrapping test" would indicate to wrap after "is", "a" and "word". Would it help you if you had access to this table?
Flinx
Posts: 188
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Result of WordWrap

Post by Flinx »

Hm, maybe, because then I could check if a change of the maximum width provides a different result.
Post Reply