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

Font rendering broken for certain tokens in RSyntaxTextArea on M1 MacOS 13.2.1 #494

Open
kspalaiologos opened this issue Feb 20, 2023 · 3 comments
Assignees
Labels

Comments

@kspalaiologos
Copy link

I have implemented my own highlighter and style the text as follows:

        scheme.getStyle(Token.COMMENT_EOL).foreground = Color.decode("#676B79");
        scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.decode("#FFB86C");
        scheme.getStyle(Token.LITERAL_NUMBER_FLOAT).foreground = Color.decode("#FFB86C");
        scheme.getStyle(Token.LITERAL_CHAR).foreground = Color.decode("#FFB86C");
        scheme.getStyle(Token.LITERAL_BOOLEAN).foreground = Color.decode("#45A9F9");
        scheme.getStyle(Token.VARIABLE).foreground = Color.decode("#E6E6E6");
        scheme.getStyle(Token.RESERVED_WORD).foreground = Color.decode("#FF75B5");
        scheme.getStyle(Token.OPERATOR).foreground = Color.decode("#B084EB");
        scheme.getStyle(Token.FUNCTION).foreground = Color.decode("#FFCC95");
        scheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).foreground = Color.decode("#6FC1FF");

Using the following font:

    public static final Font aplFont;

    static {
        try {
            aplFont = Font.createFont(Font.TRUETYPE_FONT, Objects.requireNonNull(IDE.class.getResourceAsStream("/APL385.ttf"))).deriveFont(Font.BOLD, 15f);
        } catch (FontFormatException | IOException e) {
            throw new RuntimeException(e);
        }
    }

This is the result on MacOS:

obraz

This is the result on Debian Linux (OpenJDK 17, 18, 19 all work the same):

obraz

The problem is clear - flt64:lerch-phi is highlighted using a completely different font from the rest of the text area. Interestingly enough, this issue manifests itself only on MacOS, only with the token type RESERVED_WORD.

The code: https://github.com/kspalaiologos/kamilalisp/tree/ide

@kspalaiologos
Copy link
Author

Originally discovered by https://github.com/mrbenjadmin - I do not use MacOS and am reporting the issue on his behalf.

@bobbylight bobbylight self-assigned this Feb 25, 2023
@bobbylight
Copy link
Owner

bobbylight commented Feb 25, 2023

What a cool issue! My first guess is macOS automatically uses a fallback font when glyphs can't be rendered. The text in the screenshots is clearly all 7-bit ASCII so my guess is it's not the codepoints themselves but has to do with TokenTypes.RESERVED_WORD defaulting to bold whereas other token types don't. Not sure yet why other OS's wouldn't also use fallback fonts or show a placeholder char like the empty rectangle, but different OS's surely have different rendering engines, so maybe there's just some limitation in the macOS JVM's font rendering implementation?

Anyway I'll try to reproduce on my Macbook

@kspalaiologos
Copy link
Author

@bobbylight I found a workaround!

Turns out that you have to reset the font in the styles, not only just call setFont on the RSTA:

        scheme.restoreDefaults(IDE.aplFont, false);

It is incredibly weird that this issue manifested only in very specific circumstances, though.

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

No branches or pull requests

2 participants