Check-in [c8ffbc0775]

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tidy up 507
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:c8ffbc0775d4151ff4131e0c531dc33384cac053886bcd6a048afd690fd0319e
User & Date: dkf 2018-11-01 08:35:25
Context
2018-11-04
15:38
Added link to implementation branch for TIP 480 check-in: fb82591e2b user: dkf tags: trunk
2018-11-01
08:35
Tidy up 507 check-in: c8ffbc0775 user: dkf tags: trunk
2018-10-31
09:46
Editorial cleanup of 290 check-in: 0eac074208 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to index.json.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
523
524
525
526
527
528
529
530
	"514":{"url":"./tip/514.md","keywords":"Tcl","created":"20-Aug-2018","post-history":"","state":"Final","tcl-branch":"tip-514","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 514: Platform differences in handling int/wide","author":["Jan Nijtmans <jan.nijtmans@gmail.com>"],"is-jest":false},
	"513":{"url":"./tip/513.md","keywords":"Tcl,data structure","created":"02-Aug-2017","post-history":"","state":"Draft","implementation-url":"https://core.tcl.tk/tips/doc/trunk/attach/513/agendas.tcl","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 513: Better support for 'agendas' as arrays, dictionaries or lists","author":["Florian Murr <florian.murr@siemens.com>"],"is-jest":false},
	"512":{"url":"./tip/512.md","keywords":"Tcl","created":"25-June-2018","post-history":"","state":"Draft","tcl-branch":"tip-512","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 512: No stub for Tcl_SetExitProc()","author":["Jan Nijtmans <jan.nijtmans@gmail.com>"],"is-jest":false},
	"511":{"url":"./tip/511.md","keywords":"Tcl,threads","state":"Accepted","type":"Project","author":["Christian Werner <undroidwish@googlemail.com>"],"vote-results":"4/0/5 accepted","votes-for":"DKF, BG, KBK, JN, JD, SL","votes-against":"none","created":"14-June-2018","title":"# TIP 511: Implement Tcl_AsyncMarkFromSignal()","post-history":"","implementation-url":"https://www.androwish.org/index.html/info/40790af1e8e4ec9f","vote":"Done","tcl-version":"8.7","votes-present":"DGP, FV, AK","is-jest":false},
	"510":{"url":"./tip/510.md","keywords":"Tk","created":"5-Jun-2018","post-history":"","state":"Draft","tk-branch":"tip-510","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 510: Add Rbc to Tk","author":["René Zaumseil <r.zaumseil@freenet.de>"],"is-jest":false},
	"509":{"url":"./tip/509.md","keywords":"Tcl,threads","state":"Final","type":"Project","author":["Frédéric Bonnet <fredericbonnet@free.fr>"],"vote-results":"8/0/1 accepted","votes-for":"DKF, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"24-May-2018","title":"# TIP 509: Implement reentrant mutexes on all platforms","post-history":"","tcl-branch":"tip-509","vote":"Done","tcl-version":"8.7","votes-present":"BG","is-jest":false},
	"508":{"url":"./tip/508.md","keywords":"Tcl,array","state":"Final","type":"Project","author":["Frédéric Bonnet <fredericbonnet@free.fr>"],"vote-results":"9/0/0 accepted","votes-for":"DKF, BG, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"13-May-2018","title":"# TIP 508: New subcommand [array default]","post-history":"","tcl-branch":"tip-508","vote":"Done","tcl-version":"8.7","votes-present":"none","is-jest":false},
	"507":{"url":"./tip/507.md","keywords":"Tk","created":"9-May-2018","post-history":"","state":"Draft","tk-branch":"tip-507","tcl-version":"8.7","vote":"","type":"Project","title":"# TIP 507: Include simple svg support with nanosvg","author":["René Zaumseil <r.zaumseil@freenet.de>"],"is-jest":false},
	"506":{"url":"./tip/506.md","created":"30-Mar-2018","post-history":"","state":"Draft","tcl-branch":"tip-506","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 506: Purge RefCount Macros","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"505":{"url":"./tip/505.md","state":"Final","type":"Project","author":["Don Porter <dgp@users.sourceforge.net>"],"vote-results":"8/0/1 accepted","votes-for":"DKF, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"26-Mar-2018","title":"# TIP 505: Make [lreplace] Accept All Out-of-Range Index Values","post-history":"","tcl-branch":"tip-505","vote":"Done","tcl-version":"8.6.9","votes-present":"BG","is-jest":false},
	"504":{"url":"./tip/504.md","keywords":"Tcl,string,insert","obsoletes":"475","created":"21-Mar-2018","post-history":"","state":"Draft","tcl-branch":"dgp-string-insert","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 504: New subcommand [string insert]","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"503":{"url":"./tip/503.md","created":"05-Feb-2018","post-history":"","state":"Final","tcl-branch":"tip-503","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 503: End Tcl 8.3 Source Compatibility Support","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"502":{"url":"./tip/502.md","created":"26-Feb-2018","post-history":"","state":"Final","tcl-branch":"tip-502","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 502: Index Value Reform","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"501":{"url":"./tip/501.md","keywords":"Tcl,string","created":"12-Feb-2018","post-history":"","state":"Draft","tcl-branch":"tip-501","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 501: string is dict","author":["Sean Woods <yoda@etoyoc.com>"],"is-jest":false},
	"500":{"url":"./tip/500.md","keywords":"Tcl, object orientation, visibility","state":"Final","type":"Project","author":["Donal K. Fellows <donal.k.fellows@manchester.ac.uk>"],"votes-for":"DKF, JN, AF, JD, SL, AK, KBK","votes-against":"none","created":"10-Feb-2018","title":"# TIP 500: Private Methods and Variables in TclOO","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-500","is-jest":false},
................................................................................
	"4":{"url":"./tip/4.md","created":"26-Oct-2000","post-history":"","state":"Draft","vote":"Pending","type":"Informative","title":"# TIP 4: Tcl Release and Distribution Philosophy","discussions-to":"news:comp.lang.tcl","author":["Brent Welch <welch@acm.org>","Donal K. Fellows <fellowsd@cs.man.ac.uk>","Larry W. Virden <lvirden@cas.org>","Larry W. Virden <lvirden@yahoo.com>"],"is-jest":false},
	"3":{"url":"./tip/3.md","created":"14-Sep-2000","post-history":"","state":"Accepted","vote":"Done","type":"Process","title":"# TIP 3: TIP Format","author":["Andreas Kupries <a.kupries@westend.com>","Donal K. Fellows <fellowsd@cs.man.ac.uk>"],"is-jest":false},
	"2":{"url":"./tip/2.md","created":"12-Sep-2000","post-history":"","state":"Draft","vote":"Pending","type":"Process","title":"# TIP 2: TIP Guidelines","author":["Andreas Kupries <a.kupries@westend.com>","Donal K. Fellows <fellowsd@cs.man.ac.uk>","Don Porter <dgp@users.sourceforge.net>","Mo DeJong <no@spam.com>","Larry W. Virden <lvirden@yahoo.com>","Kevin Kenny <kennykb@acm.org>"],"is-jest":false},
	"1":{"url":"./tip/1.md","created":"14-Sep-2000","post-history":"","state":"Active","vote":"No voting","type":"Informational","title":"# TIP 1: TIP Index","author":["TIP Editor <donal.fellows@cs.man.ac.uk>"],"is-jest":false},
	"0":{"url":"./tip/0.md","created":"11-Dec-2000","post-history":"","state":"Final","vote":"Done","type":"Process","title":"# TIP 0: Tcl Core Team Basic Rules","author":["John Ousterhout <ouster@pacbell.net>"],"is-jest":false},
	"@min": 0,
	"@max": 525
}, "@timestamp": 1540846327}







|







 







|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
523
524
525
526
527
528
529
530
	"514":{"url":"./tip/514.md","keywords":"Tcl","created":"20-Aug-2018","post-history":"","state":"Final","tcl-branch":"tip-514","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 514: Platform differences in handling int/wide","author":["Jan Nijtmans <jan.nijtmans@gmail.com>"],"is-jest":false},
	"513":{"url":"./tip/513.md","keywords":"Tcl,data structure","created":"02-Aug-2017","post-history":"","state":"Draft","implementation-url":"https://core.tcl.tk/tips/doc/trunk/attach/513/agendas.tcl","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 513: Better support for 'agendas' as arrays, dictionaries or lists","author":["Florian Murr <florian.murr@siemens.com>"],"is-jest":false},
	"512":{"url":"./tip/512.md","keywords":"Tcl","created":"25-June-2018","post-history":"","state":"Draft","tcl-branch":"tip-512","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 512: No stub for Tcl_SetExitProc()","author":["Jan Nijtmans <jan.nijtmans@gmail.com>"],"is-jest":false},
	"511":{"url":"./tip/511.md","keywords":"Tcl,threads","state":"Accepted","type":"Project","author":["Christian Werner <undroidwish@googlemail.com>"],"vote-results":"4/0/5 accepted","votes-for":"DKF, BG, KBK, JN, JD, SL","votes-against":"none","created":"14-June-2018","title":"# TIP 511: Implement Tcl_AsyncMarkFromSignal()","post-history":"","implementation-url":"https://www.androwish.org/index.html/info/40790af1e8e4ec9f","vote":"Done","tcl-version":"8.7","votes-present":"DGP, FV, AK","is-jest":false},
	"510":{"url":"./tip/510.md","keywords":"Tk","created":"5-Jun-2018","post-history":"","state":"Draft","tk-branch":"tip-510","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 510: Add Rbc to Tk","author":["René Zaumseil <r.zaumseil@freenet.de>"],"is-jest":false},
	"509":{"url":"./tip/509.md","keywords":"Tcl,threads","state":"Final","type":"Project","author":["Frédéric Bonnet <fredericbonnet@free.fr>"],"vote-results":"8/0/1 accepted","votes-for":"DKF, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"24-May-2018","title":"# TIP 509: Implement reentrant mutexes on all platforms","post-history":"","tcl-branch":"tip-509","vote":"Done","tcl-version":"8.7","votes-present":"BG","is-jest":false},
	"508":{"url":"./tip/508.md","keywords":"Tcl,array","state":"Final","type":"Project","author":["Frédéric Bonnet <fredericbonnet@free.fr>"],"vote-results":"9/0/0 accepted","votes-for":"DKF, BG, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"13-May-2018","title":"# TIP 508: New subcommand [array default]","post-history":"","tcl-branch":"tip-508","vote":"Done","tcl-version":"8.7","votes-present":"none","is-jest":false},
	"507":{"url":"./tip/507.md","keywords":"Tk","created":"9-May-2018","post-history":"","state":"Draft","tk-branch":"tip-507","tcl-version":"8.7","vote":"","type":"Project","title":"# TIP 507: Include simple SVG support with nanosvg","author":["René Zaumseil <r.zaumseil@freenet.de>"],"is-jest":false},
	"506":{"url":"./tip/506.md","created":"30-Mar-2018","post-history":"","state":"Draft","tcl-branch":"tip-506","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 506: Purge RefCount Macros","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"505":{"url":"./tip/505.md","state":"Final","type":"Project","author":["Don Porter <dgp@users.sourceforge.net>"],"vote-results":"8/0/1 accepted","votes-for":"DKF, KBK, JN, JD, DGP, FV, SL, AK","votes-against":"none","created":"26-Mar-2018","title":"# TIP 505: Make [lreplace] Accept All Out-of-Range Index Values","post-history":"","tcl-branch":"tip-505","vote":"Done","tcl-version":"8.6.9","votes-present":"BG","is-jest":false},
	"504":{"url":"./tip/504.md","keywords":"Tcl,string,insert","obsoletes":"475","created":"21-Mar-2018","post-history":"","state":"Draft","tcl-branch":"dgp-string-insert","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 504: New subcommand [string insert]","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"503":{"url":"./tip/503.md","created":"05-Feb-2018","post-history":"","state":"Final","tcl-branch":"tip-503","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 503: End Tcl 8.3 Source Compatibility Support","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"502":{"url":"./tip/502.md","created":"26-Feb-2018","post-history":"","state":"Final","tcl-branch":"tip-502","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 502: Index Value Reform","author":["Don Porter <dgp@users.sourceforge.net>"],"is-jest":false},
	"501":{"url":"./tip/501.md","keywords":"Tcl,string","created":"12-Feb-2018","post-history":"","state":"Draft","tcl-branch":"tip-501","tcl-version":"8.7","vote":"In progress","type":"Project","title":"# TIP 501: string is dict","author":["Sean Woods <yoda@etoyoc.com>"],"is-jest":false},
	"500":{"url":"./tip/500.md","keywords":"Tcl, object orientation, visibility","state":"Final","type":"Project","author":["Donal K. Fellows <donal.k.fellows@manchester.ac.uk>"],"votes-for":"DKF, JN, AF, JD, SL, AK, KBK","votes-against":"none","created":"10-Feb-2018","title":"# TIP 500: Private Methods and Variables in TclOO","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-500","is-jest":false},
................................................................................
	"4":{"url":"./tip/4.md","created":"26-Oct-2000","post-history":"","state":"Draft","vote":"Pending","type":"Informative","title":"# TIP 4: Tcl Release and Distribution Philosophy","discussions-to":"news:comp.lang.tcl","author":["Brent Welch <welch@acm.org>","Donal K. Fellows <fellowsd@cs.man.ac.uk>","Larry W. Virden <lvirden@cas.org>","Larry W. Virden <lvirden@yahoo.com>"],"is-jest":false},
	"3":{"url":"./tip/3.md","created":"14-Sep-2000","post-history":"","state":"Accepted","vote":"Done","type":"Process","title":"# TIP 3: TIP Format","author":["Andreas Kupries <a.kupries@westend.com>","Donal K. Fellows <fellowsd@cs.man.ac.uk>"],"is-jest":false},
	"2":{"url":"./tip/2.md","created":"12-Sep-2000","post-history":"","state":"Draft","vote":"Pending","type":"Process","title":"# TIP 2: TIP Guidelines","author":["Andreas Kupries <a.kupries@westend.com>","Donal K. Fellows <fellowsd@cs.man.ac.uk>","Don Porter <dgp@users.sourceforge.net>","Mo DeJong <no@spam.com>","Larry W. Virden <lvirden@yahoo.com>","Kevin Kenny <kennykb@acm.org>"],"is-jest":false},
	"1":{"url":"./tip/1.md","created":"14-Sep-2000","post-history":"","state":"Active","vote":"No voting","type":"Informational","title":"# TIP 1: TIP Index","author":["TIP Editor <donal.fellows@cs.man.ac.uk>"],"is-jest":false},
	"0":{"url":"./tip/0.md","created":"11-Dec-2000","post-history":"","state":"Final","vote":"Done","type":"Process","title":"# TIP 0: Tcl Core Team Basic Rules","author":["John Ousterhout <ouster@pacbell.net>"],"is-jest":false},
	"@min": 0,
	"@max": 525
}, "@timestamp": 1541061299}

Changes to index.md.

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<td valign='top'><a href='/tcl/timeline?r=tip-508'>Link</a></td>
</tr>
<tr class='project projectdraft projectdraft87 project87'>
<td valign='top'><a href='./tip/507.md'>507</a></td>
<td valign='top'>Project</td>
<td valign='top'>8.7</td>
<td valign='top'>Draft</td>
<td valign='top'># TIP 507: Include simple svg support with nanosvg</td>
<td valign='top'><a href='/tk/timeline?r=tip-507'>Link</a></td>
</tr>
<tr class='invote'>
<td valign='top'><a href='./tip/506.md'>506</a></td>
<td valign='top'>Project</td>
<td valign='top'>8.7</td>
<td valign='top'>Voting</td>







|







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<td valign='top'><a href='/tcl/timeline?r=tip-508'>Link</a></td>
</tr>
<tr class='project projectdraft projectdraft87 project87'>
<td valign='top'><a href='./tip/507.md'>507</a></td>
<td valign='top'>Project</td>
<td valign='top'>8.7</td>
<td valign='top'>Draft</td>
<td valign='top'># TIP 507: Include simple SVG support with nanosvg</td>
<td valign='top'><a href='/tk/timeline?r=tip-507'>Link</a></td>
</tr>
<tr class='invote'>
<td valign='top'><a href='./tip/506.md'>506</a></td>
<td valign='top'>Project</td>
<td valign='top'>8.7</td>
<td valign='top'>Voting</td>

Changes to tip/507.md.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61


62


63



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# TIP 507: Include simple svg support with nanosvg
	Author:         René Zaumseil <r.zaumseil@freenet.de>
	State:          Draft
	Type:           Project
	Vote:           
	Created:        9-May-2018
	Post-History:   
	Keywords:       Tk
	Tcl-Version:    8.7
	Tk-Branch:      tip-507
-----

# Abstract

Tk needs scalable images on high res mobile devices. This TIP proposes to let Tk be able to read an SVG image (plus information about orientation and pixel scale) and make it into a photo. It is therefore a (lossy and single direction) conversion operation from an SVG format to a pixel format.

# Rationale

Tk is running on desktop and mobile devices. The out of the box image formats
do not scale and are to tiny on high res mobile devices.
The same goes for the image formats provided by the img extension.

There is already a Tk image extension at https://github.com/auriocus/tksvg
The implementation is using nanosvg. It has no other external dependencies
and is only 2 header files.

**nanosvg** was choosen because it:

- has a suitable license
- is written in 2 plain C header files and can easily included
- is really lightweight
- is tested with tksvg
- can render images
- has no other external dependencies

The original nanosvg project is hosted at https://github.com/memononen/nanosvg

# Specification

The already existing tksvg extension will be adapted and included in Tk.
A new image format will be created. The name is **svgnano**.
The choosen name hints the usage of a not fully compatible svg parser.
It leaves the image name **svg** open for further usage.

The **svgnano** image format has the following format suboptions:

**svgnano** *-dpi dpiValue -scale scaleValue -unit unitValue -x xValue -y yValue*

*dpiValue* is used in conversion between given coordiantes and screen resolution. The value must be greater then 0.0. The default value is 96.

*scaleValue* is used to scale the resulting image. The value must be greater then 0.0. The default value is 1.

*unitValue* is the unit of all coordinates in the svg data. Available units are px (default, coordinates in pixel), pt (1/72 inch), pc (12 pt), mm, cm and in.

*xValue* is used to move the created image in x-direction. The default value is 0.

*yValue* is used to move the created image in y-direction. The default value is 0.

The given format options are only used at creation time of the image and are not preserved in the image. This means that:

  1. **$img data -format svgnano** triggers error **"image string format "svgnano" is not supported"**


  


  2. **$img configure -format {svgnano -scale 2} ; $img configure -format {svgnano -x 10}    ;** # the second call takes -scale as the default value (1)




# Supported SVG

The svgnano format supports a wide range of SVG features, however some features (e.g. 'text') are missing and silently ignored when reading the SVG data.

## Elements

- g
- path
- rect
- circle
- ellipse
- line
- polyline
- polygon
- linearGradient
- radialGradient
- stop
- defs
- svg
- style

## Attributes

- width, height
- viewBox
- preserveAspectRatio with none, xMin, xMid, xMax, yMin, yMid, yMax, slice

## Gradient Attributes

- gradientUnits with objectBoundingBox
- gradientTransform
- cx, cy, r
- fx, fy
- x1, y1, x2, y2
- spreadMethod with pad, reflect or repeat
- xlink:href

## Poly Attributes

- points

## Line Attributes

- x1, y1, x2, y2

## Ellipse Attributes

- cx, cy
- rx, ry

## Circle Attributes

- cx, cy
- r

## Rectangle Attributes

- x, y
- width, height
- rx, ry

## Path Attributes

- d with m, M, l, L, h, H, v, V, c, C, s, S, q, Q, t, T, a, A, z, Z

## Style Attributes

- display with none, visibility, hidden, visible
- fill with nonzero, evenodd
- opacity
- fill-opacity
- stroke
- stroke-width
- stroke-dasharray
- stroke-dashoffset
- stroke-opacity
- stroke-linecap with butt, round, square
- stroke-linejoin with miter round bevel
- stroke-miterlimit
- fill-rule
- font-size
- transform with matrix, translate, scale, rotate, skewX, skewY
- stop-color
- stop-opacity
- offset
- id
- class

# Discussion

- http://code.activestate.com/lists/tcl-core/19871/
- http://code.activestate.com/lists/tcl-core/19994/

## Open questions

- Are all of the above format options necessary? May be remove the *xValue* and *yValue* options.

# Implementation

A patch implementing these changes is available in the fossil repository in the [tip-507 branch]
(https://core.tcl.tk/tk/timeline?r=tip-507).

The new format is described in the photo.n man page.

# Example of use

	    # the image data
	    set data {<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
	    <path fill="none" stroke="#000000" d="M0 0 h16 v16 h-16 z"/>
	    <path fill="none" stroke="#000000" d="M8 4 v 8 M4 8 h 8"/>
	    <circle fill="yellow" stroke="red" cx="10" cy="80" r="10" />
	    <ellipse fill="none" stroke="blue" stroke-width="3" cx="60" cy="60" rx="10" ry="20" />
	    <line x1="10" y1="90" x2="50" y2="99"/>
	    <rect fill="none" stroke="green"  x="20" y="20" width="60" height="50" rx="3" ry="3"/>
	    <polyline fill="red" stroke="purple" points="80,10 90,20 85,40"/>
	    <polygon fill ="yellow" points="80,80 70,85 90,90"/>
	    </svg>}
	    # create image
	    image create photo foo -data $data
	    # change size
	    foo configure -format {svgnano -scale 2}
	    # move right and up, all other values are reset
	    foo configure -format {svgnano -x 10 -y -20}
	    # use other unit
	    foo configure -format {svgnano -unit mm}

# Alternatives

- Use of another library with full svg support instead of the current proposal for partial support: could be done as a further step.

- Direct manipulation of SVG vector graphics (as opposed to the present proposal of converting SVG to pixel format in a photo) would be desirable. However this can always be done later, for instance in the frame of the canvas widget. It is deemed an already large improvement to have Tk be able to read SVG images and convert them to pixel-based photos.

# Copyright

This document has been placed in the public domain.
|













|





|

|






|











|




|













|
>
>
|
>
>
|
>
>
>







|
|
|
|
|
|
|
|
|
|
|
|
|
|



|
|
|



|
|
|
|
|
|
|



|



|



|
|



|
|



|
|
|



|



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|












|
<

|



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|



|






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# TIP 507: Include simple SVG support with nanosvg
	Author:         René Zaumseil <r.zaumseil@freenet.de>
	State:          Draft
	Type:           Project
	Vote:           
	Created:        9-May-2018
	Post-History:   
	Keywords:       Tk
	Tcl-Version:    8.7
	Tk-Branch:      tip-507
-----

# Abstract

Tk needs scalable images on high resolution mobile devices. This TIP proposes to let Tk be able to read an SVG image (plus information about orientation and pixel scale) and make it into a photo image. It is therefore a (lossy and single direction) conversion operation from an SVG format to a pixel format.

# Rationale

Tk is running on desktop and mobile devices. The out of the box image formats
do not scale and are to tiny on high res mobile devices.
The same goes for the image formats provided by the Img extension.

There is already a [Tk image extension](https://github.com/auriocus/tksvg).
The implementation is using nanosvg. It has no other external dependencies
and is only 2 header files.

**nanosvg** was choosen because it:

- has a suitable license
- is written in 2 plain C header files and can be easily included
- is really lightweight
- is tested with tksvg
- can render images
- has no other external dependencies

The original nanosvg project is hosted at https://github.com/memononen/nanosvg

# Specification

The already existing tksvg extension will be adapted and included in Tk.
A new image format will be created. The name is **svgnano**.
The choosen name hints the usage of a not fully compatible SVG parser.
It leaves the image name **svg** open for further usage.

The **svgnano** image format has the following format suboptions:

 > **svgnano** **-dpi** _dpiValue_ **-scale** _scaleValue_ **-unit** _unitValue_ **-x** _xValue_ **-y** _yValue_

*dpiValue* is used in conversion between given coordiantes and screen resolution. The value must be greater then 0.0. The default value is 96.

*scaleValue* is used to scale the resulting image. The value must be greater then 0.0. The default value is 1.

*unitValue* is the unit of all coordinates in the svg data. Available units are px (default, coordinates in pixel), pt (1/72 inch), pc (12 pt), mm, cm and in.

*xValue* is used to move the created image in x-direction. The default value is 0.

*yValue* is used to move the created image in y-direction. The default value is 0.

The given format options are only used at creation time of the image and are not preserved in the image. This means that:

  1. `$img data -format svgnano` triggers the error _"image string format
     "svgnano" is not supported"_; Tk cannot convert a photo image into an
     SVG.

  2. In this:

        $img configure -format {svgnano -scale 2}
        $img configure -format {svgnano -x 10}

    the second call takes `-scale` as the default value (1).

# Supported SVG

The svgnano format supports a wide range of SVG features, however some features (e.g. 'text') are missing and silently ignored when reading the SVG data.

## Elements

- `g`
- `path`
- `rect`
- `circle`
- `ellipse`
- `line`
- `polyline`
- `polygon`
- `linearGradient`
- `radialGradient`
- `stop`
- `defs`
- `svg`
- `style`

## Attributes

- `width`, `height`
- `viewBox`
- `preserveAspectRatio` with `none`, `xMin`, `xMid`, `xMax`, `yMin`, `yMid`, `yMax`, `slice`

## Gradient Attributes

- `gradientUnits` with `objectBoundingBox`
- `gradientTransform`
- `cx`, `cy`, `r`
- `fx`, `fy`
- `x1`, `y1`, `x2`, `y2`
- `spreadMethod` with `pad`, `reflect` or `repeat`
- `xlink:href`

## Poly Attributes

- `points`

## Line Attributes

- `x1`, `y1`, `x2`, `y2`

## Ellipse Attributes

- `cx`, `cy`
- `rx`, `ry`

## Circle Attributes

- `cx`, `cy`
- `r`

## Rectangle Attributes

- `x`, `y`
- `width`, `height`
- `rx`, `ry`

## Path Attributes

- `d` with `m`, `M`, `l`, `L`, `h`, `H`, `v`, `V`, `c`, `C`, `s`, `S`, `q`, `Q`, `t`, `T`, `a`, `A`, `z`, `Z`

## Style Attributes

- `display` with `none`, `visibility`, `hidden`, `visible`
- `fill` with `nonzero`, `evenodd`
- `opacity`
- `fill-opacity`
- `stroke`
- `stroke-width`
- `stroke-dasharray`
- `stroke-dashoffset`
- `stroke-opacity`
- `stroke-linecap` with `butt`, `round`, `square`
- `stroke-linejoin` with `miter`, `round`, `bevel`
- `stroke-miterlimit`
- `fill-rule`
- `font-size`
- `transform` with `matrix`, `translate`, `scale`, `rotate`, `skewX`, `skewY`
- `stop-color`
- `stop-opacity`
- `offset`
- `id`
- `class`

# Discussion

- http://code.activestate.com/lists/tcl-core/19871/
- http://code.activestate.com/lists/tcl-core/19994/

## Open questions

- Are all of the above format options necessary? May be remove the *xValue* and *yValue* options.

# Implementation

A patch implementing these changes is available in the fossil repository in the [tip-507 branch](https://core.tcl.tk/tk/timeline?r=tip-507).


The new format is described in the photo(n) man page.

# Example of use

    # the image data
    set data {<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
    <path fill="none" stroke="#000000" d="M0 0 h16 v16 h-16 z"/>
    <path fill="none" stroke="#000000" d="M8 4 v 8 M4 8 h 8"/>
    <circle fill="yellow" stroke="red" cx="10" cy="80" r="10" />
    <ellipse fill="none" stroke="blue" stroke-width="3" cx="60" cy="60" rx="10" ry="20" />
    <line x1="10" y1="90" x2="50" y2="99"/>
    <rect fill="none" stroke="green"  x="20" y="20" width="60" height="50" rx="3" ry="3"/>
    <polyline fill="red" stroke="purple" points="80,10 90,20 85,40"/>
    <polygon fill ="yellow" points="80,80 70,85 90,90"/>
    </svg>}
    # create image
    image create photo foo -data $data
    # change size
    foo configure -format {svgnano -scale 2}
    # move right and up, all other values are reset
    foo configure -format {svgnano -x 10 -y -20}
    # use other unit
    foo configure -format {svgnano -unit mm}

# Alternatives

- Use of another library with full SVG support instead of the current proposal for partial support: could be done as a further step.

- Direct manipulation of SVG vector graphics (as opposed to the present proposal of converting SVG to pixel format in a photo) would be desirable. However this can always be done later, for instance in the frame of the canvas widget. It is deemed an already large improvement to have Tk be able to read SVG images and convert them to pixel-based photos.

# Copyright

This document has been placed in the public domain.