Skip to main content
Participant
July 7, 2010
Question

How to read textline formatting

  • July 7, 2010
  • 1 reply
  • 719 views

I want to get the formatting applied on the selected line or words in a paragraph display under TextFlow controller. I am able to read the textline from a selected paragraph as I am using TextFlowLine class to read the textline. This feature is only rendering me the plain text of the selected line instead of applied formatting on it. Find below the reference code:

var textFlowLine:TextFlowLine;

var startTextFlowLineIndex:int = objArr[0].txtFlow.flowComposer.findLineIndexAtPosition(begin);
textFlowLine = objArr[0].txtFlow.flowComposer.getLineAt(startTextFlowLineIndex);


// Read & Get plain text

text=textFlowLine.getTextLine().textBlock.content.text.substring((begin-textFlowLine.paragraph.getAbsoluteStart()),(end-textFlowLine.paragraph.getAbsoluteStart()));

Is anyone has any idea? How can I achieve the same?

This topic has been closed for replies.

1 reply

Adobe Employee
July 9, 2010

A TextLine by itself doesn't have formatting. You can get the formatting from the range of TLF text that is in the line -- I think you can do this by using the text positions in the TextFlowLine (absolutePosition & textLength), and then creating an ElementFormat based on that. Or you can get the leaf nodes, and work your way up from there, but usually ElementFormat is more convenient.

- robin

R_BSAuthor
Participant
July 13, 2010

Thanks Robin,

I have work around the logic to get the TextRange out of the selected area from the TextFlow. However I fail to do this. Other way I have tried this with TextArea control and get the TextRange of the selected text and able to modify with the changed content. Find below the workaround, I have tried with TextArea control:

var textInput:TextArea = new TextArea();
textInput.text = textFlowLine.getTextLine().textBlock.content.text.toString();
textInput.validateNow();

var textRange:mx.controls.textClasses.TextRange = new mx.controls.textClasses.TextRange(textInput,false,begin,end);
      
textRange.htmlText = "Changed Text";

textInput.setSelection(begin,end);

The above code gives me the HTML formatted text content with changed text. However I require to pass this updated content into the TextFlowElement object under TextFlow control.

Any suggestion.

Regards,

Ranjit

R_BSAuthor
Participant
August 3, 2010

I am able to get the HTML formatted text into the TextFlow object. This acheives through two process in TextConvert class:

  1. TEXT_FIELD_HTML_FORMAT
  2. TEXT_LAYOUT_FORMAT

Find below the code helps you to first read the HTML formatted content and then transform it into TEXT Layout formatted content:

// Get textflow in HTML format layout
textFlow = TextConverter.importToFlow(textvalue, TextConverter.TEXT_FIELD_HTML_FORMAT);

textFlow.whiteSpaceCollapse = WhiteSpaceCollapse.COLLAPSE;

var strOutput:String = "";

// Export textflow in Text Layout format and store the output in string object
strOutput = TextConverter.export(textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE) as String;

return strOutput;

Regards,

Ranjit