{"id":2280,"date":"2010-11-30T23:38:49","date_gmt":"2010-11-30T23:38:49","guid":{"rendered":"http:\/\/t.motd.kr\/articles\/2280\/how-to-disable-font-hinting-in-swing-or-how-to-strip-hints-from-a-font"},"modified":"2022-12-28T01:44:48","modified_gmt":"2022-12-27T16:44:48","slug":"how-to-disable-font-hinting-in-swing-or-how-to-strip-hints-from-a-font","status":"publish","type":"post","link":"https:\/\/vault.motd.kr\/wordpress\/posts\/2280\/how-to-disable-font-hinting-in-swing-or-how-to-strip-hints-from-a-font\/","title":{"rendered":"How to disable font hinting in Swing (or how to strip hints from a font)"},"content":{"rendered":"\n
In my GNOME<\/span> desktop, I disable hinting<\/a> or set hinting level to \u2018slight\u2019. The hinting level beyond \u2018slight\u2019 (i.e. \u2018moderate\u2019 or \u2018full\u2019) makes glyph look too thin to read easily. Moreover, especially when screen DPI<\/span> is high, unhinted or slightly hinted glyphs look much more beautiful than fully hinted ones:<\/p>\n\n\n\n If you think fully hinted one looks better or you are using Mac OS X, you are so lucky that you can skip this article. My font preference is often a problem to Java Swing based applications such as IntelliJ IDEA<\/span><\/a> (and that was always why I go back to SWT<\/span>-based Eclipse<\/a>). Although Swing uses Freetype<\/a> to render glyphs, which is the same library that GTK<\/span> uses to render glyphs, it doesn\u2019t seem to respect my font appearance settings:<\/p>\n\n\n\n This issue was raised a couple times in the community, but the latest OpenJDK 7 snapshot still doesn\u2019t seem to fix this issue unfortunately. Therefore, there\u2019s no way currently to disable font hinting in Sun\/Oracle JDK<\/span> or OpenJDK on Linux. What\u2019s possible is working around the problem by stripping the hinting information out from your font files so that Swing does not apply any hinting because of the missing information.<\/p>\n\n\n\n To strip the hinting information from a TrueType font, you can use FontForge<\/a>:<\/p>\n\n\n\n If you don\u2019t want to replace the existing font, press CTRL<\/span>+SHIFT+F to update the metadata before the last step. A \u2018Font Information\u2019 dialog will show up and you can edit font names there.<\/p>\n\n\n\n Once the new fonts are generated, you can update your ~\/.fonts.conf<\/tt> to make the unhinted fonts your default desktop:<\/p>\n\n\n\n If configured properly, hinting will be automatically disabled for all desktop applications soon no matter what hinting option you specified because there\u2019s no hinting information in the new fonts.<\/p>\n\n\n\n Now open or restart your favorite Swing application and choose GTK<\/span> Look & Feel. If you have to specify the font name explicitly, choose the unhinted one (e.g. Liberation Mono U). The result is your new-born Swing application with its ever-pleasing look:<\/p>\n\n\n\n Actually, the italicized bold glyphs doesn\u2019t look perfect, but I can live with it. It would be really nice if OpenJDK delivers a proper fix in the near future, though.<\/p>\n","protected":false},"excerpt":{"rendered":" In my GNOME desktop, I disable hinting or set hinting level to \u2018slight\u2019. The hinting level beyond \u2018slight\u2019 (i.e. \u2018moderate\u2019 or \u2018full\u2019) makes glyph look too thin to read easily. Moreover, especially when screen DPI is high, unhinted or slightly hinted glyphs look much more beautiful than fully hinted ones: If you think fully hinted… Continue reading <\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n<fontconfig>\n <!-- Note that I actually appended 'U' to all unhinted font names -->\n <match target=\"pattern\">\n <test qual=\"any\" name=\"family\">\n <string>sans-serif<\/string>\n <\/test>\n <edit name=\"family\" mode=\"prepend\" binding=\"strong\">\n <string>Liberation Sans U<\/string>\n <string>WenQuanYi Zen Hei U<\/string>\n <\/edit>\n <\/match>\n <match target=\"pattern\">\n <test qual=\"any\" name=\"family\">\n <string>sans-serif<\/string>\n <\/test>\n <edit name=\"family\" mode=\"prepend\" binding=\"strong\">\n <string>Liberation Serif U<\/string>\n <string>WenQuanYi Zen Hei U<\/string>\n <\/edit>\n <\/match>\n <match target=\"pattern\">\n <test qual=\"any\" name=\"family\">\n <string>monospace<\/string>\n <\/test>\n <edit name=\"family\" mode=\"prepend\" binding=\"strong\">\n <string>Liberation Mono U<\/string>\n <string>WenQuanYi Zen Hei U<\/string>\n <\/edit>\n <\/match>\n<\/fontconfig><\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n