Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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
Java Linux和OSX在使用Batik-to-SVG将SVG转换为PNG时的文本差异_Java_Linux_Svg_Mozilla_Batik - Fatal编程技术网

Java Linux和OSX在使用Batik-to-SVG将SVG转换为PNG时的文本差异

Java Linux和OSX在使用Batik-to-SVG将SVG转换为PNG时的文本差异,java,linux,svg,mozilla,batik,Java,Linux,Svg,Mozilla,Batik,当我在Linux环境中运行相同的代码并尝试使用蜡染将svg转换为png时,文本的位置会发生变化 OSX中的相同代码给出了正确的png。在Linux中,所有文本元素的位置似乎都在右移 Linux: OSX: 为什么Linux上的映像错误 代码如下: TranscoderInput input = new TranscoderInput(svgPath); // define OutputStream to PNG Image and attach to TranscoderOutput Ou

当我在Linux环境中运行相同的代码并尝试使用蜡染将svg转换为png时,文本的位置会发生变化

OSX中的相同代码给出了正确的png。在Linux中,所有文本元素的位置似乎都在右移

Linux

OSX

为什么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文件


第一层
SSSSS

首先,我不确定你想要达到什么样的结果。这两个截图和问题中嵌入的片段都显示了不同的内容。您是否试图使文本的结尾与矩形的左侧重合

这里有几个潜在的问题:

  • 并非所有环境中都使用相同的字体。你可以从截图中看出这一点。“sans serif”在不同的操作系统中不一定是相同的字体。尤其是如果两个屏幕上没有安装完全相同的字体

  • 即使使用完全相同的字体、不同的字体呈现引擎,文本呈现也会略有不同。你不一定会得到像素完美的定位

  • 我可能错了,但我怀疑Batik可能不支持对齐基线。因此,这将影响您的文本定位

  • 如果希望一段文本的结尾与某个点完全重合,则使用
    text-anchor=“end”
    使文本右对齐。见下文

  • 
    精确角
    
    您需要在问题、屏幕截图中添加更多细节。如何复制等。SVG文件中有什么?我无法了解实际原因。但最有可能的是,我在考虑字体问题,因为在mac和Windows系统中,所有的东西都工作得很好。您可以看到附加的图像Hey@SufiyanGhori您也可以看到我附加的图像。这确实表明不支持对齐基线。感谢您的检查。