• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

TextScrap missing formatting

New Here ,
May 13, 2009 May 13, 2009

Copy link to clipboard

Copied

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?

TOPICS
Text layout framework

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , May 14, 2009 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));

Votes

Translate

Translate
Adobe Employee ,
May 14, 2009 May 14, 2009

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2009 May 14, 2009

Copy link to clipboard

Copied

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));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 14, 2009 May 14, 2009

Copy link to clipboard

Copied

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));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2010 Feb 01, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 01, 2010 Feb 01, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2010 Feb 02, 2010

Copy link to clipboard

Copied

Dear Robin,

thank you so much for taking the time. We are developing web2print solutions

and are greatly relieved, that you guys are aiming to approach DTP

functionality with the new textlayout. Our main task is to offer companies,

like AAA, a platform on which they can personalize brochures and flyers,

that their ad agency had developed. Thank you and please keep up!

The odd copy and paste behaviour that I mentioned in last entry:

Write a text (Work is an intrinsic occupation), format in red, 30pt size,
Franklin Heavy. Then mark "an" and paste the two words "a very". In Open
Office, Quark, InDesign the pasted words would appear in red, 30pt size,
Franklin. You are absolutely right, MS Word does have a "bug" (which they
would probably name feature and which drives us as professional typesetters
crazy) at that point, that pasted text might inherit some obscure other
format. But definitely the above described behaviour would be the wanted
one.

If you do the same with the tlf sample editor (as I did on the other screen
shot) you can see the unexpected and unwanted result.

Now, it would not be that bad, if one could "reformat" the TextScrap before
pasting. That is the reason, we are trying to access the .textFlow property
of the TextScrap. Is there any other way to intervene with the clipboard
contents before it is pasted? TextClipboard.getContent() will also only give
one a TextScrap which cannot be further formatted ... at least not to my
knowledge.

So, if you may, could you give me hint or workaround to change the described
behaviour?

Thanks in advance, Jo

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 02, 2010 Feb 02, 2010

Copy link to clipboard

Copied

This is not something we could change at the moment. But you could. Here's a sketch of a possible solution.Attach a FlowOperationEvent listener for flowOperationBegin and flowOperationEnd on the TextFlow. On a flowOperationBegin of a paste, save off the pointFormat. On a flowOperationEnd of a paste operation, apply the pointFormat to the pasted text. Basically, instead of trying to fix the text before it is pasted, wait until after the paste. Can you try that?

- robin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

Hej Robin,

thanks for offering a workaround. I tried entering a flowOperationEvent with Begin and End but id does not offer anything different to overwriting the

pasteTextScrap function of the EditManager

.

During both events you have access to the operation in the event and have information about the textFlow selection it is being pasted into and the selection start and end of the originating textFlow.

The numbers of characters being added (_numCharsToBeAdded) is protected, the only other information you have is the TextScrap itself with its protected textFlow property.

So there is really no way of figuring out, how many Chars are to be added, what the text is like and to reconfigure the TextScrap, since it cannot be exported in any way, right? So I cannot really change Format after the paste, especially if pasted text contains couple of paragraphs, right?

So the only way would be to probably intersect with the paste, do a deepCopy of the textFlow at selection, then pasteTextScrap into that copy of textFlow, add an interactionManager, then select all, change ALL STYLES in ALL ELEMENTS according to pointFormat at selection of original textFlow, then creating a TextScrap from this newly created tlf and let super paste this TextScrap into the textFlow?

override public function pasteTextScrap(tScrapToPaste:TextScrap, operationState:SelectionState = null):void {
     
   var selectedElementRange:ElementRange = ElementRange.createElementRange(selectionState.textFlow, selectionState.absoluteStart, selectionState.absoluteEnd);
   var characterFormat:ITextLayoutFormat = _textFlow.interactionManager.activePosition == _textFlow.interactionManager.anchorPosition ? _textFlow.interactionManager.getCommonCharacterFormat() : selectedElementRange.characterFormat;
   var paragraphFormat:ITextLayoutFormat = selectedElementRange.paragraphFormat;
   var containerFormat:ITextLayoutFormat = selectedElementRange.containerFormat;
     
      var tlf:TextFlow = textFlow.deepCopy(this.absoluteStart,this.absoluteStart) as TextFlow;
     var tem:EditManager = new EditManager();
   tlf.interactionManager = tem;
   tem.pasteTextScrap(tScrapToPaste,new SelectionState(tlf,0,0) );
   tlf.flowComposer.updateAllControllers();
   tem.selectAll();
   tem.applyFormat(selectedCharacterFormat,selectedParagraphFormat,selectedContainerFormat);
   tlf.flowComposer.updateAllControllers();
   var newTextScrap:TextScrap = tem.cutTextScrap();
   super.pasteTextScrap(newTextScrap,operationState);
   this.textFlow.flowComposer.updateAllControllers();
}

It seems a little oversized to perform such a tiny task and maybe we can move Adobe to think about an "applyFormat(pointFormat)" functionality or -- even easier -- to extend pointFormat to automatically apply on pasted text?

Anyways, hope this solution will be helpful?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 12, 2011 Jul 12, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 12, 2011 Jul 12, 2011

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines