Skip to main content
Participant
January 6, 2011
Question

how to get the textflow in pagning textlayout

  • January 6, 2011
  • 2 replies
  • 1080 views

Dear Sir:

I put long text xml in pagning textlayout ,but when I want get the xml or text in  paged container,I choking...

how can I get the each page's text xml?

my code like this;

var controller:IContainerController;
   var count:Number = 0;
  
   for(;;)
   {  
   
    _textflow.flowComposer.compose();
   
    while (_containers.length < _textflow.flowComposer.numControllers)
    {
     controller = _textflow.flowComposer.getControllerAt(_containers.length);    
     trace(TextFlow(controller.rootElement).getFirstLeaf().text )
     //trace(TextFilter.export(controller.textFlow,TextFilter.TEXT_LAYOUT_FORMAT,ConversionType.XML_TYPE) as XML)    
     _containers.push(Sprite(controller.container));
     if (controller.textLength == 0 || controller.absoluteStart + controller.textLength >= _textflow.textLength)
     {
      // all the text has fit into the containers.  now display the textlines and done
      _textflow.flowComposer.updateAllContainers();
      return;
     }     
    }   
   
    for (var idx = 0; idx < 10; idx++)
    {
     controller = new DisplayObjectContainerController(new PageBackGround(),_setting.Width,_setting.Height);
     controller.horizontalScrollPolicy = ScrollPolicy.OFF;
     controller.verticalScrollPolicy = ScrollPolicy.OFF;
     controller.containerFormat = _formates.ContFormat;       
     _textflow.flowComposer.addController(controller);
    }
   }

please help me!

This topic has been closed for replies.

2 replies

ozDiGennaro
Participating Frequently
January 14, 2011

This is a hard problem and I used a rather brute force method.  My textflow is wrapped in a richeditabletext container.

Draw increasingly many paragraphs, until it does not fit; then draw one less.  (Like I said: brute force, but actually very flexible).

It's pretty fast and the addition of paragraphs has a certain visual appeal.  The last two displays of too many pargraphs and then the correct number (again) is not visible.

     parse the XML representation of the text desired

     extract a count of paragraphs (start with one paragraph) - importing it into the text flow

     wait for the UPDATE_COMPLETE event of the richtext

     use the richtext.contentHeight property and compare with the desired size

     if the textflow fits, go back to "start" but increment the paragraph count.

No matter what, display one paragraph, even if it needs scrolling.  (oops, I just realized that I don't handle that case yet...)

The logic to keep track of how far I am and when I have overshot, etc. - looks something like this:

    richText.addEventListener(FlexEvent.CREATION_COMPLETE,paginateEvent);
    richText.addEventListener(FlexEvent.UPDATE_COMPLETE,paginateEvent);

    private function paginateEvent(event:Event):void {

            ....

            if (paragraphCountMax == 0 || paragraphCountSave < paragraphCountMax) {
                    paragraphCountSave += 1;
                    trace("increasing: \n   " + "contentHeight : " + int(richText.contentHeight) + " richText: " + richText.height + " paragraphCount: " + paragraphCountSave);
                    decorateAndReimportTextFlow();

             }

Adobe Employee
January 7, 2011

There is currently no direct way to get the XML for a subset of the text. To get just the XML for the text that falls into a single container, you could copy the text from that container into its own TextFlow, and export that. But if you are trying to stich together the results back into a single TextFlow, it will be difficult to merge back the paragraphs that are split between containers. If the main problem is just that you need to break the TextFlow into pieces to export each piece and then combine the XML's, I would suggest ignoring the container boundaries and using a certain number of paragraphs at a time. You could move an array of paragraphs into an empty TextFlow, export the flow, and then move the paragraphs back and repeat the process.

How big is the TextFlow when it starts slowing down in the export? This is something we could investigate for making performance improvements. Can you send us an example?

Thanks very much,

- robin

tangmsAuthor
Participant
January 7, 2011

yes,I try to read a text book into flash,and pagenation show it.I need get every chapter's page number and more...

so,Is It good for use tlf?maybe I need render myselft?

Adobe Employee
January 7, 2011

I don't know what format the book starts in, but we definitely recommend breaking a book length text into separate chapters, and putting each chapter in its own TextFlow as its needed, and letting go of it when its no longer needed. This greatly reduces how much content needs to be in memory at once. The invdividual chapters can still be paginated using multiple ContainerControllers. There's an example of how to do this in the sample Pagination application, which is posted on our blog:

http://blogs.adobe.com/tlf/2010/11/tlf-1-1-and-2-0-textlayouteditor-demo-source.html

For instance, if you could put each chapter into its own String (possibly a String of XML content if its formatted text), then you could instantiate one chapter at a time into a TextFlow.

Hope this helps,

- robin