TIP 545: image photo SVG options: remove -unit and add target height/width option

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Author:         Harald Oehlmann <[email protected]>
State:          Draft
Type:           Project
Vote:           Pending
Created:        19-May-2019
Keywords:       Tk, image
Tcl-Version:    8.7
Tk-Branch:     tip-545-svg-options

Abstract

Image photo SVG support was added to Tk by TIP 507. This TIP is about the options of SVG rendering:

Rationale

This TIP included two components:

Remove option "-unit"

Remove the option "-unit", which has no effect. The given unit is used to set the unit of the intermediate set of polygons. The final unit is pixel anyway, so setting this to anything else than pixels does not make sense.

Add a possibility to scale to a given width or height in pixels

A common usage of svg is to render button images for a given button height or width. Buttons of applications may have all the same height or width when aranged in button lines aranged horizontally or vertically.

The current solution to render a svg to a given height "$height" is:

image create photo p -file "test.svg"
set imageHeight [image height p]
p configure [list svg -scale [expr {double($height) / $imageHeight}]

This two step procedure has a high performance impact, as the image is rendered twice. The aim is to render it only once by one parameter.

Specification

Remove option "-unit"

Add new option -scaletoheight

The option "-scaletoheight entier" specifies the image height in pixels to scale to. The image width is found by the aspect-ratio.

Example with an image "test.svg" with an aspect ration of width:height = 2:1. The required height is 16 pixels:

% image create photo p -file "test.svg" -format {svg -scaletoheight 16}
p
% image height p
16
% image width p
32

The entier argument must be positive. The option may not be specified together with "-scale" and/or "-scaletowidth".

Add new option -scaletowidth

The option "-scaletowidth entier" specifies the image width in pixels to scale to. The image height is found by the aspect-ratio.

Example with an image "test.svg" with an aspect ration of width:height = 2:1. The required width is 16 pixels:

% image create photo p -file "test.svg" -format {svg -scaletowidth 16}
p
% image width p
16
% image height p
8

The entier argument must be positive. The option may not be specified together with "-scale" and/or "-scaletoheight".

Implementation

Implementation may start soon with the tag tip-545-svg-options.

Copyright

This document has been placed in the public domain.