Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
蜡染到SVG,设置缩放&;画布大小_Svg_Graphics2d_Vector Graphics_Batik - Fatal编程技术网

蜡染到SVG,设置缩放&;画布大小

蜡染到SVG,设置缩放&;画布大小,svg,graphics2d,vector-graphics,batik,Svg,Graphics2d,Vector Graphics,Batik,我们正在使用Batik,以便使用java Graphics2D(实际上是SVGGraphics2D)创建SVG文档。除了缩放/大小调整之外,所有这些都非常有效 我们希望使用EMU作为所有渲染的坐标。() 关键代码是: // set the userspace to scale to EMUs. All calls pass EMUs for coordinates and this maps it to the pixels. public static final int EPI = 9144

我们正在使用Batik,以便使用java Graphics2D(实际上是SVGGraphics2D)创建SVG文档。除了缩放/大小调整之外,所有这些都非常有效

我们希望使用EMU作为所有渲染的坐标。()

关键代码是:

// set the userspace to scale to EMUs. All calls pass EMUs for coordinates and this maps it to the pixels.
public static final int EPI = 914400;
int dpi = getDPI(); // returns 600
AffineTransform scaleToEmus = AffineTransform.getScaleInstance(dpi / (float) EPI, dpi / (float) EPI);
graphics.transform(scaleToEmus);

// size (extent) of the SVG object.
svgGraphics.setSVGCanvasSize(new Dimension(width, height));
这导致了几个问题。这最终会在
元素上设置宽度和高度属性

<svg width="1466850" height="1200150" …
然而,这并不是在所有情况下都有效。例如,如果DPI=600,宽度=1466850(emu),则scaleX变为6.561679765582085E-4,缩放宽度变为963。但是svg将包含矩阵(0.0007,…),这将导致图形不适合画布。这是一个生成矩阵元素的人,他将值舍入为6.561679765582085E-4=>0.0007

一个解决方案是找出取整算法并使用它来缩放画布大小。但我不喜欢通过调整数字来查看哪些数据通过了我的特定用例

解决这个问题的建议方法是什么

更新:答案可能是通过定义viewBox进行缩放吗

<g transform="matrix(0.0007,0,0,0.0007,0,0)" …
svgGraphics.setSVGCanvasSize(new Dimension((int)Math.ceil(width * graphics.getTransform().getScaleX()), (int)Math.ceil(height * graphics.getTransform().getScaleY())));