适用于 Linux 的优秀 SVG 渲染器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11198340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:02:48  来源:igfitidea点击:

Good SVG renderer for Linux?

linuxsvg

提问by rubenafo

I'm developing some scripts to generate SVG files and I wonder what good SVG renderers exist for Linux. I know Firefox/Chrome provide SVG support (and I have the feeling that Chrome is faster at rendering) but maybe there are other standalone SVG renderers that I'm missing. I'm aware of pySVG's existence.

我正在开发一些脚本来生成 SVG 文件,我想知道 Linux 有哪些好的 SVG 渲染器。我知道 Firefox/Chrome 提供 SVG 支持(我觉得 Chrome 渲染速度更快)但也许我缺少其他独立的 SVG 渲染器。我知道 pySVG 的存在。

By good enough I mean to cover the SVG 1.1 specification as much as possible. The reason I prefer a standalone library is that my workflow is faster, as I don't have to press F5 every time.

足够好我的意思是尽可能多地涵盖 SVG 1.1 规范。我更喜欢独立库的原因是我的工作流程更快,因为我不必每次都按 F5。

采纳答案by Tom Goodfellow

The SVG 1.1 exported by the draw.io tool is too "modern" for correct rendering by the current Batik, Cairo, qiv, or even FireFox: it seems none of them support the <foreignObject> element. However WebKit does render it properly, so to convert SVG to high-quality images I use the "wkhtmlto..." tools from http://wkhtmltopdf.org.

draw.io 工具导出的 SVG 1.1 对于当前 Batik、Cairo、qiv 甚至 FireFox 的正确渲染来说过于“现代”:似乎它们都不支持 <foreignObject> 元素。然而,WebKit 确实可以正确呈现它,因此要将 SVG 转换为高质量图像,我使用来自http://wkhtmltopdf.org的“wkhtmlto...”工具。

wkhtmltoimagegenerates output at screen resolution and its --zoomswitch scaled lines and text differently resulting in clipping (although opening the same SVG in Chrome and zooming performed correctly). So instead I'm using wkhtmltopdfto generate an intermediate pdf then rendering that as a high-resolution image with ghostscript:

wkhtmltoimage以屏幕分辨率生成输出,其--zoom开关缩放线条和文本会导致剪切(尽管在 Chrome 中打开相同的 SVG 并正确执行缩放)。因此,相反,我使用wkhtmltopdf生成一个中间 pdf,然后使用 ghostscript 将其渲染为高分辨率图像:

wkhtmltopdf callbacks.svg callbacks.pdf
gs -sDEVICE=pnggray -sOutputFile=callbacks.png -dBATCH -dNOPAUSE -r900 callbacks.pdf

EDIT: a disadvantage of going via a Page Description Format is that the image file produced may have very large borders. You can experiment with paper sizes and layouts to minimise this or just auto-crop them off, e.g. with ImageMagick:

编辑:通过页面描述格式的缺点是生成的图像文件可能具有非常大的边框。您可以尝试使用纸张大小和布局来最小化这种情况,或者只是自动裁剪它们,例如使用 ImageMagick:

convert callbacks.png -trim callbacks.png

EDIT: FireFox 49.0.2 (Nov 2016) now renders the draw.io SVG correctly. Haven't retested Cairo or Batik. sample draw.io file

编辑:FireFox 49.0.2(2016 年 11 月)现在可以正确呈现 draw.io SVG。没有重新测试开罗或蜡染。示例 draw.io 文件

回答by Sergiu Dumitriu

Apache Batikis a very good collection of libraries/programs with support for a very large part of the SVG specification. It includes a stand-alone viewer/editor, and a command line rasterizer that can convert SVGs to raster image formats.

Apache Batik是一个非常好的库/程序集合,支持 SVG 规范的很大一部分。它包括一个独立的查看器/编辑器,以及一个可以将 SVG 转换为光栅图像格式的命令行光栅化器。

回答by CapelliC

Qt SVG it's just 2 clicks away, if you install Qt 4.7 and select the locally installed sample project svgviewer. Just build and run to get an animated viewport:

Qt SVG 如果您安装 Qt 4.7 并选择本地安装的示例项目svgviewer,只需点击 2 次即可。只需构建并运行即可获得动画视口:

enter image description here

在此处输入图片说明

回答by jbeard4

I recommend WebkitGtk. This is the renderer that is used to power Safari, Chrome, and a number of other browsers. It supports rendering SVG as well as HTML.

我推荐 WebkitGtk。这是用于支持 Safari、Chrome 和许多其他浏览器的渲染器。它支持渲染 SVG 和 HTML。

Just apt-get install libwebkitgt-3.0-0. You can try it out by running /usr/lib/webkitgtk-3.0-0/libexec/GtkLauncher.

只是apt-get install libwebkitgt-3.0-0。您可以通过运行来尝试一下/usr/lib/webkitgtk-3.0-0/libexec/GtkLauncher

You can then use whatever language/bindings you like to build a GUI around the SVG renderer, including Python's Gtk bindings: http://www.aclevername.com/articles/python-webgui/

然后,您可以使用您喜欢的任何语言/绑定围绕 SVG 渲染器构建 GUI,包括 Python 的 Gtk 绑定:http: //www.aclevername.com/articles/python-webgui/

Here's another good article about building desktop UIs using Webkit and pygtk bindings: http://arstechnica.com/information-technology/2009/07/how-to-build-a-desktop-wysiwyg-editor-with-webkit-and-html-5/

这是另一篇关于使用 Webkit 和 pygtk 绑定构建桌面 UI 的好文章:http: //arstechnica.com/information-technology/2009/07/how-to-build-a-desktop-wysiwyg-editor-with-webkit-and- html-5/

回答by renick

You can try the command-line app qivwith the -m -Tflags.

您可以尝试qiv带有-m -T标志的命令行应用程序。