graphite

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package graphite Graphite implements a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FeatureValue

type FeatureValue struct {
	ID    Tag   // ID of the feature
	Value int16 // Value to use
}

FeatureValue specifies a value for a given feature.

type FeaturesValue

type FeaturesValue []FeatureValue

FeaturesValue are sorted by Id

func (FeaturesValue) FindFeature

func (feats FeaturesValue) FindFeature(id Tag) *FeatureValue

FindFeature return the feature for the given tag, or nil.

type FontOptions

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

FontOptions allows to specify a scale to get position in user units rather than in font units.

func NewFontOptions

func NewFontOptions(ppem uint16, face *GraphiteFace) *FontOptions

NewFontOptions builds options from the given points per em.

type GID

type GID = fonts.GID

type GraphiteFace

type GraphiteFace struct {
	fonts.FaceMetrics
	// contains filtered or unexported fields
}

GraphiteFace contains the specific OpenType tables used by the Graphite engine. It also wraps the common OpenType metrics record.

func LoadGraphite

func LoadGraphite(font *truetype.Font) (*GraphiteFace, error)

LoadGraphite read graphite tables from the given OpenType font. It returns an error if the tables are invalid or if the font is not a graphite font.

func (*GraphiteFace) FeaturesForLang

func (f *GraphiteFace) FeaturesForLang(lang Tag) FeaturesValue

FeaturesForLang selects the features and values for the given language, or the default ones if the language is not found.

func (*GraphiteFace) Shape

func (face *GraphiteFace) Shape(font *FontOptions, text []rune, script Tag, features FeaturesValue, dir int8) *Segment

Shape process the given `text` and applies the graphite tables found in the font, returning a shaped segment of text. `font` is optional: if given, the positions are scaled; otherwise they are expressed in font units. If `features` is nil, the default features from the `Sill` table are used. Note that this not the same as passing an empty slice, which would desactivate any feature. `script` is optional and may help to select the correct `Silf` subtable. `dir` sets the direction of the text.

type Position

type Position struct {
	X, Y float32
}

func (Position) MarshalJSON

func (pos Position) MarshalJSON() ([]byte, error)

type Segment

type Segment struct {
	// Start of the segment (may be nil for empty segments)
	First *Slot

	// Advance of the whole segment
	Advance Position

	// Number of slots (output characters).
	// Since slots may be added or deleted during shaping,
	// it may differ from the number of characters ot the text input.
	// It could be directly computed by walking the linked list but is cached
	// for performance reasons.
	NumGlyphs int
	// contains filtered or unexported fields
}

Segment represents a line of text. It is used internally during shaping and returned as the result of the operation.

type Slot

type Slot struct {
	// Next is the next slot along the segment (that is the next element in the linked list).
	// It is nil at the end of the segment.
	Next *Slot

	// Each slot is associated with a range of characters in the input slice,
	// delimited by [Before, After].
	// Before is also the index of the position of the cursor before this slot.
	// After is also the index of the position of the cursor after this slot.
	Before, After int

	// Offset ot the glyph from the start of the segment.
	Position Position
	// Glyph advance for this glyph as adjusted for kerning
	Advance Position
	// contains filtered or unexported fields
}

Slot represents one glyph in a shaped line of text. Slots are created from the input string, but may also be added or removed by the shaping process.

func (*Slot) CanInsertBefore

func (sl *Slot) CanInsertBefore() bool

CanInsertBefore returns whether text may be inserted before this glyph.

This indicates whether a cursor can be put before this slot. It applies to base glyphs that have no parent as well as attached glyphs that have the .insert attribute explicitly set to true. This is the primary mechanism for identifying contiguous sequences of base plus diacritics.

func (*Slot) GID

func (sl *Slot) GID() fonts.GID

GID returns the glyph id to be rendered at the position given by the slot. Some slots may have a pseudo glyph, which is unknown to the font, but used during shaping, but the returned value is the real glyph and never a pseudo glyph.

type Tag

type Tag = truetype.Tag

Jump to

Keyboard shortcuts

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