【问题标题】:How to keep line feed in svg file (Inkscape)?如何在 svg 文件(Inkscape)中保留换行符?
【发布时间】:2018-01-09 09:40:03
【问题描述】:

我用 Incskape 创建了一个 svg 文件。 它包含一个像这样的文本元素:

<text
  [..]><tspan
  [..]
    style="font-style:normal;fill:#c913ff;fill-opacity:1">My Text</tspan></text>

我想使用 git 来跟踪我的更改。 由于 git 使用整行来查找更改,因此我使用文本编辑器编辑 svg 文件以将样式属性与文本本身分开。

<text
  [..]><tspan
  [..]
    style="font-style:normal;fill:#c913ff;fill-opacity:1">
My Text
</tspan></text>

这样我可以在不影响其他提交的情况下更改不同提交中的样式和文本。

不幸的是,Inkscape 在每次保存时都会重写 svg 文件,并且文本会与样式回到同一行。 :(

有没有办法阻止 Inkscape 这样做?

我知道可能有一种解决方法,方法是为样式使用某种变量并更改文件另一部分中的变量值。 但我不想那样做。

【问题讨论】:

  • 我从德国翻译过来的。所以normal SVG 在英语中可能是plain SVG

标签: xml git svg inkscape


【解决方案1】:

以下解决方法对我有用。

当我将文件保存为 normal SVG 而不是 Inkscape SVG 时,文件的格式是我想要的。

<text
   transform="scale(0.97808647,1.0224045)"
   id="text3779"
   y="396.1929"
   x="159.78862"
   style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;line-height:0%;font-family:Corbel;-inkscape-font-specification:'Corbel Bold';letter-spacing:0px;word-spacing:0px;fill:#ff9715;fill-opacity:1;stroke:none"
   xml:space="preserve"><tspan
     style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:124.21698761px;line-height:1.25;font-family:Corbel;-inkscape-font-specification:'Corbel Bold';fill:#ff9715;fill-opacity:1"
     y="396.1929"
     x="159.78862"
     id="tspan3781">My Text</tspan></text>

但是,这只是一种解决方法,因为 Inkscape-SVG 可能比普通 SVG 有一些优势。

【讨论】:

    【解决方案2】:

    您可以为 Git 编写一个 clean 过滤器,以便您的 svg 文件在暂存前缩进。您可以在您的 .gitattributes 文件中添加这样的内容(如果您还没有,请在您的存储库根目录中创建它):

    *.svg filter=indent
    

    然后调整你的 git 配置以告诉 git 过滤器的作用。假设您在此处安装了indent

    git config filter.indent.clean indent
    git config filter.indent.smudge cat
    

    这将在暂存它们之前通过一个名为“indent”的程序运行所有 svg 文件,因此它们在你的 repo 中的格式似乎很好,并且日志看起来会更好。签出文件时,它们通过cat 运行,不会修改文件。

    【讨论】:

    • 听起来是一个非常好的解决方法。有时间我会看看的。
    猜你喜欢
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    相关资源
    最近更新 更多