KDiff3 font rendering of changed text broken

Bug #999925 reported by Jonas T. on 2012-05-15
This bug affects 42 people
Affects Status Importance Assigned to Milestone
kdiff3 (Ubuntu)

Bug Description

In a number of versions of Ubuntu (including 12.04, 13.10, 14.04, XUbuntu 12.04, and probably others) the font rendering of changed text parts is broken. It seems as if the kerning is not evaluated correctly.

Steps to reproduce:
- compare two files with differences
- the changed parts will have partially unreadable characters, looking as if multiple characters are rendered atop of each other instead of next to each other

Selecting the incorrectly rendered parts of the text magically fixes the rendering inside the selection, but just 'moves' the broken rendering outside of the selection.

-Selecting particular font face & size combinations can alleviate the issue for many users.

Jonas T. (jo-t) wrote :
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in kdiff3 (Ubuntu):
status: New → Confirmed
ugtar (uokrent) wrote :

I've found that the problem goes away at various font sizes. For example, I have the problem at font size 11 (which was my preferred font size). If I change it to 12 or 9, the problem goes away. I'm using font size 9 for now (but the text is a little tiny)

Benoît Thébaudeau (btheb) wrote :

I'm affected by this bug too. I have also noticed that it depends on the font and on the font size.

For me, it occurs whether Kdiff3 is run from Unity 2D/3D or Gnome Classic/Shell.

My Ubuntu 12.04 is installed as a VMware Player guest within a Windows 7 host.

The worst consequence of this bug for me is that if you edit a modification during a manual merge, the cursor is not showing where you are actually typing, but a few characters before. This is a nightmare to use.

This bug may be common to all KDE applications: With Kate or Kdevelop, the same column is not painted at the same position for all lines (using mono fonts). E.g., you can see on the attached screenshot that "int a" and "int b" are not aligned albeit on the same column. It also depends on the font and on the font size.

Jonas T. (jo-t) wrote :

Interestingly, I cannot see any difference if I vary the used font and font size. Of course, I havent tried all combinations, but at least from some experients with 3 fonts (Monospace, DeJaVu Sans Mono, and FreeMono) and varying font sizes from 7 to 18, I cannot confirm that the bug is really gone with any of those combinations.

The bug is always there. The only thing that varies is its "visible effect". That is, the smaller the font size, the worse the effect. The overlapping of characters is worse with smaller font sizes and less visible with larger font sizes. However, the "moving" of the broken rendering outside of the selection is very visible with all font sizes I tried.

description: updated
Benoît Thébaudeau (btheb) wrote :

According to the few tests I have performed, there seems to be one particular size specific to each font that makes this rendering bug invisible. For my configuration, this size is 10.0 for Monospace Regular, and 9.0 for Ubuntu Mono Regular.

Jonas T. (jo-t) wrote :

Ok, that I can confirm. For the fonts you mentioned, the same font sizes work correctly here.

mar (marltu) wrote :

t also affects cursor location (it looks like the same bug). I attached screenshot of cursor location (which is actually at the end of line). Adding more text pushes cursor even more to the left.

Benoît Thébaudeau (btheb) wrote :

Yes, it's the same bug. It's what I explained in comment 4 about the cursor.

I can confirm this bug.

Trying size 9 with Ubuntu Mono Regular the problem is minimized but not entirely gone. Other fonts and other sizes are basically unusable.


I (developer of KDiff3) now also had a look into this bug.

On Ubuntu 12.04 I can reproduce it too.

When making a screenshot and zooming in, it appears that same characters are
rendered differently every time.

Qt provides an integer based QFontMetrics and a QFontMetricsF class that
returns double values. For normal widgets previously QFontMetrics was
sufficient because the width of a character was an integer value in pixels
only. This seems to have changed because QFontMetricsF::width() returns values
that are no ints.

For the moment I can only say that I am working on a solution.

And with a little test I was able to find two fonts that still have an integer
Ubuntu Mono, Regular, Size 12
Ubuntu Mono, Regular, Size 9

Benoît Thébaudeau also pointed out Monospace Regular, Size 10, which comes
very close (8.0156 instead of 8.000) and should suffice mostly.

