equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.85k stars 171 forks source link

Itallic fonts are clipped #154

Open equalsraf opened 8 years ago

equalsraf commented 8 years ago

Reported by @khalidchawtany, italic text in some fonts is clipped

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 commented 8 years ago

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

equalsraf commented 8 years ago

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

khalidchawtany commented 8 years ago

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

khalidchawtany commented 8 years ago

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

Before:

before

After:

after

khalidchawtany commented 8 years ago

Wait I am mistaken!!! just a second

equalsraf commented 8 years ago

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

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

khalidchawtany commented 8 years ago

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 commented 8 years ago

However, this makes some chars look a little displaced.

equalsraf commented 8 years ago

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

khalidchawtany commented 8 years ago

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

khalidchawtany commented 8 years ago

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

khalidchawtany commented 8 years ago

@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 commented 8 years ago

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

equalsraf commented 8 years ago

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
khalidchawtany commented 8 years ago

Here is the result fontinfo.txt

khalidchawtany commented 8 years ago

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

khalidchawtany commented 8 years ago

Sorry copy paste :) fontinfo.txt

equalsraf commented 8 years ago

Clearly text layout is not my thing

Pushed a commit too, but it doesn't seem correct.

khalidchawtany commented 8 years ago

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 commented 8 years ago

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

Himura2la commented 6 years ago

DejaVu Sans Mono for Powerline same thing image

Dmitra commented 5 years ago

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

yatli commented 5 years ago

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

mangelozzi commented 5 years ago

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

void-m4110c commented 4 years ago

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

yatli commented 4 years ago

@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
jgehrig commented 4 years ago

@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 commented 4 years ago

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

calmman84 commented 1 year ago

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?

lifei commented 10 months ago

any update?