MyNixOS website logo
Description

Unicode segmentation and shaping using kb_text_shape.

kb-text-shape

Haskell wrapper for the kb_text_shape.h unicode segmentation and shaping library.

  Your text       A        Text runs with         B       Sequence of glyphs      C
  (Probably ------------> uniform direction ------------> ready to rasterize ------------> Pixels
  UTF-8)                    and script

We call arrow A text segmentation, arrow B text shaping, and arrow C rasterization. This library does A and B.

import KB.Text.Shape where qualified as TextShape

main = do
  TextShape.withContext \ctx -> do
    _fallback <- TextShape.pushFontFromFile ctx "test/NotoSans-Regular.ttf" 0
    _main <- TextShape.pushFontFromFile ctx "test/Ubuntu-R.ttf" 0
    results <- TextShape.run ctx do
      TextShape.text_ "A bunch of characters"
      TextShape.char_ '!'
    forM_ results \(run, glyphs) ->
      forM_ glyphs \glyph ->
        print (run.font, glyph.id, glyph.gpos.advanceX)

Font blobs

The library has an internal "blob" format for the pre-processed font data for leaner files and faster loading.

import KB.Text.Shape.Font qualified as Font

main = do
  ttfData <- ByteString.readFile "test/Ubuntu-R.ttf"
  putStrLn $ "Distilling " <> show (ByteString.length ttfData `div` 1024) <> "Kb of TTF"
  blobData <- Font.extractBlob ttfData 0
  putStrLn $ "Distilled into " <> show (ByteString.length blobData `div` 1024) <> "Kb blob"
  ByteString.writeFile "test/Ubuntu-R.kbts" blobData

The savings are modest, but can be improved even further with compression.

Distilling 1047Kb of TTF
Distilled into 618Kb blob
Metadata

Version

0.1.0.0

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows