A simple library for font loading and glyph rasterization using FontConfig, FreeType and pixman.
Find a file
Daniel Eklöf c01a5e8626
All checks were successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/push/woodpecker Pipeline was successful
changelog: add new 'unreleased' section
2025-03-13 13:21:06 +01:00
.builds ci: "meson [options]" is deprecated (do "meson setup [options]" instead) 2025-01-04 12:00:51 +01:00
3rd-party/nanosvg nanosvg: update to ea6a6aca009422bba0dbad4c80df6e6ba0c82183 2025-01-24 07:01:28 +01:00
doc doc: bump version to 3.3.1 2025-03-13 13:17:15 +01:00
example example: add -e,--emoji-presentation command line option 2025-03-12 09:31:53 +01:00
fcft fcft_set_scaling_filter(): regression: fix binary incompat with fcft >= 3.2 2025-03-13 13:13:09 +01:00
nanosvg meson/nanosvg: add support for linking against system's nanosvg 2024-07-18 15:32:56 +02:00
subprojects subprojects: add tllist.wrap 2024-06-22 08:56:17 +02:00
unicode unicode: update license 2025-01-02 17:37:08 +01:00
.gitignore subprojects: add tllist.wrap 2024-06-22 08:56:17 +02:00
.gitmodules tllist: remove submodule 2020-09-16 21:32:48 +02:00
.woodpecker.yaml ci: "meson [options]" is deprecated (do "meson setup [options]" instead) 2025-01-04 12:00:51 +01:00
CHANGELOG.md changelog: add new 'unreleased' section 2025-03-13 13:21:06 +01:00
fcft.c fcft: don't apply a scaling filter when scaling non-emoji bitmap glyphs 2025-03-12 09:39:47 +01:00
generate-emoji-data.py generate-emoji-data: disable debug print 2022-02-27 11:24:30 +01:00
generate-unicode-precompose.sh fcft: replace wchar_t with uint32_t 2022-01-15 13:13:16 +01:00
generate-version.sh generate-version: handle git repo not having any tags 2021-10-11 20:19:47 +02:00
LICENSE license: add missing license (MIT) file. Closes #3 2020-07-25 08:48:01 +02:00
log.c log: don't colorize output when NO_COLOR is defined and not empty 2024-07-18 08:27:50 +02:00
log.h log: improve logging configurability 2021-04-17 12:17:51 +02:00
meson.build meson+pkgbuild: bump version to 3.3.1 2025-03-13 13:16:56 +01:00
meson_options.txt meson/nanosvg: add support for linking against system's nanosvg 2024-07-18 15:32:56 +02:00
nanosvg.c meson/nanosvg: add support for linking against system's nanosvg 2024-07-18 15:32:56 +02:00
nanosvgrast.c meson/nanosvg: add support for linking against system's nanosvg 2024-07-18 15:32:56 +02:00
PKGBUILD meson+pkgbuild: bump version to 3.3.1 2025-03-13 13:16:56 +01:00
README.md readme: update Unicode license link 2025-01-02 17:38:23 +01:00
screenshot.png example: improved default text string 2022-11-30 15:12:04 +01:00
svg-backend-nanosvg.c meson/nanosvg: add support for linking against system's nanosvg 2024-07-18 15:32:56 +02:00
svg-backend-nanosvg.h fcft: initial support for OT-SVG glyphs 2022-04-30 23:01:19 +02:00
test.c fcft: deprecate fcft_set_scaling_filter(), use fcft_font_options instead 2025-03-12 09:10:07 +01:00

CI status

fcft

Packaging status

fcft is a small font loading and glyph rasterization library built on-top of FontConfig, FreeType2 and pixman.

It is aimed at applications that value speed and simplicity. Its only dependencies are those listed above, and optionally nanosvg (for OT-SVG support). Fcft is perfect for pixman based applications, since its "output" (the rasterized glyphs) are pixman images.

The primary goal of fcft is speed. It was created to support foot, for which I found Cairo to be too slow.

To achieve this, fcft has first class support for threaded glyph lookup, and it aggressively caches rasterized glyphs. This is what allows foot to make full use of its multiple worker (rendering) threads.

Feature wise, it sits somewhere between Cairo, pango. Compared to Cairo, it does not do generic 2D graphics, but it does do more advanced font shaping.

Compared to pango, its font shaping support is more limited, but instead it has better support for different font file formats (pango only supports the font formats supported by HarfBuzz, while fcft supports those handled by FreeType - and FreeType supports more font formats than HarfBuzz).

