Skip to main content
May 13, 2009
Answered

TextScrap missing formatting

  • May 13, 2009
  • 3 replies
  • 3375 views

With the last weekly build, we needed to switch from:

     var textScrap:TextScrap = textFlow.interactionManager.createTextScrap();
     var sTxt:String = String(TextFilter.export(textScrap.textFlow, TextFilter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE));

to:
     var textScrap:TextScrap = TextScrap.createTextScrap( textFlow.interactionManager.getSelectionState() );
     var newTextFlow:TextFlow = new TextFlow();
     newTextFlow.interactionManager = new EditManager();
     EditManager(newTextFlow.interactionManager).pasteTextScrap( textScrap , new SelectionState(newTextFlow,0,0) );
     var sTxt:String = String(TextFilter.export( newTextFlow, TextFilter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE));

However, now my formatting is missing (fontFamily, textAlign, etc.).  What is the best way to populate the formatting from the selection to the TextScrap?

This topic has been closed for replies.
Correct answer robin_briggs

Do you need a TextScrap at all? What if you did this:

var textFlowCopy:TextFlow = textFlow.deepCopy(start, end);

var sTxt:String = String(TextFilter.export(textFlowCopy, TextFilter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE));

3 replies

July 12, 2011

Hi,

I am curious if the final behavior in TLF 2.0 has changed since these postings.

Let's say I have a range of text selected, and this text has some overridden values such as font size, font family, and text color applied at the paragraph and span element levels. If I paste in plain text, the pasted text picks up default styling (none of the previous values are preserved). However, if I start typing instead of paste, the newly typed text picks up all these overridden values. To me, it makes more sense that these two operations would have the same result, with behavior from typing (attributes preserved) being the preference.

Is the above described behavior still the way TLF 2.0 works? That is, paste of plain text yields default properties while typing picks up surrounding properties. Or is there another way to get pasted plain text to pick up formatting of the surrounding text (easily)? Thank you for the info.

Will

July 12, 2011

I may have made an incorrect observation. Looks like TLF 2.0 is picking up the styles on paste, but TLF 1.1 isn't?

Will

robin_briggsCorrect answer
Adobe Employee
May 14, 2009

Do you need a TextScrap at all? What if you did this:

var textFlowCopy:TextFlow = textFlow.deepCopy(start, end);

var sTxt:String = String(TextFilter.export(textFlowCopy, TextFilter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE));

Known Participant
February 1, 2010

Hej Robin,

one place we need the textScrap dearly is while pasting text, trying to keep the format of the paragraph you paste into. In some built you changed the behaviour, so that pasted text does not inherit the format of the selection being pasted into (why did you do that? It is really not dtp or office behaviour).

Or is there another, better way?


Since setting pointFormat of selection manager does not work, we can only do a workaround, deploying a derivation of the EditManager and overwriting the pastTextScrap function.

override public function pasteTextScrap(tScrapToPaste:TextScrap, operationState:SelectionState = null):void {
           
            var tob:Object = Object(tScrapToPaste);
            if(tob.hasOwnProperty("textFlow")){
             var tf:TextFlow = tob.textFlow;
             applyFormatToElement(tf,selectedFormat);
             trace("FORMAT APPLIED: "+selectedFormat);
            }
            //super.insertText(<helpful to paste any text here>);
            super.pasteTextScrap(tScrapToPaste, operationState);
}

I would greatly appreciate your help, Robin, it is an issue that is really hard to solve and dearly needed.

Also tried to get help through original post http://forums.adobe.com/thread/567102, but no answer offered so far.

Adobe Employee
February 2, 2010

How the text appears when it is pasted depends on how the properties are applied. Suppose you have the following text in your scrap:

<p><span fontSize="60">Hello world</span></p>

If you paste that into a paragraph, I would expect it would appear with fontSize of 60. Suppose instead you had this text in the scrap:

<TextFlow fontSize="60"><p><span>Hello world</span></p></TextFlow>

Then I would expect that the text would inherit the properties applied to the paragraph.

The rationale is, in both cases the span is added to the main text. In the second case, the span has the fontSize applied to it, and this overrides whatever fontSize was applied to the paragraph or TextFlow. In the first case, the text in the scrap had a fontSize of 60, but the fontSize was applied at the TextFlow level, and the TextFlow wasn't pasted in, only the span was.

There's a case in the middle, where properties are applied at the paragraph level. When pasting, if the entire paragraph was copied, the entire paragraph will get pasted into the text, along with whatever properties are applied to it. If only part of the paragraph was copied, then the paragraph is not copied to the main text, only its contents are.

I hope this is clear -- its a little complicated explaining it, but simple enough if you try a few examples.

- robin

Adobe Employee
May 14, 2009

Looks like we forced an ugly code change on you. I'm sorry, that was not intended. We will look into a better way to handle this use case. What we were trying to do was to block client code from changing a TextFlow that is in a TextScrap. In your case, you are not trying to change it, but just need it to export. I am going to look into this.

In the meantime, I would guess that your problems with attributes are with attributes that are on the TextFlow itself, not on the child elements. How about if you made the new TextFlow using a shallowCopy of the old TextFlow?

Instead of :

     var newTextFlow:TextFlow = new TextFlow();

You would have

     var newTextFlow:TextFlow = textFlow.shallowCopy();

May 14, 2009

The textFlow.shallowCopy() will give me the entire TextFlow, but I only want a portion of it (just the formatted text from one controller container).

I added this code to help preserve the formatting. I am not sure if it will preserve all formatting or not.

     var fmt:TextLayoutFormat = TextLayoutFormat(textFlow.interactionManager.getCommonCharacterFormat());
     var pFmt:ITextLayoutFormat = textFlow.interactionManager.getCommonParagraphFormat();
     fmt.concat(pFmt);

     var configuration:Configuration = new Configuration();
     configuration.textFlowInitialFormat = fmt;

     var textScrap:TextScrap = TextScrap.createTextScrap( textFlow.interactionManager.getSelectionState() );          

     var newTextFlow:TextFlow = new TextFlow(configuration);

     newTextFlow.interactionManager = new EditManager();
     EditManager(newTextFlow.interactionManager).pasteTextScrap( textScrap , new SelectionState(newTextFlow,0,0) );
     var sTxt:String = String(TextFilter.export( newTextFlow, TextFilter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE));