svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
20.98k stars 1.39k forks source link

--pretty print ignores xml:space="preserve" #1029

Closed JoKalliauer closed 3 years ago

JoKalliauer commented 6 years ago

Prozessing File:Anatomy_of_Human_Ear_with_Cochlear_Frequency_Mapping.svg adds to wrong spaces because of option pretty

svgo -i Bug1028_Input.svg.txt -o Bug1028_Output.svg.txt --pretty --indent=1 --disable=removeUnknownsAndDefaults

This issue might be related to #878 and #1001

Input

Bug1028_Input.svg.txt

<?xml version="1.0" encoding="UTF-8"?>
<svg width="674.23" height="518.84" font-size="20" xmlns="http://www.w3.org/2000/svg">
 <g font-family="DejaVu Sans">
  <text x="324.34" y="145.05" xml:space="preserve">Incus</text>
  <text x="221.74" y="162.22" xml:space="preserve">Malleus</text>
  <text x="585.99" y="44.5" text-anchor="end" xml:space="preserve">Semicircular<tspan x="585.99" y="64.5">Canals</tspan></text>
  <text x="529.44" y="100.43" xml:space="preserve">Vestibular<tspan x="529.44" y="120.43">Nerve</tspan></text>
  <text x="552.77" y="316.31" xml:space="preserve">Cochlear<tspan x="552.77" y="336.31">Nerve</tspan></text>
  <text x="473.44" y="478.41" xml:space="preserve">Eustachian Tube</text>
  <g text-anchor="middle">
   <text x="256.58" y="473.16" xml:space="preserve">Tympanic<tspan x="256.58" y="493.16">Membrane</tspan></text>
   <text x="205.55" y="400.94" xml:space="preserve">External<tspan x="205.55" y="420.94">Auditory Canal</tspan></text>
   <text x="380.3" y="45.09" xml:space="preserve">Stapes<tspan x="383.48" y="65.09">(attached to</tspan><tspan x="380.3" y="85.09">oval window)</tspan></text>
  </g>
  <text x="551.55" y="392.43" xml:space="preserve">Cochlea</text>
  <text x="410.58" y="471.95" text-anchor="middle" xml:space="preserve">Round<tspan x="410.58" y="491.95">Window</tspan></text>
  <text transform="rotate(-90)" x="-495.1" y="35.53" xml:space="preserve">Auricle</text>
  <text x="317.11" y="408.92" xml:space="preserve">Tympanic<tspan x="317.11" y="428.92">Cavity</tspan></text>
  <g fill="#c00">
   <text x="534.94" y="361.07" xml:space="preserve">16 kHz</text>
   <text x="535.58" y="218.26" xml:space="preserve">6 kHz</text>
   <text x="512.12" y="162.52" xml:space="preserve">0.5 kHz</text>
  </g>
 </g>
</svg>

bug1028_input

Output

<svg width="674.23" height="518.84" font-size="20" xmlns="http://www.w3.org/2000/svg">
 <g font-family="DejaVu Sans">
  <text x="324.34" y="145.05" xml:space="preserve">
   Incus
  </text>
  <text x="221.74" y="162.22" xml:space="preserve">
   Malleus
  </text>
  <text x="585.99" y="44.5" text-anchor="end" xml:space="preserve">
   Semicircular<tspan x="585.99" y="64.5">Canals</tspan>
  </text>
  <text x="529.44" y="100.43" xml:space="preserve">
   Vestibular<tspan x="529.44" y="120.43">Nerve</tspan>
  </text>
  <text x="552.77" y="316.31" xml:space="preserve">
   Cochlear<tspan x="552.77" y="336.31">Nerve</tspan>
  </text>
  <text x="473.44" y="478.41" xml:space="preserve">
   Eustachian Tube
  </text>
  <g text-anchor="middle">
   <text x="256.58" y="473.16" xml:space="preserve">
    Tympanic<tspan x="256.58" y="493.16">Membrane</tspan>
   </text>
   <text x="205.55" y="400.94" xml:space="preserve">
    External<tspan x="205.55" y="420.94">Auditory Canal</tspan>
   </text>
   <text x="380.3" y="45.09" xml:space="preserve">
    Stapes<tspan x="383.48" y="65.09">(attached to</tspan><tspan x="380.3" y="85.09">oval window)</tspan>
   </text>
  </g>
  <text x="551.55" y="392.43" xml:space="preserve">
   Cochlea
  </text>
  <text x="410.58" y="471.95" text-anchor="middle" xml:space="preserve">
   Round<tspan x="410.58" y="491.95">Window</tspan>
  </text>
  <text transform="rotate(-90)" x="-495.1" y="35.53" xml:space="preserve">
   Auricle
  </text>
  <text x="317.11" y="408.92" xml:space="preserve">
   Tympanic<tspan x="317.11" y="428.92">Cavity</tspan>
  </text>
  <g fill="#c00">
   <text x="534.94" y="361.07" xml:space="preserve">
    16 kHz
   </text>
   <text x="535.58" y="218.26" xml:space="preserve">
    6 kHz
   </text>
   <text x="512.12" y="162.52" xml:space="preserve">
    0.5 kHz
   </text>
  </g>
 </g>
</svg>

Bug1028_Output.svg.txt bug1028_output

Comparison

green ist desired input, red is output comparison


Copyright of the picture License: [cc-by-sa-2.5](https://creativecommons.org/licenses/by-sa/2.5) Author: [Inductiveload](https://commons.wikimedia.org/wiki/User:Inductiveload) Details (and Source): https://commons.wikimedia.org/wiki/File:Anatomy_of_Human_Ear_with_Cochlear_Frequency_Mapping.svg
TrySound commented 3 years ago

Fixed in https://github.com/svg/svgo/releases/tag/v2.1.0