Yet if anyone can tell where this problem comes from, I'd like to know.
Disabling antialiasing globally didn't help. (See /etc/fonts/conf.d/10-

One more possible idea would be to build Qt yourself and disable fontconfig (
configure option "-no-fontconfig".)


joachimeibl (joachim-eibl) wrote :

Another workaround: Use a bitmap font like "Fixed [misc]".
See also https://wiki.ubuntu.com/Fonts#Enabling_Bitmapped_Fonts


Jonas T. (jo-t) wrote :


good to hear you are working on it!

It may be worth checking with the KDevelop people. I have seen very similar behavior there shortly after I reported the bug. NB: I'm not using KDevelop actively -- they might have fixed the bug in the meantime.


joachimeibl (joachim-eibl) wrote :


I now made an inofficial version for you to test:

I changed the internal renderer to use QTextLayout from Qt. This means
that even variable width fonts should work fine now.

Please write if this works for you or if you still have some issues with it.


gc (greger-cronquist) wrote :

I've been using a version I pulled from git a few days back (when I saw the commit on QTextLayout), and for me it's resolved the font rendering issues. That said, I only use fixed width fonts, not truly variable width.

Cheers, Greger

Benoît Thébaudeau (btheb) wrote :

Hi Joachim,

I've just tested your package with Monospace Regular 9.0.

The issue of overlapping colored characters in the diff view is fixed.

The issue of the cursor displayed at a wrong position is fixed.

I still have an issue with the width displayed for tab characters with the text from my screenshot in comment #4 (the second line starts with 6 tabs and 1 space). I get exactly the same result as before. However, if I replace each tab with 8 spaces in this text, then the display is correct contrary to before. Your package still does not display tabs as exactly 8-space wide.

Also, when you will have fixed tabs, can you do the same fix for Kate and Kdevelop?

Best regards,

Jonas T. (jo-t) wrote :


for fixed-width fonts, the problem seems to be resolved with kdiff3-0.9.98a.

In contrast to what Benoît reports, tab rendering with fixed-width fonts and interleaved tab+space usage (e.g., 1 tab followed by 4/8 spaces) is perfect here, at least for tab widths 4 and 8. I haven't check any other tab widths. However, kate and kile packages show funny offsets when rendering text with interleaved tab+spaces.

I didn't/couldn't check with variable-width fonts -- it seems KDiff3 doesn't even let me select such fonts.


joachimeibl (joachim-eibl) wrote :

In the git repo on sourceforge I've now fixed the tab issue and the problem
that the kde-version didn't allow to select variable width fonts.

Regarding the tab width: I had to use
 QFontMetricsF( font() ).width(' ') * tabSize
to calculate the correct width instead of the previously used
      fontMetrics().width(' ')*tabSize
which is only integer based.

I also wrote to the mailing list for kate and kwrite (<email address hidden>)
and told them about this issue and my workaround.


Jonas T. (jo-t) wrote :

Yep, revision 21cbbda works here, also with variable-width fonts.

Just a side note/question: The diff settings toolbar ("show whitespace" option etc.)has disappeared in this version and I can't find a way, not even in cmake, to re-enable it?

Benoît Thébaudeau (btheb) wrote :

Thanks Joachim, everything is now fixed for me.

Just some nit picking: When merging files, the cursor now leaves a black pixel when blinking. This pixel follows the cursor, so it's not a big problem.

Best regards,

Benoît Thébaudeau (btheb) wrote :

Hi Joachim,

This bug is still present in Ubuntu 12.10, for both KDiff3 and Kate. When will your fix be applied?

Best regards,

Am Freitag, 2. November 2012, 18:40:49 schrieben Sie:
> Hi Joachim,
> This bug is still present in Ubuntu 12.10, for both KDiff3 and Kate.
> When will your fix be applied?
> Best regards,
> Benoît

Hi Benoît and all others waiting for the fix,

The changes I made to KDiff3 to fix this problem and others were quite
substantial because I thought (and still think) that using QTextLayout is the
way to go.

But after some testing I also see that the text layouting step takes very long
for certain files that are either binary files or decoded as utf8 when they
are not. The text layouting can take several minutes even for short files
then. When only comparing a file this might not be such a problem, but when
doing a big directory merge, this definitely is, because killing the KDiff3-
process then will also discard the directory merge states.

