termtab-0.1.0.0: TUI guitar tablature and score editor
Safe HaskellNone
LanguageGHC2021

Termtab.Graphics.FreeType

Description

Minimal FFI binding to the system FreeType library.

We deliberately bind the handful of FreeType entry points we need rather than depend on the freetype2 Hackage package: that package vendors and compiles FreeType's C source (including a bundled zlib) which does not build on the hermetic Apple-SDK toolchain. Linking the nixpkgs system freetype via pkgconfig-depends: freetype2 is robust across clang versions.

This is the raw rasterization layer: it turns a glyph (a Unicode code point, e.g. a SMuFL notehead in Bravura) into an 8-bit grayscale coverage bitmap plus placement metrics. Glyph caching lives one layer up in Termtab.Graphics.Font.

Synopsis

Documentation

data FontFace Source #

A loaded font face together with the library that owns it.

newFontFace :: FilePath -> IO FontFace Source #

Load a font face from a file path. Throws via error on failure.

freeFontFace :: FontFace -> IO () Source #

Release a font face and its owning library.

data GlyphBitmap Source #

An 8-bit grayscale coverage bitmap plus FreeType placement metrics.

Constructors

GlyphBitmap 

Fields

  • gbImage :: Image Pixel8

    Coverage: 0 = transparent, 255 = fully inked.

  • gbLeft :: Int

    Horizontal bearing: pixels from the pen x to the bitmap's left edge.

  • gbTop :: Int

    Vertical bearing: pixels from the baseline up to the bitmap's top edge.

  • gbAdvance :: Int

    Horizontal advance in whole pixels.

renderGlyph :: FontFace -> Int -> Char -> IO (Maybe GlyphBitmap) Source #

Render a single character at the given pixel height. Returns Nothing only if FreeType could not load/render the glyph. A whitespace glyph with no ink renders as a 0x0 image (its gbAdvance is still meaningful).