SlideShare a Scribd company logo
SERIOUSLY, YOU CAN DO
     COOL THINGS:
Getting Advanced with the Text Layout Framework
               by Huyen Tue Dao
ABOUT ME
• Name ≈ “Hwin Tweh Dow”

• Computer/Electrical Engineering @
  University of Maryland

• Flex developer since 2006; also worked in
  C/C++, Java, Perl, .NET

• numTimesSpeaking = 5

• Favorite race in SC is the Zerg: open with
  10 pool speedling

• About to start 3rd play-through of ME2
  in anticipation of ME3
  “I’m Commander Shepard and this is my favorite store on the Citadel.”
WHAT ARE WE GOING TO
          TALK ABOUT?
•   Overview of Text Layout Framework and Flash Text Engine
•   Using the Text Layout Framework in Manual
•   Extending the Text Layout Framework
•   Leveraging the Flash Text Engine
•   Combining with other Flex components
•   Conclusion/questions
Stage

                                                               TextLine
TextBlock
                                                               TextLine

                                    createTextLine()
                                                               TextLine
 TextElement


   string content   ElementFormat




            Rendering Text With FTE
                        Artist (not so much) rendering
My Title
                                            Here’s some text.

                                            Here’s some other text.

                                            Here’s some more text. And
                                            here’s the last bit of text.




                                                      TextFlow




                           p       p                 p                                       p




  span             span                     span                                span                            span
“My Title”   “Here’s some text.”   “Here’s some other text.”           “Here’s some more text. “   “And here’s the last bit of text.”




                               TLF’s TextFlow
                          Artist (not so much) rendering
interactionManager:ISelectionManager




                         changes to TextFlow          passing input and user events




                                                                              Stage

                                                                                Container
TextFlow
                                                                                            TextLine

                                                                                            TextLine
 flowComposer:IFlowComposer                ContainerController
                                                                                Container
                                          ContainerController

                                                                                            TextLine




                                      TLF’S MVC
                          Artist (not so much) rendering
OVERVIEW OF TLF AND FTE
•   TLF utilizes FTE for advanced text rendering
    •   Adds in MVC framework, automated/advanced layout,
        selection/editing
•   FTE = bricklayer, contractor; TLF = architect
USING THE TLF IN MANUAL
•   “Manual?”
    •   Set up text flow, containers, controllers, and interaction
        manager by hand
    •   add/remove/setup containers
    •   set composition bounds
    •   setup selection/read/write ability, setup undo/redo
USING THE TLF IN MANUAL
•   “Automatic”: family of Spark components utilize TLF
    •   Base TLF Spark components: RichText, RichEditableText
    •   Other components build on these: TextInput, Text Area
    •   Most of TLF functionality encapsulated within components
    •   Can access parts of TLF (listen for events) but manipulating is
        difficult, not great idea.
USING THE TLF IN MANUAL
•   “Semi-automatic”
    •   TextContainerManager, class that handles a single-container TLF
        setup
    •   Provide it container, text/TextFlow, composition bounds,
        formatting options, editing mode
    •   “Consider using TextContainerManager for better performance
        in cases where there is a one container per TextFlow, and the
        TextFlow is not the main focus, is static text, or is infrequently
        selected.”
USING THE TLF IN MANUAL
•   Basic classes involved
    •   TextFlow and classes for importing/exporting a TextFlow:
        •   TextConverter: static class providing import/export methods
            for different formats, types
        •   Also have TextFlowUtil (simplified export/import),
            PlainTextExporter (provides some customization options)
        •   Configuration: specify initial formatting options for TextFlow
            creation, including selection formats, link formats, scrolling
            options, ENTER/TAB key behavior
USING THE TLF IN MANUAL
•   IFlowComposer: currently only StandardFlowComposer
    implementation and TextFlow automatically initializes one
    •   Composes layout and updates display
    •   Adds/removes containers (by adding/removing controllers)
    •   Normalizes the TextFlow after changes are made
    •   Provides information about and access to composite
        TextFlowLines, wrappers for generated TextLines
