Batik JSVGCanvas 中的 SVG 图像在旋转和设置边界框后按比例缩小

SVG image within a Batik JSVGCanvas is scaled down after rotation and setting bounding box

我在 JSVGCanvas 内旋转有问题。
用户可以将 SVG 图像加载到文档页面 (JLayeredPane)。
每张图片都显示在自己的 JSVGCanvas 中,并且有自己的 class.
用户可以通过拖动端点来调整图像大小,也可以四处移动图像。

旋转完美 (Basic and rotated situation)
只有 Canvas 的边界框的后续更改导致缩放,不再对应于原始大小 (Finally after setting Boundingbox)

UpdateManager() 中的代码片段:

....
// calculating new canvas bounding box
AffineTransform at = AffineTransform.getRotateInstance(rotation*Math.PI/180.0,
                              originalX + originalW/2.0,
                              originalY + originalH/2.0);
Rectangle2D.Double rect = new Rectangle2D.Double(originalX, originalY, originalW, originalH);
Shape s = at.createTransformedShape(rect);
xx = s.getBounds2D().getX();
yy = s.getBounds2D().getY();
ww = s.getBounds2D().getWidth();
hh = s.getBounds2D().getHeight();
canvas.setRenderingTransform(AffineTransform.getRotateInstance(rotation*Math.PI/180.0,
                              originalW/2.0, originalH/2.0));
// this.setBounds() will do the stuff and also change the Canvas Bounds
setBounds(xx, yy, ww, hh);
....

非常感谢您的帮助。

已解决...
我找到了解决这个问题的方法:

....  
// calculating new canvas bounding box
AffineTransform at = AffineTransform.getRotateInstance(rotation*Math.PI/180.0,
                          originalX + originalW/2.0,
                          originalY + originalH/2.0);
Rectangle2D.Double rect = new Rectangle2D.Double(originalX, originalY, originalW, originalH);
Shape s = at.createTransformedShape(rect);
xx = s.getBounds2D().getX();
yy = s.getBounds2D().getY();
ww = s.getBounds2D().getWidth();
hh = s.getBounds2D().getHeight();
double rotScale = originalW/ww;
double diffX = (originalW * rotScale - originalW) / 2.0 * -1.0;
double diffY = (originalH * rotScale - originalH) / 2.0 * -1.0;
AffineTransform af = AffineTransform.getScaleInstance(rotScale, rotScale);
af.preConcatenate(AffineTransform.getTranslateInstance(diffX, diffY));
af.preConcatenate(AffineTransform.getRotateInstance(rotation*Math.PI/180.0, originalW/2.0, originalH/2.0));
canvas.setRenderingTransform(af);
// this.setBounds() will do the stuff and also change the Canvas Bounds
setBounds(xx, yy, ww, hh);
....

也许这会对遇到同样问题的其他人有所帮助。 Picture solved