Tk Source Code

View Ticket
Login
Ticket UUID: d4e20ca3dc74316187a79eb7b464665526c8b27b
Title: Font height calculation seems to be wrong
Type: Bug Version: 8.6
Submitter: anonymous Created on: 2017-01-23 11:01:03
Subsystem: None Assigned To: nobody
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2017-08-22 06:22:56
Resolution: Invalid Closed By: fvogel
    Closed on: 2017-08-22 06:22:56
Description:
(I was told to reopen this bug report here, as my, but as it was not found I 
have created a new one.  Ref: <http://core.tcl.tk/tcl/tktview
/185712c86116912ee9b853ee2e1ec9f39365d8ad>)

The priority should possibly be set to something that would correspond to
"annoying!".

Problem description:
The lower few points of fonts are missing, at least for some (fonts and) sizes.

Font used:                     DejaVu Sans Mono
Problem visible at sizes:      4, 7, 10
Lower line(s) disappear for:   '_', not so visible for g,j,p,q and y 

OS: Linux/Ubuntu 16.10 (I do not think the problem was present in the 16.04
    version)
HW:   Lenovo y70-70 Touch

The impact is less for large fonts as there are more points available.

I have confirmed that wish itself (or sub-functionality) and not git-gui is to
blame using the console.tcl found at <http://wiki.tcl.tk/786> referenced from
<http://wiki.tcl.tk/36843>. I have also verified that the problem is not found
in Libre Office Writer for the same fonts and sizes. 

Preliminay analysis:
It seems that the lower line(s) are missing when the font size, n, devided by 3
gives m + 1/3 and is rounded down to m. (integer division). If the value had
been rounded up, the problem would probably not appear/exist.

Workaround alternatives:
- Change font.
- Change font size.
- Stop using underscores.

Discovery:
I have been using wish through git-gui for some years. When comparing versions
using git-gui I noticed that the underscores were missing and the code looked
very strange. If this had been normal texts (like from a book etc) the problem
would not be so severe. But as I am a C programmer, underscores (_) are often
used to separate words in a variable or function name etc. This would therefore
apply to other C programmers as well.

I believe the problem appeared when changing from Ubuntu 16.04 to Ubuntu 16.10.
User Comments: fvogel added on 2017-08-22 06:22:56:

x-ref: [6386ce66a4]


fvogel added on 2017-01-28 12:30:49:
Done, thanks!

anonymous added on 2017-01-27 21:58:31:
Yes, it can be closed.

fvogel added on 2017-01-27 20:36:10:
My understanding then is that this is a font bug, not a Tk bug, and that the present ticket can therefore be closed. Correct?

anonymous added on 2017-01-27 07:57:53:
I installed the older core package (v 2.35-1) of DejaVu and trouble went away :-)

bll added on 2017-01-26 14:49:55:
Yes it appears to be a font hinting bug.

Here, the user was able to download and install a new freetype package to resolve the issue:

http://askubuntu.com/questions/781430/font-or-windows-scaling-changed-between-15-10-and-16-04

Or simply configure your system to use a different monospace font for the time being.

anonymous added on 2017-01-26 14:27:56:
Just found out that eclipse has (more or less) the same issue.  The lower part of the font disappears.  Seems the underscore gets cut in half at 10 points and so it is still visible.  At 7 points the underscore disappears.  

It is just a tad better in eclipse compared to wish.

The referenced bug report seems to be similar (at least).

bll added on 2017-01-24 20:02:57:
Possibly related:

https://bugs.launchpad.net/ubuntu/+source/fonts-dejavu/+bug/1589046

bll added on 2017-01-24 19:38:04:
DejaVu Sans Mono is the only mono spaced font that appears to have this problem.


package require Tk

ttk::label .ts -text [tk scaling]
pack .ts -anchor w

set text {abc_jgpq_def}

set fonts [list]
font create tempf
foreach {f} [lsort -nocase -unique [font families]] {
  font configure tempf -family $f
  array set fm [font metrics tempf]
  if { $fm(-fixed) } {
    lappend fonts $f
  }
}

# [list 4 5 6 7 8 9 10 11 12 13]
foreach {s} [list 10] {
 foreach {ff} $fonts {
  font create f$ff$s
  font configure f$ff$s -size -$s -family $ff
#  font configure f$s -size -$s -family {DejaVu Sans Mono}
#  font configure f$s -size -$s -family {Droid Sans Mono}
#  font configure f$s -size -$s -family {Courier New}
  label .ll$ff$s -text \
      "$ff: $s: $text" \
      -font f$ff$s
  pack .ll$ff$s -anchor w
  ttk::label .l$ff$s -text $text -font f$ff$s
  pack .l$ff$s -anchor w
  text .t$ff$s -height 2 -width 40 -font f$ff$s
  .t$ff$s insert 0.0 $text
  .t$ff$s insert end "\nactual:[font actual f$ff$s] metrics:[font metrics f$ff$s]"
  pack .t$ff$s -anchor w
 }
}

