How to disable font hinting in Swing (or how to strip hints from a font)

In my GNOME desktop, I disable hinting or set hinting level to ‘slight’. The hinting level beyond ‘slight’ (i.e. ‘moderate’ or ‘full’) 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 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 (and that was always why I go back to SWT-based Eclipse). Although Swing uses Freetype to render glyphs, which is the same library that GTK uses to render glyphs, it doesn’t seem to respect my font appearance settings:

This issue was raised a couple times in the community, but the latest OpenJDK 7 snapshot still doesn’t seem to fix this issue unfortunately. Therefore, there’s no way currently to disable font hinting in Sun/Oracle JDK or OpenJDK on Linux. What’s 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.

To strip the hinting information from a TrueType font, you can use FontForge:

  1. Open your TTF file with FontForge.
  2. Press CTRL+A to select all glyphs.
  3. Choose Hints -> Clear Hints menu item (and wait for a while)
  4. Choose Hints -> Clear Instructions menu item (and wait for a while)
  5. Choose File -> Generate Fonts menu iteam and replace the existing font with the unhinted one.

If you don’t want to replace the existing font, press CTRL+SHIFT+F to update the metadata before the last step. A ‘Font Information’ dialog will show up and you can edit font names there.

Once the new fonts are generated, you can update your ~/.fonts.conf to make the unhinted fonts your default desktop:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <!-- Note that I actually appended 'U' to all unhinted font names -->
  <match target="pattern">
    <test qual="any" name="family">
      <string>sans-serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Liberation Sans U</string>
      <string>WenQuanYi Zen Hei U</string>
    </edit>
  </match>
  <match target="pattern">
    <test qual="any" name="family">
      <string>sans-serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Liberation Serif U</string>
      <string>WenQuanYi Zen Hei U</string>
    </edit>
  </match>
  <match target="pattern">
    <test qual="any" name="family">
      <string>monospace</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Liberation Mono U</string>
      <string>WenQuanYi Zen Hei U</string>
    </edit>
  </match>
</fontconfig>

If configured properly, hinting will be automatically disabled for all desktop applications soon no matter what hinting option you specified because there’s no hinting information in the new fonts.

Now open or restart your favorite Swing application and choose GTK 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:

Actually, the italicized bold glyphs doesn’t look perfect, but I can live with it. It would be really nice if OpenJDK delivers a proper fix in the near future, though.

Advanced Bash-Scripting Guide in ePub and MOBI format

Mendel Cooper’s Advanced Bash-Scripting Guide is the most definitive and up-to-date guide for Bash. If you are interested in some advanced topics in shell scripting, this book is for you.
However, if you prefer to read a document in your e-book reader such as Kindle and Sony Reader, you are in trouble because the guide is only provided in TXT, HTML, PDB, and PDF / PS format. PDB is the closest thing to the modern e-book formats, but it seems like there’s no good free converter yet.
Good news is, because I really wanted to read it in my Kindle, I converted it into ePub and MOBI format. Download them here:

Unfortunately, the conversion was done manually, so I’m not sure I’ll update it again when a new version is released since the guide is already good enough for me. Hopefully, once the author converts the SGML source into XML and DocBook ePub stylesheet matures, the conversion will be much simpler and completely automatic.

최고의 순간은 오지 않았다

요즘은 ‘최고의 순간은 아직 오지 않았다’ 라는 말을 자주 되새긴다. 이 말은 여러 곳에서 자주 나오지만 나는 브리짓 존스의 일기사운드트랙 중 한 곡인 Dina Carroll 이 부른 Someone Like You 에서 처음 접했다.

방향을 잃고 무너져가는 것 같은 순간이 오면 그 말을 되새긴다. 무엇이든 진지하게 해 나아간다면 스스로에게 있어 최고의 순간은 매일 찾아오는 것에 다름없음을 어리석으나마 재차 깨닫는다. 좋은 결과가 따라온다면 더 좋겠지만 그렇지 않아도 상관은 없다. 나 자신의 주인이 되는 것만큼 즐거운 것은 없다.

아무리 그렇다고 해도 매일 매일 맞딱뜨리는 고민과 갈등이 하나도 힘들지 않다면 거짓말이다. 가족이나 친구처럼 기댈 수 있는 존재가 있기에 이런 달콤한 이야기도 할 수 있다. 매일 매일 찾아 오는 최고의 순간이라면 매일 매일 함께 축하하고 축하받고 싶다.