Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Itallic fonts are clipped #154

Open
equalsraf opened this issue Jul 11, 2016 · 30 comments
Open

Itallic fonts are clipped #154

equalsraf opened this issue Jul 11, 2016 · 30 comments
Labels
font Relating to font options or rendering

Comments

@equalsraf
Copy link
Owner

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
Copy link
Owner Author

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

@equalsraf
Copy link
Owner Author

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
Copy link
Contributor

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

@khalidchawtany
Copy link
Contributor

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

Before:

before

After:

after

@khalidchawtany
Copy link
Contributor

Wait I am mistaken!!! just a second

@equalsraf
Copy link
Owner Author

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
Copy link
Contributor

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
Copy link
Contributor

However, this makes some chars look a little displaced.

@equalsraf
Copy link
Owner Author

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

@khalidchawtany
Copy link
Contributor

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

@khalidchawtany
Copy link
Contributor

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

@khalidchawtany
Copy link
Contributor

@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
Copy link
Contributor

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

@equalsraf
Copy link
Owner Author

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
Copy link
Contributor

Here is the result fontinfo.txt

@khalidchawtany
Copy link
Contributor

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

@khalidchawtany
Copy link
Contributor

Sorry copy paste :)
fontinfo.txt

@equalsraf
Copy link
Owner Author

Clearly text layout is not my thing

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

@khalidchawtany
Copy link
Contributor

khalidchawtany commented Aug 19, 2016

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
Copy link
Contributor

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
Copy link

DejaVu Sans Mono for Powerline
same thing
image

@equalsraf equalsraf added the font Relating to font options or rendering label Jul 25, 2018
@Dmitra
Copy link

Dmitra commented Apr 20, 2019

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

@yatli
Copy link

yatli commented Apr 20, 2019

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

@mangelozzi
Copy link

mangelozzi commented Aug 21, 2019

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
Copy link

void-m4110c commented Nov 14, 2020

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
Copy link

yatli commented Nov 14, 2020

@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
Copy link
Collaborator

jgehrig commented Nov 14, 2020

@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
Copy link
Collaborator

jgehrig commented Nov 14, 2020

@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
Copy link

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
Copy link

lifei commented Jan 21, 2024

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
font Relating to font options or rendering
Projects
None yet
Development

No branches or pull requests

10 participants