samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.7k stars 66 forks source link

Always have a `<rect>` when saving as SVG #91

Closed yisibl closed 2 years ago

yisibl commented 2 years ago
const canvas = new Canvas(900, 900)
const ctx = canvas.getContext('2d')

ctx.font = '800px Arial'
ctx.fillStyle = 'red'
ctx.fillText('B', 0, 900)
canvas.saveAsSync('foo.svg')

I hope there is no <rect>.

<?xml version="1.0" encoding="utf-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="900" height="900">
    <rect width="900" height="900"/>
    <path fill="red" d="M58.5938 899.573L58.5938 326.917L273.438 326.917Q339.062 326.917 378.711 344.3Q418.359 361.683 440.82 397.815Q463.281 433.948 463.281 473.401Q463.281 510.12 443.359 542.542Q423.438 574.964 383.203 594.886Q435.156 610.12 463.086 646.839Q491.016 683.558 491.016 733.558Q491.016 773.792 474.023 808.362Q457.031 842.933 432.031 861.683Q407.031 880.433 369.336 890.003Q331.641 899.573 276.953 899.573L58.5938 899.573ZM134.375 567.542L258.203 567.542Q308.594 567.542 330.469 560.901Q359.375 552.308 374.023 532.386Q388.672 512.464 388.672 482.386Q388.672 453.87 375 432.19Q361.328 410.511 335.938 402.503Q310.547 394.495 248.828 394.495L134.375 394.495L134.375 567.542ZM134.375 831.995L276.953 831.995Q313.672 831.995 328.516 829.261Q354.688 824.573 372.266 813.636Q389.844 802.698 401.172 781.8Q412.5 760.901 412.5 733.558Q412.5 701.526 396.094 677.893Q379.688 654.261 350.586 644.69Q321.484 635.12 266.797 635.12L134.375 635.12L134.375 831.995Z"/>
</svg>