*/
private void transform(Sprite sprite) {
double deltaDegrees = 0;
double deltaScaleX = 1;
double deltaScaleY = 1;
Matrix matrix = new Matrix();
Rotation rotation = sprite.getRotation();
Scaling scaling = sprite.getScaling();
Translation translation = sprite.getTranslation();
XElement element = getElement(sprite);
Style style = element.getStyle();
Element skew = element.getPropertyJSO("skew").cast();
if (rotation != null) {
matrix.rotate(rotation.getDegrees(), rotation.getX(), rotation.getY());
deltaDegrees += rotation.getDegrees();
}
if (scaling != null) {
matrix.scale(scaling.getX(), scaling.getY(), scaling.getCenterX(), scaling.getCenterY());
deltaScaleX *= scaling.getX();
deltaScaleY *= scaling.getY();
}
if (translation != null) {
matrix.translate(translation.getX(), translation.getY());
}
if (viewBoxShift != null) {
matrix.scale(viewBoxShift.getX(), viewBoxShift.getY(), -1, -1);
matrix.add(1, 0, 0, 1, viewBoxShift.getCenterX(), viewBoxShift.getCenterY());
}
if (!(sprite instanceof ImageSprite) && skew != null) {
// matrix transform via VML skew
skew.setPropertyString(
"matrix",
new StringBuilder().append(toFixed(matrix.get(0, 0), 4)).append(", ").append(toFixed(matrix.get(0, 1), 4)).append(
", ").append(toFixed(matrix.get(1, 0), 4)).append(", ").append(toFixed(matrix.get(1, 1), 4)).append(
", 0, 0").toString());
skew.setPropertyString(
"offset",
new StringBuilder().append(toFixed(matrix.get(0, 2), 4)).append(", ").append(toFixed(matrix.get(1, 2), 4)).toString());
} else {
double deltaX = matrix.get(0, 2);
double deltaY = matrix.get(1, 2);
// Scale via coordsize property
double zoomScaleX = zoom / deltaScaleX;
double zoomScaleY = zoom / deltaScaleY;
element.setPropertyString("coordsize", Math.abs(zoomScaleX) + " " + Math.abs(zoomScaleY));
// Rotate via rotation property
double newAngle = deltaDegrees * (deltaScaleX * ((deltaScaleY < 0) ? -1 : 1));
if ((style.getProperty("rotation") == null && newAngle != 0)) {
style.setProperty("rotation", String.valueOf(newAngle));
} else if (style.getProperty("rotation") != null && newAngle != Double.valueOf(style.getProperty("rotation"))) {
style.setProperty("rotation", String.valueOf(newAngle));
}
if (deltaDegrees != 0) {
// Compensate x/y position due to rotation
Matrix compMatrix = new Matrix();
compMatrix.rotate(-deltaDegrees, deltaX, deltaY);
deltaX = deltaX * compMatrix.get(0, 0) + deltaY * compMatrix.get(0, 1) + compMatrix.get(0, 2);
deltaY = deltaX * compMatrix.get(1, 0) + deltaY * compMatrix.get(1, 1) + compMatrix.get(1, 2);
}
String flip = "";
// Handle negative scaling via flipping
if (deltaScaleX < 0) {