It can load and cache fonts from a fontconfig-formatted name string, e.g. Monospace:size=12, optionally with user configured fallback fonts.

After a font has been loaded, you can rasterize glyphs. When doing so, the primary font is first considered. If it does not have the requested glyph, the user configured fallback fonts (if any) are considered. If none of the user configured fallback fonts has the requested glyph, the FontConfig generated list of fallback fonts are checked.

The API is documented as man pages. These are built and installed when fcft is built as a standalone project, but not when built as a subproject.

Starting with 2.3.0, fcft gained the ability to do text shaping using HarfBuzz (an optional dependency). Initially, only individual grapheme clusters could be shaped. With 2.4.0, the ability to shape whole text-runs were added. It should be noted however, that fcft does not aim to compete with e.g. Pango, and that the text shaping support may not be (and perhaps never will be) sufficient for “professional” text layout.

screenshot

The screenshot above is the output of the example program shipped with the fcft sources (but not built by default). It showcases the three different levels, at which fcft can rasterize glyphs:

Top: fcft_glyph_rasterize()
Glyphs are rasterized character by character; no ligatures, no grapheme shaping, and right-to-left scripts are not rendered correctly.
Middle: fcft_grapheme_rasterize()
Glyphs are rasterized grapheme by grapheme. Here, graphemes are shaped correctly (e.g. the family emoji), but ligatures and RTL scripts are still not rendered correctly.
Bottom: fcft_text_run_rasterize()
The entire string is rasterized in one go. This means full shaping is applied; ligatures, graphemes, and RTL scripts.

Requirements

  • fontconfig
  • freetype (>= 2.12 required for SVG support)
  • pixman
  • harfbuzz (optional, for grapheme and “run” shaping support)
  • libutf8proc (optional, for “run” shaping support)
  • tllist, unless built as a subproject

Features

  • Supports all fonts loadable by FreeType2
  • Antialiasing
  • Subpixel antialiasing
  • Color bitmap fonts (emoji fonts)
  • OT-SVG (requires FreeType >= 2.12)
  • Font caching
  • Glyph caching
  • Kerning1
  • Basic text shaping if compiled with HarfBuzz support

Not supported

  • Subpixel positioning

Remember, this is a simple library, not a full blown layout engine.

Projects using fcft

Integrating

You can either install fcft as a system library, or use it as a meson subproject (assuming your project is meson based, of course).

Installing

If you install fcft as a system library, you can use pkg-config to get the compiler flags needed to find and link against fcft.

Meson

If your project is meson based, you can use fcft as a subproject. In your main project's meson.build, do something like:

fcft = subproject('fcft').get_variable('fcft')
executable('you-executable', ..., dependencies: [fcft])

Or, if fcft has been installed as a system library, a regular

fcft = dependency('fcft')

will suffice. Optionally, you can combine the two; search for a system library first, and fallback to a subproject:

fcft = dependency('fcft', version: '>=0.4.0', fallback: 'fcft')

Building

Run-time dependencies:

  • fontconfig
  • freetype2
  • pixman
  • harfbuzz (optional, for text shaping support)
  • utf8proc2
  • wayland2
  • wayland-protocols2

Build dependencies:

  • Development packages of the run-time dependencies
  • meson
  • ninja
  • scdoc (optional, enabled automatically or disabled with -Ddocs=disabled)
  • tllist
  • check (optional, for unit tests)

For most users, this is typically enough:

meson build --buildtype=release
ninja -C build
ninja -C build test
sudo ninja -C build install

The tests require at least one latin font to be installed.

By default, fcft will be built with support for text-shaping if HarfBuzz is available. You can explicitly enable or disable this with the -Dtext-shaping=disabled|enabled|auto meson command line option.

If text-shaping is enabled, you might also want to enable the associated tests. Use -Dtest-text-shaping=true to do so. Note that these tests require an emoji font to be installed, and fc-match emoji must return that font first.

SVG support is also enabled by default, using the bundled nanosvg library. You can disable this with -Dsvg-backend=none.

To build the example programs, use the -Dexamples=true meson command line option.

License

fcft is released under the MIT license.

fcft uses Unicode data files released under the Unicode License V3.


  1. only basic kerning supported (i.e. the old 'kern' tables, not the new 'GPOS' tables) ↩︎

  2. required by example programs ↩︎