【问题标题】:Merging two SVG Paths: Open Bezier and Line合并两个 SVG 路径:Open Bezier 和 Line
【发布时间】:2021-05-29 13:23:45
【问题描述】:

我的问题的合并部分在这里得到了很好的回答:https://stackoverflow.com/a/49051988/4272389 解决了两个 LineGradients 一个线节点和另一个路径节点。

在我的情况下,我有一个 Open Bezier 路径和一个 Line 路径,但不确定 LineGradient 的答案是否仍然适用

<g class="com.sun.star.drawing.OpenBezierShape">
 <g id="id5">
  <rect class="BoundingBox" stroke="none" fill="none" x="7699" y="4699" width="303" height="203"/>
  <path fill="none" stroke="rgb(52,101,164)" d="M 7700,4900 C 7816,4847 7964,4842 8000,4700"/>
 </g>
</g>
<g class="com.sun.star.drawing.LineShape">
 <g id="id6">
  <rect class="BoundingBox" stroke="none" fill="none" x="8799" y="6099" width="30" height="3"/>
  <path fill="none" stroke="rgb(52,101,164)" d="M 8800,6100 L 8827,6100"/>
 </g>
</g>

使用先前答案 (https://svgwg.org/svg2-draft/coords.html#ComputingAViewportsTransform) 中建议的视图框变换过程,合并是否需要扩展边界框,然后使用 id5 的原点,然后将 id6 坐标转换为展开框内的相对值,我称之为“合并“?: 我的算术表达式是伪代码来表示我的变换公式)

<g id="merged">
  <rect class="BoundingBox" stroke="none" fill="none" x="8799" y="6099" width="300+(8799-7699)+30" height="203+(6100-4699)+3"/>
  <path fill="none" stroke="rgb(52,101,164)" d="M 7700,4900 C 7816,4847 7964,4842 8000,4700 m [(8799-7699) + (8800-8799), (6099-4699) + (6100-6099)] l (8827-8799),(6100-6099)"/>
</g>

原因:片段是用 LibreOffice draw 绘制的,路径是用 Inkscape 连接的,但我不能完全这样做,所以我必须手动关闭最终 Inkscape 结果中的路径。

【问题讨论】:

    标签: svg inkscape libreoffice-draw


    【解决方案1】:

    路径可以有多个子路径。所以大多数时候,你可以把它们附加在一起,像这样:

    d="M 7700,4900 C 7816,4847 7964,4842 8000,4700 M 8800,6100 L 8827,6100"/>
    

    您唯一需要注意的是第二个路径中的移动命令是否是小写的m。在单个路径中,以m(相对移动)开头是错误的,它被解释为M(绝对移动)。但是,如果将其附加到另一个路径,则小写的 m 将是有效的。因此,您需要在追加时将m 更改为M

    至于边界框,你只需要做一个“并集”操作即可。换句话说,找到两个矩形的最小和最大 X 和 Y 坐标。

    Box 1: minX="7699" minY="4699" maxX="7699 + 303 = 8002" maxY="4699 + 203 = 4902"
    Box 2: minX="8799" minY="6099" maxX="8799 + 30 = 8829" maxY="6099 + 3 = 6102"
    
    Union: minX="7699" minY="4699" maxX="8829" maxY="6102"
    Box:   x="7699" y="4699" width="1130" height="1403"
    

    所以合并后的路径应该是:

    <g id="merged">
      <rect class="BoundingBox" stroke="none" fill="none" x="7699" y="4699" width="1130" height="1403"/>
      <path fill="none" stroke="rgb(52,101,164)" d="M 7700,4900 C 7816,4847 7964,4842 8000,4700 M 8800,6100 L 8827,6100"/>
    </g>
    

    【讨论】:

    • 非常感谢。我担心当边界框的大小发生变化时,贝塞尔曲线坐标也可能需要缩放。也许在另一种情况下,当曲线出现在线元素之后,然后需要曲线的相对值? (但我发现反转绘图的方向,向下的图形 Y 坐标是怪物中最糟糕的)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多