systemfont

package
v0.0.0-...-c8481c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

README

systemfont

Purpose

systemfont resolves fonts from local machine sources.

It prefers a fontconfig list (fontlist.txt under the app config area) and falls back to platform directory scanning. fontlist.txt is the output of fontconfig command fc-list. Place it into os.UserConfigDir()/myapp/fontlist.txt, with «myapp» being the shortname of your application.

See package os: os.UserConfigDir

API

  • type IO (injectable host I/O for tests)
  • Find(appkey, io) locate.FontLocator
  • FindLocalFont(appkey, io, pattern, style, weight) (fontfind.ScalableFont, error)

appkey determines where fontconfig list data is looked up.

Example

desc := fontfind.Descriptor{
	Pattern: "Noto Sans",
	Style:   font.StyleNormal,
	Weight:  font.WeightNormal,
}
systemSearcher := systemfont.Find("myapp", nil)
font, err := locate.ResolveFontLoc(desc, systemSearcher).Font()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(appkey string, io IO) locate.FontLocator

Find creates a FontLocator that resolves fonts from local system sources.

appkey identifies the caller's config area used for fontconfig list lookup. io customizes host I/O and may be nil.

func FindLocalFont

func FindLocalFont(appkey string, io IO, pattern string, style font.Style, weight font.Weight) (
	fontfind.ScalableFont, error)

FindLocalFont searches for a locally installed font variant.

If present and configured, FindLocalFont uses the fontconfig system (https://www.freedesktop.org/wiki/Software/fontconfig/).

If fontconfig is not configured, FindLocalFont will fall back to scanning system font folders (OS dependent).

Types

type IO

type IO interface {
	UserConfigDir() (string, error)
	DirFS(string) fs.FS
	ReadAll(io.Reader) ([]byte, error)
}

IO decouples font lookup from OS I/O for testability.

var USE_SYSTEM_IO IO = nil

Use this as an IO parameter if you do not want to provide any and to rely on normal OS behaviour.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL