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

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


The following commit(s) were added to refs/heads/develop by this push:
     new a1105c8cb0 Enhance DisplayUtils with SVG support and deprecate 
getTransormMatrix method
a1105c8cb0 is described below

commit a1105c8cb0882ab21fd179ff96ab41d804d9be86
Author: Harbs <[email protected]>
AuthorDate: Mon Jul 13 10:35:25 2026 +0300

    Enhance DisplayUtils with SVG support and deprecate getTransormMatrix method
---
 .../royale/org/apache/royale/utils/DisplayUtils.as | 22 ++++--
 .../test/royale/flexUnitTests/DisplayUtilsTest.as  | 87 ++++++++++++++++++++++
 2 files changed, 102 insertions(+), 7 deletions(-)

diff --git 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/DisplayUtils.as
 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/DisplayUtils.as
index 6800eb6ba2..29d5d5a64c 100644
--- 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/DisplayUtils.as
+++ 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/DisplayUtils.as
@@ -59,6 +59,7 @@ package org.apache.royale.utils
                 *  @param obj The object to test.
                 *  @param boundsBeforeTransform Optional untransformed local 
bounds. On JS,
                 *  these bounds are transformed into viewport coordinates for 
SVG elements.
+                *  The supplied rectangle is not modified.
                 *
                 *  @return The object's axis-aligned bounds in the top-level 
visible coordinate space.
                 *  
@@ -84,9 +85,9 @@ package org.apache.royale.utils
                                        var r:Object = (obj.element as 
HTMLElement).getBoundingClientRect();
                                        bounds = new Rectangle(r.left, r.top, 
r.right - r.left, r.bottom - r.top);
                                }
-                               if (obj.element is SVGElement)
+                               if (boundsBeforeTransform != null && 
obj.element is SVGElement)
                                {
-                                       var m:org.apache.royale.geom.Matrix = 
getTransormMatrix(obj);
+                                       var m:org.apache.royale.geom.Matrix = 
getTransformMatrix(obj);
                                        var tl:Point = 
m.transformPoint(bounds.topLeft);
                                        var tr:Point = m.transformPoint(new 
Point(bounds.right, bounds.top));
                                        var bl:Point = m.transformPoint(new 
Point(bounds.left, bounds.bottom));
@@ -95,10 +96,7 @@ package org.apache.royale.utils
                                        var topY:Number = Math.min(tl.y, tr.y, 
bl.y, br.y);
                                        var rightX:Number = Math.max(tl.x, 
tr.x, bl.x, br.x);
                                        var bottomY:Number = Math.max(tl.y, 
tr.y, bl.y, br.y);
-                                       bounds.top = topY;
-                                       bounds.left = leftX;
-                                       bounds.bottom = bottomY;
-                                       bounds.right = rightX;
+                                       bounds = new Rectangle(leftX, topY, 
rightX - leftX, bottomY - topY);
                                }
                                return bounds;
                        }
@@ -117,7 +115,7 @@ package org.apache.royale.utils
                 *  @royaleignorecoercion HTMLElement
                 *  @royaleignorecoercion org.apache.royale.core.ITransformHost
                 */
