【问题标题】:change svg:g id to inkscape:label将 svg:g id 更改为 inkscape:label
【发布时间】:2014-11-28 05:11:56
【问题描述】:

我在 Inkscape 中制作了一个矢量图形,包括图层和子图层,以便在 Processing 中进一步使用。我命名了 UI 中的所有层,并意识到最终的 SVG 只创建了一个具有该名称的 inkscape:label 属性,但 id 仍然是通用的:

<svg:g id="layer1" inkscape:label="My custom label">

我知道我可以在 XML 编辑器中手动编辑标签,但是否有设置自动使用图层名称作为 id?

【问题讨论】:

  • 这通常是不可能的。 id 属性对可以在其中使用的字符有限制。您不能只让人们为 id 值输入任何内容 - 而不必以某种方式对非法字符进行编码..

标签: svg inkscape


【解决方案1】:

我最近遇到了这个问题,因为我正在寻找相同的主题。事实证明,Inkscape (v0.92) 现在具有用于此目的的功能。

您可以在 Inkscape GUI 的 Object Properties 菜单中设置 IDsLabels,然后它们将应用于 XML 代码。

示例

Inkscape 图形用户界面

  • 绘制一个黄色矩形并选择它
  • 点击对象 -> 对象属性...
  • 在菜单中将 ID 设置为 yellow_rect 并将 Label 设置为 #yellow_rect
  • 通过点击Set应用更改
  • 要完成这个例子,重复上述步骤创建red_rect,设置标签和ID
  • 最终,对两个矩形进行分组,并为该组设置标识符。

XML 代码

当我打开 SVG 文件时,Inkscape 将我的标识符放入适当的 XML 标记中。

    <g
       id="rect_group">
      <rect
         rx="0.11797347"
         y="250.69791"
         x="5.0270834"
         height="18.785416"
         width="30.427082"
         id="yellow_rect1"
         style="fill:#f4ff00;fill-opacity:1;stroke:#000000;stroke-width:0.52916667;stroke-linejoin:round;stroke-miterlimit:3.79999995;stroke-dasharray:none;stroke-opacity:1" />
      <rect
         rx="0.11797347"
         y="258.89999"
         x="24.606249"
         height="16.933332"
         width="33.602081"
         id="red_rect1"
         style="fill:#f40000;fill-opacity:1;stroke:#000000;stroke-width:0.52916664;stroke-linejoin:round;stroke-miterlimit:3.79999995;stroke-dasharray:none;stroke-opacity:1" />
    </g>

【讨论】:

    【解决方案2】:

    当我为 Fritzing 创建 svg 时,我有同样的要求,因为 fritzing 不引用 inkscape:label。在这种情况下,我可以确保标签持有 id 的合法值。所以我制作了一个脚本来让自己摆脱肮脏和繁重的工作。

    请注意,脚本只能读取“纯 SVG” 格式。 https://gist.github.com/TerrenceSun/972ef4eea97f331af1e6abfcafb7c6e5

    【讨论】:

    • 我不是我需要的程序员,所以我恭请@terrencesun 更新此脚本,以便它可以处理 Inkscape SVG 文件。我有一个包含 82 层的文件,更改每一层都容易出错。我试图将我的文件保存为纯 SVG,但所有图层分组都丢失了。我的最终目标是通过命令行将每一层导出到一个单独的 PNG 文件中。如果您能帮助我,我将不胜感激!
    【解决方案3】:

    我不知道自动使用图层名称作为 id 的设置。但是为什么不反过来呢:如果你删除了inkscape:label 属性,那么在inkscape UI 中,图层名称会自动变成svg:gidinkscape:groupmode=layer 属性足以使svg:g 成为一个层元素。

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 2012-11-25
      • 2011-07-13
      • 2016-04-12
      • 2021-03-19
      相关资源
      最近更新 更多