commit 2231504a840b023fbd09c92652f472237a4f1167
parent 8e7971d885d6bc249a634748d40eb12aaca10d5c
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Mon, 10 Nov 2025 07:38:51 +0000
Bug 1999117 - Coerce singular matrix from GetCTM to identity. r=longsonr,firefox-svg-reviewers
This seems to match WebKit / Blink.
Differential Revision: https://phabricator.services.mozilla.com/D271897
Diffstat:
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/dom/svg/SVGContentUtils.cpp b/dom/svg/SVGContentUtils.cpp
@@ -427,7 +427,10 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, CTMType aCTMType,
ret = SVGUtils::GetTransformMatrixInUserSpace(f);
}
if (shouldIncludeChildToUserSpace) {
- ret = e->ChildToUserSpaceTransform() * ret;
+ auto t = e->ChildToUserSpaceTransform();
+ if (!t.IsSingular()) {
+ ret = t * ret;
+ }
}
return ret;
};
@@ -453,7 +456,8 @@ static gfx::Matrix GetCTMInternal(SVGElement* aElement, CTMType aCTMType,
if (SVGOuterSVGFrame* frame =
do_QueryFrame(element->GetPrimaryFrame())) {
Matrix childTransform;
- if (frame->HasChildrenOnlyTransform(&childTransform)) {
+ if (frame->HasChildrenOnlyTransform(&childTransform) &&
+ !childTransform.IsSingular()) {
return gfx::ToMatrix(matrix) * childTransform;
}
}
diff --git a/testing/web-platform/tests/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html b/testing/web-platform/tests/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html
@@ -6,6 +6,9 @@
<link rel="help" href="https://svgwg.org/svg2-draft/types.html#InterfaceSVGGraphicsElement" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
+<style>
+ svg { vertical-align: top } /* To avoid baseline alignment */
+</style>
<div id="container" style="width: 500px; height: 0px;">
<svg width="100%" height="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs></defs>
@@ -25,6 +28,13 @@
assert_identity(document.querySelector(".viewport").getCTM());
}, "getCTM");
test(function() {
- assert_identity(document.querySelector(".viewport").getScreenCTM());
+ let m = document.querySelector(".viewport").getScreenCTM();
+ assert_equals(m.a, 1, "a");
+ assert_equals(m.d, 1, "d");
+ assert_equals(m.b, 0, "b");
+ assert_equals(m.c, 0, "c");
+ // For the <body> margin.
+ assert_equals(m.e, 8, "e");
+ assert_equals(m.f, 8, "f");
}, "getScreenCTM");
</script>