---
title: "onefont Go cookbook"
url: https://recursiveai.org/onefont/go/cookbook/
description: "9 onefont-go recipes, each with complete code."
version: "1.1.1"
---

# onefont Go cookbook

## Font outlines and metrics

- [Measure text width in Go with a font](https://recursiveai.org/onefont/go/cookbook/measure-shaped-text-width/index.md): Shape text with a TTF or OTF font in Go, then convert the run’s horizontal advance from font units to pixels at your chosen size.
- [Convert a glyph outline to an SVG path in Go](https://recursiveai.org/onefont/go/cookbook/export-glyph-outline-as-svg-path/index.md): Read a TTF or OTF glyph outline in Go and turn its lines and curves into SVG path data, flipping the y coordinates so the glyph stays upright.
- [Set a variable font axis in Go](https://recursiveai.org/onefont/go/cookbook/instantiate-variable-font-axis/index.md): Create a Roboto Flex instance at a chosen weight in Go, then read the glyph advance at that coordinate and compare it with the default.

## Shape and segment text

- [Split mixed RTL and LTR text into bidi runs in Go](https://recursiveai.org/onefont/go/cookbook/resolve-bidirectional-text-runs/index.md): Use Unicode bidirectional resolution in Go to split mixed Hebrew and Latin text into runs in display order and inspect each run’s direction.

## Read font files

- [Decompress WOFF2 to a font file in Go](https://recursiveai.org/onefont/go/cookbook/decompress-woff2-to-sfnt/index.md): Unpack WOFF2 in Go and save the result as TTF, OTF, or TTC by reading its font signature instead of guessing from the web font’s name.

## Break text

- [Find Thai line break opportunities in Go](https://recursiveai.org/onefont/go/cookbook/find-thai-line-breaks/index.md): Find Thai line break opportunities without splitting on spaces. Get UTF-8 byte offsets with onefont-go’s built-in dictionary before measuring lines.
- [Iterate Unicode grapheme clusters in Go](https://recursiveai.org/onefont/go/cookbook/split-string-into-grapheme-clusters/index.md): Iterate user-perceived characters in a Go string without splitting accents or emoji sequences. Get whole clusters or UTF-8 byte boundaries.

## Shape text

- [Choose an emoji fallback font in Go](https://recursiveai.org/onefont/go/cookbook/shape-text-with-emoji-fallback/index.md): Keep text in your primary font and prefer a color emoji font for emoji sequences. Shape both presentations in Go and see which font each run uses.
- [Apply an OpenType feature to a range in Go](https://recursiveai.org/onefont/go/cookbook/apply-opentype-feature-to-text-range/index.md): Apply a ranged OpenType feature in Go using UTF-8 byte offsets. Disable the fi ligature in one part of a string without changing the rest.