bll added on 2017-01-24 19:15:29:
It appears that starting with Ubuntu 16.04, the DejaVu Sans Mono metrics changed:
16.04: ascent 9 descent 2 linespace 11
15.02: ascent 10 descent 3 linespace 13

Windows with courier new and droid sans mono did not have any issues.
The other thing I can try is testing all of the mono spaced fonts available on 16.04/10 and see if any others have an issue.

Current script:

package require Tk

ttk::label .ts -text [tk scaling]
pack .ts -anchor w

set text {abc_jgpq_def}

foreach {s} [list 4 5 6 7 8 9 10 11 12 13] {
  font create f$s
  font configure f$s -size -$s -family {DejaVu Sans Mono}
#  font configure f$s -size -$s -family {Droid Sans Mono}
#  font configure f$s -size -$s -family {Courier New}
  label .ll$s -text \
      "$s: $text" \
      -font f$s
  pack .ll$s -anchor w
  ttk::label .l$s -text $text -font f$s
  pack .l$s -anchor w
  text .t$s -height 2 -width 40 -font f$s
  .t$s insert 0.0 $text
  .t$s insert end "\nactual:[font actual f$s] metrics:[font metrics f$s]"
  pack .t$s -anchor w
}

fvogel added on 2017-01-24 18:47:58:
Looking for common grounds in the tests you made: What does [font actual] and [font metrics] spit in all these cases? My guess is that the font actually used could be different from what would be expected at first sight from the -family specification.

bll added on 2017-01-24 18:29:48:
Ubuntu 16.10: DejaVu Sans Mono / 8.6.6 : bug present
Ubuntu 16.10: Courier New / 8.6.6 : no problem
Ubuntu 16.04: DejaVu Sans Mono / 8.6.5 : bug present
Ubuntu 16.04: Courier New / 8.6.5 : no problem
Ubuntu 15.02 (32-bit): DejaVu Sans Mono / 8.6.1 : no problem
Ubuntu 15.02 (32-bit): DejaVu Sans Mono / 8.6.6 : no problem
Ubuntu 15.02 (32-bit): Courier New / 8.6.1 : no problem
Ubuntu 15.02 (32-bit): Courier New / 8.6.6 : no problem
Linux Mint 17.3 (ubuntu 14.04): DejaVu Sans Mono / 8.6.1 : no problem
Linux Mint 17.3 (ubuntu 14.04): DejaVu Sans Mono / 8.6.6 : no problem
Linux Mint 17.3 (ubuntu 14.04): Courier New / 8.6.1 : no problem

bll (claiming to be [email protected]) added on 2017-01-24 18:15:16:
Appears to happen with the 'text' widget at certain sizes with certain fonts.
See attached image 2017-01-24.png.
Changing the height of the 'text' widget did not make a difference.

( font configure f$s -size -$s -family {DejaVu Sans Mono} )

At this point, only tested on Ubuntu 16.10.

bll added on 2017-01-23 22:23:47:
# Redo with pixels sized fonts:

package require Tk

ttk::label .ts -text [tk scaling]
pack .ts

set text {abc_jgpq_def}

foreach {s} [list 4 5 6 7 8 9 10 11 ] {
  font create f$s
  font configure f$s -size -$s
  label .ll$s -text $text -font f$s
  pack .ll$s -anchor w
  ttk::label .l$s -text $text -font f$s
  pack .l$s -anchor w
  text .t$s -height 1 -width 17 -font f$s
  .t$s insert 0.0 $text
  pack .t$s -anchor w
}

bll (claiming to be [email protected]) added on 2017-01-23 22:19:41:
package require Tk

ttk::label .ts -text [tk scaling]
pack .ts

set text {abc_jgpq_def}

foreach {s} [list 4 5 6 7 8 9 10 11 ] {
  font create f$s
  font configure f$s -size $s
  label .ll$s -text $text -font f$s
  pack .ll$s -anchor w
  ttk::label .l$s -text $text -font f$s
  pack .l$s -anchor w
  text .t$s -height 1 -width 17 -font f$s
  .t$s insert 0.0 $text
  pack .t$s -anchor w
}

bll (claiming to be [email protected]) added on 2017-01-23 19:46:28:
Unable to duplicate.
Fresh install of Ubuntu 16.10 ; Unity ; Tcl 8.6.6

Which desktop manager are you using?

A script that reproduces the problem would be useful.

Attachments: