For anyone who may be looking at this 6+ years later, I ended up using this claude-assisted script to evenly distribute the text across a designated number of lines:
'***ENTER INFO HERE***
dim textName as string = "Text"
dim textWidth as decimal = 1000
dim maxNbLines as integer = 2
'***ENTER INFO HERE***
dim text as xpBaseObject
self.getObjectByName(textName, text)
'Turn off limits for clean measurement
text.autoSqueeze = false
text.wordWrap = false
'Single line that already fits - nothing to do
dim fullWidth as decimal = text.boundingBox.width
if fullWidth < textWidth then return
dim words() as string = split(text.text, " ")
'==========================================================
' PASS 1 - greedy fill (each line packed to the frame width)
'==========================================================
dim result as string = ""
dim line as string = ""
dim lineIndex as integer = 1
for i as integer = 0 to (words.length - 1)
dim w as string = words(i)
if lineIndex >= maxNbLines then
if line = "" then line = w else line = line & " " & w
elseif line = "" then
line = w
else
text.text = line & " " & w
if text.boundingBox.width > textWidth then
if result = "" then result = line else result = result & vbCrLf & line
line = w
lineIndex = lineIndex + 1
else
line = line & " " & w
end if
end if
next
if line <> "" then
if result = "" then result = line else result = result & vbCrLf & line
end if
'Only the last line can overflow in a greedy fill, so this checks it
text.text = result
if text.boundingBox.width <= textWidth then return 'fits - keep greedy result
'==========================================================
' PASS 2 - too long to fit; rebalance evenly across all
' lines so the squeeze is uniform instead of cramming one
'==========================================================
dim target as decimal = fullWidth / maxNbLines
result = ""
line = ""
lineIndex = 1
for i as integer = 0 to (words.length - 1)
dim w as string = words(i)
if lineIndex >= maxNbLines then
if line = "" then line = w else line = line & " " & w
elseif line = "" then
line = w
else
text.text = line
dim widthWithout as decimal = text.boundingBox.width
text.text = line & " " & w
dim widthWith as decimal = text.boundingBox.width
if widthWith > target then
if (widthWith - target) >= (target - widthWithout) then
if result = "" then result = line else result = result & vbCrLf & line
line = w
lineIndex = lineIndex + 1
else
line = line & " " & w
if result = "" then result = line else result = result & vbCrLf & line
line = ""
lineIndex = lineIndex + 1
end if
else
line = line & " " & w
end if
end if
next
if line <> "" then
if result = "" then result = line else result = result & vbCrLf & line
end if
text.text = result
'Lines are now even - squeeze them all uniformly to the frame
text.autoSqueeze = true
text.autoSqueezeWidth = textWidth
#XPression