【发布时间】:2018-10-07 20:58:02
【问题描述】:
当我在 Linux 环境中运行相同的代码并尝试使用蜡染将 svg 转换为 png 时,文本的位置会发生偏移。
OSX 中的相同代码给出了正确的 png。似乎在 Linux 中所有文本元素的位置都在向右移动。
Linux:
OS X:
为什么 Linux 上的图片有问题?
代码如下:
TranscoderInput input = new TranscoderInput(svgPath);
// define OutputStream to PNG Image and attach to TranscoderOutput
OutputStream ostream = null;
File tempOutputFile = File.createTempFile(svgPath, ".png");
tempOutputFile.deleteOnExit();
try {
ostream = new FileOutputStream(tempOutputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
TranscoderOutput output = new TranscoderOutput(ostream);
// create a JPEG transcoder
PNGTranscoder t = new PNGTranscoder();
// set the transcoding hints
// convert and write output
t.transcode(input, output);
// flush and close the stream then exit
ostream.flush();
ostream.close();
return tempOutputFile;
SVG 文件:
<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<!-- Created with SVG-edit - https://github.com/SVG-Edit/svgedit-->
<title>Layer 1</title>
<rect display-height="NaN" display-width="NaN" display-y="125.5" display-x="65.25" rect-id="0" id="svg_1" height="194" width="316" y="115" x="129" stroke-width="0.5" stroke="#000000" fill="none"/>
<text alignment-baseline="text-before-edge" xml:space="preserve" text-anchor="start" font-family="serif" font-size="24" id="svg_2" y="125.5" x="65.25" stroke-width="0" stroke="#000000" fill="#000000">sssssss</text>
</svg>
【问题讨论】:
-
您需要为您的问题添加更多详细信息,截图..如何重现等。
-
SVG 文件中有什么?
-
我无法得到真正的原因。但很可能我正在考虑字体问题,因为在 mac 和 windows 系统中一切正常。你可以看到附件图片
-
嘿@SufiyanGhori 你也可以看到我附上了图片
标签: java linux svg mozilla batik