Custom Font For Plugin File Type?
Is it possible to set a custom font for a filetype defined by a plugin?
I'm working on a plugin for a custom language which uses a lot of special brackets which generally look bad in normal fonts (I've already created a font for them on that page.)
I came across this link which seems to suggest this functionality may not exist (though I'm hoping that's just in relation to font settings per-token as opposed to per-document changes.)
Please sign in to leave a comment.
Related requests:
https://youtrack.jetbrains.com/issue/IDEA-161729
https://youtrack.jetbrains.com/issue/IDEA-146471
The second one is probably the easier of the two, but I'm curious if it's possible to change the font of a document from within a plugin (not through settings exposed to the end user.)
It's possible to change editor's font via Editor.getColorsScheme().setEditorFontName(fontName).
Is it possible to limit that change to only specific documents? The special characters I'm using are pretty far outside of the ASCII range so I could likely override it for everything, just feels like bad practice to do it that way.
This is set on per-editor basis, you can check file type of document before doing that.
BTW, if you worry that default font will be unable to display special characters, that shouldn't be an issue - editor implements font fallback mechanism internally, so it will look for suitable font itself. Unless you want to use specific fallback font, there's no need to do anything.
These are the brackets I'm using so the failover probably isn't the best route. The font in IntelliJ does find characters, but they generally look really bad kerning-wise, aiming to replace these with a fixed-width version, so I'll likely hack this on top of the font used by IntelliJ and include it with the plugin:
{???(???[???<???text???>???]???)???}
I see. When fallback is used, character widths might not match indeed, so if there's a monospaced font which can display all related characters, it can be a better option.
I noticed that the DejaVu Sans Mono font used by IntelliJ is an open source font - do you know how often IntelliJ is synced off this? Since none of the brackets in the otherwise mono spaced font are actually mono spaced (and generally deviate from the appearance of the actual unicode characters) it might make more sense for me to push changes to the font repo itself for these brackets (the 4 standard pairs look fine of course, so it's just the 12 non-standard pairs I would be updating.)
We don't bundle DejaVu Sans Mono, we use it as a default font, if it's installed on user's machine (on Linux).
Ah OK, a custom font is probably better then, though I'll likely use that as a base and just merge my characters into it then post it as well.
In regard to:
Editor.getColorsScheme().setEditorFontName(fontName)
What is the appropriate location to make that call?
There are multiple options you can try. One is FileEditorManagerListener.fileOpenedSync (appeared in master branch recently, should be available in 2018.2 release, or a bit less convenient in this case 'fileOpened' can be used). Another is EditorFactoryListener.editorCreated. The former is called on opening any file in main editor pane (editor can be non-text one, so you should check first whether FileEditor is TextEditor). The latter is for text editor components only (but these components can be used anywhere, e.g. as a console or a plain text input field, so you should be more careful in filtering what editors to apply your font changes to).