Container layout in TextFlowLines                                                      Stage
                                                                                   Container
      TextFlowLine 0   line height
                                     text height   ascent             TextLine 0
                                                   descent


      TextFlowLine 1
                                                                      TextLine 1



      TextFlowLine 2
                                                                      TextLine 2


                                                                         …




               TextFlowLines + TextLines
                                     Artist (not so much) rendering
USING THE TLF IN MANUAL
•   ContainerController: connects TextFlow and a container, tracks
    width and height of text area in that container, places TextLines
    in container, manages scrolling
    •   Contains reference to TextFlow to which it belongs
•   ISelectionManager: handles selection and TextFlow events
    •   Includes methods that provide information about selection
        including formatting properties of the selection
•   IEditManager: extends ISelectionManager adds edit functionality
    including undo/redo, cut/copy/paste, keyboard shortcuts
USING THE TLF IN MANUAL
•   Basic setup:
    •   Import/create TextFlow
    •   Create one or more containers (Sprites)
    •   Create a ContainerController with each container and call
        TextFlow.flowComposer.addController
    •   (Optional) Setup TextFlow.interactionManager
    •   Call TextFlow.flowComposer.updateAllControllers/
        updateToController
USING THE TLF IN MANUAL
•   Basic setup:
    •   Import/create TextFlow
    •   Create one or more containers (Sprites)
    •   Create a ContainerController with each container and call
        TextFlow.flowComposer.addController
    •   (Optional) Setup TextFlow.interactionManager
    •   Call TextFlow.flowComposer.updateAllControllers/
        updateToController
USING THE TLF IN MANUAL
•   So what can we do in “manual?”
•   Play with containers:
    •   Use multiple, linked containers: easy, just add new
        ContainerController via IFlowComposer.addController
    •   Remove containers: easy, IFlowComposer.removeController/
        removeControllerAt/removeAllControllers
    •   Take it further: what if we wanted to use just enough containers
        to fit text? Like how a word processor paginates content…
USING THE TLF IN MANUAL
•   States of a text container in TLF:
    •   Damaged: when model or layout changes, IFlowComposer
        marks relevant lines as “damaged” and needing of
        recomposition
    •   Composition:TextFlowLines/TextLines created and assigned to
        container based on current position, dimensions of container;
        •   IFlowComposer.composing: indicates currently composing
    •   Display: Old TextLines cleaned up, new TextLines positioned
USING THE TLF IN MANUAL
•   Useful/Import TextFlow events:
    •   DamageEvent.DAMAGE: dispatched whenever changes are
        made to the model or to the layout
    •   CompositionCompleteEvent.COMPOSITION_COMPLETE:
        dispatched whenever composition finishes
    •   UpdateCompleteEvent.UPDATE_COMPLETE: dispatched
        whenever text is ready to display but has not been painted to
        screen yet.
USING THE TLF IN MANUAL
•   Implementing pagination in TLF: check if the last container added
    renders the end of the text:
    •   ContainerController.verticalScrollPolicy = ScrollPolicy.OFF
    •   ContainerController.absoluteStart: character position in
        TextFlow at which text in container starts
    •   ContainerController.textLength: total number of characters
        displayed in container including whitespace
    •   TextFlow.textLength: total number of characters in TextFlow
(ContainerController.absoluteStart
+
ContainerController.textLength)
==
TextFlow.textLength

USING THE TLF IN MANUAL
•   When do we perform this check?
    •   Need to wait for the last page added to compose and display
        completely so check is accurate
    •   Add handler for UpdateCompleteEvent and perform check
        and if needed add/remove a page and then update again
    •   Will repeat until have enough pages
USING THE TLF IN MANUAL
•   Playing with containers: Useful TLF stuff
    •   addController/removeController
    •   DamageEvent, CompositionCompleteEvent,
        UpdateCompleteEvent
    •   ContainerController.absoluteStart,
        ContainerController.textLength,
        ContainerController.verticalScrollPolicy
EXTENDING THE TLF
•   Extending the Text Layout Framework
    •   Can be difficult: some classes are marked final (that you wish
        were not), many useful methods are private, some are just
        complicated
    •   Likely candidates: FlowOperations, SelectionManager,
        EditManager, UndoManager, ContainerController
    •   Let’s talk about operations…
