You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2019/12/30 00:35:53 UTC

[royale-asjs] 10/13: fix measuring text

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 3c8843810ad639d504d9406abfbb99cce4915a34
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri Dec 27 23:59:15 2019 -0800

    fix measuring text
---
 .../MXRoyale/src/main/royale/mx/core/UITextField.as   | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextField.as b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextField.as
index 90068fc..3e74a0d 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextField.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextField.as
@@ -38,6 +38,7 @@ import flash.text.TextLineMetrics;
  import mx.styles.IStyleManager2;
  import mx.utils.StringUtil;
  
+ import org.apache.royale.core.TextLineMetrics;
  import org.apache.royale.events.Event;
  
  COMPILE::JS
@@ -459,6 +460,8 @@ public class UITextField  extends UIComponent implements IUITextField
             dispatchEvent(new Event("textFieldWidthChange")); */
     }
     
+     private var usingHTML:Boolean;
+     
      //----------------------------------
      //  htmlText
      //----------------------------------
@@ -666,6 +669,9 @@ public class UITextField  extends UIComponent implements IUITextField
       */
      public function set htmlText(value:String):void
      {
+         lineMetrics = null;
+         usingHTML = true;
+         
          COMPILE::SWF
              {
                  ITextModel(model).html = value;
@@ -747,6 +753,9 @@ public class UITextField  extends UIComponent implements IUITextField
       */
      public function set text(value:String):void
      {
+         lineMetrics = null;
+         usingHTML = false;
+         
          COMPILE::SWF
              {
                  ITextModel(model).text = value;
@@ -2982,14 +2991,20 @@ public class UITextField  extends UIComponent implements IUITextField
          return true;
      }
      
+     private var lineMetrics:TextLineMetrics;
+     
      public function get textWidth():Number
      {
-         return width;
+         if (!lineMetrics)
+             lineMetrics = getUITextFormat().measureText(usingHTML ? htmlText : text);
+         return lineMetrics.width;
      }
      
      public function get textHeight():Number
      {
-         return height;
+         if (!lineMetrics)
+             lineMetrics = getUITextFormat().measureText(usingHTML ? htmlText : text);
+         return lineMetrics.height;
      }
      
      public function get wordWrap():Boolean