KDiff3 font rendering of changed text broken

Bug #999925 reported by Jonas T.
206
This bug affects 42 people
Affects Status Importance Assigned to Milestone
kdiff3 (Ubuntu)
Confirmed
High
Unassigned

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.

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

Revision history for this message
Jonas T. (jo-t) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

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

Changed in kdiff3 (Ubuntu):
status: New → Confirmed
Revision history for this message
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)

Revision history for this message
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.

Revision history for this message
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
Revision history for this message
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.

Revision history for this message
Jonas T. (jo-t) wrote :

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

Revision history for this message
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.

Revision history for this message
Benoît Thébaudeau (btheb) wrote :

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

Revision history for this message
Carl-Eric Menzel (duesenklipper) wrote :

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.

Revision history for this message
joachimeibl (joachim-eibl) wrote : Re: [Bug 999925] [NEW] KDiff3 font rendering of changed text broken

Hi,

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
width.
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-
antialias.conf)

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

Regards,
Joachim

Revision history for this message
joachimeibl (joachim-eibl) wrote :

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

Joachim

Revision history for this message
Jonas T. (jo-t) wrote :

Hey,

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.

Best,
Jonas

Revision history for this message
joachimeibl (joachim-eibl) wrote :

Hi,

I now made an inofficial version for you to test:
http://kdiff3.sourceforge.net/kdiff3-0.9.98a.tar.gz

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.

Joachim

Revision history for this message
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

Revision history for this message
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,
Benoît

Revision history for this message
Jonas T. (jo-t) wrote :

Joachim,

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.

Best,
Jonas

Revision history for this message
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.

Joachim

Revision history for this message
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?

Revision history for this message
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

Revision history for this message
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,
Benoît

Revision history for this message
joachimeibl (joachim-eibl) wrote : Re: [Bug 999925] Re: KDiff3 font rendering of changed text broken

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,
Joachim

Revision history for this message
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,
Benoît

Revision history for this message
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

Revision history for this message
Michael Mess (michael-michaelmess) wrote :

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
Revision history for this message
Benoît Thébaudeau (btheb) wrote :

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

Revision history for this message
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.

Revision history for this message
Andrew Schwartz (aschwartz) wrote :

Attaching screenshot with monospace 9

Revision history for this message
Andrew Schwartz (aschwartz) wrote :

Attaching screenshot with monospace 11

Revision history for this message
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.

Regards,
Benoît

Revision history for this message
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

Revision history for this message
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?

Revision history for this message
Andrew Schwartz (aschwartz) wrote :

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

Please find the first file attached.

Revision history for this message
Andrew Schwartz (aschwartz) wrote :

And here's file2.

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Benoît Thébaudeau (btheb) wrote :

Still broken in Ubuntu 14.04.

tags: added: trusty
Changed in kdiff3 (Ubuntu):
importance: Undecided → High
ChrisW (chrisw6543)
description: updated
Revision history for this message
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  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.