EXTENDING THE TLF
•   FlowOperations: family of objects utilized by IEditManager to
    encapsulate changes to TextFlow and provide undo/redo
•   If you need undo, you need operations:
    •   TextFlow.generation: incremented every time it changes
    •   IEditManager uses generation to track changes and to validate
        undos/redos
•   Operations are not necessary if do not care about undo, but
    making changes through IEditManager also provides some
    support for auto-managing selection state with changes
EXTENDING THE TLF
•   Creating your own operations:
    •   FlowTextOperation: subclass of for transforming text
    •   Create subclass, override doOperation, undo(), redo()
    •   doOperation():Boolean does the actual work of changing
        TextFlow
        •   Return value indicates whether the operation completed
            correctly; if not, return false and IEditManager rolls back
            generation
EXTENDING THE TLF
•   undo():SelectionState, contains logic for reversing changes,
    return value is the selection state desired after undo
•   redo():SelectionState, redoes operation, returns SelectionState
    originally passed to doOperation; don’t have to implement
•   How do you actually call your operation?
    •   IEditManager.doOperation: does bookkeeping and calls
        FlowTextOperation.doOperation
    •   Extend EditManager and add interface for calling your
        operation
EXTENDING THE TLF
•   Things to keep in mind
    •   You can use other operations within your operation
        •   Take advantage of existing classes
        •   Makes undo easy to implement (but remember to undo
            operations in reverse order)
    •   Alternatively, can use
        IEditManager.beginCompositeOperation/
        endCompositeOperation to group operations on the fly
EXTENDING THE TLF
•   Stay away from using FlowElement references in your
    operation
    •   When using copy/cut/paste or TextFlow normalizes,
        FlowElements are often replaced or removed
    •   If you need to reference a particular element; use
        FlowElement.id and textFlow.getElementById instead
•   Make sure you consider any changes to selection state that
    your operation induces and set it in doOperation if necessary
•   use namespace tlf_internal: many helpful methods are tucked
    away in there
LEVERAGING THE FTE
•   Understanding underlying FTE parts of TLF can help you:
    •   Decorate/enhance TLF-rendered text without changing the
        model or the layout
    •   Get more specific information about layout of text lines within
        a container and the TextFlow as a whole
•   TextFlowLine: TLF wrapper for TextLines that actually reside on
    stage; both provide useful information
•   StandardFlowComposer -> TextFlowLine -> TextLine
LEVERAGING THE FTE
•   StandardFlowComposer: methods for grabbing TextFlowLines
    •   findLineAtPosition/findLineIndexAtPosition: gets reference to/
        index of TextFlowLine that contains the text at a given position
•   ContainerController: couple of tlf_internal methods for getting
    specific TextFlowLines
    •   tlf_internal getFirstVisibleLine():TextFlowLine
    •   tlf_internal getLastVisibleLine():TextFlowLine
•   TextFlowLine.getLine():TextLine
LEVERAGING THE FTE
•   TextLine: methods for getting position, index information for
    individual characters
    •   getAtomBounds: get bounds relative to TextLine of a particular
        atom (character)
    •   getAtomIndexAtPoint: get index of atom at given point (relative
        to the stage)
•   So how can we use all this?
    •   Draw on top of the TextLine
    •   Pinpoint a position relative to the stage or another component
        from a text position
COMBINING WITH OTHER
        FLEX COMPONENTS
•   Ideally, we would love to be to create custom FlowElements that
    provide new functionality and integrate nicely with TLF but not
    always possible or time efficient so what else can we do?
•   http://platustalksflex.blogspot.com/2010/07/position-
    uicomponents-inside-textflow.html
•   Basically, use an InlineGraphicElement as a placeholder, and then
    position another component on top of it.
COMBINING WITH OTHER
      FLEX COMPONENTS
•   Need to assign id to differentiate our placeholder
    InlineGraphicElements from others
•   Keep a mapping of these id’s to the Flex components
•   Update all of these components on UpdateCompleteEvent
•   Can even utilize this with TLF selection/editing (takes some
    work though)
COMBINING WITH OTHER
  FLEX COMPONENTS
