render

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	Pix    []byte
	W, H   int32
	Stride int32
}

Canvas is a thin view over the raw shm buffer bytes.

func (*Canvas) DrawString

func (c *Canvas) DrawString(set *FaceSet, penX, baselineY int32, s string, fg color.RGBA) int32

DrawString rasterises s at the given baseline (penX, baselineY) in fg colour onto the canvas, returning the final pen X position. It performs alpha compositing against whatever is already in the canvas.

func (*Canvas) DrawStringBold

func (c *Canvas) DrawStringBold(set *FaceSet, penX, baselineY int32, s string, fg color.RGBA) int32

DrawStringBold is the bold-styled variant of DrawString. If the FaceSet carries a real Bold face, each glyph is taken from it (one blit per glyph). If it doesn't, every glyph is blitted twice — once at the pen position and once shifted one pixel to the right — to fake bold. The advance grows by one pixel per glyph in that case, so the caller's MeasureStringBold and our drawing here stay in sync.

func (*Canvas) Fill

func (c *Canvas) Fill(col color.RGBA)

Fill paints the entire canvas with a solid colour. As the bottom layer it replaces every pixel outright (no compositing), so a translucent background is written straight in.

func (*Canvas) FillCircle

func (c *Canvas) FillCircle(cx, cy, r float64, col color.RGBA)

FillCircle paints an anti-aliased filled disc of radius r centred at (cx, cy), blended over whatever is already in the canvas. Coordinates are in pixels; the disc edge gets a one-pixel coverage ramp.

func (*Canvas) FillRect

func (c *Canvas) FillRect(x, y, w, h int32, col color.RGBA)

FillRect paints a rectangular region with solid colour (clipped to the canvas). An opaque colour overwrites the region; a translucent one is alpha-composited over whatever is already there, so it blends with the bar background beneath it.

func (*Canvas) FillRoundRect

func (c *Canvas) FillRoundRect(x, y, w, h, radius int32, col color.RGBA)

FillRoundRect paints a rounded rectangle, anti-aliasing the four corners against whatever is already in the canvas. radius is clamped to half of the shorter side. The rectangle's straight edges and interior are painted at full coverage; only the corner curves are blended.

type Face

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

Face is one FreeType face opened at a fixed pixel size. The rest of the renderer treats it as an opaque glyph source via Metrics / Advance / MeasureString / lookup.

func LoadFace

func LoadFace(path string, sizePx float64, _ float64) (*Face, error)

LoadFace opens a TTF/OTF font through FreeType so the font's own TrueType/CFF hinting is honoured (unlike the pure-Go opentype rasteriser, which ignored it and left diagonals soft). The first argument is either:

  • an absolute / relative / ~-expanded path to a font file, or
  • a fontconfig pattern that fc-match can resolve ("JetBrains Mono", "Ubuntu Nerd Font Propo:weight=bold").

sizePx is honoured directly: the face is sized at 72 DPI so a char height of sizePx points rasterises at exactly sizePx physical pixels, with sub-pixel precision for fractional DPI scales. The dpi argument is accepted for API compatibility and ignored.

func (*Face) Advance

func (f *Face) Advance(r rune) int

Advance returns the horizontal advance for a single rune in pixels.

func (*Face) MeasureString

func (f *Face) MeasureString(s string) int

MeasureString sums advances; no kerning (advance-only is fine for a status bar).

func (*Face) Metrics

func (f *Face) Metrics() (ascent, descent, height int)

Metrics returns ascent/descent/line-height in pixels (rounded up).

type FaceSet

type FaceSet struct {
	Primary  *Face
	Fallback *Face
	Bold     *Face
}

FaceSet bundles a primary face with an optional fallback; on a missing glyph we consult the fallback. The intended use is a text primary plus a Nerd Font fallback that supplies icon glyphs the primary face doesn't carry.

Bold is an optional bold variant of the primary face. When non-nil, bold-styled text is rasterised via this face. When nil, callers requesting bold get synthetic bold (the same glyph drawn twice with a one-pixel horizontal offset).

func (*FaceSet) IconInkExtent

func (s *FaceSet) IconInkExtent(sample string) (minY, maxY int, ok bool)

IconInkExtent returns the combined vertical ink bounds of sample using the full primary→fallback glyph resolution, so a glyph that exists only in the fallback (Nerd Font icon) face is measured too — InkExtent looks at the primary face alone and would miss it. Callers use this to vertically centre an icon on the bar's mid-line: different icon fonts position their glyphs around different baselines, so drawing an icon at the text baseline leaves it sitting high or low relative to the text. ok is false when no rune in sample has a renderable glyph.

func (*FaceSet) InkExtent

func (s *FaceSet) InkExtent(sample string) (minY, maxY int, ok bool)

InkExtent returns the vertical ink bounds of the primary face across the runes of sample, measured relative to the baseline (Y grows downward, so a glyph drawn above the baseline yields a negative minY). It lets callers centre text by its actual pixels instead of the font's ascent/descent. The fallback face is intentionally not consulted: vertical centring should track the text face, not the (often differently-sized) icon face. ok is false when none of the sample runes resolved to an inked glyph.

func (*FaceSet) Lookup

func (s *FaceSet) Lookup(r rune) *glyph

Lookup returns the primary face's glyph for r, falling back to the fallback face when the primary has no inked glyph. nil means neither face has the rune.

func (*FaceSet) LookupBold

func (s *FaceSet) LookupBold(r rune) *glyph

LookupBold is the bold-styled variant of Lookup. It consults the Bold face first, then falls through to the regular Primary / Fallback. The caller is still responsible for synthetic bold (double-blit) when no Bold face is registered — this only switches which face supplies the glyph.

func (*FaceSet) MeasureString

func (s *FaceSet) MeasureString(str string) int

MeasureString sums glyph advances across str.

func (*FaceSet) MeasureStringBold

func (s *FaceSet) MeasureStringBold(str string) int

MeasureStringBold is the bold-styled variant of MeasureString. When the FaceSet carries a real Bold face, glyph advances come from there. When it doesn't, str is treated as synthetic bold: advances stay the same but each glyph gains one pixel of horizontal slack to make room for the offset second blit.

func (*FaceSet) Metrics

func (s *FaceSet) Metrics() (ascent, descent, height int)

Metrics on the set returns the primary face's metrics (used for line layout).

Jump to

Keyboard shortcuts

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