Skip to main content
Inspiring
March 25, 2009
Answered

Need to extend TextLayoutImporter (importing XML with InlineGraphicElements)

  • March 25, 2009
  • 3 replies
  • 858 views
I had an email from someone asking a way to re-import TLF XML that contains InlineGraphicElements that are not using an external image file.

For example, an instance of MyBoxClass, or MySmileyElement. A user may add a bunch of these to a TextFlow, and when you export the XML you get the standard toString() of that class in the source="" attribute, for example:

<flow:TextFlow whiteSpaceCollapse="preserve" xmlns:flow=" http://ns.adobe.com/textLayout/2008">
<flow:p fontSize="24">
<flow:span>Lorem</flow:span>
<flow:img height="50" width="50" source="[object MySmileyElement]"/>
<flow:span>Ipsum</flow:span>
</flow:p>
</flow:TextFlow>

So one idea is to simply override the toString() method in my custom graphic class to provide enough info to reconstruct my smiley as it was, but even so, the TLF's standard layout importer needs to know how to instantiate these custom graphic classes so...

After digging through the code and placing some breakpoints, I see that we actually need to extend the TextLayoutImporter class, as that is one of the classes that implements ITextImporter. But this is an internal class (I believe?) and so we can't. On top of that, we'd need to have a way to instruct the TextFilter class to use our customised ITextImporter.

Is this something that will be planned. I can't see how people can build editors with custom graphic elements without being able to export/import their TextFlow's from disk/DB?

Thanks in advance for any suggestions.

Richard
This topic has been closed for replies.
Correct answer rdermer
I agree we need to give users some mechanism to convert graphics to a string that is written in the source and then from that string to a DisplayObject.

TLF doesn't load graphics on import. They get loaded the first time they are composed. This prevents graphics on the clipboard and dangling copies from being loaded and wasting memory or if they have an audio track from making noise. In any case fixing this via client hooks is going to take some work and won't be done soon.

What I'd suggest is the following:
1) Ignore the source property
2) Tag every ILG with a custom style that describes your custom representation of the graphic. This will get exported.
3) After import walk the tree and use the custom style's value to calculate a display object (to set to ILG.graphic) or source property (to set to ILG.source).
4) The paste operation will need to do something similar as a post process to the pasted range.

Hope that helps,
Richard

3 replies

Adobe Employee
March 27, 2009
See this posting for suggestions on how to do an ILG event listener.

http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=669&threadid=1435310&forumid=72

Richard
Inspiring
March 26, 2009
That is indeed a workable solution. Thank you.

Richard
rdermerCorrect answer
Adobe Employee
March 26, 2009
I agree we need to give users some mechanism to convert graphics to a string that is written in the source and then from that string to a DisplayObject.

TLF doesn't load graphics on import. They get loaded the first time they are composed. This prevents graphics on the clipboard and dangling copies from being loaded and wasting memory or if they have an audio track from making noise. In any case fixing this via client hooks is going to take some work and won't be done soon.

What I'd suggest is the following:
1) Ignore the source property
2) Tag every ILG with a custom style that describes your custom representation of the graphic. This will get exported.
3) After import walk the tree and use the custom style's value to calculate a display object (to set to ILG.graphic) or source property (to set to ILG.source).
4) The paste operation will need to do something similar as a post process to the pasted range.

Hope that helps,
Richard

March 27, 2009
Hi rdermer

interesting solution...
Is it possible you could give a quick example.
And is there anyway to add a mouse event listener to an inline graphic. Working on a project that is at a stand still until I can sort this out

Help with this would be appreciated

Thanks in advance