A solution would be to start a separate process for each file comparison or to
provide other means of interrupting the text layout process.

Seeing these difficulties I might also go for completely different solution,
that does not have these problems.

Yet currently I also have very little time to implement and test these ideas.
Sorry for that.

Regarding Kate: That's a different project. I wrote to that mailing list
already, but please don't expect any fix from me.

Best regards,

Benoît Thébaudeau (btheb) wrote :

Hi Joachim,

Here is the status for me on Ubuntu 13.04 with Monospace Regular 9.0:
 - The issue of overlapping colored characters in the diff view is fixed.
 - The issue of the cursor displayed at a wrong position is still present.
 - The issue of the wrong width displayed for tab characters with the text from my screenshot in comment #4 (the second line starts with 6 tabs and 1 space) is still a little bit present in the A/B/C views (there is an offset of about 2 pixels between both lines), but fixed in the Output view.
 - The issue of the black pixel left when blinking in the Output view is fixed.

Best regards,

Patrick Strasser (c-patrick) wrote :

For me here with Ubuntu 13.04, problems still exist with Monospace Regular 9.0 (which seems to be default)
  - I still have overlapping characters
  - When I click into text, even previously unaffected text parts get shifted left and have overlapping characters.
I can not say anything about tabs, do not have an example.

My version here is 0.9.97-1ubuntu

I have the same issue with Monospace Regular 9.0 on Ubuntu 12.04.
When I choose 10.0 as font size as workaround, the setting is only effective until I exit KDiff3, then KDiff3 forgets the font setting because of bug 1074468.
This is quite annoying when launching KDiff3 for editing multiple files from a script.
Thus I have to choose the font for each of the >100 files to diff. :-(

tags: added: precisecise
tags: added: precise
removed: precisecise
Benoît Thébaudeau (btheb) wrote :

With Ubuntu 13.10, all the issues described in this KDiff3 bug are back.

Andrew Schwartz (aschwartz) wrote :

Has anyone been able to find a workaround?

With Ubuntu 13.10, kdiff3 0.9.97, I'm seeing the problem but can't work around it using font size 10.

Andrew Schwartz (aschwartz) wrote :

Attaching screenshot with monospace 9

Andrew Schwartz (aschwartz) wrote :

Attaching screenshot with monospace 11

Benoît Thébaudeau (btheb) wrote :

Hi Andrew,

Are you sure about your font settings? On my 64-bit Ubuntu 13.10 machine, Monospace normal 10 is still a valid workaround for this issue with KDiff3 4.11.5 0.9.97-1ubuntu1.


Andrew Schwartz (aschwartz) wrote :

Yes, I'm sure. Attached please find everything in a single screenshot (the two cat'ed files, the kdiff3 diff display, and the font dialog box).

I am on a 64-bit Ubuntu 13.10 machine. Kdiff3 4.11.5 0.9.97

Benoît Thébaudeau (btheb) wrote :

So maybe it's your test files that allow to show the issue and not mine, or there is something depending on some machine settings. How many tabs or spaces are there before "ab" and "ac" in your test files?

Andrew Schwartz (aschwartz) wrote :

Might be easier for me to just give you the files.

Please find the first file attached.

Andrew Schwartz (aschwartz) wrote :

And here's file2.

Benoît Thébaudeau (btheb) wrote :

I have just tested again with your files, and I don't experience your issue.

From your screenshot, you seem to be using a theme, a skin or something, and not the default Ubuntu layout. Maybe this disturbs KDiff3 a bit more, or there is something else specific to your machine triggering the issue.

Andrew Schwartz (aschwartz) wrote :

I'm running KDE. That seems to be the issue.

I just tried Monospace 10 under Gnome and Unity and the problem is solved.

I'm running KDE 4.11.5.

Benoît Thébaudeau (btheb) wrote :

Still broken in Ubuntu 14.04.

tags: added: trusty
Changed in kdiff3 (Ubuntu):
importance: Undecided → High
ChrisW (chrisw6543) on 2014-10-01
description: updated
Benoît Thébaudeau (btheb) wrote :

This appears to be fixed for me in Ubuntu 14.10.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers