当使用canvg将Highchart SVG转换为PNG时,所有文本都出现两次 - 如何解决? [英] When using canvg to convert Highchart SVG into PNG, all text appears twice - how to solve?

查看:199
本文介绍了当使用canvg将Highchart SVG转换为PNG时,所有文本都出现两次 - 如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的(截断的)示例SVG图像(使用Highcharts制作, http://www.highcharts.com/ ) - 当我将它渲染到画布上时(使用canvg( https://github.com/gabelerner/ canvg 和代码改编自: https://stackoverflow.com/a/8997520/2067690 )所有生成的PNG中的文本是重复的,这意味着它的输出是双倍的,一个文本后面再次紧跟相同的文本。我怎样才能确保它只出现一次?

Here's my (truncated) example SVG image (made with Highcharts, http://www.highcharts.com/ ) - when I render that onto a canvas (with canvg (https://github.com/gabelerner/canvg and code adapted from here: https://stackoverflow.com/a/8997520/2067690) all text in the resulting PNG is duplicated, meaning that it's output double, one piece of text immediately followed by the same text once again. How can I ensure it appears once only?

<svg height="400" width="1170" version="1.1" xmlns="http://www.w3.org/1999/svg">
<text zIndex="8" text-anchor="end" style="font-family:&quot;Lucida Grande&quot;, &quot;Lucida Sans Unicode&quot;, Verdana, Arial, Helvetica, sans-serif;font-size:9px;cursor:pointer;color:#909090;fill:#909090;" y="22" x="220">
  <tspan x="220">Highcharts.com</tspan>
</text>
</svg>


推荐答案

在删除了我的示例SVG图像的部分内容后,找到错误消失的时候,我发现它是 tspan 标签 - 一旦我将它们遗漏,canvg将只按预期显示一次文本。

After much deleting parts of my example SVG image, to find when the error would go away, I found that it's the tspan tags - once I leave them out, canvg will display text only once as intended.

这篇关于当使用canvg将Highchart SVG转换为PNG时,所有文本都出现两次 - 如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