Skip to main content
Participating Frequently
June 28, 2010
Question

Is there any possible way to import ms word formatting in TLF?

  • June 28, 2010
  • 1 reply
  • 1587 views

hi just wondering if anybody knows whether it is theorectically possible to implement cut and paste operations from ms word into the TLF? When I have tried it I have not been able to achieve this as all formatting is lost in the paste operation. Would it be possible to intercept the paste operation to work out what has been pasted and reformat it prior to insertion.
I know this sounds like it probably can't be done; but it would be great to have this confirmed if that is the case. I have been asked to evaluate this part of a feature request.

Any help appreciated.

This topic has been closed for replies.

1 reply

Adobe Employee
June 28, 2010

I think it is possible, but maybe not as easy as you'd like. A paste comes into the EditManager as an event to the editHandler method. The editHandler does this:

                    pasteTextScrap(TextClipboard.getContents());

TextClipboard.getContents is looking for formatted text in the TEXT_LAYOUT_MARKUP first, and if its not found will try to import the clipboard contents as plain text. Either way, the text on the clipboard comes in as a String and has to be converted into a TextFlow. What you'd like it to do is to check for RTF, and invoke an RTF converter to convert the string to a TextFlow that can then be pasted.

What I'd suggest is that you make a derived EditManager class (MyEditManager) that you use in place of the EditManager, and MyEditManager should override the editHandler function. It calls the system clipboard to see if there is RTF there. Here's a generic call, you'll have to figure out what the correct format identifier is for RTF:

                     var systemClipboard:Clipboard = Clipboard.generalClipboard;
                     var clipboardContents:String =  (systemClipboard.hasFormat(format)) ? String(systemClipboard.getData(format)) : null;

If it is RTF, you then will have convert the RTF and use it to construct a TextFlow. If there are only selected portions of RTF you are interested in, this might not be too hard. Once you have a TextFlow, you can use it to create a TextScrap. There is a little bit of trickiness in making a TextScrap so that when you paste it it will blend in correctly to the target textFlow. I would suggest following the code path TLF uses for plain text:

                        retTextScrap = new TextScrap(textFlow);
                        var firstLeaf:FlowLeafElement = textFlow.getFirstLeaf();
                        if (firstLeaf)
                        {
                            retTextScrap.beginMissingArray.push(firstLeaf);
                            retTextScrap.beginMissingArray.push(firstLeaf.parent);
                            retTextScrap.beginMissingArray.push(textFlow);
                           
                            var lastLeaf:FlowLeafElement = textFlow.getLastLeaf();
                            retTextScrap.endMissingArray.push(lastLeaf);
                            retTextScrap.endMissingArray.push(lastLeaf.parent);
                            retTextScrap.endMissingArray.push(textFlow);
                        }

The TextScrap you then paste by calling EditManager.pasteTextScrap. If the clipboard does not have RTF, you can fall back to the superclass implementation of editHandler.

I think this should work, although I haven't tried it myself.

- robin

wtf2009Author
Participating Frequently
June 28, 2010

Excellent and full reply as ever Robin. Many thanks