* Mark Summerfield <[email protected]>
| It fails with this error:
| Error in startup script: unknown option "-scaletowidth"
| while executing
| "image create photo -file $svg {*}$opt"
| (procedure "icon" line 3)
| invoked from within
| "icon test.svg 24"
| invoked from within
| "ttk::button .button -command {destroy .} -image [icon test.svg 24]"
| (file "./svgtest2.tcl" line 8)
| Can someone tell me what I'm doing wrong?
| I'm using Tcl/Tk 9.0b2 on Debian Linux.
The manpage says:
Image formats may support sub-options, which are specified using
additional words in the value to the -format option.
This sounds to me as if you need to specify the additional options like -scaletowidth *with* the -format option, like so:
-format [list svg -scaletowidth 24]
instead of
-format svg -scaletowidth 24
R'
I think adding support for SVG images is a real plus for Tk.
* Mark Summerfield <[email protected]>[snip]
| Can someone tell me what I'm doing wrong?
| I'm using Tcl/Tk 9.0b2 on Debian Linux.
The manpage says:
Image formats may support sub-options, which are specified using
additional words in the value to the -format option.
This sounds to me as if you need to specify the additional options like -scaletowidth *with* the -format option, like so:
-format [list svg -scaletowidth 24]
instead of
-format svg -scaletowidth 24
On Mon, 08 Jul 2024 14:16:45 +0200, Ralf Fassel wrote:
* Mark Summerfield <[email protected]>[snip]
| Can someone tell me what I'm doing wrong?
| I'm using Tcl/Tk 9.0b2 on Debian Linux.
The manpage says:
Image formats may support sub-options, which are specified using
additional words in the value to the -format option.
This sounds to me as if you need to specify the additional options like
-scaletowidth *with* the -format option, like so:
-format [list svg -scaletowidth 24]
instead of
-format svg -scaletowidth 24
Thank you, I'm now using:
proc util::icon {svg {width 0}} {
set opt [expr {$width ? [list -format [list svg -scaletowidth $width]]
\
: ""}]
image create photo -file $::PATH/images/$svg {*}$opt
}
And when I call this for menu items I use:
set width [expr {int(16 * [tk scaling])}]
...
-image [util::icon new.svg $width]
The 'int' is *essential* since -scaletowidth won't accept a real.
I think adding support for SVG images is a real plus for Tk.
The way you are using [tk scaling] is not quite correct. I guess your intention was to scale 16 x 16 px images according to the display's (or
Tk's) scaling level. However, [tk scaling] is the number of pixels per point, hence it is not appropriate for scaling a width given in pixels.
The recommended method in Tk 9 is to use the variable tk::svgFmt when creating scaling-aware images (see man tk_svgFmt). This variable is set
at Tk initialization time to {svg -scale 1.0}, {svg -scale 1.25}, etc.,
and is updated automatically if you increase the scaling with the aid of
the "tk scaling" command. For example, if you invoke "tk scaling
1.666666" or "tk scaling 1.7" then tk::svgFmt will automatically become
{svg -scale 1.25}, hence its use as the value of the -format option will result in images of the size 20 x 20 px.
On Tue, 9 Jul 2024 11:15:38 +0200, nemethi wrote:
[snip]
The way you are using [tk scaling] is not quite correct. I guess your
intention was to scale 16 x 16 px images according to the display's (or
Tk's) scaling level. However, [tk scaling] is the number of pixels per
point, hence it is not appropriate for scaling a width given in pixels.
The recommended method in Tk 9 is to use the variable tk::svgFmt when
creating scaling-aware images (see man tk_svgFmt). This variable is set
at Tk initialization time to {svg -scale 1.0}, {svg -scale 1.25}, etc.,
and is updated automatically if you increase the scaling with the aid of
the "tk scaling" command. For example, if you invoke "tk scaling
1.666666" or "tk scaling 1.7" then tk::svgFmt will automatically become
{svg -scale 1.25}, hence its use as the value of the -format option will
result in images of the size 20 x 20 px.
when I try:
puts $tk::svgFmt
I get "Error in startup script: can't read "tk::svgFmt": no such variable"
But in any case it wouldn't give me what I want.
I have svg images that I'm using as icons that happen to have a notional
size of 48x48 px. The scale factor of 16 * [tk scaling] simply represents
the size that works for me (i.e., makes the icons a little taller than a capital letter), say for the File menu's "New" menu item. So I'm not
really scaling to a particular pixel size, just a size that works visually and that should work at different scales on different screens (although I haven't yet tried that).
In Tk 9 it makes a difference whether you write $tk::svgFmt or
$::tk::svgFmt -- the former will only work at global level.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 02:21:26 |
| Calls: | 12,098 |
| Calls today: | 6 |
| Files: | 15,003 |
| Messages: | 6,517,869 |