commit 83871a1e560aa0aca7664d05635dc38d6306cc85
parent bfa6a93a2fa7a222815b5f286f04cf10e974c957
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Tue, 11 Nov 2025 08:19:01 +0000
Bug 1998071 - Deal with transform-origin consistently for textPath. r=longsonr,firefox-svg-reviewers
Transform-origin is a bit special in svg and this helper deals with it
properly.
Differential Revision: https://phabricator.services.mozilla.com/D272121
Diffstat:
3 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/dom/svg/SVGGeometryElement.cpp b/dom/svg/SVGGeometryElement.cpp
@@ -16,6 +16,7 @@
#include "gfxPlatform.h"
#include "mozilla/RefPtr.h"
#include "mozilla/SVGContentUtils.h"
+#include "mozilla/SVGUtils.h"
#include "mozilla/dom/DOMPointBinding.h"
#include "mozilla/dom/SVGLengthBinding.h"
#include "mozilla/gfx/2D.h"
@@ -238,24 +239,11 @@ already_AddRefed<DOMSVGPoint> SVGGeometryElement::GetPointAtLength(
}
gfx::Matrix SVGGeometryElement::LocalTransform() const {
- gfx::Matrix result;
nsIFrame* f = GetPrimaryFrame();
if (!f || !f->IsTransformed()) {
- return result;
+ return {};
}
- nsStyleTransformMatrix::TransformReferenceBox refBox(f);
- const float a2css = AppUnitsPerCSSPixel();
- nsDisplayTransform::FrameTransformProperties props(f, refBox, a2css);
- if (!props.HasTransform()) {
- return result;
- }
- auto matrix = nsStyleTransformMatrix::ReadTransforms(
- props.mTranslate, props.mRotate, props.mScale,
- props.mMotion.ptrOr(nullptr), props.mTransform, refBox, a2css);
- if (!matrix.IsIdentity()) {
- std::ignore = matrix.CanDraw2D(&result);
- }
- return result;
+ return gfx::Matrix(SVGUtils::GetTransformMatrixInUserSpace(f));
}
float SVGGeometryElement::GetPathLengthScale(PathLengthScaleForType aFor) {
diff --git a/testing/web-platform/tests/svg/text/reftests/text-path-transformed-002-ref.html b/testing/web-platform/tests/svg/text/reftests/text-path-transformed-002-ref.html
@@ -0,0 +1,7 @@
+<!doctype html>
+<svg width="400" height="200" viewBox="-150 0 600 200">
+ <path id="rotated-anchor" d="M 20 200 A 125 125 0 0 1 289 175" transform="rotate(36 150 190)" fill="none" stroke="black"/>
+ <text>
+ <textPath href="#rotated-anchor">XXXX</textPath>
+ </text>
+</svg>
diff --git a/testing/web-platform/tests/svg/text/reftests/text-path-transformed-002.html b/testing/web-platform/tests/svg/text/reftests/text-path-transformed-002.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<meta charset="utf-8">
+<style>
+#rotated-anchor {
+ transform: rotate(36deg);
+ transform-origin: 150px 190px;
+}
+</style>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="author" title="Mozilla" href="https://mozilla.org">
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1998071">
+<link rel="match" href="text-path-transformed-002-ref.html">
+<svg width="400" height="200" viewBox="-150 0 600 200">
+ <path id="rotated-anchor" d="M 20 200 A 125 125 0 0 1 289 175" fill="none" stroke="black"/>
+ <text>
+ <textPath href="#rotated-anchor">XXXX</textPath>
+ </text>
+</svg>