You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/05/22 10:30:53 UTC
[royale-asjs] 01/03: Workaround for an issue with text measurement
requested in content that is not yet in the DOM. Needs review.
This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 2b6cf7ebe24d93c76e7417fcfced301c9c7562d5
Author: greg-dove <gr...@gmail.com>
AuthorDate: Fri May 22 21:41:28 2020 +1200
Workaround for an issue with text measurement requested in content that is not yet in the DOM. Needs review.
---
.../src/main/royale/mx/core/UITextFormat.as | 47 ++++++++++++++--------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextFormat.as b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextFormat.as
index 1ce581a..1b2d696 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextFormat.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UITextFormat.as
@@ -558,7 +558,10 @@ public class UITextFormat extends TextFormat
return lineMetrics;
}
-
+
+ COMPILE::JS
+ private static var measuringElementRef:HTMLSpanElement
+
/**
* @royaleignorecoercion mx.managers.SystemManager;
* @royaleignorecoercion HTMLSpanElement;
@@ -566,25 +569,37 @@ public class UITextFormat extends TextFormat
COMPILE::JS
private function measure(s:String, html:Boolean, roundUp:Boolean):TextLineMetrics
{
- var sm:SystemManager = systemManager as SystemManager;
- if (sm.measuringElement == null)
- {
- sm.measuringElement = document.createElement("span") as HTMLSpanElement;
- //everything else is absolute position so should be above this element
- //sm.measuringElement.style.position = "float"; // to try to keep it from affecting position of other elements
- // offsetWidth/Height not computed for display: none
- //sm.measuringElement.style.display = "none"; // to try to keep it hidden
- sm.measuringElement.style.opacity = 0;
- sm.measuringElement.style["pointer-events"] = "none";
- sm.element.appendChild(sm.measuringElement);
+ //sometimes this can be requested in some code that does not pass a reference to systemManager, so use
+ //a cached reference to the measuringElement - needs review
+ var measuringElement:HTMLSpanElement = measuringElementRef;
+
+ if (!measuringElement) {
+ measuringElementRef = (systemManager as SystemManager).measuringElement;
+ measuringElement = measuringElementRef;
+ if (!measuringElement) {
+ var sm:SystemManager = systemManager as SystemManager;
+ if (sm.measuringElement == null)
+ {
+ measuringElement = document.createElement("span") as HTMLSpanElement;
+ //everything else is absolute position so should be above this element
+ //sm.measuringElement.style.position = "float"; // to try to keep it from affecting position of other elements
+ // offsetWidth/Height not computed for display: none
+ //sm.measuringElement.style.display = "none"; // to try to keep it hidden
+ measuringElement.style.opacity = 0;
+ measuringElement.style["pointer-events"] = "none";
+ sm.element.appendChild(measuringElement);
+ sm.measuringElement = measuringElement;
+ }
+ }
}
+
if (s.indexOf(" ") >= 0)
- sm.measuringElement.innerHTML = s;
+ measuringElement.innerHTML = s;
else
- sm.measuringElement.textContent = s;
+ measuringElement.textContent = s;
var tlm:TextLineMetrics = new TextLineMetrics();
- tlm.width = sm.measuringElement.offsetWidth;
- tlm.height = sm.measuringElement.offsetHeight;
+ tlm.width = measuringElement.offsetWidth;
+ tlm.height = measuringElement.offsetHeight;
return tlm;
}