need currentContainer in order to measure text

Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c341287a
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c341287a
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c341287a

Branch: refs/heads/tlf
Commit: c341287ab8773dd3ea516f6485390c608843109a
Parents: 91ef059
Author: Alex Harui <[email protected]>
Authored: Mon May 8 11:07:53 2017 -0700
Committer: Alex Harui <[email protected]>
Committed: Mon May 8 11:59:03 2017 -0700

----------------------------------------------------------------------
 .../container/TextContainerManager.as           |  3 +-
 .../flex/textLayout/factory/ITLFFactory.as      | 10 ++++-
 .../textLayout/factory/StandardTLFFactory.as    | 11 ++++++
 .../org/apache/flex/text/engine/ITextFactory.as | 10 +++++
 .../apache/flex/text/html/HTMLTextFactory.as    | 14 ++++++-
 .../flex/org/apache/flex/text/html/TextBlock.as |  7 ++++
 .../flex/org/apache/flex/text/html/TextLine.as  | 40 ++++++++++++++++----
 7 files changed, 84 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
index 72ba0c1..4488faf 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
@@ -1632,7 +1632,8 @@ package org.apache.flex.textLayout.container
                private function convertToTextFlow():void
                {
                        CONFIG::debug { assert(_sourceState != 
SOURCE_TEXTFLOW,"bad call to convertToTextFlow"); }
-                                                                       
+       
+                       TLFFactory.defaultTLFFactory.currentContainer = 
container;                                                              
                        _textFlow = new TextFlow(TLFFactory.defaultTLFFactory, 
_config);
                        _textFlow.hostFormat = _hostFormat;
                        if(_swfContext)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/ITLFFactory.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/ITLFFactory.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/ITLFFactory.as
index 4b204b5..c8da7ad 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/ITLFFactory.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/ITLFFactory.as
@@ -25,6 +25,14 @@ package org.apache.flex.textLayout.factory {
                function get textFactory():ITextFactory;
                function getRect():IRect;
                function getCompoundGraphic():ICompoundGraphic;
-               function getContainer():IParentIUIBase;         
+               function getContainer():IParentIUIBase;
+               
+               // in JS, in order to measure text, TextLines need to be put
+               // in the DOM early, so you need to pick one DOM widget to use 
as
+               // at least a temporary parent.
+               // in SWF, this isn't really needed since FTE is given all
+               // of the font information it needs
+               function get currentContainer():IParentIUIBase;
+               function set currentContainer(value:IParentIUIBase):void
        }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/StandardTLFFactory.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/StandardTLFFactory.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/StandardTLFFactory.as
index 460621b..7ed3439 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/StandardTLFFactory.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/factory/StandardTLFFactory.as
@@ -45,7 +45,18 @@ package org.apache.flex.textLayout.factory {
                public function get textFactory() : ITextFactory {
                        if(!factory)
                                factory = new HTMLTextFactory();
+                       factory.currentContainer = currentContainer;
                        return factory;
                }
+               
+               private var _currentContainer:IParentIUIBase;
+               public function get currentContainer():IParentIUIBase
+               {
+                       return _currentContainer;
+               }
+               public function set currentContainer(value:IParentIUIBase):void
+               {
+                       _currentContainer = value;
+               }
        }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/engine/ITextFactory.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/engine/ITextFactory.as
 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/engine/ITextFactory.as
index 5ef254c..6987c22 100644
--- 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/engine/ITextFactory.as
+++ 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/engine/ITextFactory.as
@@ -19,11 +19,21 @@
 package org.apache.flex.text.engine
 {
        import org.apache.flex.core.IUIBase;
+       import org.apache.flex.core.IParentIUIBase;
 
        public interface ITextFactory
        {
         function getTextBlock():ITextBlock;
         function getTextContainer():IUIBase;
         function getFontLoader():IFontLoader;
+               
+               // in JS, in order to measure text, TextLines need to be put
+               // in the DOM early, so you need to pick one DOM widget to use 
as
+               // at least a temporary parent.
+               // in SWF, this isn't really needed since FTE is given all
+               // of the font information it needs
+               function get currentContainer():IParentIUIBase;
+               function set currentContainer(value:IParentIUIBase):void
+
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/HTMLTextFactory.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/HTMLTextFactory.as
 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/HTMLTextFactory.as
index e7021b7..48bd8bf 100644
--- 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/HTMLTextFactory.as
+++ 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/HTMLTextFactory.as
@@ -21,6 +21,7 @@ package org.apache.flex.text.html
     import org.apache.flex.text.engine.ITextFactory;
     import org.apache.flex.text.engine.ITextBlock;
     import org.apache.flex.core.IUIBase;
+       import org.apache.flex.core.IParentIUIBase;
     import org.apache.flex.html.Div;
     import org.apache.flex.text.engine.IFontLoader;
 
@@ -40,7 +41,18 @@ package org.apache.flex.text.html
         {
             // no fontLoader for this factory at this point. It uses standard 
broswer fonts.
             return _fontLoader;
-        }        
+        }
+               
+               private var _currentContainer:IParentIUIBase;
+               public function get currentContainer():IParentIUIBase
+               {
+                       return _currentContainer;
+               }
+               public function set currentContainer(value:IParentIUIBase):void
+               {
+                       _currentContainer = value;
+               }
+        
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextBlock.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextBlock.as 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextBlock.as
index 088588a..934b8e5 100644
--- 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextBlock.as
+++ 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextBlock.as
@@ -30,6 +30,8 @@ package org.apache.flex.text.html
        import org.apache.flex.text.html.TextLine;
        import org.apache.flex.html.Span;
        
+       import org.apache.flex.core.IParent;
+       
        public class TextBlock implements ITextBlock
        {
                public function TextBlock(factory:ITextFactory)
@@ -182,6 +184,9 @@ package org.apache.flex.text.html
                
                private var lines:Array = [];
                
+               /**
+                * @flexjsignorecoercion org.apache.flex.core.IParent
+                */
                public function createTextLine(previousLine:ITextLine = null, 
width:Number = 1000000, lineOffset:Number = 0.0, fitSomething:Boolean = 
false):ITextLine
                {
                        if (previousLine == null)
@@ -209,8 +214,10 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
+                               textFactory.currentContainer.addElement(tl); // 
add to DOM early so textWidth is valid
                                var span:Span = new Span();
                                span.text = textElem.text;
+                               //span.element.style.display = "block";
                                tl.addElement(span);
                        }
                        if (previousLine == null)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c341287a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
index fbb17a3..b865f33 100644
--- 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
+++ 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
@@ -71,10 +71,14 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return 0;
+                               // needs improvement.  For now assume 2 pixel 
descent.
+                               return 
_textBlock.content.elementFormat.fontSize - 2;
                        }
                }
                
+               /**
+                * @flexjsignorecoercion HTMLElement
+                */
                public function get atomCount():int
                {
                        COMPILE::SWF
@@ -83,7 +87,7 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return 0;
+                               return (element.firstChild as 
HTMLElement).firstChild["length"];
                        }
                }
                
