How to fix font anti-aliasing in IntelliJ IDEA when using high DPI?

79

95

I use a higher DPI setting which makes IntelliJ (actually Android Studio) have really messed up fonts.

I use MacType which renders my fonts beautifully elsewhere, but I guess Java VM somehow intercepts it or something, it's killing me.

Bloke

Posted 2013-07-03T09:58:18.507

Reputation: 1 067

Answers

112

I’m on a high-dpi display and I got it working with a perfect font rendering, to achieve this you need to:

  • (On Linux) Install and use Oracle JDK (I’m using 1.7) and not OpenJDK (also the patched one with fontfix was useless for me). See how to do this.

  • Edit the .vmoptions configuration file that you find into the Bin installation folder (eg. studio.vmoptions and for 64bit studio64.vmoptions, or WebStorm.exe.vmoptions etc. according to the version of the IDE you installed) by adding these lines:
    -Dawt.useSystemAAFontSettings=on
    -Dswing.aatext=true
    -Dsun.java2d.xrender=true

  • Remove hinting informations from the font that you would like to use and select the new font into IntelliJ IDEA preferences (Setting -> Editor -> Font);
    if you don’t know how to do this, install FontForge then:

    1. Open your font in FontForge
    2. Select all glyphs via Ctrl+A and clear all hints (Hints -> Clear Hints)
    3. Select glyphs again and use Hints -> Clear Instruction
    4. Save the font with different name ( File -> Generate Fonts)
    5. Install the new font, select it in IDEA

If you followed the above tips and you’re experiencing lags when fast scrolling the code (this sometimes could happen on Linux distributions with a not optimized gpu driver), try removing the line
-Dsun.java2d.xrender=true
from the .vmoptions file.

Finally, here is a screenshot of the result:

IDE screenshot


(fonts used here are LucidaMAC for the main IDE and Ubuntu Mono with removed hinting informations for the code editor)

guari

Posted 2013-07-03T09:58:18.507

Reputation: 1 236

3cant clear hints and instructions on fonts in font forge... There are errors when i try to save them after that... What am i doing wrong – Mario Zderic – 2014-09-12T10:05:05.843

2Wow. Still helpful a year later. JetBrains needs to make this the default or at least perform some auto detection. The blurriness without these settings makes IntelliJ look awful and unusable. – Andrew T Finnell – 2014-09-19T13:18:06.410

@guari your answer is what did it for me – clav – 2014-12-18T00:09:18.493

for me, on Windows 8.1, with UHD resolution and scaling set at 225% (it's a 15,6' display), all of the above didn't help. I must be missing something (Skype for desktop also exhibits this issue, blurred fonts). Any help or pointers would be highly appreciated :) – andreimarinescu – 2015-02-06T11:33:16.053

on a mac the result is unfortunately not so good.. (you can take Xcode unhinted fonts, copy them to system lib, you might need to use font finagler to clear the cache, restart your machine, set jdk 1.8 or 1.9, launch the ide from the console. But the result is not so good..again – Snicolas – 2015-05-29T04:44:09.300

1@CoryKlein which font did you removied hints/instructions via FontForge and how did you save it? – octohedron – 2015-10-04T07:55:55.493

1@Gazta Sorry, that was from a different job, different machine, and too long ago. I don't remember. :( – Cory Klein – 2015-10-05T16:31:59.230

1@CoryKlein dont worry, I finally found out that any TTF font will work. – octohedron – 2015-10-05T16:50:00.933

FYI changing to Oracle's Java is not necessary, everything else is. – mshindal – 2015-11-03T00:21:26.250

Worked great on my PhpStorm 9->10 transition just now. After upgrading the IDE my Input Mono font went from regular weight to a bold weight (the rendering was fine though, the weight just was not the same). Removing hinting did the trick and I'm back to the old lighter weight. The startup config settings had no effect on Ubuntu. – ojrask – 2015-11-03T06:30:42.663

I didn't do any of what you said and simply changing antialiasing to Greyscale for both editor and IDE solved my problem. – None – 2015-11-06T20:01:01.477

@mshindal - funny, changing to Oracle's Java was the only that that was necessary to fix this for me. – Mr. Bungle – 2016-01-14T09:53:10.923

Could you please upload your Ubuntu Mono with removed hinting information somewhere and paste the link here pleeease? – Bloke – 2016-01-14T10:39:17.750

If you're too lazy to do the font part, see @user1185087 's answer below – tsusanka – 2016-01-17T20:51:11.237

I have actually done it more than once, but I can't get it to look as great as @guari's. I did succeed on Windows, but I'm having trouble with Mint now. Don't really like the way that font looks like in that answer – Bloke – 2016-01-19T14:27:09.980

4Awesome! Works in Windows as well :)) thank you :* – Bloke – 2013-07-25T10:06:06.110

