Skip to content

Commit

Permalink
Negative SVGTransform scale values should be correctly stringified
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264752
rdar://problem/118656892

Reviewed by Said Abou-Hallawa.

This patch is to align WebKit with Blink / Chromium and partially with Gecko / Firefox.

Merge: https://chromium.googlesource.com/chromium/blink/+/8a7252a2602bd8067c83d48c8fd525ef322708c2

Before this patch, SVGTransformValue::appendScale used AffineTransform::{x,y}Scale},
which computed transform scale values by computing norm of projected unit vectors.
However, that would always return positive values, even if negative scale values were specified.

This patch changes the implementation to use `a` and `d` values instead. This is valid,
as the scale matrix is guaranteed to be in the below simple form when the transform has
type `SVG_TRANSFORM_SCALE`.

|xscale    0   0|
|   0   yscale 0|

* Source/WebCore/svg/SVGTransformValue.h:
(appendScale):
* LayoutTests/svg/transforms/negative-scale-value.html: Add Test Case
* LayoutTests/svg/transforms/negative-scale-value-expected.txt: Add Test Case Expectation

Canonical link: https://commits.webkit.org/272885@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jan 11, 2024
1 parent 9abc579 commit 2efdea0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/svg/transforms/negative-scale-value-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SVG scale transform with negative scale values should be correctly converted to strings.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS g.getAttribute('transform') is "scale(-2 -4)"
PASS successfullyParsed is true

TEST COMPLETE

15 changes: 15 additions & 0 deletions LayoutTests/svg/transforms/negative-scale-value.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<script src='../../resources/js-test.js'></script>
<script>
description("SVG scale transform with negative scale values should be correctly converted to strings.");

var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
var transform = svg.createSVGTransform();
transform.setScale(-2, -4);

var list = g.transform.baseVal;
list.appendItem(transform);

shouldBeEqualToString("g.getAttribute('transform')", "scale(-2 -4)");
</script>
5 changes: 3 additions & 2 deletions Source/WebCore/svg/SVGTransformValue.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
* Copyright (C) 2019 Apple Inc. All rights reserved.
* Copyright (C) 2019-2024 Apple Inc. All rights reserved.
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -264,7 +265,7 @@ class SVGTransformValue {

void appendScale(StringBuilder& builder) const
{
appendFixedPrecisionNumbers(builder, m_matrix->value().xScale(), m_matrix->value().yScale());
appendFixedPrecisionNumbers(builder, m_matrix->a(), m_matrix->d());
}

void appendRotate(StringBuilder& builder) const
Expand Down

0 comments on commit 2efdea0

Please sign in to comment.