msdf

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RED     EdgeColor = 1 << 0 // = 1 (bit 0)
	GREEN             = 1 << 1 // = 2 (bit 1)
	BLUE              = 1 << 2 // = 4 (bit 2)
	WHITE             = RED | GREEN | BLUE
	CYAN              = GREEN | BLUE
	MAGENTA           = RED | BLUE
	YELLOW            = RED | GREEN
	CLEAR             = 0x00
)
View Source
const (
	DEG = 180.0 / math.Pi
	RAD = math.Pi / 180.0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BruteForceMinDistanceFinder

type BruteForceMinDistanceFinder struct {
	Step float64
}

func (*BruteForceMinDistanceFinder) Find

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

func (*Canvas) Image

func (c *Canvas) Image() *image.RGBA

func (*Canvas) Put

func (c *Canvas) Put(x, y int, g *Canvas)

func (*Canvas) Save

func (c *Canvas) Save(s string)

func (*Canvas) Set

func (c *Canvas) Set(x, y int, r, g, b uint8)

type ClockDirection

type ClockDirection int
const (
	CW  ClockDirection = 1
	CCW ClockDirection = 0
)

func (ClockDirection) String

func (c ClockDirection) String() string

type Config

type Config struct {
	Seed             uint
	Size             float64
	DistanceField    float64
	Scale            float64
	DebugArtifactDir string
	DistanceFinder   MinDistanceFinder
	EdgeColorizer    EdgeColorizer
	// contains filtered or unexported fields
}

type Contour

type Contour struct {
	Symbol  rune
	Edges   []*Edge
	Winding ClockDirection
}

func (*Contour) Debug

func (c *Contour) Debug(g *Canvas, m *Metrics)

func (*Contour) Ensure3Edges

func (c *Contour) Ensure3Edges()

func (Contour) String

func (c Contour) String() string

type Coords

type Coords struct {
	Top    float64 `json:"top"`
	Bottom float64 `json:"bottom"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
}

type CubicBezier

type CubicBezier struct {
	P0, P1, P2, P3 fixed.Point26_6
	// contains filtered or unexported fields
}

func (*CubicBezier) CurvatureAt

func (cb *CubicBezier) CurvatureAt(t float64) Point

func (CubicBezier) GetDirectionVector

func (c CubicBezier) GetDirectionVector() *Vector

func (CubicBezier) GetLowResPoints

func (c CubicBezier) GetLowResPoints() []fixed.Point26_6

func (*CubicBezier) GetSignedArea

func (c *CubicBezier) GetSignedArea() float64

func (*CubicBezier) IsConnected

func (c *CubicBezier) IsConnected(c2 Curve) bool

func (*CubicBezier) IsCorner

func (c1 *CubicBezier) IsCorner(c2 Curve, threshold float64) bool

func (*CubicBezier) PointAt

func (cb *CubicBezier) PointAt(t float64) Point

func (*CubicBezier) Split

func (cb *CubicBezier) Split() (Curve, Curve)

func (CubicBezier) String

func (cb CubicBezier) String() string

func (*CubicBezier) TangentAt

func (cb *CubicBezier) TangentAt(t float64) Point

type Curve

type Curve interface {
	CurveSampler
	IsCorner(c2 Curve, threshold float64) bool
	IsConnected(c Curve) bool
	GetSignedArea() float64
	GetLowResPoints() []fixed.Point26_6
	GetDirectionVector() *Vector
}

type CurveSampler

type CurveSampler interface {
	PointAt(t float64) Point
	TangentAt(t float64) Point
	CurvatureAt(t float64) Point
	Split() (Curve, Curve)
	String() string
}

type Edge

type Edge struct {
	Kind  EdgeKind
	Color EdgeColor
	Curve Curve
	// contains filtered or unexported fields
}

func (*Edge) ID

func (e *Edge) ID() string

func (*Edge) String

func (e *Edge) String() string

type EdgeColor

type EdgeColor byte

func (EdgeColor) Has

func (e EdgeColor) Has(color EdgeColor) bool

func (EdgeColor) RGB

func (e EdgeColor) RGB() color.RGBA

func (EdgeColor) String

func (e EdgeColor) String() string

type EdgeColorPalette

type EdgeColorPalette struct {
	// contains filtered or unexported fields
}

func (*EdgeColorPalette) Init

func (cp *EdgeColorPalette) Init() EdgeColor

func (*EdgeColorPalette) Shuffle

func (cp *EdgeColorPalette) Shuffle(color *EdgeColor)

func (*EdgeColorPalette) ShuffleEx

func (cp *EdgeColorPalette) ShuffleEx(color *EdgeColor, banned EdgeColor)

type EdgeColorizer

type EdgeColorizer interface {
	Colorize(contours []*Contour, palette *EdgeColorPalette)
}

type EdgeKind

type EdgeKind string
const (
	LineEdge            EdgeKind = "L"
	QuadraticBezierEdge EdgeKind = "Q"
	CubicBezierEdge     EdgeKind = "C"
)

type Glyph

type Glyph struct {
	Canvas  *Canvas
	Options *GlyphOptions
}

type GlyphOptions

type GlyphOptions struct {
	Unicode     int     `json:"unicode"`
	Advance     float64 `json:"advance"`
	PlaneBounds Coords  `json:"planeBounds"`
	AtlasBounds Coords  `json:"atlasBounds"`
}

type Line

type Line struct {
	P0, P1 fixed.Point26_6
	// contains filtered or unexported fields
}

func (*Line) CurvatureAt

func (l *Line) CurvatureAt(t float64) Point

func (Line) GetDirectionVector

func (c Line) GetDirectionVector() *Vector

func (Line) GetLowResPoints

func (c Line) GetLowResPoints() []fixed.Point26_6

func (*Line) GetSignedArea

func (c *Line) GetSignedArea() float64

func (*Line) IsConnected

func (c *Line) IsConnected(c2 Curve) bool

func (*Line) IsCorner

func (c1 *Line) IsCorner(c2 Curve, threshold float64) bool

func (*Line) PointAt

func (ln *Line) PointAt(t float64) Point

func (*Line) Split

func (l *Line) Split() (Curve, Curve)

func (Line) String

func (l Line) String() string

func (*Line) TangentAt

func (l *Line) TangentAt(t float64) Point

type Metadata

type Metadata struct {
	Atlas   MetadataAtlas   `json:"atlas"`
	Metrics MetadataMetrics `json:"metrics"`
	Glyphs  []GlyphOptions  `json:"glyphs"`
}

func (*Metadata) Save

func (m *Metadata) Save(path string) error

type MetadataAtlas

type MetadataAtlas struct {
	Type          string  `json:"type"`
	DistanceRange float64 `json:"distanceRange"`
	Size          float64 `json:"size"`
	Width         int     `json:"width"`
	Height        int     `json:"height"`
	YOrigin       string  `json:"yOrigin"`
}

type MetadataMetrics

type MetadataMetrics struct {
	EmSize             int `json:"emSize"`
	LineHeight         int `json:"lineHeight"`
	Ascender           int `json:"ascender"`
	Descender          int `json:"descender"`
	UnderlineY         int `json:"underlineY"`
	UnderlineThickness int `json:"underlineThickness"`
}

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

func (*Metrics) GetAdvance

func (e *Metrics) GetAdvance() float64

func (*Metrics) GetBounds

func (e *Metrics) GetBounds() image.Rectangle

func (*Metrics) GetPlaneBounds

func (e *Metrics) GetPlaneBounds() fixed.Rectangle26_6

func (*Metrics) GetRange

func (e *Metrics) GetRange() (float64, float64)

func (*Metrics) Scale

func (e *Metrics) Scale(p fixed.Point26_6, bounds image.Rectangle, padding int) (int, int)

func (*Metrics) ToFloat

func (e *Metrics) ToFloat(x, y int) (float64, float64)

type MinDistanceFinder

type MinDistanceFinder interface {
	Find(c Curve, Q Point) (float64, float64)
}

type Msdf

type Msdf struct {
	// contains filtered or unexported fields
}

func New

func New(addr string, cfg *Config) (*Msdf, error)

func (*Msdf) CreateAtlas

func (m *Msdf) CreateAtlas(size int, charset string) (*Canvas, *Metadata, error)

func (*Msdf) Get

func (m *Msdf) Get(r rune) (*Glyph, error)

type Point

type Point struct {
	X, Y float64
}

func (Point) Sub

func (p Point) Sub(b Point) *Vector

type QuadraticBezier

type QuadraticBezier struct {
	P0, P1, P2 fixed.Point26_6
	// contains filtered or unexported fields
}

func (*QuadraticBezier) CurvatureAt

func (qb *QuadraticBezier) CurvatureAt(t float64) Point

func (QuadraticBezier) GetDirectionVector

func (c QuadraticBezier) GetDirectionVector() *Vector

func (QuadraticBezier) GetLowResPoints

func (c QuadraticBezier) GetLowResPoints() []fixed.Point26_6

func (*QuadraticBezier) GetSignedArea

func (c *QuadraticBezier) GetSignedArea() float64

func (*QuadraticBezier) IsConnected

func (c *QuadraticBezier) IsConnected(c2 Curve) bool

func (*QuadraticBezier) IsCorner

func (c1 *QuadraticBezier) IsCorner(c2 Curve, threshold float64) bool

func (*QuadraticBezier) PointAt

func (qb *QuadraticBezier) PointAt(t float64) Point

func (*QuadraticBezier) Split

func (qb *QuadraticBezier) Split() (Curve, Curve)

func (QuadraticBezier) String

func (qb QuadraticBezier) String() string

func (*QuadraticBezier) TangentAt

func (qb *QuadraticBezier) TangentAt(t float64) Point

type SimpleEdgeColorizer

type SimpleEdgeColorizer struct{}

func (SimpleEdgeColorizer) Colorize

func (sc SimpleEdgeColorizer) Colorize(contours []*Contour, palette *EdgeColorPalette)

type SubvisionMinDistanceFinder

type SubvisionMinDistanceFinder struct {
	MaxSubdivisions   int
	MinSegmentLength  float64
	FlatnessThreshold float64
	ScaleFactor       int
}

func (*SubvisionMinDistanceFinder) Find

type Vector

type Vector struct {
	X, Y float64
}

func (*Vector) Cross

func (v *Vector) Cross(b *Vector) float64

func (*Vector) Distance

func (v *Vector) Distance() float64

func (*Vector) Dot

func (v *Vector) Dot(b *Vector) float64

func (*Vector) Fixed

func (v *Vector) Fixed() fixed.Point26_6

func (*Vector) Normalize

func (v *Vector) Normalize() *Vector

func (*Vector) String

func (v *Vector) String() string

Jump to

Keyboard shortcuts

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