esizer

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

The esizer subpackage defines the Sizer interface used within etxt and provides multiple ready-to-use implementations.

The only job of a Sizer is to determine how much space should be taken by each glyph. While font files already contain this information, using an interface as a middle layer allows etxt users to modify spacing manually and achieve specific effects like ignoring kerning, adding extra padding between letters or accounting for the extra space taken by custom glyph rasterizers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAdvanceFunc

func DefaultAdvanceFunc(f *Font, glyphIndex GlyphIndex, size fixed.Int26_6, buffer *sfnt.Buffer) fixed.Int26_6

A default method to respond to glyph advance requests. Can be used while implementing your own sizers.

func DefaultKernFunc

func DefaultKernFunc(f *Font, prevGlyphIndex GlyphIndex, currGlyphIndex GlyphIndex, size fixed.Int26_6, buffer *sfnt.Buffer) fixed.Int26_6

A default method to respond to glyph kern requests. Can be used while implementing your own sizers.

func DefaultMetricsFunc

func DefaultMetricsFunc(f *Font, size fixed.Int26_6, buffer *sfnt.Buffer) font.Metrics

A default method to respond to font metrics requests. Can be used while implementing your own sizers.

Types

type AdvancePadSizer

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

Like HorzPaddingSizer, but adds the extra padding in the advance instead of the kern.

If you aren't modifying the glyphs, only padding them horizontally, use HorzPaddingSizer instead. This sizer is intended to deal with modified glyphs that have actually become wider.

func (*AdvancePadSizer) Advance

func (self *AdvancePadSizer) Advance(f *Font, glyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*AdvancePadSizer) Kern

func (self *AdvancePadSizer) Kern(f *Font, prevGlyphIndex GlyphIndex, currGlyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*AdvancePadSizer) Metrics

func (self *AdvancePadSizer) Metrics(f *Font, size fixed.Int26_6) font.Metrics

Satisfies the Sizer interface.

func (*AdvancePadSizer) SetPadding

func (self *AdvancePadSizer) SetPadding(value int)

Sets the configurable horizontal padding value, in pixels.

func (*AdvancePadSizer) SetPaddingFloat

func (self *AdvancePadSizer) SetPaddingFloat(value float64)

Like AdvancePadSizer.SetPadding, but expecting a float64 instead of an int.

func (*AdvancePadSizer) SetPaddingFract

func (self *AdvancePadSizer) SetPaddingFract(value fixed.Int26_6)

Like AdvancePadSizer.SetPadding, but expecting a fixed.Int26_6 instead of an int.

type DefaultSizer

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

The default Sizer used by etxt renderers. For more information about sizers, see the documentation of the Sizer interface.

func (*DefaultSizer) Advance

func (self *DefaultSizer) Advance(font *Font, glyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*DefaultSizer) Kern

func (self *DefaultSizer) Kern(font *Font, prevGlyphIndex GlyphIndex, currGlyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*DefaultSizer) Metrics

func (self *DefaultSizer) Metrics(font *Font, size fixed.Int26_6) font.Metrics

Satisfies the Sizer interface.

type FixedSizer

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

A Sizer with a fixed advance between glyphs.

func (*FixedSizer) Advance

func (self *FixedSizer) Advance(*Font, GlyphIndex, fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*FixedSizer) Kern

Satisfies the Sizer interface.

func (*FixedSizer) Metrics

func (self *FixedSizer) Metrics(font *Font, size fixed.Int26_6) font.Metrics

Satisfies the Sizer interface.

func (*FixedSizer) SetAdvance

func (self *FixedSizer) SetAdvance(advance int)

Sets the fixed advance between characters.

func (*FixedSizer) SetAdvanceFloat

func (self *FixedSizer) SetAdvanceFloat(advance float64)

Like FixedSizer.SetAdvance, but expecting a float64 instead of an int.

func (*FixedSizer) SetAdvanceFract

func (self *FixedSizer) SetAdvanceFract(advance fixed.Int26_6)

Like FixedSizer.SetAdvance, but expcting a fixed.Int26_6 instead of an int.

type Font

type Font = sfnt.Font

Same as etxt.Font.

type GlyphIndex

type GlyphIndex = sfnt.GlyphIndex

Same as etxt.GlyphIndex.

type HorzPaddingSizer

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

A Sizer that behaves like the default one, but with a configurable horizontal padding factor that's added to the kern between glyphs.

func (*HorzPaddingSizer) Advance

func (self *HorzPaddingSizer) Advance(f *Font, glyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*HorzPaddingSizer) Kern

func (self *HorzPaddingSizer) Kern(f *Font, prevGlyphIndex GlyphIndex, currGlyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*HorzPaddingSizer) Metrics

func (self *HorzPaddingSizer) Metrics(f *Font, size fixed.Int26_6) font.Metrics

Satisfies the Sizer interface.

func (*HorzPaddingSizer) SetHorzPadding

func (self *HorzPaddingSizer) SetHorzPadding(value int)

Sets the configurable horizontal padding value, in pixels.

func (*HorzPaddingSizer) SetHorzPaddingFloat

func (self *HorzPaddingSizer) SetHorzPaddingFloat(value float64)

Like HorzPaddingSizer.SetHorzPadding, but expecting a float64 instead of an int.

func (*HorzPaddingSizer) SetHorzPaddingFract

func (self *HorzPaddingSizer) SetHorzPaddingFract(value fixed.Int26_6)

Like HorzPaddingSizer.SetHorzPadding, but expecting a fixed.Int26_6 instead of an int.

type NoKernSizer

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

A default Sizer without kerning (the kern function always returns 0).

func (*NoKernSizer) Advance

func (self *NoKernSizer) Advance(font *Font, glyphIndex GlyphIndex, size fixed.Int26_6) fixed.Int26_6

Satisfies the Sizer interface.

func (*NoKernSizer) Kern

Satisfies the Sizer interface.

func (*NoKernSizer) Metrics

func (self *NoKernSizer) Metrics(font *Font, size fixed.Int26_6) font.Metrics

Satisfies the Sizer interface.

type Sizer

type Sizer interface {
	Metrics(*Font, fixed.Int26_6) font.Metrics
	Advance(*Font, GlyphIndex, fixed.Int26_6) fixed.Int26_6
	Kern(*Font, GlyphIndex, GlyphIndex, fixed.Int26_6) fixed.Int26_6
}

When drawing or traversing glyphs, we need some information related to the "font metrics". For example, how much we need to advance after drawing a glyph or what's the kerning between a specific pair of glyphs.

Sizers are the interface that Renderers use to access that information.

You rarely need to care about Sizers, but they can be useful in the following cases:

  • Disable kerning and adjust horizontal spacing.
  • Make full size adjustments for a custom rasterizer (e.g., a rasterizer that puts glyphs into boxes, bubbles or frames).

Jump to

Keyboard shortcuts

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