拉斐尔 svg 导入尺寸
我已经从 Illustrator 图像创建了 SVG 文件。我正在使用这个: https://github.com/wout/raphael-svg-import 导入并显示矢量图像。
我以文本形式读取 svg 文件,并将其提交给导入功能:
var mygetrequest = new XMLHttpRequest();
var svgdata = mygetrequest.responseText;
paper.importSVG(svgdata); //where paper is my Raphael canvas
一切都运行良好。
但我似乎找不到任何有关如何更改图像设置和视图的信息或提示? 例如,我非常希望它填满它的容器,而不管它的大小。
有什么想法吗?一路上为我提供帮助的文档?任何事情,真的...
I've created and SVG-file from an Illustrator-image. I'm using this: https://github.com/wout/raphael-svg-import to import and display the vector-image.
I read the svg-file in as text, and submit it to the import-function:
var mygetrequest = new XMLHttpRequest();
var svgdata = mygetrequest.responseText;
paper.importSVG(svgdata); //where paper is my Raphael canvas
All working very nicely.
But I can't seem to find any info or hints on how to change the settings and view of the image?
For example I would very much like it to fill out its container, disregarding the size of this.
Any ideas? Documentation to help me along the way? Anything, really...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以为您提供两个想法:
1)也许 SVG 导入会考虑原始大小并为您进行缩放。然而,在 illustrator 中编辑时,您可能周围有一个更大的文档,这会让 svgImport 感到困惑?
2) 否则,您可以将论文作为一组导入。并缩放集合。
(如果没有示例,我不确定 centerx 和 centery 应该是什么)。
[编辑(批准后)]
看来 Raphael 使您能够获取集合的边界框:
所以我想说您可以:
set.translate
将边界框的中心与纸张的中心对齐(例如,使用( paperwidth / 2 ) - ( bbox.x + bbox.width / 2 )
进行 x 翻译)。1
的那个(paper.width/bbox.width 和 paper.height/bbox.height )。
我是从头顶做的,所以它可能不是 100% 准确,但如果你知道你可能能够消除这些故障。
There's two ideas I can offer you:
1) maybe the SVG import takes into account the original size and does scaling for you. However when editing in illustrator you might have a much bigger document around it, which confuses the svgImport?
2) Otherwise, you could import the paper as a set. And scale the set.
(I'm not sure without an example to play with, what centerx and centery should be).
[EDIT (after approval)]
It seems Raphael enables you to get a set's bounding box:
So I'd say you could:
set.translate
to align the bounding box's center with the center of the paper (use something like( paperwidth / 2 ) - ( bbox.x + bbox.width / 2 )
for example for the x translation).1
(ofpaper.width/bbox.width
andpaper.height/bbox.height
).I did this from the top of my head so it might not be 100% accurate, but if you get the idea you'll probably be able to get rid of the glitches.
我有类似的问题。我所做的是在 Inkscape (SVG 编辑器程序)中打开 SVG,更改大小直到可以......但是可能有更好的方法!
I had a similar problem. What I did was open the SVG in Inkscape (SVG editor program), change the size until it was OK... but there is probably a better way!
我遇到了与原始海报完全相同的问题。我也在做着和他一样的事情。即使在阅读 Jochem 的解决方案/想法后,我也遇到了几天无法解决的问题。
我的具体问题是,在 Internet Explorer(所有版本)中,图像不断呈现超出范围,特别是将其自身与包含的 div 的右下角对齐。
在花了这么多时间在这个问题上之后,我的高级开发人员得出结论,这个插件有缺陷并且无法使用。
到目前为止,我还没有找到满足我的特定要求的替代解决方案(由于公司政策,我们不能使用 Flash)。对于那些没有这种限制的人,我推荐 Google 的 SVGWeb
虽然这不是OP问题的答案,我的发现可能会为将来可能遇到此问题的人节省一些时间。
I had exactly the same problem as the original poster. I was doing the same thing that he did. I came across problems that I was not able to solve for days even after I read the solution/ideas from Jochem.
My specific problem was that in Internet Explorer (all versions), the image kept rendering out of bounds, specifically aligning itself to the bottom right hand corner of the containing div.
After spending so much time on this issue, my senior developer concluded that this plugin is flawed and is unusable.
So far, I have not been able to find a alternative solution that meets my specific requirements (we cannot use Flash because of company policies). For those without that constrain, I recommend Google's SVGWeb
Although this is not a answer to the OP's question, my findings may save some time for someone who might come across this issue in the future.