fontnik

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 16 Imported by: 0

README

Fontnik

GoDoc Widget Build Status codecov Go Report Card

Generates Signed Distance Field glyphsets from OpenType fonts

Inspired by https://github.com/mapbox/sdf-glyph-foundry https://github.com/mapbox/tiny-sdf

Documentation

Index

Constants

View Source
const INF = 1e20

Variables

View Source
var File_glyph_proto protoreflect.FileDescriptor

Functions

func CalcSDF

func CalcSDF(img image.Image, radius float64, cutoff float64) []uint8

func DrawGlyph

func DrawGlyph(glyph *Glyph, smoothstep bool) image.Image

func SavePNG

func SavePNG(path string, img image.Image)

Types

type Fontstack

type Fontstack struct {
	Name   string   `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Range  string   `protobuf:"bytes,2,opt,name=range,proto3" json:"range,omitempty"`
	Glyphs []*Glyph `protobuf:"bytes,3,rep,name=glyphs,proto3" json:"glyphs,omitempty"`
	// contains filtered or unexported fields
}

Stores fontstack information and a list of faces.

func (*Fontstack) Descriptor deprecated

func (*Fontstack) Descriptor() ([]byte, []int)

Deprecated: Use Fontstack.ProtoReflect.Descriptor instead.

func (*Fontstack) GetGlyphs

func (x *Fontstack) GetGlyphs() []*Glyph

func (*Fontstack) GetName

func (x *Fontstack) GetName() string

func (*Fontstack) GetRange

func (x *Fontstack) GetRange() string

func (*Fontstack) ProtoMessage

func (*Fontstack) ProtoMessage()

func (*Fontstack) ProtoReflect

func (x *Fontstack) ProtoReflect() protoreflect.Message

func (*Fontstack) Reset

func (x *Fontstack) Reset()

func (*Fontstack) String

func (x *Fontstack) String() string

type Glyph

type Glyph struct {
	Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// A signed distance field of the glyph with a border of 3 pixels.
	Bitmap []byte `protobuf:"bytes,2,opt,name=bitmap,proto3,oneof" json:"bitmap,omitempty"`
	// Glyph metrics.
	Width   uint32 `protobuf:"varint,3,opt,name=width,proto3" json:"width,omitempty"`
	Height  uint32 `protobuf:"varint,4,opt,name=height,proto3" json:"height,omitempty"`
	Left    int32  `protobuf:"zigzag32,5,opt,name=left,proto3" json:"left,omitempty"`
	Top     int32  `protobuf:"zigzag32,6,opt,name=top,proto3" json:"top,omitempty"`
	Advance uint32 `protobuf:"varint,7,opt,name=advance,proto3" json:"advance,omitempty"`
	// contains filtered or unexported fields
}

Stores a glyph with metrics and optional SDF bitmap information.

func (*Glyph) Descriptor deprecated

func (*Glyph) Descriptor() ([]byte, []int)

Deprecated: Use Glyph.ProtoReflect.Descriptor instead.

func (*Glyph) GetAdvance

func (x *Glyph) GetAdvance() uint32

func (*Glyph) GetBitmap

func (x *Glyph) GetBitmap() []byte

func (*Glyph) GetHeight

func (x *Glyph) GetHeight() uint32

func (*Glyph) GetId

func (x *Glyph) GetId() uint32

func (*Glyph) GetLeft

func (x *Glyph) GetLeft() int32

func (*Glyph) GetTop

func (x *Glyph) GetTop() int32

func (*Glyph) GetWidth

func (x *Glyph) GetWidth() uint32

func (*Glyph) ProtoMessage

func (*Glyph) ProtoMessage()

func (*Glyph) ProtoReflect

func (x *Glyph) ProtoReflect() protoreflect.Message

func (*Glyph) Reset

func (x *Glyph) Reset()

func (*Glyph) String

func (x *Glyph) String() string

type Glyphs

type Glyphs struct {
	Stacks []*Fontstack `protobuf:"bytes,1,rep,name=stacks,proto3" json:"stacks,omitempty"`
	// contains filtered or unexported fields
}

func (*Glyphs) Descriptor deprecated

func (*Glyphs) Descriptor() ([]byte, []int)

Deprecated: Use Glyphs.ProtoReflect.Descriptor instead.

func (*Glyphs) GetStacks

func (x *Glyphs) GetStacks() []*Fontstack

func (*Glyphs) ProtoMessage

func (*Glyphs) ProtoMessage()

func (*Glyphs) ProtoReflect

func (x *Glyphs) ProtoReflect() protoreflect.Message

func (*Glyphs) Reset

func (x *Glyphs) Reset()

func (*Glyphs) String

func (x *Glyphs) String() string

type SDFBuilder

type SDFBuilder struct {
	Font *truetype.Font
	Face font.Face
	SDFBuilderOpt
	// contains filtered or unexported fields
}

func NewSDFBuilder

func NewSDFBuilder(font *truetype.Font, opts ...SDFBuilderOpt) *SDFBuilder

func (*SDFBuilder) Glyph

func (b *SDFBuilder) Glyph(x rune) *Glyph

func (*SDFBuilder) Glyphs

func (b *SDFBuilder) Glyphs(min int, max int) *Glyphs

func (*SDFBuilder) Init

func (b *SDFBuilder) Init()

type SDFBuilderOpt

type SDFBuilderOpt struct {
	FontSize float64
	Buffer   float64
}

Jump to

Keyboard shortcuts

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