Menu

#231 Underscores and other hanging characters not drawn in v4.0

Compilation Issues
closed-fixed
nobody
None
5
2014-07-28
2014-07-28
No

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.

1 Attachments

Related

Bugs: #231

Discussion

  • Nathan Smith

    Nathan Smith - 2014-07-28

    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()

     
  • Nathan Smith

    Nathan Smith - 2014-07-28

    The same change must also be made to lineNumbers.cpp or else the line numbers don't line up with their lines.

     
  • Martin Blais

    Martin Blais - 2014-07-28

    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.

     
    • Nathan Smith

      Nathan Smith - 2014-07-28

      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.

      This value is always equal to leading()+height().
      height():

      Returns the height of the font.

      This is always equal to ascent()+descent()+1 (the 1 is for the base line).
      leading():

      Returns the leading of the font.

      This is the natural inter-line spacing.

      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
      • Nathan Smith

        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.

         
    • globs110

      globs110 - 2014-07-28

      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.


      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: #231

  • Martin Blais

    Martin Blais - 2014-07-28

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

     
    • Nathan Smith

      Nathan Smith - 2014-07-28

      Looks good to me. Thanks everyone!

       
  • Martin Blais

    Martin Blais - 2014-07-28
    • status: open --> closed-fixed
     

Log in to post a comment.