Underscores and other hanging characters not drawn in v4.0
Brought to you by:
blais
When comparing two files with underscores or other characters that hang beneath a line (such as the tails of g, j, p, q, and y), the bottoms of these characters are clipped. I've tried several different fonts and they all do the same thing. This is especially problematic for underscores as they appear as just an empty space.
I've attached a screenshot of the bug when comparing two files that say:
This_is_an_example _____surrounded_by_underscores_____
This was taken using xxdiff's tip (3830b1288eb7) on Ubuntu 12.04 running Qt 4.8, though it also appeared in 4.0.
Attached is a patch that corrects the problem. text.cpp was using QFontMetrics::lineSpacing() to determine the height of the line, but that just provides the distance from the top of the line to the baseline. Some characters extend beneath the baseline, such as those listed above. To get the height of them, you must call QFontMetrics::descent(). The correct height of the line, then, is QFontMetrics::lineSpacing() + QFontMetrics::descent()
The same change must also be made to lineNumbers.cpp or else the line numbers don't line up with their lines.
Hi Nathan,
Thanks for reporting the bug. I've seen it before but never had the time to fix it.
Your change may work, but it looks like the reason for it is incorrect:
http://openhome.cc/Gossip/Qt3Gossip/QPainter2.html
I'd like to apply it, but I'd want to figure out why just using the lineSpacing() does not work before doing that. I believe that it should work with just lineSpacing(), something else is wrong.
I don't want to patch it up by adding descent() without understanding why lineSpacing() does not work by itself.
Re-reading what's in the official documentation, I believe that you are right. http://qt-project.org/doc/qt-4.8/qfontmetrics.html#lineSpacing
lineSpacing():
Returns the distance from one base line to the next.
Returns the height of the font.
Returns the leading of the font.
So it appears that lineSpacing() is leading() + ascent() + descent() + 1, where ascentis the "distance from the baseline to the highest position characters extend to" and descentis the "distance from the base line to the lowest point characters extend to." It sounds like this should cover the whole character both above, below and on the baseline. Throw in leading(space between lines) and it doesn't seem like clipping should be happening. Even if leading were 0, the worst that shouldhappen is that there is no gap between the bottom of one line and the top of the next.
Last edit: Nathan Smith 2014-07-28
Part of the problem is that leading() can be negative. In the case of Lucidatypewriter,9,-1,2,50,0,0,0,1,0, the leading is -1. I tried adding this back in, but it still clips some of the characters.
The problem is not unique to this code. I found someone having the same problem on stackoverflow: http://stackoverflow.com/questions/13432746/why-is-qfontmetricslinespacing-smaller-than-the-height-of-the-characters-bo. Unfortunately there is no posted solution.
That would probably be my fault. While adjusting the text position and
spacing during the qt3 to qt4 port, I could not get something as compact as
in the qt3 version, and tried to remove a couple of additional pixels. I
must have removed one too many.
--
Alexandre Féblot
(envoyé depuis mon iPhone)
Le 28 juil. 2014 à 20:03, Martin Blais blais@users.sf.net a écrit :
Hi Nathan,
Thanks for reporting the bug. I've seen it before but never had the time to
fix it.
Your change may work, but it looks like the reason for it is incorrect:
http://openhome.cc/Gossip/Qt3Gossip/QPainter2.html
I'd like to apply it, but I'd want to figure out why just using the
lineSpacing() does not work before doing that. I believe that it should
work with just lineSpacing(), something else is wrong.
I don't want to patch it up by adding descent() without understanding why
lineSpacing() does not work by itself.
other hanging characters not drawn in v4.0*
Status: open
Group: Compilation Issues
Created: Mon Jul 28, 2014 03:09 PM UTC by Nathan Smith
Last Updated: Mon Jul 28, 2014 03:29 PM UTC
Owner: nobody
When comparing two files with underscores or other characters that hang
beneath a line (such as the tails of g, j, p, q, and y), the bottoms of
these characters are clipped. I've tried several different fonts and they
all do the same thing. This is especially problematic for underscores as
they appear as just an empty space.
I've attached a screenshot of the bug when comparing two files that say:
This_is_an_example__surrounded_by_underscores__
This was taken using xxdiff's tip (3830b1288eb7) on Ubuntu 12.04 running Qt
4.8, though it also appeared in 4.0.
Sent from sourceforge.net because you indicated interest in
https://sourceforge.net/p/xxdiff/bugs/231/
To unsubscribe from further messages, please visit
https://sourceforge.net/auth/subscriptions/
Related
Bugs:
#231I think I found it.
The leading is negative for the default font.
I must use fm.height().
But if I do just that, it still did not work.
It did not work because I rendered starting at y+1.
I have to clue why I was doing that--this is code I wrote a long, long, long time ago.
I changed it back to render at y+0, and it looks... just right.
I also made a global static inline helper to compute the desired height.
It works now on my box, where the underscores were previously also not showing. Try it and please let me know if that fixes the problem for you too.
Thank you Nathan,
Looks good to me. Thanks everyone!