Skip to main content
Known Participant
June 5, 2009
Answered

Bounds of a part of the text

  • June 5, 2009
  • 2 replies
  • 874 views

I am trying to get the bounds of a portion of a textFlow. I tried to extract the part via:

var tf:TextFlow = _textFlow.deepCopy(start, end) as TextFlow;
trace(tf.flowComposer.numLines);

I wanted to use the TextLine.getBounds() method to get the bounding box of the text. But the number of lines is always zero, so I can't extract the line via

_textFlow.flowComposer.findLineAtPosition(0).

I tried working with compose() and so on, but the number of lines stays at zero.

Is there another possibility to get the bounds?

Thanks in advance.

This topic has been closed for replies.
Correct answer robin_briggs

The number of lines is zero until the text has been composed. It needs to have a controller before that can be done.

If the text is already composed the way you want in the original TextFlow, you could get the lines that intersect the area you care about. You can do this by calling into the flowComposer. That gives you the TextFlowLine, and that you can iterate forward through the lines to the last one in the area you care about. Here's an example of what this might look like:

         var lineIndex:int = textFlow.flowComposer.findLineIndexAtPosition(startPosition);

         var endLineIndex:int = textFlow.flowComposer.findLineIndexAtPosition(endPosition);

          while (lineIndex <= endLineIndex)

          {

               var line:TextFlowLine = textFlow.flowComposer.getLineAt(lineIndex);

               ... do something with the line ...

               ++lineIndex;

          }

Hope this helps,

- robin

2 replies

Participating Frequently
June 9, 2009

BTW, if you could get by with using a background rather than a border to highlight part of the text, you can do this with the 'backgroundColor' format, which can be applied to, for example, a particular SpanElement.

robin_briggsCorrect answer
Adobe Employee
June 8, 2009

The number of lines is zero until the text has been composed. It needs to have a controller before that can be done.

If the text is already composed the way you want in the original TextFlow, you could get the lines that intersect the area you care about. You can do this by calling into the flowComposer. That gives you the TextFlowLine, and that you can iterate forward through the lines to the last one in the area you care about. Here's an example of what this might look like:

         var lineIndex:int = textFlow.flowComposer.findLineIndexAtPosition(startPosition);

         var endLineIndex:int = textFlow.flowComposer.findLineIndexAtPosition(endPosition);

          while (lineIndex <= endLineIndex)

          {

               var line:TextFlowLine = textFlow.flowComposer.getLineAt(lineIndex);

               ... do something with the line ...

               ++lineIndex;

          }

Hope this helps,

- robin

Known Participant
June 8, 2009

I actually want to highlight a part of the text with a border. After I assigned a controller it worked perfectly.

Thank you very much.

Hmm but I think the getAtomBounds method of a TextLine could be a faster way to get this data.