0

我正在使用 Python 的 svgwrite 库生成这个键盘 SVG。

没有考虑文本大小和文本位置。不考虑相对于字母组的 x 和 y 位置。绝对的字体大小在inkscape中显示得更大。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="297mm" version="1.1" viewBox="0 0 210 297" width="210mm">
  <defs/>
  <g id="kbgroup" transform="translate(10,10)">
    <g id="Q" transform="translate(0,0)">
      <rect fill="black" height="15.0" id="box-Q" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">Q</text>
    </g>
    <g id="W" transform="translate(19,0)">
      <rect fill="black" height="15.0" id="box-W" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">W</text>
    </g>
    <g id="E" transform="translate(38,0)">
      <rect fill="black" height="15.0" id="box-E" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">E</text>
    </g>
    <g id="R" transform="translate(57,0)">
      <rect fill="black" height="15.0" id="box-R" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">R</text>
    </g>
    <g id="T" transform="translate(76,0)">
      <rect fill="black" height="15.0" id="box-T" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">T</text>
    </g>
    <g id="Y" transform="translate(95,0)">
      <rect fill="black" height="15.0" id="box-Y" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:4px; font-family:Bitstream Vera Sans; fill:white" x="2.0" y="5.0">Y</text>
    </g>
  </g>
</svg>

我希望文本大小是以 px 表示的大小。文本相对于组的插入位置必须以无单位表示,因此以 mm 为单位,因为这是使用 viewbox 设置的默认单位。

4

1 回答 1

0

它的效果并不明显。SVG 节点的heightwidth值正在整体缩放绘图。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="297mm" version="1.1" viewBox="0 0 210 297" width="210mm">

观察当你增加和减少font-size每个字母时会发生什么,然后是svg节点的高度和宽度(这里是一个演示

虽然我确定您在这里寻找的布局是您正在构建的 SVG 的修改版本(不mm作为svg节点大小的单位)并且居中的字体稍大):(演示

<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="297" version="1.1" viewBox="0 0 210 297" width="210">
  <defs/>
  <g id="kbgroup" transform="translate(10,10)">
    <g id="Q" transform="translate(0,0)">
      <rect fill="black" height="15.0" id="box-Q" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">Q</text>
    </g>
    <g id="W" transform="translate(19,0)">
      <rect fill="black" height="15.0" id="box-W" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">W</text>
    </g>
    <g id="E" transform="translate(38,0)">
      <rect fill="black" height="15.0" id="box-E" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">E</text>
    </g>
    <g id="R" transform="translate(57,0)">
      <rect fill="black" height="15.0" id="box-R" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">R</text>
    </g>
    <g id="T" transform="translate(76,0)">
      <rect fill="black" height="15.0" id="box-T" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">T</text>
    </g>
    <g id="Y" transform="translate(95,0)">
      <rect fill="black" height="15.0" id="box-Y" stroke="none" stroke-width="0.5" width="12.5" x="0" y="0"/>
      <text style="text-anchor:end;text-align:start;writing-mode:ltr;     font-size:8px; font-family:Bitstream Vera Sans; fill:white" y="10" x="9">Y</text>
    </g>
  </g>
</svg>
于 2013-07-15T22:20:55.737 回答