SVG

Difference between version 30 and 31 - Previous - Next
Scalable [vector graphics]:  "very cool stuff".

   * http://www.w3.org/Graphics/SVG/Overview.htm8
   * http://www.xml.com/pub/a/2003/07/16/svg-prescod.html
   * http://www.adobe.com/svg/demos/main.html
   * http://www.adobe.com/svg/community/external.html
   * http://nokiko.com/svg/links.asp?ID=12
   * http://www.kevlindev.com/samples/index.htm
   * http://entwickler.com/itr/online_artikel/show.php3?nodeid=97&id=332
   * http://entwickler.com/itr/online_artikel/show.php3?nodeid=97&id=325

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 [http://xml.apache.org/batik]
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
[http://coccinella.svn.sourceforge.net/viewvc/coccinella/trunk/coccinella/contrib/can2svg.tcl?content-type=text%2Fplain].
----
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).''
"—[roger] re-read: The counterpart for Tk text ... is <flowRoot>"

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/

----
'''[roger] - 2010-04-06 08:56:31'''

Converting Tk text objects to SVG 1.1 text requires to "synchronize" anchor and
alignment; this is necessary because font-substitutions are very likely to occur with
SVG-viewers.
 

----
'''[CMcC] - 2010-04-13 06:24:01'''

I've written a Tcl OO object hierarchy to parse, manipulate, and generate SVG, [TclSVG]


----
'''[errordeveloper] - 2010-07-18 15:33:26'''

simple list-in/object-out with tDOM an no extra packages:

`$BROWSER http://github.com/errordeveloper/svgdom`

`git clone git:://github.com/errordeveloper/svgdom.git`

i will keep this updated as it goes,

add CDATA JavaScript and SVG Parameters ..and may be SMIL

but it basically takes a list in and recursively adds tags and attributes

test it with say: "{{rect {x 10 y 25 width 100 height 250}} {rect {x 20 y 100 width 100 height 250}}}"


**Tk 8.7 features limited SVG support within image photos**
[HaO] 2019-059-106:
With [http://core.tcl-lang.tkorg/tips/doc/trunk/tip/507.md%|%TIP507%|%], svg-support was added to tk8.7+.
To get (nearly) the same support on tk 8.6, use package [https://github.com/auriocus/tksvg%|%tksvg%|%] by Auriocus.
***ApplWith [https://core.tcl-lang.org/tips/doc/trun: k/tip/545.mdy%|%TIP545%|%], the options "-scamletoheight" and "-scallyetowidth" were added to scale the izmage to a given height*** or width in pixels.
This is handy for button icons.
[https://github.com/auriocus/tksvg%|%tksvg%|%] version 0.3 supports this change and contains now windows 32 binaries of the DLL.
Within my applications, the user interface items may be scaled by setting the font height.
The buttons with images should follow.
Here is a code sketch to scale a button on a given (font) height:

======tcl
# init
if {![package vsatisfies [package require Tk] 8.7-]} {
    package require tksvg
}
image create photo myPhoto -file myphoto.svg
set originalHeight(myPhoto) [expr {double([image height myPhoto])}]

# size on font height of $fontHeight pixels
myPhoto configure [list svg -scale [expr {$fontHeight/$originalHeight(myPhoto)}]]
======

***Text items in svg***

The used svg implementation "svgnano" does not support text items.
I paint my icons using [www.inkscape.org%|%InkScape%|%] as follows:
To display text, first use the text tool to print the text.
Then go to the path menu and select "transform object to path" with the shortcut "Shift-Control-C".
After save, the text is visible within tclnano.

<<categories>> Graphics