neovim-qt
                                
                                
                                
                                    neovim-qt copied to clipboard
                            
                            
                            
                        Itallic fonts are clipped
Reported by @khalidchawtany, italic text in some fonts is clipped
- Menlo
 - Courier
 - Source Code Pro
 - Firea Code
 

Presumably this is expected behavior from Qt (from SO) a result of left/right bearing. This is a problem because we can't change the font metrics between italics and non italics (they must be the same width).
We can adjust the drawing function, but its still unclear if this would fix the issue or cause a similar issue on the right side.
It would seem I was wrong here. Source Code Pro reports positive left and right bearings.
I retract my previous statement, other fonts do report negative bearings, maybe there is something to be done here e.g.
index a02a1f3..9d24084 100644                                                                 
--- a/src/gui/shellwidget/shellwidget.cpp
+++ b/src/gui/shellwidget/shellwidget.cpp
@@ -153,6 +153,18 @@ void ShellWidget::paintEvent(QPaintEvent *ev)
                                        // Draw chars at the baseline
                                        QPoint pos(r.left(), r.top()+m_ascent+m_lineSpace);
+
+                                       // Adjust according to font bearing
+                                       int rBearing = p.fontMetrics().rightBearing(cell.c);
+                                       int lBearing = p.fontMetrics().leftBearing(cell.c);
+                                       if (lBearing + rBearing < 0) {
+                                               // Not much we can do, the font does not
+                                               // fit the cell
+                                       } else if (lBearing < 0) {
+                                               pos.setX(pos.x()-lBearing);
+                                       } else if (rBearing < 0 ) {
+                                               pos.setX(pos.x()+rBearing);
+                                       }
                                        p.drawText(pos, QString(cell.c));
                                }
~
~
~
ping @khalidchawtany
I will try it in a moment. Thanks for investigating.
To be honest I don't see any difference in rendering.
Before:

After:

Wait I am mistaken!!! just a second
Depends very much on the font. Which ones are you using?
For me it completely failed with Source Code Pro, but worked with Courier.
This is after:
It does make it a little better, but not foll chars.

However, this makes some chars look a little displaced.
In linux the debug builds should be printing all the offending chars and font info into the terminal, not sure about OS X.
In OSX it launches an app without a terminal. However, I can set a NVIM_QT_LOG to get it in a file.
Nope, no offending char is written in to the log. new_qt_log.txt
@equalsraf how would you go about displaying chars that do not fit the cell? I just like to know any ideas you may have about tackling this issue.
How do I build a debug build? I just run make.
How do I build a debug build? I just run make.
Default is debug, and there are entries in the log so it should be working
Nope, no offending char is written in to the log.
Strange, then they should fit or the font metrics are weird.
I've pushed a new branch tb-italics it already has the patch I posted above. It also has a modified version of fontinfo. Can you grab that branch and then
make fontinfo
bin/fontinfo fontname
                                    
                                    
                                    
                                
Here is the result fontinfo.txt
Wait I think I made a mistake in the font name :)
Sorry copy paste :) fontinfo.txt
Clearly text layout is not my thing
- https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html (section 3)
 
Pushed a commit too, but it doesn't seem correct.
The pushed commits are better than previous ones. However, now the left bottom side of letter p (not P) is cropped.
Update:
Actually now most characters like letters, marks and : in the cmd are strange looking :)
It seems that both iTerm and the built-in terminal of OS X are keeping parts of previous character. Yet, they don't have any redrawing problems when moving the cursor in neovim.

DejaVu Sans Mono for Powerline
same thing

Can confirm the issue with Inconsolata https://fontlibrary.org/en/font/inconsolata-lgc-markup
FYI can confirm with Iosevka https://github.com/be5invis/Iosevka
In Windows using the QT interface, and Consolas, or Courier New, or any other fixed-width font I tried, italic fonts were clipped.
With no font set (using the default), this is what it looks like:

Hello, the year 2020 finally comes to an end and we still don't seem to have a fix for this. I wanted to ask politely if there are any plans to fix this issue somehow? I mean, this was reported in 2016... All the best
@equalsraf as long as the characters are drawn individually this problem cannot be completely solved. My strategy in fvim:
- split the redraw update into consecutive segments with the same hl group, so that each segment can be drawn as a full glyph run.
 - render the segments backwards, because italics lean to the right :D
 
@void-m4110c
Give GuiRenderLigatures a try!
:GuiRenderLigatures 0:

GuiRenderLigatures 1:

The feature is only available in `master, and is still alpha quality. If you see any issues please report them in #771.
FYI, there is a known issue with some fonts #781, they use a encoding scheme I did not expect... The API we're using is vaguely documented.
@yatli
Good point...
- This is essentially the rendering scheme used in 
GuiRenderLigatures. - We don't currently render backwards, but in Qt this may not be necessary? I think we can simply expand the 
boundingRectused for thedrawTextcalls. I think the act of drawing the background color (not the text) is causing the clipping. 
I'm somewhat hesitant to fix this for GuiRenderLigatures 0. Changing the boundingRect may regress other scenarios (emoji, guifontwide, non-monospace fonts, etc).
Perhaps fixing this for GuiRenderLigatures 1 is the best course forward...
This issue is not completely resolved by the GuiRenderLigature.
The rightmost letter is still clipped, as shown below.
Are there any other improvements planned?