Tk Source Code

View Ticket
Login
2009-10-11
02:39 Closed ticket [1961455f]: Font underlining seems broken on X11 plus 8 other changes artifact: 51c15676 user: dkf
2009-04-24
14:18 Ticket [1961455f]: 4 changes artifact: b3d8a26c user: dkf
2009-04-23
23:05 Ticket [1961455f]: 4 changes artifact: 24b039b3 user: nobody
2009-04-04
20:22 Ticket [1961455f]: 4 changes artifact: 071317ba user: dkf
2009-01-14
02:06 Ticket [1961455f]: 1 change artifact: f3f7fb4c user: patthoyts
2008-09-11
22:14 Ticket [1961455f]: 4 changes artifact: 74b0fd34 user: teopetuk
18:22 Ticket [1961455f]: 4 changes artifact: 4f5c3a3b user: nobody
17:15 Ticket [1961455f]: 4 changes artifact: 2e40917c user: nobody
2008-09-10
20:38 Ticket [1961455f]: 4 changes artifact: b0392791 user: teopetuk
20:21 Ticket [1961455f]: 4 changes artifact: 1da86949 user: teopetuk
2008-05-10
18:23 Ticket [1961455f]: 4 changes artifact: 18d56aa1 user: pcaffin
11:17 New ticket [1961455f]. artifact: 6ddda3c0 user: pcaffin

Ticket UUID: 1961455
Title: Font underlining seems broken on X11
Type: Bug Version: obsolete: 8.5.2
Submitter: pcaffin Created on: 2008-05-10 11:17:34
Subsystem: 46. Unix Fonts Assigned To: dkf
Priority: 9 Immediate Severity:
Status: Closed Last Modified: 2009-10-11 02:39:36
Resolution: Fixed Closed By: dkf
    Closed on: 2009-10-10 19:39:36
Description:
The following should see the label's font underlined during mouse-over.

===========
catch {font create url}
catch {font create urlmo}
font configure url   -family Arial -size 12 -underline 0
font configure urlmo -family Arial -size 12 -underline 1

grid [ttk::label .l -text "Should be underlined on mouse-over." -font url -foreground darkgreen]

bind .l <Enter> ".l configure -cursor hand2 -font urlmo -foreground darkblue" 
bind .l <Leave> ".l configure -cursor arrow -font url -foreground darkgreen" 
bind .l <Button-1> ".l configure -font urlmo -foreground red ; # someProc"
===========

The font's colour changes on X11 (so the rest of the configure works).

Underline tested OK on Windows and Mac OS X.
User Comments: dkf added on 2009-10-11 02:39:36:

allow_comments - 1

Fixed for 8.5 and HEAD.
The HEAD fix was awkward because the underline/overstrike had to also work rotated...

dkf added on 2009-04-24 14:18:32:
The fundamental problem is that xft/fontconfig doesn't provide a mechanism for determining the underlining metrics (position and size of underline rule, though size is not critical).

[email protected] added on 2009-04-23 23:05:53:
is there a plan to fix this?  It seems like using the "old (ugly) font engine" (ID: 2778846) using the --disable-xft option to configure might not even fix the underline problem (from  teopetuk on Date: 2008-09-10 13:38, below) and would probably introduce old issues as well.
I have tested this underline problem up to 8.5.7, and it still doesn't work, even though there is a "Group:" status as "obsolete: 8.5.2". Is that right?
I see a code change below, but should this change be incorporated into the code base?

thanks,

Blaine

dkf added on 2009-04-04 20:22:10:
Much googling indicates that Keith Packard forgot to include (or deliberately omitted) properties for the underline position and rendering in Xft/fontconfig.

At least one alternative puts the underline at 0.1 of the character height (within the bounding box cell), or at 0.5 for strikeout.

teopetuk added on 2008-09-11 22:14:09:
After looking through unix/tkUnixRFont.c I'd say that neither -underline nor -overstrike are implemented for Xft fonts. So, curently the only way to get underlined or overstricken fonts outside text widget is to use X core fonts.

[email protected] added on 2008-09-11 18:22:43:
Sorry... i mean _overstrike_
This is a code snippet that works fine in linux wish8.4 but not 8.5
-----
set LABEL1 [label .l1 -text {overstrike = 0}]
set LABEL2 [label .l2 -text {overstrike = 1}]
set lFont [$LABEL1 cget -font]
set overstruckfont [font actual "[font actual $lFont] -overstrike 1"]
.l2 configure -font $overstruckfont
pack .l1 -side top
pack .l2 -side bottom
-----

[email protected] added on 2008-09-11 17:15:37:
Font understrike doesn't work either on all 8.5 i've tested, up to 8.5.4.
(stevenaaus)

teopetuk added on 2008-09-10 20:38:39:
Apparently I've tested the patch using Xft-disabled build. So, while it fixes canvas postscript problem, it doesn't fix underlined fonts. Sorry for the noise.

teopetuk added on 2008-09-10 20:21:26:
While investigating another font related bug (see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498408) I've found that when using old X11 fonts Tk never uses negative font sizes (it converts them to positive throug TkFontGetPoints()). So, I suppose that there's code which uses fonts and implicitly assumes that its size is always positive.

After applying the attached patch which simply converts font size to a positive value (size in points) both bug in canvas and this bug are gone. Though probably in long run it would be better to find code which cannot work if font size is negative and fix it.

(Can't find how to attach the patch, so listing it here)

--- tk8.5-8.5.4.orig/unix/tkUnixRFont.c
+++ tk8.5-8.5.4/unix/tkUnixRFont.c
@@ -260,6 +260,7 @@
     ftFont = GetFont(fontPtr, 0);
     fontPtr->font.fid = XLoadFont(Tk_Display(tkwin), "fixed");
     GetTkFontAttributes(ftFont, &fontPtr->font.fa);
+    fontPtr->font.fa.size = TkFontGetPoints(tkwin, fontPtr->font.fa.size);
     GetTkFontMetrics(ftFont, &fontPtr->font.fm);
 
     return fontPtr;
@@ -517,6 +518,7 @@
 /* Actual font used to render the character */
 
     GetTkFontAttributes(ftFont, faPtr);
+    faPtr->size = TkFontGetPoints(tkwin, faPtr->size);
     faPtr->underline = fontPtr->font.fa.underline;
     faPtr->overstrike = fontPtr->font.fa.overstrike;
 }

pcaffin added on 2008-05-10 18:23:57:
Logged In: YES 
user_id=2029956
Originator: YES

The first example using ttk::label, but, I've just tested with the standard Tk label and it's much the same. Definitely font related rather than widget related.