我已经为此挣扎了一段时间,似乎在任何地方都找不到一个(有效的)答案。我有一个SVG文件,看起来像这样:

<svg

   xmlns:dc="http://purl.org/dc/elements/1.1/"
   ...
   width="72.9375"
   height="58.21875"
   ...>
   ...
   <g
     ...
     transform="translate(10.75,-308.96875)"
     style="...">
     <path
       inkscape:connector-curvature="0"
       d="m -10.254587,345.43597 c 0,-1.41732 0.17692,-2.85384 0.5312502,-3.5625 0.70866,-1.41733 2.14518,-2.82259 3.5625,-3.53125 1.41733,-0.70866 2.11392,-0.70867 3.53125,0 1.41732,0.70866 ... z"
       ... />
  </g>
</svg>

我想删除transform="…"行,但仍然有我的图像留在我已经放置它(在InkScape)。如果我手动删除转换,图像将压缩到屏幕的另一部分(正如预期的那样),但我需要完全删除转换,同时让图像保持在我想要的位置。是否有一种方法可以移除/平展转换到路径坐标本身?(我唯一需要处理的变换是平移和缩放,没有矩阵。)


当前回答

我在2004年通过了1.0的测试

虽然这个帖子很老了,但我还是想把我的经验/解决方案贴出来。我在尝试为FreeCAD的TechDrawing工作台创建模板时遇到了这个问题。这些模板不能包含任何转换。

在我的例子中,我必须从外部.svg文件中添加一个公司标志(完全由Inkscape制作)。该标志包含图形和文本元素。当将该标志复制到模板中时,会创建转换,这导致模板不能在FreeCAD中正确工作。

首先,这个解决方案建议在www.freecadweb.org/…对我没用。这就是为什么我在网上搜索并找到了这个讨论。 第二,上面建议的解决方案没有一个对我有效,但它们让我走上了正确的道路。Charlie的答案很接近,但是Object > Transform > Uncheck relative move > Apply没有显示出区别。

对我有用的是:

正如其他人所提到的,取消所有内容的分组。 将文本对象转换为路径-在我的情况下,这似乎是必不可少的! 删除xml-Editor中所有现有的转换,并观察相关对象的情况。在我的例子中,相应的元素改变了它们的位置。 手动纠正这些更改,但不要对任何内容进行分组。 另存为普通svg(普通=没有使用优化或其他特殊设置)

当我在FreeCAD中使用该模板时,工作很好。


一个奇怪的细节: 虽然我的解决方案暗示文本元素是我的问题所在,但它并不是那么容易。事实上,基本文档(我将徽标复制到其中的那个文档)包含大量文本元素,我没有转换它们中的任何一个。所以它可以是“外部源”和文本元素的组合。我发布这个细节只是给其他人一个提示,他们可能有相关的问题。

其他回答

This seems random, but nothing else I tried worked, so here you go random other person. Some of my paths had a sort of margin around them that could only be seen when selecting them (). I think this was created when I pasted a layer from another inkscape file and rotated it 90 deg. This made a pattern fill on the shapes have a different transform (lines spaced further apart). It also made align objects not work as expected. Using the Apply Transform mentioned by @Piotr_cz fixed the transform problem, but the strange margin remained. I accidentally got rid of it by changing the Blur on Stroke to any value and changing it back to zero.

我找到了问题所在。我希望不必求助于罗伯特的回答,尽管我很高兴确认它会起作用!Duopixel的答案实际上是最接近的,尽管事实证明还有其他原因。

When you're working with different paths in Inkscape documents, I believe its default behaviour is to group them together under an <svg:g.../> tag. When modifying paths in a group, Inkscape will automatically add a transform to the group to represent these changes. However, if you open the XML editor and drag your path outside the <svg:g.../> tag and make it its own <svg:path.../> tag, Inkscape is free to edit the individual points at will. In the end it did turn out to be a grouping problem even though I was only working with one path! Hope this helps others in similar situations.

SVGO是一个非常优秀的开源命令行工具,可以实现这一点和其他一些优化。它还有一个同样出色的在线web UI,叫做SVGOMG

本例中的相关选项是moveGroupAttrsToElems (SVGOMG:将组attrs移动到元素),将转换属性从组移动到路径元素,加上convertPathData (SVGOMG:舍入/重写路径),将转换平坦为d。

对于团队来说,重组可以很快完成任务。选择组,按Ctrl+Shift+G(去组),然后按Ctrl+G(组)。

对于一些有类似问题的对象,例如螺旋线和星形,快速的方法是按Ctrl+Alt+C(描边到路径)-然而,这将对象转换为纯路径,并删除所有额外的属性,如sodipodi:cx, sodipodi:revolutions等等。

发现:

Set your desired page size* If your current layer has a transform (check with the XML editor, it's the top group under the SVG element) then create a new layer and move all objects to it Ungroup any groups (this may not be needed, YMMV) Select all objects and apply a null transform (such as scale by 100% 100%, or arrow right + arrow left) while having Store transformation: Optimized in Preferences / Transforms If you had to undo any groups, you can now regroup them Save a copy as Optimized SVG and set your desired numeric precision

*:或者至少把对象放在你需要它们的地方,相对于页面的左上角。不幸的是,SVG坐标引用左上角,而Inkscape则根据左下角调整页面大小!