How to fix font of IntelliJ

Before and after fixing font in Android Studio
Before and after fixing font in Android Studio

Problem

IntelliJ and other tools based on it, like Android Studio, look terrible on Ubuntu 14.04 with OpenJDK 7. The font rendering in the UI is terribly aliased and is a pain on the eyes. This is surprising since Eclipse renders beautifully using the same JDK and Ubuntu system.

Solution

Eclipse uses GTK for its GUI while IntelliJ and Android Studio use Swing. Thankfully, this situation can be fixed.

  • Replace the OpenJDK with a version in which font rendering has been fixed:
$ sudo apt-get purge openjdk-7-jdk
$ sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
$ sudo apt-get update
$ sudo apt install openjdk-7-jdk
  • Open the studio64.vmoptions file and change the anti-aliased font setting to -Dawt.useSystemAAFontSettings=on. Other options suggested by users online did not work for me.

Now IntelliJ or Android Studio should render the font much better. I still notice a bit of aliasing with Consolas, but it is manageable.

Tried with: Android Studio 1.4 and Ubuntu 14.04

Advertisements

Unity Tweak Tool

Unity Tweak Tool is the tool to manage the desktop settings on Ubuntu. This tool seems to be a fork or updated version of the GNOME Tweak Tool.

  • It can be installed from the Ubuntu archives:
$ sudo apt install unity-tweak-tool
  • It can be started as Unity Tweak Tool from the Dash or unity-tweak-tool from the shell.

  • I primarily use it to set the fonts in the desktop apps.

  • Note that when you change the Default Font, the entire desktop has to be restarted. Unity will kill all your desktop apps, logout of your session and leave you at the login screen!

Tried with: Unity Tweak Tool 0.0.6 and Ubuntu 14.04

How to set default font in LibreOffice Calc

LibreOffice Calc is an excellent open-source replacement for the popular spreadsheet program Microsoft Excel. One irritation for me is that the default font and font size it uses are not what I would like. To set your own font, font size and other text formatting as default it takes a few steps as described below.

  1. Open LibreOffice Calc. It opens with a new spreadsheet document.

  2. First, we set our font as default for this spreadsheet document: Go to Format -> Styles and Formatting. Right-click on Default and choose Modify. In the Font tab, set the font, font size and other formatting options that you would like to be the default. Click OK.

  3. We now save this format as a template: Go to File -> Templates -> Save As Template. Choose My Templates and click Save. Give your template a name.

  4. Finally, we make our template as the default template: Go to File -> Templates -> Manage. In the Spreadsheets tab, click on your template and click Set as default. We are done! 🙂

All new spreadsheets created by Libreoffice Calc will now have the default font set in this template. Note that this is the font that will also be used for comments in Calc.

Tried with: LibreOffice 4.2.8.2 and Ubuntu 14.04

Fonts for Math in LaTeX

Similar to fonts for textual content, there are formatting styles or fonts that can be used on math expressions in LaTeX. For example, the set of real numbers R is typically written with what is called a blackboard bold font.

The formatting styles for math in LaTeX are:

mathnormal: This is the default for math expressions. The letters are italicized a bit. No need to apply it explicitly.
mathrm:     Non-italicized version of normal.
mathit:     Italicized like normal, but suits words better.
mathbf:     Bold. Use for vectors and so on.
mathsf:     Sans serif.
mathtt:     Fixed-width.
mathfrak:   Fraktur. Used for lie algebras.
mathcal:    Calligraphic.
mathbb:     Used for real sets.
mathscr:    Script.

A table of these fonts applied on symbols can be seen here.

Tried with: Ubuntu 14.04

Type 3 fonts not OK error on submitting PDF

20150313_fonts

Problem

Certain online submission services check the fonts used in the submitted PDF file. Many of them allow only Type 1 and TrueType fonts in the PDF. Type 3 fonts which may not scale well in printing are not allowed. I got the error shown in the screenshot above when I tried submitting to one such website.

Solution

  • Find out which fonts are being used in your PDF and for what objects. This can be done by using the PDFFonts tool as described here.
    For example, I found that I had been using Type 3 fonts in a SVG image and in a plot generated by Matplotlib.

  • Next fix the source of these font problems. I edited the SVG image to use Type 1 or TrueType fonts. I requested Matplotlib to use LaTeX fonts for text rendering, as described here.

The PDF file regenerated from these files passed the font checks 🙂

Tried with: Ubuntu 14.04

PDFFonts