@@ -103,7 +107,11 @@ package org.apache.flex.text.html
                        {
                                return textField.getLineMetrics(0).descent;
                        }
-                       return 0;
+                       COMPILE::JS
+                       {
+                               // needs improvement.  For now assume 2 pixel 
descent.
+                               return 2;
+                       }
                }
                
                private var _doubleClickEnabled:Boolean;
@@ -150,7 +158,7 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return 0;
+                               return atomCount;
                        }
                }
                
@@ -172,6 +180,9 @@ package org.apache.flex.text.html
                        return _beginIndex;
                }
                
+               /**
+                * @flexjsignorecoercion HTMLElement
+                */
                public function get textHeight():Number
                {
                        COMPILE::SWF
@@ -180,10 +191,13 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return 0;
+                               return (element.firstChild as 
HTMLElement).getClientRects()[0].height;
                        }
                }
                
+               /**
+                * @flexjsignorecoercion HTMLElement
+                */
                public function get textWidth():Number
                {
                        COMPILE::SWF
@@ -192,7 +206,15 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return 0;
+                               if (element.firstChild.textContent == "\u2029")
+                               { 
+                                 // if para terminator, use nbsp instead
+                                 (element.firstChild as HTMLElement).innerHTML 
= "\u00A0";
+                                 var w:Number = (element.firstChild as 
HTMLElement).getClientRects()[0].width;
+                                 (element.firstChild as HTMLElement).innerHTML 
= "\u2029";
+                                 return w;
+                               }
+                               return (element.firstChild as 
HTMLElement).getClientRects()[0].width;
                        }
                }
                
@@ -277,7 +299,7 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return null;
+                               return new Rectangle(element.offsetLeft, 
element.offsetTop, element.offsetWidth, element.offsetHeight);
                        }
                }
                
@@ -295,7 +317,8 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
-                               return null;
+                               // fake an answer
+                               return new Rectangle(0, 1.2 - 
_textBlock.content.elementFormat.fontSize, 3, 1.2);
                        }
                }
 
@@ -325,6 +348,7 @@ package org.apache.flex.text.html
                        }
                        COMPILE::JS
                        {
+                               trace("getAtomIndexAtPoint not implemented");
                                //TODO atom locations. This one will be fun...
                                return 0;
                        }

Reply via email to