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/28 08:00:06 UTC
[royale-asjs] 03/04: fix measuring text
This is an automated email from the ASF dual-hosted git repository.
aharui pushed a commit to branch adg_grouped
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 8e958c36d614d3c92a22e06c4a44a95634a94067
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