Number of lines in wordwrapped TextSOP?

Hi there,

I need to find out how many lines a word-wrapped TextSop with a fixed width is producing.

I’m using a mono spaced font, size 1 text, 0 line spacing.

Weird thing is, if I get a reference to the TextSOP op, and look at the y component of op.size for 1 line text, 2 line text, 3 line text, etc, I get:

1 = 1.52
2 = 3.39
3 = 5.93
4 = 8.14

It’s strange. Adding a single additional line of text doesn’t seem to affect the height of the bounds predictably.

Am I missing something? Can anyone think of another way to get the correct number of lines every time?

Had to find a way around this, so in case anyone finds this post later, I ended up solving the problem a couple different ways:

  1. I wrote my own word wrap code in Python that manually inserted the breaks after a certain number of characters. It’s not foolproof (doesn’t work if you just have a single really really long string with no spaces), but it might be useful. I’ll post below:
def wordWrap(line, lineWidthInChars=30)

	lineMod = ""
	
	lineTok = line.split("\n")
	for l in lineTok:
		
		spaceTok = l.split(" ")
		count = 0
		
		for word in spaceTok:	
			
			if count + len(word) >= lineWidthInChars:
				lineMod = lineMod + "\n" + word
				count = len(word)
				
			else:
				lineMod = lineMod + word
				count = count + len(word)
			
			lineMod += " "
			count += 1
		
		lineMod += "\n"
		
	return lineMod
  1. I used a TextSOP and was able to get better bounding information that way.

For defining line breaks based on character length, there’s a Python module called textwrap — [url]https://docs.python.org/2/library/textwrap.html[/url]

Sorry I can’t help with your original question, but I thought I’d mention it because I’m using it on my current project. It’s a one-liner that returns the output lines in a list with appropriate newline endings.