Inkscape cli:选择所有填充特定颜色的文本对象并将其全部对齐到底部

问题描述 投票:0回答:1

我有一个 svg 文件,其中包含许多填充颜色

0070c0
的文本对象。它还包含其他对象。

我想通过 CLI 仅选择那些具有该填充的文本对象,然后将它们全部对齐到底部。

我尝试使用此命令选择那些,但无法使用

fill=#0070c0
参数进行选择

inkscape --actions="select-by-selector:text;select-invert;delete;export-plain-svg;export-filename:out.svg;export-do" input.svg
inkscape
1个回答
0
投票

目前,在 Inkscape 中,

select-by-selector
有一些限制(请参阅此处了解详细信息)。但是,您可以使用 Python 中的
lxml
模块或任何其他工具来获取具有特定填充颜色的文本元素的 ID。然后我们可以使用 Inkscape 操作来对齐文本元素。

  1. 以下Python脚本
    get_ids.py
    提取具有特定填充颜色的文本元素的ID:

get_ids.py

from lxml import etree

# Change the input filename
tree = etree.parse("input.svg")
namespaces = {'svg': 'http://www.w3.org/2000/svg'}

# Change the fill color
elements = tree.xpath("//svg:text[contains(@style, 'fill:#0000ff')]/@id", namespaces=namespaces)

print(','.join(elements))

确保您已安装 lxml:

python3 -m pip install lxml
  1. 使用 inkscape CLI 将文本元素与页面底部对齐:

在 bash 等类 Unix shell 中:

inkscape --actions="select-by-id:$(python3 get_ids.py); object-align: bottom  page;export-do" input.svg

在 Windows 上使用 Powershell(我还没有测试过,但它应该可以工作):

$id = python get_ids.py
inkscape --actions="select-by-id:$id;object-align:bottom page;export-do" input.svg

结果:

之前

之后

© www.soinside.com 2019 - 2024. All rights reserved.