Documentation
¶
Index ¶
- type Canvas
- func (c *Canvas) DrawString(set *FaceSet, penX, baselineY int32, s string, fg color.RGBA) int32
- func (c *Canvas) DrawStringBold(set *FaceSet, penX, baselineY int32, s string, fg color.RGBA) int32
- func (c *Canvas) Fill(col color.RGBA)
- func (c *Canvas) FillCircle(cx, cy, r float64, col color.RGBA)
- func (c *Canvas) FillRect(x, y, w, h int32, col color.RGBA)
- func (c *Canvas) FillRoundRect(x, y, w, h, radius int32, col color.RGBA)
- type Face
- type FaceSet
- func (s *FaceSet) IconInkExtent(sample string) (minY, maxY int, ok bool)
- func (s *FaceSet) InkExtent(sample string) (minY, maxY int, ok bool)
- func (s *FaceSet) Lookup(r rune) *glyph
- func (s *FaceSet) LookupBold(r rune) *glyph
- func (s *FaceSet) MeasureString(str string) int
- func (s *FaceSet) MeasureStringBold(str string) int
- func (s *FaceSet) Metrics() (ascent, descent, height int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
Canvas is a thin view over the raw shm buffer bytes.
func (*Canvas) DrawString ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) MeasureString ¶
MeasureString sums advances; no kerning (advance-only is fine for a status bar).
type FaceSet ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MeasureString sums glyph advances across str.
func (*FaceSet) MeasureStringBold ¶
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.