PDFFonts is a useful tool to view information about the fonts in a PDF file. Typically, you need to bother with this only if you are having problems with submitting a PDF online or printing it.

This tool ships along with Poppler. To install it:

$ sudo apt install poppler-utils

Usage is straightforward. It is illustrated here with a sample PDF file:

$ pdffonts foo.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
MMFXPR+NimbusSanL-Bold               Type 1            Custom           yes yes no      25  0
KPMIUD+NimbusRomNo9L-ReguItal        Type 1            Custom           yes yes no      31  0
Arial,Bold                           TrueType          WinAnsi          no  no  no      77  0
Times New Roman,Bold                 TrueType          WinAnsi          no  no  no      78  0
ABCDEE+Calibri                       TrueType          WinAnsi          yes yes no      79  0
NHFWQZ+CMMI10                        Type 1            Builtin          yes yes no     160  0
COBEQK+CMMI7                         Type 1            Builtin          yes yes no     166  0
FOCRQR+CMR12                         Type 1            Custom           yes yes no     175  0
UJTTFG+CMR8                          Type 1            Builtin          yes yes no     266  0
DejaVuSans                           Type 3            Custom           yes no  no     283  0
SBITTL+CMMI8                         Type 1            Builtin          yes yes no     331  0
Cmr10                                Type 3            Custom           yes no  no     475  0
DejaVuSans                           Type 3            Custom           yes no  no     958  0

It displays various attributes of the font:

  • Name of the font
  • Type of the font (Type 1, Type 3 or TrueType)
  • The encoding (Builtin, WinAnsi or Custom)
  • Whether the font is embedded in the PDF
  • ID of the object in the PDF which uses this font

Tried with: Poppler-Utils 0.24.5 and Ubuntu 14.04

How to set font in GVim

20150311_guifont

The font used by GVim can be set by choosing Edit -> Select Font, which displays a dialog to pick the font. You can get the same dialog by using the command :set guifont=*

The chosen font is used only for the current session and GVim reverts back to its default font after that.

To set the default font used by GVim, add a command of the form set guifont= to your gvimrc. If you want to add it to vimrc file, then enclose this command in a if has("gui_running") block.

The only tricky part here is, what is the format in which the font and font size should be specified? An easy trick is to set the font and font size in the font dialog and then query it back using :set guifont?. Use the exact value that it displays. Note that the format of the font string varies according to the platform. A Ubuntu Mono font in size 10 is given as Ubuntu Mono:h10 on Windows and as Ubuntu Mono 10 on Linux.

Also on Linux, note that you should not enclose the font string in single or double quotes. If the font string has spaces, then escape them using backslashes. Enclosing in quotes works fine on Windows.

Tried with: Vim 7.4 and Ubuntu 14.04

Fonts in OpenCV

Fonts available in OpenCV
Fonts available in OpenCV

OpenCV can be used to render text on an image buffer using the putText function. Several simple fonts are available in OpenCV which can be used to write text.

The available fonts can be seen defined in modules/core/include/opencv2/core/core.hpp header file:

enum
{
    FONT_HERSHEY_SIMPLEX = 0,
    FONT_HERSHEY_PLAIN = 1,
    FONT_HERSHEY_DUPLEX = 2,
    FONT_HERSHEY_COMPLEX = 3,
    FONT_HERSHEY_TRIPLEX = 4,
    FONT_HERSHEY_COMPLEX_SMALL = 5,
    FONT_HERSHEY_SCRIPT_SIMPLEX = 6,
    FONT_HERSHEY_SCRIPT_COMPLEX = 7,
    FONT_ITALIC = 16
};

FONT_ITALIC is not a font, but can be combined with the other fonts to get italic text.

Tried with: OpenCV 2.4.9 and Ubuntu 14.04

GNOME Tweak Tool

GNOME Tweak Tool
GNOME Tweak Tool

GNOME Tweak Tool is a tool that can be used to change the fonts and other UI elements of GNOME. Since Ubuntu Unity is based on GNOME, this affects how many of your applications and desktop will look.

Installing the tool is easy:

$ sudo apt install gnome-tweak-tool

It can be invoked from the Dash as Tweak Tool or from the shell as gnome-tweak-tool.

I typically use this tool to change the fonts for the Window Titles, Interface and Documents. These apply to an astonishing array of UI elements in many applications that are built on GTK or GNOME.

Tried with: GNOME Tweak Tool 3.10.1-2 and Ubuntu 14.04