jakearchibald / svgomg

Web GUI for SVGO
https://jakearchibald.github.io/svgomg/
MIT License
5.76k stars 476 forks source link

remove transforms, apply transform="translate(...)" to x and y coordinates #428

Open milahu opened 11 months ago

milahu commented 11 months ago

input

<svg version="1.1" viewBox="0 0 33.951 42.07" xmlns="http://www.w3.org/2000/svg">
  <g transform="translate(-.5821)" font-family="sans-serif" font-size="3.5278px">
    <g transform="translate(-18.031 -47.378)" fill="none" stroke="#000" stroke-width=".26458px">
      <path d="m35.631 55.041 0 26.779"/>
      <path d="m28.936 75.125 13.389 0"/>
    </g>
    <text x="16.597956" y="5.1086421">2</text>
    <text x="16.81669" y="39.515091">1</text>
    <text x="3.0625346" y="29.008286">401</text>
    <text x="26.690271" y="29.008286">301</text>
  </g>
</svg>

actual output

the transform="translate(...)" is moved from <g> to child elements

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 34 42.1">
  <g font-family="sans-serif" font-size="3.5">
    <path fill="none" stroke="#000" stroke-width=".3" d="M17 7.7v26.7m-6.7-6.7h13.4"/>
    <text x="16.6" y="5.1" transform="translate(-.6)">2</text>
    <text x="16.8" y="39.5" transform="translate(-.6)">1</text>
    <text x="3.1" y="29" transform="translate(-.6)">401</text>
    <text x="26.7" y="29" transform="translate(-.6)">301</text>
  </g>
</svg>

expected diff

the transform="translate(...)" should be removed and the translate should be applied to the x and y coordinates

 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 34 42.1">
   <g font-family="sans-serif" font-size="3.5">
     <path fill="none" stroke="#000" stroke-width=".3" d="M17 7.7v26.7m-6.7-6.7h13.4"/>
-    <text x="16.6" y="5.1" transform="translate(-.6)">2</text>
+    <text x="16" y="5.1">2</text>
-    <text x="16.8" y="39.5" transform="translate(-.6)">1</text>
+    <text x="16.2" y="39.5">1</text>
-    <text x="3.1" y="29" transform="translate(-.6)">401</text>
+    <text x="2.5" y="29">401</text>
-    <text x="26.7" y="29" transform="translate(-.6)">301</text>
+    <text x="26.1" y="29">301</text>
   </g>
 </svg>

the option round/rewrite transforms is enabled

related: