Version 23 of SVG

Updated 2010-04-04 14:05:20 by lars_h

Scalable vector graphics: "very cool stuff".

The "native" language for scripting SVG--that is, for animating an SVG document by run-time modification of its node tree with SVGDOM--is JavaScript. Steve Ball has been thinking about the desirability of binding Tcl to SVGDOM (perhaps by way of Batik [L1 ] and Jacl?).

tkpath binary extensions supplies many SVG "path" features for native use on Tk canvases - very nice!


RS: Many of SVG's items have a very close correspondence to canvas items, so one might consider using SVG for "serializing" a canvas content to XML, and loading canvas contents from XML... Consider this snippet:

  <polygon fill="yellow" stroke="none"
    points="350 75, 379 161, 469 161, 397 215,
            423 301, 350 250, 277 301, 303 215,
            231 161, 321 161"
    transform="scale(.5)" />

With some string manipulation (and determining the center from the bounding box, for scaling) this could easily be transformed into two canvas commands.


An elaborate canvas to SVG dumper is at [L2 ].


Read (svg2can) and write (can2svg) SVG files (in Tcl) are available in Coccinella communication tool.


DKF: SVG is really very close indeed to the Java2D API, and even more especially to the base model used in PostScript and Acrobat (PDF). Not surprising really, given that they all came out of Adobe...


Rolf Ade This is the start of a list of SVG features, that have no native support by the canvas (some of them could eventually be simulated).

  • Text along arcs (or pathes, as the SVG calls it)
  • SVG allows to alter plenty of font properties, for which I found no correspondent in Tcl.
  • SVG allows text to run vertically or right to left.
  • Filter effects.
  • Clipping paths.
  • 'Masking' (transparency effects)

Lars H: Conversely, I've found that SVG seems to lack a counterpart of the -anchor option of a canvas text item, which severely complicates mixing text and graphics. (In the horizontal direction, there is an attribute which does what one wants, although technically it takes its "left" and "right" from the directionality of the text. In the vertical direction there is no direct counterpart; it should in principle be possible to emulate vertical anchoring using baseline alignment and font size changes, but no browser did that correctly.)

AK: IIRC the GTk canvas widget was derived from the Tk Canvas, and enhanced. I believe it does transparency. We might want to have a look at it and see what features we can 'steal' back.


roger - 2010-04-03 05:47:21

SMIL is the native language for animating SVG. DOM-access is being used for more complex interactions.

SVG is intended to replace PDF and PostScript, see the sub-specification SVG-Print: http://lists.w3.org/Archives/Public/public-svg-print/

The aim of SVG-Print is to create an universal printing mechanism from any computerized device (mobile device) to every printer.

Adobe® and Microsoft® also work on similar xml-based specifications, too.

The counterpart for the Tk text window and canvas text object is <flowRoot> from the SVG 1.2 specification. --It may be possible to convert a Tk text window into a SVG flow element.

The SVG 1.1 text object is graphical text, not supporting text flow, like Tk's text elements do. An anchor attribute is superfluous within flowroot, since the alignment is being defined by the graphical object, used as the flow region. Lars H: You seem to confuse -anchor with -justify; the former is needed also for single line text. What I found no way of getting done with SVG 1.1 (there wasn't even any main 1.2 draft at the time) was to center an "R" or "I" label within a square (without having to know the exact font metrics in advance, which circumstances would not permit).

The Tk canvas window is definitely not close to SVG. SVG is a powerful visualization system, supporting viewports, transformations, gradients, transparency...

tkpath 0.3 introduced groups, and thus made a big step toward viewport and full transformation support.

Jeszra converts SVG into Tcl/Tk code and an entire Tk-GUI into SVG (including tkpath 0.2, 03 and the general stuff from tkzinc), as you can see throughout Jeszra's own documentation: http://jeszra.sourceforge.net/