Documentation
¶
Overview ¶
The sizer subpackage defines the Sizer interface used within etxt and provides multiple ready-to-use implementations.
The 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 ¶
- type CustomVertSizer
- func (self *CustomVertSizer) Ascent(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *CustomVertSizer) Descent(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *CustomVertSizer) GlyphAdvance(font *Font, buffer *Buffer, size fract.Unit, g GlyphIndex) fract.Unit
- func (self *CustomVertSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
- func (self *CustomVertSizer) LineAdvance(*Font, *Buffer, fract.Unit, int) fract.Unit
- func (self *CustomVertSizer) LineGap(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *CustomVertSizer) LineHeight(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *CustomVertSizer) NotifyChange(_ *Font, _ *Buffer, size fract.Unit)
- type DefaultSizer
- func (self *DefaultSizer) Ascent(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *DefaultSizer) Descent(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *DefaultSizer) GlyphAdvance(font *Font, buffer *Buffer, size fract.Unit, g GlyphIndex) fract.Unit
- func (self *DefaultSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
- func (self *DefaultSizer) LineAdvance(*Font, *Buffer, fract.Unit, int) fract.Unit
- func (self *DefaultSizer) LineGap(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *DefaultSizer) LineHeight(*Font, *Buffer, fract.Unit) fract.Unit
- func (self *DefaultSizer) NotifyChange(font *Font, buffer *Buffer, size fract.Unit)
- type PaddedAdvanceSizer
- type PaddedKernSizer
- type PaddedScalableKernSizer
- type Sizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomVertSizer ¶
type CustomVertSizer struct {
AscentMult fract.Unit
DescentMult fract.Unit
LineGapMult fract.Unit
// contains filtered or unexported fields
}
A sizer that ignores the specific vertical metrics provided by the font and instead replaces them with fixed values relative to the font size. This can be used to manually control the line height for a single font or a small set of fonts.
One must call CustomVertSizer.NotifyChange() to properly update values after changing AscentMult, DescentMult or LineGapMult.
func (*CustomVertSizer) Ascent ¶
func (self *CustomVertSizer) Ascent(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) Descent ¶
func (self *CustomVertSizer) Descent(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) GlyphAdvance ¶
func (self *CustomVertSizer) GlyphAdvance(font *Font, buffer *Buffer, size fract.Unit, g GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) Kern ¶
func (self *CustomVertSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) LineAdvance ¶
Satisfies the Sizer interface.
func (*CustomVertSizer) LineGap ¶
func (self *CustomVertSizer) LineGap(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) LineHeight ¶
func (self *CustomVertSizer) LineHeight(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*CustomVertSizer) NotifyChange ¶
func (self *CustomVertSizer) NotifyChange(_ *Font, _ *Buffer, size fract.Unit)
Satisfies the Sizer interface.
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) Ascent ¶
func (self *DefaultSizer) Ascent(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) Descent ¶
func (self *DefaultSizer) Descent(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) GlyphAdvance ¶
func (self *DefaultSizer) GlyphAdvance(font *Font, buffer *Buffer, size fract.Unit, g GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) Kern ¶
func (self *DefaultSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) LineAdvance ¶
Satisfies the Sizer interface.
func (*DefaultSizer) LineGap ¶
func (self *DefaultSizer) LineGap(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) LineHeight ¶
func (self *DefaultSizer) LineHeight(*Font, *Buffer, fract.Unit) fract.Unit
Satisfies the Sizer interface.
func (*DefaultSizer) NotifyChange ¶
func (self *DefaultSizer) NotifyChange(font *Font, buffer *Buffer, size fract.Unit)
Satisfies the Sizer interface.
type PaddedAdvanceSizer ¶
type PaddedAdvanceSizer struct {
// contains filtered or unexported fields
}
Like PaddedKernSizer, but adds the extra padding in the advance instead of the kern.
If you aren't modifying the glyphs, only padding them horizontally, use PaddedKernSizer instead. This sizer is intended to deal with modified glyphs that have actually become wider, like in a faux bold process.
func (*PaddedAdvanceSizer) GetPadding ¶
func (self *PaddedAdvanceSizer) GetPadding() fract.Unit
Returns the configurable horizontal padding value.
func (*PaddedAdvanceSizer) GlyphAdvance ¶
func (self *PaddedAdvanceSizer) GlyphAdvance(font *Font, buffer *Buffer, size fract.Unit, g GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*PaddedAdvanceSizer) SetPadding ¶
func (self *PaddedAdvanceSizer) SetPadding(value fract.Unit)
Sets the configurable horizontal padding value.
type PaddedKernSizer ¶
type PaddedKernSizer 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.
See also PaddedScalableKernSizer if you need to deal with scalable text.
func (*PaddedKernSizer) GetPadding ¶
func (self *PaddedKernSizer) GetPadding() fract.Unit
Returns the configurable horizontal kern padding value.
func (*PaddedKernSizer) Kern ¶
func (self *PaddedKernSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*PaddedKernSizer) SetPadding ¶
func (self *PaddedKernSizer) SetPadding(value fract.Unit)
Sets the configurable horizontal kern padding value.
type PaddedScalableKernSizer ¶
type PaddedScalableKernSizer struct {
PaddingAt16px fract.Unit
// contains filtered or unexported fields
}
Similar to PaddedKernSizer, but instead of taking the padding as an absolute value, it uses a value relative to a font size of 16px and scales it automatically based on the active font size.
After modifying PaddingAt16px you must call [PaddedScalableKernSizer.NotifyChanges]().
func (*PaddedScalableKernSizer) GetPaddingAtSize ¶
func (self *PaddedScalableKernSizer) GetPaddingAtSize(size fract.Unit) fract.Unit
Returns the current padding scaled by the given size.
func (*PaddedScalableKernSizer) Kern ¶
func (self *PaddedScalableKernSizer) Kern(font *Font, buffer *Buffer, size fract.Unit, g1, g2 GlyphIndex) fract.Unit
Satisfies the Sizer interface.
func (*PaddedScalableKernSizer) NotifyChange ¶
func (self *PaddedScalableKernSizer) NotifyChange(font *Font, buffer *Buffer, size fract.Unit)
Satisfies the Sizer interface.
type Sizer ¶
type Sizer interface {
// Returns the ascent of the given font, at the given size,
// as an absolute value.
//
// The given font and sizes must be consistent with the
// latest Sizer.NotifyChange() call.
Ascent(*Font, *Buffer, fract.Unit) fract.Unit
// Returns the descent of the given font, at the given size,
// as an absolute value.
//
// The given font and sizes must be consistent with the
// latest Sizer.NotifyChange() call.
Descent(*Font, *Buffer, fract.Unit) fract.Unit
// Returns the line gap of the given font, at the given size,
// as an absolute value.
//
// The given font and sizes must be consistent with the
// latest Sizer.NotifyChange() call.
LineGap(*Font, *Buffer, fract.Unit) fract.Unit
// Utility method equivalent to Ascent() + Descent() + LineGap().
LineHeight(*Font, *Buffer, fract.Unit) fract.Unit
// Returns the line advance of the given font at the given size.
//
// The given font and the size must be consistent with the
// latest Sizer.NotifyChange() call.
//
// The given int indicates that this is the nth consecutive
// call to the method (consecutive line breaks). In most cases,
// the value will be 1. Values below 1 are invalid. Values
// can only be strictly increasing by +1.
LineAdvance(*Font, *Buffer, fract.Unit, int) fract.Unit
// Returns the advance of the given glyph for the given font
// and size.
//
// The given font and the size must be consistent with the
// latest Sizer.NotifyChange() call.
GlyphAdvance(*Font, *Buffer, fract.Unit, GlyphIndex) fract.Unit
// Returns the kerning value between two glyphs of the given font
// and size.
//
// The given font and the size must be consistent with the
// latest Sizer.NotifyChange() call.
Kern(*Font, *Buffer, fract.Unit, GlyphIndex, GlyphIndex) fract.Unit
// Must be called to sync the state of the sizer and allow it
// to do any caching it may want to do in relation to the given
// active font or size.
NotifyChange(*Font, *Buffer, fract.Unit)
}
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 obtain that information.
You rarely need to care about sizers, but they can be useful in the following cases:
- Customize line height or advances.
- Disable kerning or adjust horizontal spacing.
- Make full size adjustments for a custom rasterizer (e.g., a rasterizer that puts glyphs into boxes, bubbles or frames).