neovim-qt icon indicating copy to clipboard operation
neovim-qt copied to clipboard

Itallic fonts are clipped

Open equalsraf opened this issue 9 years ago • 30 comments

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.

equalsraf avatar Jul 11 '16 09:07 equalsraf

It would seem I was wrong here. Source Code Pro reports positive left and right bearings.

equalsraf avatar Aug 19 '16 13:08 equalsraf

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

equalsraf avatar Aug 19 '16 13:08 equalsraf

I will try it in a moment. Thanks for investigating.

khalidchawtany avatar Aug 19 '16 13:08 khalidchawtany

To be honest I don't see any difference in rendering.

Before:

before

After:

after

khalidchawtany avatar Aug 19 '16 13:08 khalidchawtany

Wait I am mistaken!!! just a second

khalidchawtany avatar Aug 19 '16 13:08 khalidchawtany

Depends very much on the font. Which ones are you using?

For me it completely failed with Source Code Pro, but worked with Courier.

equalsraf avatar Aug 19 '16 13:08 equalsraf

This is after: It does make it a little better, but not foll chars. screen shot 2016-08-19 at 5 00 48 pm

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

However, this makes some chars look a little displaced.

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

In linux the debug builds should be printing all the offending chars and font info into the terminal, not sure about OS X.

equalsraf avatar Aug 19 '16 14:08 equalsraf

In OSX it launches an app without a terminal. However, I can set a NVIM_QT_LOG to get it in a file.

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

Nope, no offending char is written in to the log. new_qt_log.txt

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

@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.

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

How do I build a debug build? I just run make.

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

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

equalsraf avatar Aug 19 '16 14:08 equalsraf

Here is the result fontinfo.txt

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

Wait I think I made a mistake in the font name :)

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

Sorry copy paste :) fontinfo.txt

khalidchawtany avatar Aug 19 '16 14:08 khalidchawtany

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.

equalsraf avatar Aug 19 '16 16:08 equalsraf

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

khalidchawtany avatar Aug 19 '16 18:08 khalidchawtany

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. iterm_terminal

khalidchawtany avatar Aug 20 '16 09:08 khalidchawtany

DejaVu Sans Mono for Powerline same thing image

Himura2la avatar Mar 09 '18 13:03 Himura2la

Can confirm the issue with Inconsolata https://fontlibrary.org/en/font/inconsolata-lgc-markup

Dmitra avatar Apr 20 '19 09:04 Dmitra

FYI can confirm with Iosevka https://github.com/be5invis/Iosevka

yatli avatar Apr 20 '19 09:04 yatli

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: image

mangelozzi avatar Aug 21 '19 08:08 mangelozzi

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

void-m4110c avatar Nov 14 '20 14:11 void-m4110c

@equalsraf as long as the characters are drawn individually this problem cannot be completely solved. My strategy in fvim:

  1. split the redraw update into consecutive segments with the same hl group, so that each segment can be drawn as a full glyph run.
  2. render the segments backwards, because italics lean to the right :D

yatli avatar Nov 14 '20 15:11 yatli

@void-m4110c

Give GuiRenderLigatures a try!

:GuiRenderLigatures 0: GuiRenderLigatures_OFF

GuiRenderLigatures 1: GuiRenderLigatures_ON

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.

jgehrig avatar Nov 14 '20 23:11 jgehrig

@yatli

Good point...

  1. This is essentially the rendering scheme used in GuiRenderLigatures.
  2. We don't currently render backwards, but in Qt this may not be necessary? I think we can simply expand the boundingRect used for the drawText calls. 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...

jgehrig avatar Nov 14 '20 23:11 jgehrig

This issue is not completely resolved by the GuiRenderLigature. The rightmost letter is still clipped, as shown below. image

Are there any other improvements planned?

calmman84 avatar Jun 18 '23 01:06 calmman84