Tk Source Code

View Ticket
Login
Ticket UUID: 2408101
Title: font sizes limited to integer values
Type: Bug Version: obsolete: 8.6a4, 8.6.18, 9.0.5, 9.1b1
Submitter: gregcouch Created on: 2008-12-09 01:10:34
Subsystem: 46. Unix Fonts Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Open Last Modified: 2026-09-30 10:52:49
Resolution: None Closed By:
    Closed on:
Description:
I believe this bug applies to fonts on all platforms with antialiased fonts and is present in all current versions of Tk. In tk8.*/generic/tkFont.h, TkFontAttributes.size is an integer.  So tkFont's converting between pixels and point sizes is inaccurate.  Also, with modern Linux font support, the user can type in non-integer point sizes for fonts in the standard font choosers.

For example, on Fedora 7 with gnome:

$ gconftool-2 --get /desktop/gnome/interface/font_name
Nimbus Sans L Condensed 11.5
$ wish
% tk scaling
1.47246376812

So is that a 16 pixel or 17 pixel high font?  What if it were 11?

The request is that TkFontAttributes.size be changed to be a float.
User Comments: serhiy.storchaka added on 2026-09-30 10:52:49:

The size is a double internally now (TkFontAttributes.size), but the Tcl interface still requires an integer: font create -size 11.5 fails with "expected integer but got "11.5"", and font actual rounds the size to an integer number of points.

This is part of [220849]. I implemented fractional font sizes there: -size accepts a fractional number, and font actual reports the actual size in points without rounding. With tk scaling 1.47, as in the example above, {Helvetica 11.5} is rendered at 16.9 pixels with Xft, and at 17 pixels (11.56 points) with X core fonts. Choosing between the variants described in [220849] needs a wider discussion.