•   Can even import/export these components
    •   Use XML: export as whatever tag required, make sure
        assign “id” attribute
    •   To import: replace XML placeholder tags with <img> tags
•   Have to take care of cut/copy/paste: end up with
    placeholders with identical id’s:
    •   Have to extend EditManager and override pasteTextScrap
    •   Go through TextScrap and replace duplicate id’s with new
        ones.
CONCLUSION
•   Before even getting into TLF, make sure it’s the right solution.
•   Most flexible, powerful way to user TLF is in “manual,” setting up
    everything yourself
•   Extend TLF classes to add new functionality and encapsulate it
•   Go lower-level by accessing and manipulating underlying FTE to
    play with interaction and rendering without changing TLF parts
•   Integrate Flex UIComponents with TextFlow layout by using
    placeholders and custom operations.
•   It takes some work (and a bit of code), but seriously, you can do
    cool things.
CREDIT WHERE CREDIT IS
             DUE
• Drawing highlights on TextLines technique from the
 HighlightAdornment example included in “Using TLF with
 Flash CS4 examples” for TLF 1.0 Beta: http://
 opensource.adobe.com/wiki/display/tlf/Text+Layout
 +Framework
• “InlineUIComponents within a TextFlow”: http://
 platustalksflex.blogspot.com/2010/07/position-uicomponents-
 inside-textflow.html
QUESTIONS?


Thanks for coming!


                       Huyen Tue Dao
                     daotueh@gmail.com
           queencodemonkey@twitter.com
             www.queencodemonkey.com

More Related Content

What's hot (6)

PPT
Workin ontherailsroad
Jim Jones
 
PPT
WorkinOnTheRailsRoad
webuploader
 
PPTX
php basic part one
jeweltutin
 
PDF
I know Java, why should I consider Clojure?
sbjug
 
PDF
ApacheCon09: Avro
Cloudera, Inc.
 
PPTX
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Igor Anishchenko
 
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
webuploader
 
php basic part one
jeweltutin
 
I know Java, why should I consider Clojure?
sbjug
 
ApacheCon09: Avro
Cloudera, Inc.
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Igor Anishchenko
 

Recently uploaded (20)

PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Learn Computer Forensics, Second Edition
AnuraShantha7
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Learn Computer Forensics, Second Edition
AnuraShantha7
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Ad