For me on Ubuntu 13.04 and IntelliJ 12.1.5, the settings in the options file did nothing, but removing Hints and Instructions from the font via FontForge did work. I also had to fiddle a bit with the settings in File->Settings->IDE Settings->Editor – Cory Klein – 2013-10-02T15:17:04.647

I followed the instructions and removed hinting from Consolas font but the problem is that now IDEA (Android Studio actually) doesn't see the font. It does see the original Consolas font. Any idea why? – tobik – 2013-11-12T15:49:23.563

1I have tried the above on my windows machine with hi dpi (3200x1800) I have adjusted the studio.vmoptions as mentioned yet everything is still blurry. Please advise if possible I'd really like to get this working? – Pace – 2014-01-07T12:06:04.020

10@Pace To remove blurry fonts you need to disable display scaling for that application (right click on its icon, select Properties, go to Compatibility tab and check Disable DPI scaling on high DPI settings, for x64 apps in Win8- you should edit the flag of the related registry key: open Regedit.exe, go to HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers and add a string value REG_SZ whose name is the full path to the application executable and whose value is HIGHDPIAWARE) ;) – guari – 2014-01-07T14:22:39.313

1@guari - Kudos to you sir! Thank you so much. I start a Coursera Android course this week and now I have perfectly rendered smooth fonts! I just upped the general font settings for the IDE and the editor to set them to 26pt and I can't believe how good it looks! Thanks again. – Pace – 2014-01-10T00:05:28.497

4

I wrote a little manual howto fix this.

   wget http://urshulyak.com/jdk-8u5-tuxjdk-b08.tar.gz
   tar -zxvf jdk-8u5-tuxjdk-b08.tar.gz
   sudo mv jdk-8u5-tuxjdk-b08 /usr/lib/jvm
   rm jdk-8u5-tuxjdk-b08.tar.gz

Script to start Intellij Idea

*only note that need to change IDEA_HOME location for your path of idea

#!/bin/sh

IDEA_HOME=/opt/idea
export JAVA_HOME=/usr/lib/jvm/jdk-8u5-tuxjdk-b08/
export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=lcd \
                      -Dsun.java2d.xrender=true"
export GNOME_DESKTOP_SESSION_ID=this-is-deprecated
exec $IDEA_HOME/bin/idea.sh "$@"

More info and screenshots of better fonts: http://urshulyak.com/?p=478

Yaroslav Urshulyak

Posted 2013-07-03T09:58:18.507

Reputation: 149

Adding -Dsun.java2d.xrender=true to bin/webstorm64.vmoptions in WebStorm's directory was enough for me. – Alicia – 2014-12-21T23:20:50.363

1the download link is broken. Please fix – jackode – 2015-01-03T15:27:53.947

This answer assumes 64bit architecture , which may not be the case – Anwar – 2016-03-26T11:41:09.267

This is essentially running arbitrary code as root - caution advised. – Thorbjørn Ravn Andersen – 2019-01-02T15:34:51.733

2

I got a similar look just by downloading the Menlo font and setting the Editor Anti-aliasing to 'grayscale' within Appearance & behaviour > Appearance

This is the result:

This is how it looks

Here is a comparison between the two platforms

enter image description here

I am using a higher resolution and better hardware at work with the MAC, that is why the fonts look a bit brighter, the result will vary depending on your machine. Anyways it's worth a shot, the changes are easy to revert

FRR

Posted 2013-07-03T09:58:18.507

Reputation: 121

Worked partially for me! Fonts are not as crisp as generic Mac UI but sharp enough to be workable. I'm on 13" Mac Pro, OS X 10.11.4 – Mayank Jain – 2016-04-14T10:43:49.867

why are you doing this on OSX?, you should get the right fonts out of the box :) – FRR – 2016-05-09T07:46:10.980

2

