fontnik

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 12 Imported by: 1

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

This section is empty.

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,req,name=name" json:"name,omitempty"`
	Range                *string  `protobuf:"bytes,2,req,name=range" json:"range,omitempty"`
	Glyphs               []*Glyph `protobuf:"bytes,3,rep,name=glyphs" json:"glyphs,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Stores fontstack information and a list of faces.

func (*Fontstack) Descriptor

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

func (*Fontstack) GetGlyphs

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

func (*Fontstack) GetName

func (m *Fontstack) GetName() string

func (*Fontstack) GetRange

func (m *Fontstack) GetRange() string

func (*Fontstack) ProtoMessage

func (*Fontstack) ProtoMessage()

func (*Fontstack) Reset

func (m *Fontstack) Reset()

func (*Fontstack) String

func (m *Fontstack) String() string

func (*Fontstack) XXX_DiscardUnknown

func (m *Fontstack) XXX_DiscardUnknown()

func (*Fontstack) XXX_Marshal

func (m *Fontstack) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Fontstack) XXX_Merge

func (m *Fontstack) XXX_Merge(src proto.Message)

func (*Fontstack) XXX_Size

func (m *Fontstack) XXX_Size() int

func (*Fontstack) XXX_Unmarshal

func (m *Fontstack) XXX_Unmarshal(b []byte) error

type Glyph

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

Stores a glyph with metrics and optional SDF bitmap information.

func (*Glyph) Descriptor

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

func (*Glyph) GetAdvance

func (m *Glyph) GetAdvance() uint32

func (*Glyph) GetBitmap

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

func (*Glyph) GetHeight

func (m *Glyph) GetHeight() uint32

func (*Glyph) GetId

func (m *Glyph) GetId() uint32

func (*Glyph) GetLeft

func (m *Glyph) GetLeft() int32

func (*Glyph) GetTop

func (m *Glyph) GetTop() int32

func (*Glyph) GetWidth

func (m *Glyph) GetWidth() uint32

func (*Glyph) ProtoMessage

func (*Glyph) ProtoMessage()

func (*Glyph) Reset

func (m *Glyph) Reset()

func (*Glyph) String

func (m *Glyph) String() string

func (*Glyph) XXX_DiscardUnknown

func (m *Glyph) XXX_DiscardUnknown()

func (*Glyph) XXX_Marshal

func (m *Glyph) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Glyph) XXX_Merge

func (m *Glyph) XXX_Merge(src proto.Message)

func (*Glyph) XXX_Size

func (m *Glyph) XXX_Size() int

func (*Glyph) XXX_Unmarshal

func (m *Glyph) XXX_Unmarshal(b []byte) error

type Glyphs

type Glyphs struct {
	Stacks                       []*Fontstack `protobuf:"bytes,1,rep,name=stacks" json:"stacks,omitempty"`
	XXX_NoUnkeyedLiteral         struct{}     `json:"-"`
	proto.XXX_InternalExtensions `json:"-"`
	XXX_unrecognized             []byte `json:"-"`
	XXX_sizecache                int32  `json:"-"`
}

func (*Glyphs) Descriptor

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

func (*Glyphs) ExtensionRangeArray

func (*Glyphs) ExtensionRangeArray() []proto.ExtensionRange

func (*Glyphs) GetStacks

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

func (*Glyphs) ProtoMessage

func (*Glyphs) ProtoMessage()

func (*Glyphs) Reset

func (m *Glyphs) Reset()

func (*Glyphs) String

func (m *Glyphs) String() string

func (*Glyphs) XXX_DiscardUnknown

func (m *Glyphs) XXX_DiscardUnknown()

func (*Glyphs) XXX_Marshal

func (m *Glyphs) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Glyphs) XXX_Merge

func (m *Glyphs) XXX_Merge(src proto.Message)

func (*Glyphs) XXX_Size

func (m *Glyphs) XXX_Size() int

func (*Glyphs) XXX_Unmarshal

func (m *Glyphs) XXX_Unmarshal(b []byte) error

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