Seriously You Can Do Cool Things: Getting Advanced with the Text Layout Framework

  • 1. SERIOUSLY, YOU CAN DO COOL THINGS: Getting Advanced with the Text Layout Framework by Huyen Tue Dao
  • 2. ABOUT ME • Name ≈ “Hwin Tweh Dow” • Computer/Electrical Engineering @ University of Maryland • Flex developer since 2006; also worked in C/C++, Java, Perl, .NET • numTimesSpeaking = 5 • Favorite race in SC is the Zerg: open with 10 pool speedling • About to start 3rd play-through of ME2 in anticipation of ME3 “I’m Commander Shepard and this is my favorite store on the Citadel.”
  • 3. WHAT ARE WE GOING TO TALK ABOUT? • Overview of Text Layout Framework and Flash Text Engine • Using the Text Layout Framework in Manual • Extending the Text Layout Framework • Leveraging the Flash Text Engine • Combining with other Flex components • Conclusion/questions
  • 4. Stage TextLine TextBlock TextLine createTextLine() TextLine TextElement string content ElementFormat Rendering Text With FTE Artist (not so much) rendering
  • 5. My Title Here’s some text. Here’s some other text. Here’s some more text. And here’s the last bit of text. TextFlow p p p p span span span span span “My Title” “Here’s some text.” “Here’s some other text.” “Here’s some more text. “ “And here’s the last bit of text.” TLF’s TextFlow Artist (not so much) rendering
  • 6. interactionManager:ISelectionManager changes to TextFlow passing input and user events Stage Container TextFlow TextLine TextLine flowComposer:IFlowComposer ContainerController Container ContainerController TextLine TLF’S MVC Artist (not so much) rendering
  • 7. OVERVIEW OF TLF AND FTE • TLF utilizes FTE for advanced text rendering • Adds in MVC framework, automated/advanced layout, selection/editing • FTE = bricklayer, contractor; TLF = architect
  • 8. USING THE TLF IN MANUAL • “Manual?” • Set up text flow, containers, controllers, and interaction manager by hand • add/remove/setup containers • set composition bounds • setup selection/read/write ability, setup undo/redo
  • 9. USING THE TLF IN MANUAL • “Automatic”: family of Spark components utilize TLF • Base TLF Spark components: RichText, RichEditableText • Other components build on these: TextInput, Text Area • Most of TLF functionality encapsulated within components • Can access parts of TLF (listen for events) but manipulating is difficult, not great idea.
  • 10. USING THE TLF IN MANUAL • “Semi-automatic” • TextContainerManager, class that handles a single-container TLF setup • Provide it container, text/TextFlow, composition bounds, formatting options, editing mode • “Consider using TextContainerManager for better performance in cases where there is a one container per TextFlow, and the TextFlow is not the main focus, is static text, or is infrequently selected.”
  • 11. USING THE TLF IN MANUAL • Basic classes involved • TextFlow and classes for importing/exporting a TextFlow: • TextConverter: static class providing import/export methods for different formats, types • Also have TextFlowUtil (simplified export/import), PlainTextExporter (provides some customization options) • Configuration: specify initial formatting options for TextFlow creation, including selection formats, link formats, scrolling options, ENTER/TAB key behavior
  • 12. USING THE TLF IN MANUAL • IFlowComposer: currently only StandardFlowComposer implementation and TextFlow automatically initializes one • Composes layout and updates display • Adds/removes containers (by adding/removing controllers) • Normalizes the TextFlow after changes are made • Provides information about and access to composite TextFlowLines, wrappers for generated TextLines
  • 13. Container layout in TextFlowLines Stage Container TextFlowLine 0 line height text height ascent TextLine 0 descent TextFlowLine 1 TextLine 1 TextFlowLine 2 TextLine 2 … TextFlowLines + TextLines Artist (not so much) rendering
  • 14. USING THE TLF IN MANUAL • ContainerController: connects TextFlow and a container, tracks width and height of text area in that container, places TextLines in container, manages scrolling • Contains reference to TextFlow to which it belongs • ISelectionManager: handles selection and TextFlow events • Includes methods that provide information about selection including formatting properties of the selection • IEditManager: extends ISelectionManager adds edit functionality including undo/redo, cut/copy/paste, keyboard shortcuts
  • 15. USING THE TLF IN MANUAL • Basic setup: • Import/create TextFlow • Create one or more containers (Sprites) • Create a ContainerController with each container and call TextFlow.flowComposer.addController • (Optional) Setup TextFlow.interactionManager • Call TextFlow.flowComposer.updateAllControllers/ updateToController
  • 16. USING THE TLF IN MANUAL • Basic setup: • Import/create TextFlow • Create one or more containers (Sprites) • Create a ContainerController with each container and call TextFlow.flowComposer.addController • (Optional) Setup TextFlow.interactionManager • Call TextFlow.flowComposer.updateAllControllers/ updateToController
  • 17. USING THE TLF IN MANUAL • So what can we do in “manual?” • Play with containers: • Use multiple, linked containers: easy, just add new ContainerController via IFlowComposer.addController • Remove containers: easy, IFlowComposer.removeController/ removeControllerAt/removeAllControllers • Take it further: what if we wanted to use just enough containers to fit text? Like how a word processor paginates content…
  • 18. USING THE TLF IN MANUAL • States of a text container in TLF: • Damaged: when model or layout changes, IFlowComposer marks relevant lines as “damaged” and needing of recomposition • Composition:TextFlowLines/TextLines created and assigned to container based on current position, dimensions of container; • IFlowComposer.composing: indicates currently composing • Display: Old TextLines cleaned up, new TextLines positioned
  • 19. USING THE TLF IN MANUAL • Useful/Import TextFlow events: • DamageEvent.DAMAGE: dispatched whenever changes are made to the model or to the layout • CompositionCompleteEvent.COMPOSITION_COMPLETE: dispatched whenever composition finishes • UpdateCompleteEvent.UPDATE_COMPLETE: dispatched whenever text is ready to display but has not been painted to screen yet.
  • 20. USING THE TLF IN MANUAL • Implementing pagination in TLF: check if the last container added renders the end of the text: • ContainerController.verticalScrollPolicy = ScrollPolicy.OFF • ContainerController.absoluteStart: character position in TextFlow at which text in container starts • ContainerController.textLength: total number of characters displayed in container including whitespace • TextFlow.textLength: total number of characters in TextFlow (ContainerController.absoluteStart
+
ContainerController.textLength)
==
TextFlow.textLength

  • 21. USING THE TLF IN MANUAL • When do we perform this check? • Need to wait for the last page added to compose and display completely so check is accurate • Add handler for UpdateCompleteEvent and perform check and if needed add/remove a page and then update again • Will repeat until have enough pages
  • 22. USING THE TLF IN MANUAL • Playing with containers: Useful TLF stuff • addController/removeController • DamageEvent, CompositionCompleteEvent, UpdateCompleteEvent • ContainerController.absoluteStart, ContainerController.textLength, ContainerController.verticalScrollPolicy
  • 23. EXTENDING THE TLF • Extending the Text Layout Framework • Can be difficult: some classes are marked final (that you wish were not), many useful methods are private, some are just complicated • Likely candidates: FlowOperations, SelectionManager, EditManager, UndoManager, ContainerController • Let’s talk about operations…
  • 24. EXTENDING THE TLF • FlowOperations: family of objects utilized by IEditManager to encapsulate changes to TextFlow and provide undo/redo • If you need undo, you need operations: • TextFlow.generation: incremented every time it changes • IEditManager uses generation to track changes and to validate undos/redos • Operations are not necessary if do not care about undo, but making changes through IEditManager also provides some support for auto-managing selection state with changes
  • 25. EXTENDING THE TLF • Creating your own operations: • FlowTextOperation: subclass of for transforming text • Create subclass, override doOperation, undo(), redo() • doOperation():Boolean does the actual work of changing TextFlow • Return value indicates whether the operation completed correctly; if not, return false and IEditManager rolls back generation
  • 26. EXTENDING THE TLF • undo():SelectionState, contains logic for reversing changes, return value is the selection state desired after undo • redo():SelectionState, redoes operation, returns SelectionState originally passed to doOperation; don’t have to implement • How do you actually call your operation? • IEditManager.doOperation: does bookkeeping and calls FlowTextOperation.doOperation • Extend EditManager and add interface for calling your operation
  • 27. EXTENDING THE TLF • Things to keep in mind • You can use other operations within your operation • Take advantage of existing classes • Makes undo easy to implement (but remember to undo operations in reverse order) • Alternatively, can use IEditManager.beginCompositeOperation/ endCompositeOperation to group operations on the fly
  • 28. EXTENDING THE TLF • Stay away from using FlowElement references in your operation • When using copy/cut/paste or TextFlow normalizes, FlowElements are often replaced or removed • If you need to reference a particular element; use FlowElement.id and textFlow.getElementById instead • Make sure you consider any changes to selection state that your operation induces and set it in doOperation if necessary • use namespace tlf_internal: many helpful methods are tucked away in there
  • 29. LEVERAGING THE FTE • Understanding underlying FTE parts of TLF can help you: • Decorate/enhance TLF-rendered text without changing the model or the layout • Get more specific information about layout of text lines within a container and the TextFlow as a whole • TextFlowLine: TLF wrapper for TextLines that actually reside on stage; both provide useful information • StandardFlowComposer -> TextFlowLine -> TextLine
  • 30. LEVERAGING THE FTE • StandardFlowComposer: methods for grabbing TextFlowLines • findLineAtPosition/findLineIndexAtPosition: gets reference to/ index of TextFlowLine that contains the text at a given position • ContainerController: couple of tlf_internal methods for getting specific TextFlowLines • tlf_internal getFirstVisibleLine():TextFlowLine • tlf_internal getLastVisibleLine():TextFlowLine • TextFlowLine.getLine():TextLine
  • 31. LEVERAGING THE FTE • TextLine: methods for getting position, index information for individual characters • getAtomBounds: get bounds relative to TextLine of a particular atom (character) • getAtomIndexAtPoint: get index of atom at given point (relative to the stage) • So how can we use all this? • Draw on top of the TextLine • Pinpoint a position relative to the stage or another component from a text position
  • 32. COMBINING WITH OTHER FLEX COMPONENTS • Ideally, we would love to be to create custom FlowElements that provide new functionality and integrate nicely with TLF but not always possible or time efficient so what else can we do? • http://platustalksflex.blogspot.com/2010/07/position- uicomponents-inside-textflow.html • Basically, use an InlineGraphicElement as a placeholder, and then position another component on top of it.
  • 33. COMBINING WITH OTHER FLEX COMPONENTS • Need to assign id to differentiate our placeholder InlineGraphicElements from others • Keep a mapping of these id’s to the Flex components • Update all of these components on UpdateCompleteEvent • Can even utilize this with TLF selection/editing (takes some work though)
  • 34. COMBINING WITH OTHER FLEX COMPONENTS • Can even import/export these components • Use XML: export as whatever tag required, make sure assign “id” attribute • To import: replace XML placeholder tags with <img> tags • Have to take care of cut/copy/paste: end up with placeholders with identical id’s: • Have to extend EditManager and override pasteTextScrap • Go through TextScrap and replace duplicate id’s with new ones.
  • 35. CONCLUSION • Before even getting into TLF, make sure it’s the right solution. • Most flexible, powerful way to user TLF is in “manual,” setting up everything yourself • Extend TLF classes to add new functionality and encapsulate it • Go lower-level by accessing and manipulating underlying FTE to play with interaction and rendering without changing TLF parts • Integrate Flex UIComponents with TextFlow layout by using placeholders and custom operations. • It takes some work (and a bit of code), but seriously, you can do cool things.
  • 36. CREDIT WHERE CREDIT IS DUE • Drawing highlights on TextLines technique from the HighlightAdornment example included in “Using TLF with Flash CS4 examples” for TLF 1.0 Beta: http:// opensource.adobe.com/wiki/display/tlf/Text+Layout +Framework • “InlineUIComponents within a TextFlow”: http:// platustalksflex.blogspot.com/2010/07/position-uicomponents- inside-textflow.html
  • 37. QUESTIONS? Thanks for coming! Huyen Tue Dao [email protected] [email protected] www.queencodemonkey.com