None of this ugly stuff is needed anymore. Download the latest IntelliJ (2016.1 onwards) for Linux. It includes a modified JRE with the fonts issue fixed. To fix Android Studio too make a symbolic link to the IntelliJ jre:

ln -s /PATH/TO/INTELLIJ/jre /PATH/TO/ANDROIDSTUDIO/jre

Alternatively, just open your file manager as root (assuming your IDEs are installed in the /opt directory or another system folder) and create a shortcut to IntelliJ's jre and move it to Android Studio installation folder, then rename it to 'jre'. This works for the latest android studio 2.0 but it should work with earlier versions too.

Aspiring Dev

Posted 2013-07-03T09:58:18.507

Reputation: 159

Which version do you mean? When I go to Help > About, I see Intellij IDEA 15.0.2 and Build #IU-143.1184 – Bloke – 2016-04-18T06:47:33.133

@Bloke just go to the site and download the latest IntelliJ. It's 2016.1.1 right now I think. They changed the way they advertise the new versions now and it has that YEAR.REVISION.UPDATE# format now. – Aspiring Dev – 2016-04-18T18:38:17.173

Oh, indeed. I have just tried it. My Source Code Pro font now looks a bit too bold, though, but that's a minor issue. Thanks! – Bloke – 2016-04-25T14:49:50.210

Using the JRE packaged with IntelliJ made all the difference for me. I had initially downloaded IntelliJ without the JRE and used my local Oracle JDK (1.7) which resulted in bad fonts. HTH. – sengs – 2017-07-27T17:02:17.007

2

On newer JetBrains IDE's solution is different.

In IDE installation folder just rename jre folder to something else. For example:

  1. $ cd your-path-to/WebStorm-162.2228.20/
  2. $ mv jre/ _jre/

Newer versions use bundled JRE instead of your system one and this bundled version causes font rendering issues.

Works fine here: WebStorm 2016.3.2 on Kubuntu 16.04 linux.

WebStorm screenshot with fixed font

ogram

Posted 2013-07-03T09:58:18.507

Reputation: 21

This is buried at the bottom, but THIS is the real culprit. Everyone above is focused on the Editor fonts, but I already had good editor fonts. My problem was the various callouts, tooltips, and modal dialogues all showed terrible font render with no antialiasing. I tried everything above and none of it resolved the issue, but hiding the packaged jre did the trick. – Dan – 2016-12-26T06:42:55.063

1

In Windows 10, I had similar issues. Checking the Disable display scaling on high DPI settings made the fonts smoother but much bigger. Here's how to do this (from a previous comment from another user):

Right click on its icon, select Properties, go to Compatibility tab and check Disable DPI scaling on high DPI settings

Going into Windows Settings and searching for Display Settings, there's a dialog with a slider that says Change the size of text, apps, and other items. I moved it from 125% to 100% and had to logoff and log back in. The fonts are small AND smooth now:

enter image description here

Even more, if I uncheck Disable display scaling on high DPI settings, it appears to still be smooth.

User1

Posted 2013-07-03T09:58:18.507

Reputation: 7 653

This was the only solution that worked for me! Thx! – DrKaoliN – 2017-12-21T11:35:28.930

1

If you can't clear hints with FontForge like guari explained in his answer. Use Cousine (Apache License v2.00) as editor font and set the size to 14. I tried a couple of other monospaced fonts. However, Cousine seems to have a nicer rendering than the most other fonts. See the screenshot at the end

  1. Download the font: cd ~/Downloads/ && wget www.fontsquirrel.com/fonts/download/cousine
  2. Create a new font family dir: sudo mkdir /usr/share/fonts/truetype/Cousine
  3. Extract the font files: sudo unzip cousine -d /usr/share/fonts/truetype/Cousine/
  4. Make them available for IntelliJ: sudo chmod -R 777 /usr/share/fonts/truetype/Cousine
  5. Update the font cache: sudo fc-cache -f -v
  6. Restart IntelliJ and choose Cousin as editor font
  7. Don't forget to set the vmoptions like guari explained

Screenshot:

user1185087

Posted 2013-07-03T09:58:18.507

Reputation: 119

Your screenshot doesn't look like it's using anti-aliasing. – Ztyx – 2017-06-15T15:34:28.307

Replaced the screenshot by a smaller one to prevent down scaling. Now you can see that anti-aliasing is used – user1185087 – 2017-06-27T13:33:30.400

0