-               public static function 
getTransormMatrix(obj:IUIBase):org.apache.royale.geom.Matrix
+               public static function 
getTransformMatrix(obj:IUIBase):org.apache.royale.geom.Matrix
                {
                        COMPILE::SWF
                        {
@@ -134,6 +132,16 @@ package org.apache.royale.utils
                        
                }
 
+               /**
+                *  @copy #getTransformMatrix()
+                *  @deprecated Use <code>getTransformMatrix()</code> instead.
+                */
+               [Deprecated(message="Use getTransformMatrix() instead")]
+               public static function 
getTransormMatrix(obj:IUIBase):org.apache.royale.geom.Matrix
+               {
+                       return getTransformMatrix(obj);
+               }
+
                /**
                 *  Evaluates the bounding boxes of two objects to see if they 
overlap.
                 * 
diff --git 
a/frameworks/projects/Core/src/test/royale/flexUnitTests/DisplayUtilsTest.as 
b/frameworks/projects/Core/src/test/royale/flexUnitTests/DisplayUtilsTest.as
index 1fbbd85679..2272b4e40f 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/DisplayUtilsTest.as
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/DisplayUtilsTest.as
@@ -19,7 +19,9 @@
 package flexUnitTests
 {
     import org.apache.royale.core.UIBase;
+    import org.apache.royale.geom.Matrix;
     import org.apache.royale.geom.Rectangle;
+    import org.apache.royale.svg.GraphicContainer;
     import org.apache.royale.test.asserts.*;
     import org.apache.royale.utils.DisplayUtils;
 
@@ -146,6 +148,60 @@ package flexUnitTests
             }
         }
 
+        [Test]
+        public function testSvgWithoutSuppliedBoundsUsesClientBounds():void
+        {
+            COMPILE::JS
+            {
+                var svg:GraphicContainer = createSvgTarget();
+                svg.transformElement.setAttribute("transform", "translate(75 
50) rotate(35)");
+                var clientBounds:Object = svg.element.getBoundingClientRect();
+                var bounds:Rectangle = DisplayUtils.getScreenBoundingRect(svg);
+
+                assertRectangleMatchesClientBounds(bounds, clientBounds);
+            }
+        }
+
+        [Test]
+        public function testSvgSuppliedBoundsUsesTransformElementMatrix():void
+        {
+            COMPILE::JS
+            {
+                var svg:GraphicContainer = createSvgTarget();
+                svg.transformElement.setAttribute("transform", "translate(75 
50) rotate(35)");
+                var localBounds:Rectangle = new Rectangle(10, 20, 30, 40);
+                var transformElement:Object = svg.transformElement;
+                var screenMatrix:Object = transformElement.getScreenCTM();
+                var bounds:Rectangle = DisplayUtils.getScreenBoundingRect(svg, 
localBounds);
+
+                assertTransformedBounds(bounds, localBounds, screenMatrix);
+                assertFalse(bounds === localBounds);
+                assertEquals(10, localBounds.left);
+                assertEquals(20, localBounds.top);
+                assertEquals(40, localBounds.right);
+                assertEquals(60, localBounds.bottom);
+            }
+        }
+
+        [Test]
+        public function testTransformMatrixCompatibilityAlias():void
+        {
+            COMPILE::JS
+            {
+                var svg:GraphicContainer = createSvgTarget();
+                svg.transformElement.setAttribute("transform", "translate(25 
40) scale(2 3)");
+                var matrix:Matrix = DisplayUtils.getTransformMatrix(svg);
+                var compatibilityMatrix:Matrix = 
DisplayUtils.getTransormMatrix(svg);
+
+                assertNear(matrix.a, compatibilityMatrix.a, "Incorrect 
compatibility matrix a");
+                assertNear(matrix.b, compatibilityMatrix.b, "Incorrect 
compatibility matrix b");
+                assertNear(matrix.c, compatibilityMatrix.c, "Incorrect 
compatibility matrix c");
+                assertNear(matrix.d, compatibilityMatrix.d, "Incorrect 
compatibility matrix d");
+                assertNear(matrix.tx, compatibilityMatrix.tx, "Incorrect 
compatibility matrix tx");
+                assertNear(matrix.ty, compatibilityMatrix.ty, "Incorrect 
compatibility matrix ty");
+            }
+        }
+
         [Test]
         public function testObjectsOverlapUsesViewportBounds():void
         {
@@ -175,6 +231,37 @@ package flexUnitTests
             assertNear(clientBounds.bottom, bounds.bottom, "Incorrect bottom 
viewport coordinate");
         }
 
+        COMPILE::JS
+        private function createSvgTarget():GraphicContainer
+        {
+            var svg:GraphicContainer = new GraphicContainer();
+            svg.element.style.position = "absolute";
+            svg.element.style.left = "250px";
+            svg.element.style.top = "300px";
+            svg.element.style.width = "200px";
+            svg.element.style.height = "150px";
+            fixture.appendChild(svg.element);
+            return svg;
+        }
+
+        COMPILE::JS
+        private function assertTransformedBounds(bounds:Rectangle, 
localBounds:Rectangle, matrix:Object):void
+        {
+            var x1:Number = matrix.a * localBounds.left + matrix.c * 
localBounds.top + matrix.e;
+            var y1:Number = matrix.b * localBounds.left + matrix.d * 
localBounds.top + matrix.f;
+            var x2:Number = matrix.a * localBounds.right + matrix.c * 
localBounds.top + matrix.e;
+            var y2:Number = matrix.b * localBounds.right + matrix.d * 
localBounds.top + matrix.f;
+            var x3:Number = matrix.a * localBounds.left + matrix.c * 
localBounds.bottom + matrix.e;
+            var y3:Number = matrix.b * localBounds.left + matrix.d * 
localBounds.bottom + matrix.f;
+            var x4:Number = matrix.a * localBounds.right + matrix.c * 
localBounds.bottom + matrix.e;
+            var y4:Number = matrix.b * localBounds.right + matrix.d * 
localBounds.bottom + matrix.f;
+
+            assertNear(Math.min(x1, x2, x3, x4), bounds.left, "Incorrect 
transformed left");
+            assertNear(Math.min(y1, y2, y3, y4), bounds.top, "Incorrect 
transformed top");
+            assertNear(Math.max(x1, x2, x3, x4), bounds.right, "Incorrect 
transformed right");
+            assertNear(Math.max(y1, y2, y3, y4), bounds.bottom, "Incorrect 
transformed bottom");
+        }
+
         COMPILE::JS
         private function assertNear(expected:Number, actual:Number, 
message:String):void
         {

Reply via email to