Editor's Notes

  • #2: \n
  • #3: \n
  • #4: \n
  • #5: \n
  • #6: \n
  • #7: \n
  • #8: \n
  • #9: \n
  • #10: \n
  • #11: \n
  • #12: \n
  • #13: \n
  • #14: \n
  • #15: \n
  • #16: \n
  • #17: \n
  • #18: \n
  • #19: Go to ManualTLF examples&amp;#x2026;\n
  • #20: Go to ManualTLF examples&amp;#x2026;\n
  • #21: Go to Pagination example&amp;#x2026;\n
  • #22: Go to Pagination example&amp;#x2026;\n
  • #23: Go to Pagination example&amp;#x2026;\n
  • #24: \n
  • #25: \n
  • #26: Go to Pagination example&amp;#x2026;\n
  • #27: Go to Pagination example&amp;#x2026;\n
  • #28: Go to Pagination example&amp;#x2026;\n
  • #29: Go to Pagination example&amp;#x2026;\n
  • #30: Go to Pagination example&amp;#x2026;\n
  • #31: Go to Pagination example&amp;#x2026;\n
  • #32: Go to Pagination example&amp;#x2026;\n
  • #33: Go to Pagination example&amp;#x2026;\n
  • #34: Go to Pagination example&amp;#x2026;\n
  • #35: Go to Bookmarks example&amp;#x2026;\n
  • #36: Go to EDI and search/replace&amp;#x2026;\n
  • #37: Go to MadLibs example&amp;#x2026;\n
  • #38: Go to MadLibs example&amp;#x2026;\n
  • #39: Go to MadLibs example&amp;#x2026;\n
  • #40: Go to MadLibs example&amp;#x2026;\n
  • #41: Go to MadLibs example&amp;#x2026;\n
  • #42: \n
  • #43: \n