Skip to content

Commit 2ee8f32

Browse files
BATIK-1361: Animated rotate tranform ignores y-origin at exactly 270 degrees by Stanimir Stamenkov
1 parent be5e76b commit 2ee8f32

File tree

5 files changed

+166
-1
lines changed

5 files changed

+166
-1
lines changed

batik-svg-dom/src/main/java/org/apache/batik/dom/svg/AbstractSVGTransformList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void assign(SVGTransform transform) {
284284
setScale(matrix.getA(), matrix.getD());
285285
break;
286286
case SVGTransform.SVG_TRANSFORM_ROTATE:
287-
if (matrix.getE() == 0.0f) {
287+
if (matrix.getE() == 0.0f && matrix.getF() == 0.0f) {
288288
rotate(transform.getAngle());
289289
} else {
290290
angleOnly = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
*/
19+
package org.apache.batik.test.svg;
20+
21+
import java.util.regex.Pattern;
22+
23+
import org.w3c.dom.Document;
24+
import org.w3c.dom.Element;
25+
import org.w3c.dom.NodeList;
26+
27+
import org.apache.batik.transcoder.SVGAbstractTranscoder;
28+
import org.apache.batik.transcoder.image.ImageTranscoder;
29+
30+
public class SVGAnimatedRotateCenterTest extends ParametrizedRenderingAccuracyTest {
31+
private float viewCenter = 100;
32+
private float shapeCenter = 50;
33+
private float animDur = 4;
34+
35+
private float cx;
36+
private float cy;
37+
private float angle;
38+
39+
public SVGAnimatedRotateCenterTest() {
40+
super.setValidating(false);
41+
}
42+
43+
@Override
44+
public void setId(String id) {
45+
super.setId(id);
46+
47+
String[] split = parameter.split(",", 3);
48+
try {
49+
cx = Float.parseFloat(split[0]);
50+
cy = Float.parseFloat(split[1]);
51+
angle = Float.parseFloat(split[2]);
52+
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
53+
throw new IllegalArgumentException(id, e);
54+
}
55+
}
56+
57+
public void setViewCenter(float viewCenter) {
58+
this.viewCenter = viewCenter;
59+
}
60+
61+
public void setShapeCenter(float shapeCenter) {
62+
this.shapeCenter = shapeCenter;
63+
}
64+
65+
public void setAnimDur(float dur) {
66+
this.animDur = dur;
67+
}
68+
69+
@Override
70+
protected String buildRefImgURL(String svgDir, String svgFile) {
71+
String parameterSuffx = Pattern.quote(parameter + PNG_EXTENSION) + "$";
72+
// Use the same reference image for all cases
73+
return super.buildRefImgURL(svgDir, svgFile)
74+
.replaceFirst(parameterSuffx, PNG_EXTENSION);
75+
}
76+
77+
@Override
78+
protected Document manipulateSVGDocument(Document doc) {
79+
doc.getDocumentElement().setAttribute("shape-rendering", "crispEdges");
80+
81+
Element container = doc.getElementById("container");
82+
Element rect = getElement(container, "rect", 0);
83+
Element transform = getElement(rect, "animateTransform", 0);
84+
85+
container.setAttribute("transform", "translate("
86+
+ (viewCenter - cx) + " " + (viewCenter - cy) + ")");
87+
88+
rect.setAttribute("x", String.valueOf(cx - shapeCenter));
89+
rect.setAttribute("y", String.valueOf(cy - shapeCenter));
90+
91+
transform.setAttribute("from", "0 " + cx + " " + cy);
92+
transform.setAttribute("to", "360 " + cx + " " + cy);
93+
94+
return doc;
95+
}
96+
97+
private static Element getElement(Element container, String name, int index) {
98+
if (container == null) {
99+
throw new IllegalStateException("null container element");
100+
}
101+
NodeList elements = container.getElementsByTagName(name);
102+
if (index >= elements.getLength()) {
103+
throw new IllegalStateException("Could not find "
104+
+ name + "[" + index + "] inside" + container.getTagName());
105+
}
106+
return (Element) elements.item(index);
107+
}
108+
109+
@Override
110+
public ImageTranscoder getTestImageTranscoder() {
111+
ImageTranscoder transcoder = super.getTestImageTranscoder();
112+
float snapshotTime = angle * animDur / 360;
113+
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_SNAPSHOT_TIME, snapshotTime);
114+
return transcoder;
115+
}
116+
117+
}
Loading
Loading

test-resources/org/apache/batik/test/samplesRendering.xml

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@
143143
<testGroup id="tests.spec.coordinates">
144144
<test id="samples/tests/spec/coordinates/percentagesAndUnits.svg" />
145145
<test id="samples/tests/spec/coordinates/em.svg" />
146+
<test id="samples/tests/spec/coordinates/animRotateCenter.svg-0,50,180"
147+
class="org.apache.batik.test.svg.SVGAnimatedRotateCenterTest" />
148+
<test id="samples/tests/spec/coordinates/animRotateCenter.svg-50,50,270"
149+
class="org.apache.batik.test.svg.SVGAnimatedRotateCenterTest" />
150+
<test id="samples/tests/spec/coordinates/animRotateCenter.svg-50,50,90"
151+
class="org.apache.batik.test.svg.SVGAnimatedRotateCenterTest" />
146152
</testGroup>
147153

148154
<testGroup id="tests.spec.filters">

0 commit comments

Comments
 (0)