tresvg

Whattresvg
Wherehttps://github.com/nico-robert/tresvg
DescriptionTcl wrapper around resvg an SVG rendering library written in Rust .
LicenseMIT License

Use tresvg if :

  • You need full SVG specification compliance.
  • You work with complex, modern SVG files.
  • Rendering quality and accuracy are priorities.
  • You need reliable text rendering.
  • You can accommodate with the build requirements.

Compatibility :

  • Tcl 8.6 or higher.

Dependencies :

  • tcl-cffi >= 2.0 and/or critcl .
  • critcl and Tk are optional for rendering SVG image to photo command.

Platforms :

  • Windows, Linux, macOS support.

Example:

  • tcl-cffi demo :
package require tresvg

set svg hello.svg

# Initialize log (optional)
tresvg::initLog

# Create options
set opt [tresvg::optionsCreate]

# Parse svg file
set tree [tresvg::parseTreeFromFile $svg $opt]

# Apply transform
set transform [tresvg::transformIdentity]

# Get image size
set size [tresvg::getImageSize $tree]
set width  [expr {int([dict get $size width])}]
set height [expr {int([dict get $size height])}]

# Render
set pixmap [tresvg::render $tree $transform $width $height]

# Save to PNG
tresvg::toPNG $pixmap $width $height "hello.png"

# Extended procedures (not a part of resvg C-API)
set xml [tresvg::getXML $tree] ; # Gets simplified XML
set version [tresvg::libVersion]

# Cleanup
tresvg::optionsDestroy $opt
tresvg::treeDestroy $tree
  • critcl demo :
package require Tk ; # Important to load Tk before 'tresvg' package.
package require tresvg

set svg hello.svg
set img [image create photo]

# Others args are optional (see listing commands in README section)
tresvg::toTkImg $svg $img

# Others examples of 'tresvg::toTkImg' command :
tresvg::toTkImg $svg $img -width 100 -height 50
tresvg::toTkImg $svg $img -scale 2 -dpi 300
tresvg::toTkImg $svg $img -mtx {1 0 0 1 0 0}
tresvg::toTkImg $svg $img -width 100 -height 50 -modeScale "fit"
tresvg::toTkImg $svg $img -initLog "true"

$img write "hello.png"

label .l -image $img
pack .l

Building :

Acknowledgments :

  • To RazrFalcon , the author of resvg, who helped me understand his library a few years ago.

Changes :