tk scaling

The Tcl/Tk command »tk scaling« is used to query and set the resolution. The default value for tk scaling is »1.0« which reads as »72ppi«. 72ppi is also the hard coded value for tk scaling under AQUA®. Tk scaling is thus inactive under AQUA®.

Tk scaling operates on each dimension property. Dimensions must be specified in resolution independent terms. Resolution independent measurements are: »p«, »i«, »c« and »m«. A dimension without any postfix is given in pixels, and thus the design becomes resolution dependent.

Fonts are defined in points. a leading - minus sign defines the font size in pixels . Only use pixels font size under peculiar circumstances, and never for any ordinary design work!

Example 7.5. Font size in Pixels

# Use »-size 20« for a 20 points font!
font create myfont \
   -family {bitstream vera sans} \
     -size -20
          

Resolution Independent Dimensions

p

»p« is a abbreviation for point. meaning the 72th part of an inch. This is the default measurement for fonts.

m, c

Metric measurements »c« := centimeter and »m« := millimeter.

i

Measured in »Inch«.

Example 7.6. Using Resolution Independent Measurement

# Button border with one point.
option add *Button.borderWidth 1p

# Internal 2mm white space.
option add *Button.padX 2m

# A 20 point height font for buttons.
option add *Button.font \
   {{bitstream vera sans} 20}
        

Test the resolution independence for a new application. Use »tk scaling« for testing the resolution independence. Keep in mind tk scaling doesn’t work under AQUA®!

Example 7.7. Test Resolution Independency

# Start wish from a terminal application:
/usr/bin/wish
# set scaling to factor 2, resembling 144ppi.
tk scaling 2.0;
source »the application«
        

Use »winfo pixels« to translate a resolution independent value into it its pixel equivalent. This is necessary for all TkPath items.

Example 7.8. Using winfo pixels

button .b
puts stdout \
   "4p are [winfo pixels .b 4p] in pixels!"