You can install Oracle JDK-8. Tested on ubuntu 14.04, should work for later also.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Check the version:

$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Took from here.

Temak

Posted 2013-07-03T09:58:18.507

Reputation: 123

0

This is how it looks like with horrible font rendering on ubuntu 16.04:

This is how it looks like with horrible font rendering on ubuntu 16.04

If you are using the IntelliJ IDEA 2016.X or later without bundled JDK, you can set an environment variable "IDEA_JDK" to specify a specific runtime. Font rendering in ubuntu 16.04 with Android studio is perfect, so you can share the same JRE with Intellij IDEA. IntelliJ looks for IDEA_JDK environment variable first, so set it by adding a file:

/etc/profile.d/IDEA_SDK.sh

Add this to the file:

export IDEA_JDK=/opt/android-studio/jre

Adjust /opt/android-studio/jre as per your installation. Logout and login back and fire your Intellij IDE

This is what it looks like after using the new JRE:

This is what it looks like after using the new JRE

Abhisek Padhi

Posted 2013-07-03T09:58:18.507

Reputation: 1

0

The accepted answer didn't work for me but I got everything working by doing this:

After reading various tutorials and messing with a bunch of fixes I've found a way that works perfectly.

First of all download JDK 8 from Oracle and execute the following lines in the terminal:

cd Downloads
tar -xvf jdk-8u25-linux-x64.tar.gz
rm jdk-8u25-linux-x64.tar.gz
sudo mkdir -p /usr/lib/jvm/
sudo mv jdk1.8.0_25 /usr/lib/jvm/

Now download the JDK font fix (Courtesy of [Urshulyak Yaroslav][2]) by executing the following:

cd ~/Downloads
wget http://urshulyak.com/jdk-8u5-tuxjdk-b08.tar.gz
tar -xvf jdk-8u5-tuxjdk-b08.tar.gz
sudo mv jdk-8u5-tuxjdk-b08 /usr/lib/jvm
rm jdk-8u5-tuxjdk-b08.tar.gz

This will extract the downloaded zip and move it to /usr/lib/jvm/. Now run the following in the terminal:

cd ~
sudo gedit .bashrc

Then add the following lines to the very bottom of the bashrc file.

JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25/
export JAVA_HOME

Save it then gedit the idea.sh. (Your script location may be different)

gedit /home/USER/Downloads/idea/bin/idea.sh

At the very bottom of the script replace the line(s) in the While Do statement at the bottom with these two lines:

eval "/usr/lib/jvm/jdk-8u5-tuxjdk-b08/bin/java" $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME "$@"
test $? -ne 88 && break

Save it then open up IntelliJ, the fonts should work and you will be using Oracle JDK 8 for development. You will likely have to edit Project Settings and set up your JDK again but be sure to use the actual JDK and not the font fix one.

This fix also works with CLion, Android Studio and [PyCharm.

These instructions assume the JDK version was 1.8.0_25, file/path names will change for future versions.

user327409

Posted 2013-07-03T09:58:18.507

Reputation:

Would you have an idea how to get this working with PhpStorm? The bottom of the file looks like this: LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JDK/bin/java"
$AGENT
"-Xbootclasspath/a:$IDE_HOME/lib/boot.jar"
-classpath "$CLASSPATH"
$VM_OPTIONS "-Djb.vmOptionsFile=$VM_OPTIONS_FILES_USED"
"-XX:ErrorFile=$HOME/java_error_in_WEBIDE_%p.log"
-Djb.restart.code=88 -Didea.paths.selector=WebIde90
$IDE_PROPERTIES_PROPERTY
$IDE_JVM_ARGS
$REQUIRED_JVM_ARGS
$MAIN_CLASS_NAME
"$@" EC=$? test $EC -ne 88 && exit $EC #test $? -ne 88 && break exec "$0" "$@"
– MichaelHindley – 2015-09-17T21:08:29.563

-1

I realized that the anti-aliasing of phpstorm works quite well using the default configuration.The comparison of the two commands shows that the only difference is phpstorm using its own java (/usr/share/phpstorm/jre64/bin/java).

I modified the startup script of idea to make it using phpstorm's java and it worked and everything is as good as phpstorm do. screen shot

jswh

Posted 2013-07-03T09:58:18.507

Reputation: 1

What changes? Do you need to install phpstorm for it? – Journeyman Geek – 2017-10-31T06:10:58.430