User:Alissa Sabre/Notes on fontconfig

From Second Life Wiki
Jump to: navigation, search

This is a discussion paper to use fontconfig in SL Viewer.

Comments are welcome.

What is fontconfig?

  • Fontconfig is an open source library that helps applications to pick up appropriate font files.
  • Fontconfig can enumerate all available font files for applications' and/or users' selection, or it can build and show a list of font files based on some criteria.
  • Fontconfig is already used by some well known open source projects, including GTK+.
  • The fontconfig development site is here.

Why we should (or should not) use it

Primarily to avoid unicode.ttf hack on Linux, and possibly to improve font finding mechanisms on all platforms.

Pluses

  • Fontconfig is available on virtually all Linux desktop these days.
  • On Linux, fontconfig mediates distribution differences such as font file paths, availability of particular fonts, or file naming.
  • Fontconfig is open source, so we can run it on Windows and MacOS.
  • Fontconfig has some knowledge on laguages and scripts, allowing prioritized listing of fonts suitable for a particular language environment.
  • Fontconfig is compatible with FreeType, that SL viewer relies on.

Minuses

  • Fontconfig is not usually available on Windows and MacOS. We can run it on them, but it doesn't work great without pre-configured font database.
  • Creation of the font database is a time consuming job. Usually takes tens of seconds to several minutes, depending on the configuration. (On Linux, font database is cached on disk. On Windows and MacOS, it is not as default.)
  • Fontconfig only knows about serif, sans serif, and monospaced styles. Moreover, its style recognition is totally human definition of an external config file. There are no guarantee that a set of selected fonts shares same or similar design.

How we can use fontconfig in Viewer

Possibilities

  • It may be possible to replace current fallback definition (FontSansSerifFallback in settings.xml) by fontconfig.
  • We can even use both; i.e., mixing fontconfig created list of fonts and those in settings.xml.
  • We can use fontconfig on Linux only, or can use on all platforms.
  • We can use fontconfig to simply enumerate all available fonts and use our own defintion to pick up ones to use.
  • Building a list of fonts using fontconfig is somewhat time consuming, so it's better to build the list once during startup.

Implementation

The changes to use fontconfig will primarily go into LLFontGL::loadFace, LLFontGL::loadFaceFallback and related methods in linden/indra/llrender/llfontgl.cpp.

  • If we use fontconfig only as a font enumerator and only on Linux, uses of getFontPathSystem() will be replaced by some calls to fontconfig functions enclosed in #ifdef LL_LINUX - #endif block.
  • If we use fontconfig to find a list of suitable fonts, loadFaceFallback method will be rewrote entirely.

Related issues

  • VWR-593: Better display of UTF characters
  • VWR-257: Symlink to unicode.ttf is invalid on some systems
  • VWR-81: Non-Latin characters such as Japanese Kanji or Korean Hangul appear as dots/lines
  • Discussion on sldev: Matsuu, Tofu, and me.

Linux uniqueness of font availability and fontconfig

When comparing Windows/MacOS, Linux font environment is unique as follows:

  • Linux has no standard fonts; availability of particular fonts depends on distributions.
  • Default fonts for a particular language/script are not the same either.
  • Linux defines no common font file directory.

This is why the current SL viewer uses uncide.ttf symbolic link. It is also one of the reason why fontconfig was originally written.

Preferred language and fonts

Viewer's current handling of fonts

Face/family abstraction

  • SL Viewer uses a Monospace font and a series of SansSerif font.
  • Monospace has a fixed height, contains Latin-1 characters only, and is used for debug/stats views.
  • SansSerif is available in four hights: small, normal, big, huge.
  • SansSerif of normal height has another variant: bold. (Itallic is not available in SL Viewer.)
  • Viewer doesn't use Serif fonts.

Base fonts and fallback fonts

  • SL Viewer is distributed with three font files. They are used as the base fonts.
    • "profontwindows.ttf" (ProFontWindows) is for Monospace.
    • "MtBkLfRg.ttf" (MetaBookLF-Roman) is for SansSerif (of all heights).
    • "MtBdLfRg.ttf" (MetaBoldLF-Roman) is for SansSerifBold.
  • Base fonts contain Latin-1 characters only.
  • Non-Latin-1 characters (glyphs) are handled by fallback font mechanism.
  • Fallback font is an ordered list of font files. A requested character is searched in the list, and the first one found in a file is used.
  • Particular fallback fonts are defined in settings.xml by the FontSansSerifFallback parameter.

MacOS

  • On MacOS X, the following three fonts are searched in this order as a default:
    • "ヒラギノ角ゴ Pro W3.otf" (Hiragino Kaku Gothic Pro W3), primarily for Japanese characters.
    • "AppleGothic.dfont" (AppleGothic Regular), primarily for Korean characters.
    • "华文细黑.ttf" (STXihei), primarily for simplified Chinese characters.
  • They are all standard MacOS fonts and installed on all language versions.

Windows

Linux

  • Linux version of viewer comes with a symbolic link of the name "unciode.ttf".
  • The link target is adjusted against a particular Linux installation, and it may or may not be a valid path on users' installation. (That may surprise users.)
  • A user is expected to correct (re-create) the symbolic link to an existing font file that contains all characters needed for his/her preferred language.