Skip to content

-[MMCoreTextView initWithFrame:] doesn't initialize fontDescent #883

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

Closed
jjgod opened this issue Apr 22, 2019 · 12 comments · Fixed by #927
Closed

-[MMCoreTextView initWithFrame:] doesn't initialize fontDescent #883

jjgod opened this issue Apr 22, 2019 · 12 comments · Fixed by #927

Comments

@jjgod
Copy link
Contributor

jjgod commented Apr 22, 2019

-[MMCoreTextView initWithFrame:] initializes font but not fontDescent:

// NOTE!  It does not matter which font is set here, Vim will set its
// own font on startup anyway.  Just set some bogus values.
font = [[NSFont userFixedPitchFontOfSize:0] retain];

so it defaults to 0. In the case of the later -setFont: is called with the same pointer as font, then other initialization related to the font won't happen.

- (void)setFont:(NSFont *)newFont
{
    if (!(newFont && font != newFont))
        return;

There are many ways to fix this, a simple way would be just to call [self setFont:[NSFont userFixedPitchFontOfSize:0]] at -initWithFrame:.

@jjgod
Copy link
Contributor Author

jjgod commented Jul 26, 2019

Any update?

@ychin
Copy link
Member

ychin commented Jul 27, 2019

I can take a look. Do you have a concrete repro that I can use to validate this? As in what are the symptoms form this issue?

@jjgod
Copy link
Contributor Author

jjgod commented Jul 27, 2019 via email

@eirnym
Copy link
Contributor

eirnym commented Jul 28, 2019

Just launch MacVim without any .vimrc/.gvimrc on macOS 10.15 beta you will see this, all the text will be clipped.

this depends on a font

@jjgod
Copy link
Contributor Author

jjgod commented Jul 28, 2019 via email

@eirnym
Copy link
Contributor

eirnym commented Jul 28, 2019

I mean the issue with clipping is font-specific. When I set to Menlo, the issue is clearly present, when I set it to Fira Code, clipping is not present. These conditions and outcomes are repeatable even you mix the order.

@jjgod
Copy link
Contributor Author

jjgod commented Jul 28, 2019 via email

@jjgod
Copy link
Contributor Author

jjgod commented Jul 28, 2019

Most fonts will have a non-zero descender. When fontDescent is not initialized properly this will defintiely be a problem.

@eirnym
Copy link
Contributor

eirnym commented Jul 28, 2019

So you want to say, that guifont setting sets fontDescent to some meaningful value? If yes, why setting Menlo after Fira Code Light I able to observe clipping?

@jjgod
Copy link
Contributor Author

jjgod commented Jul 28, 2019

I'm sorry, exactly what you do to trigger this? Do you have steps to reproduce this behavior?

As far as I can tell,

https://github.com/macvim-dev/macvim/blob/master/src/MacVim/MMCoreTextView.m#L327

fontDescent = ceil(CTFontGetDescent(fontRef));

Since it always assigns fontDescent here it shouldn't be a problem as long as -setFont: is being called properly every time a guifont changes.

@ychin
Copy link
Member

ychin commented Jul 29, 2019

If I'm guessing correctly, this happens in 10.15 because macOS is reusing and caching NSFont objects internally. Previously, we just naively assume setFont will always be called (which is true), and then the font will be different from the initial dummy font. However, it appears that macOS 10.15 will just pass the same NSFont to us (if your vimrc doesn't override the default font), causing the first setFont to early-out and not set up fontDescent properly. I commented on your pull request for further improvements before I want to merge it in.

@jjgod
Copy link
Contributor Author

jjgod commented Jul 29, 2019

Correct. PR updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants