Discarding the last TextLine and trying again with a new width

Hi all,
I'm using TextBlock to create a paragraph.   This paragraph has regions which do not render any text (so that I could put some images down within the generated text in a way more similiar to CSS float styles.  BTW, I'm not trying to achieve an inline image rendering; I know that is possble already with TextBlock).
So, my problem:
If one of these 'block out' regions are close to the boundary of the overall paragraph region, then this is the result:
In the left column, because those words are not broken on natural word breaks, createTextLine results in TextLineCreationResult.EMERGENCY.
That's great--I can detect this situation from the API.   However, I can't figure out what to do once I'm aware of it!
What I want to do is this:  I want to throw away any EMERGENCY TextLine (I've tried releaseLines), and then  'rewind' one createTextLine attempt so that I can try to generate the next TextLine using the same context as before the EMERGENCY failed attempt.
For clarity, this would mean in the above image, I'd hope to just discard the 'achi', 'year', 'repr', 'won', 'digr', 'prog', 'achi' TextLines on that thin left column... meaning only whitespace would occur in that thin column.   On the first line of the right of that skipped block, you'd see 'achievement' on the first broken line, because the 'achi' would be considered during the next createTextLine() attempt.
Regards,
Seth

Hi Robin,
So, that's exactly what I was trying to do, or so I thought.  Your example forced me to look at my code harder... here's the moral of the story.  The structure of my code processing the TextLines was like so:
if
     // attempt create textLine
else if (condition = emergency)
     // discard line, don't set previous
else (textLine != null)
     // keep line, place it on stage, and set previousLine to the newly created one
Notice the oddity... I put a condition on the else statement!  Putting a condition on an else statement causes to behave like an else/if (so I just learned).  I had done some refactoring and left the condition on the else statement by accident, so both the else if and else statement were executing!!  This caused  my emergency block to be 'persisted' into the textblock instead of discarded.
Thanks for your help Robin,
Seth

Similar Messages

Maybe you are looking for