webfont

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package webfont performs common rune and glyph processing operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseNeededGlyphs

func ParseNeededGlyphs(fontData *FontData, message string, processor Processor) error

ParseNeededGlyphs parses the needed glyphs from the font and populates the glyph details. If processor is non-nil, it calls the processor methods as it processes each necessary glyph.

func UTF8toRune

func UTF8toRune(s *string) rune

UTF8toRune converts the utf8 codepoint to a rune.

Types

type Font

type Font struct {
	ID           string        `xml:"id,attr"`
	HorizAdvX    float64       `xml:"horiz-adv-x,attr"`
	FontFace     *FontFace     `xml:"font-face"`
	MissingGlyph *MissingGlyph `xml:"missing-glyph"`
	Glyphs       []*Glyph      `xml:"glyph"`

	Data string // Used to send protobuf data to text/template.
}

Font represents the <font> XML block of the webfont data.

type FontData

type FontData struct {
	Font *Font `xml:"defs>font"`
}

FontData represents the SVG webfont data.

type FontFace

type FontFace struct {
	UnitsPerEm float64 `xml:"units-per-em,attr"`
	Ascent     float64 `xml:"ascent,attr"`
	Descent    float64 `xml:"descent,attr"`
}

FontFace represents the <font-face> XML block of the webfont data.

type Glyph

type Glyph struct {
	HorizAdvX float64 `xml:"horiz-adv-x,attr"`
	Unicode   *string `xml:"unicode,attr,omitempty"`
	D         *string `xml:"d,attr,omitempty"`
	DOrig     *string `xml:"d-orig,attr,omitempty"`
	GerberLP  *string `xml:"gerber-lp,attr,omitempty"`

	// D is parsed into a sequence of PathSteps:
	PathSteps []*PathStep

	// MBB is the minimum bounding box of the glyph in native units.
	MBB MBB

	// If Processor is non-nil, it is called to process the glyph
	// as it is being parsed and when parsing is finished.
	Processor Processor
}

Glyph represents a <glyph> XML block of the webfont data.

func (*Glyph) GenGerberLP

func (g *Glyph) GenGerberLP(ff *FontFace)

GenGerberLP renders a glyph to figure out the curve polarity and populate the GerberLP field. It also uses heuristics to determine the proper rendering order of the path subcommands.

func (*Glyph) ParsePath

func (g *Glyph) ParsePath()

ParsePath parses a Glyph path.

func (*Glyph) ReorderByArea

func (g *Glyph) ReorderByArea(polyInfo []polyInfoT)

type MBB

type MBB = vec2.Rect

MBB represents a minimum bounding box.

type MissingGlyph

type MissingGlyph struct {
	HorizAdvX float64 `xml:"horiz-adv-x,attr"`
}

MissingGlyph represents the <missing-glyph> XML block of the webfont data.

type PathStep

type PathStep struct {
	C string
	P []float64
}

PathStep represents a single path step.

There are 20 possible commands, broken up into 6 types, with each command having an "absolute" (upper case) and a "relative" (lower case) version.

MoveTo: M, m LineTo: L, l, H, h, V, v Cubic Bézier Curve: C, c, S, s Quadratic Bézier Curve: Q, q, T, t Elliptical Arc Curve: A, a ClosePath: Z, z

type Processor

type Processor interface {
	// NewGlyph is called before the processing of a new glyph.
	NewGlyph(g *Glyph)

	// The following operations can be used to record SVG font paths with lossless detail.
	// For each rune, they are called _before_ ProcessGlyph.
	MoveTo(g *Glyph, cmd string, x, y float64)
	LineTo(g *Glyph, cmd string, x, y float64)
	CubicTo(g *Glyph, cmd string, x1, y1, x2, y2, ex, ey float64)
	QuadraticTo(g *Glyph, cmd string, x1, y1, x2, y2 float64)

	// ProcessGlyph is called when the glyph has been fully parsed
	// and after all the operations above are completed.
	ProcessGlyph(r rune, g *Glyph)
}

Processor is an interface used to process glyphs.

Jump to

Keyboard shortcuts

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