svg

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package svg draws a scene as SVG.

Colors of the theme are written as CSS variables, --limu-surface and the rest, with the theme's colors as their fallbacks, so a page restyles a diagram without drawing it again; with Options.Literal they are written as colors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(sc *scene.Scene, o *Options) string

Render writes a scene as an SVG document.

Types

type Options

type Options struct {
	Look style.Look
	// Literal writes the theme's colors as colors, not as variables.
	Literal bool
	// The fonts the scene was measured in; the page's --limu-font and --limu-font-mono come
	// first when it sets them.
	FontFamily, MonoFamily string
	// LinkSchemes are the schemes a link may use besides a relative address; nil is http,
	// https, mailto and tel. A link of another is drawn as no link.
	LinkSchemes []string
	// ImageSchemes are the schemes an image may be loaded with besides a relative address;
	// nil is http and https.
	ImageSchemes []string
	// IconMarkup gives the markup inside an icon's <svg>, on a box of 24 by 24, by the
	// icon's name: of an item's picture, or of an icon in a label. The icon's <svg> sets
	// its color to that of the item's text, for the markup to draw in as currentColor.
	// Labels leave room only for icons the measurer was told of; without IconMarkup, icons
	// are left out.
	IconMarkup func(name string) string
	// Draw, when set, writes each item in place of the default, which next writes; the
	// Writer's Item, Parts, Ends, Picture and Label write the default's pieces. It is given
	// the item's style cascaded from the look, its paints not settled into colors, so that
	// Paint writes the theme's as CSS variables.
	Draw func(w *Writer, it *scene.Item, s style.Style, next func())
}

Options say how a scene is written.

type Writer

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

A Writer is the document being written, for an Options.Draw of one's own.

func (*Writer) Ends

func (w *Writer) Ends(it *scene.Item, st style.Style)

Ends writes the markers at the ends of an edge, in the color of its stroke, each part as scene.Marker.Outline says, solid, with the edge's caps and with its corners turned as the marker's type says or else as the edge's are, as Pele draws them.

func (*Writer) Item

func (w *Writer) Item(it *scene.Item, st style.Style)

Item writes an item as Pele does: a group of its outline, its markers, its picture and its label, with its tooltip and its link, at the style's opacity.

func (*Writer) Label

func (w *Writer) Label(it *scene.Item, st style.Style)

Label writes an item's label about its At, as Pele's labelSvg does: a line's baseline is a little below the middle of its line's height. A line is anchored at At as the item's Align says, in the middle, at its start or at its end, and its spans follow one another as the font draws them, so that where a line begins or ends does not depend on how its text was measured. A line with an icon in it is placed span by span from where layout measured them, as Pele places one. A halo is the text again under it, stroked. A label turned by its Rotate is written in a group turned about its At, with its icons.

func (*Writer) Num

func (w *Writer) Num(f float64)

Num writes a number to two decimals, with no more digits than it needs.

func (*Writer) Opacity

func (w *Writer) Opacity(p style.Paint) float64

Opacity is the part of a paint's opacity that Paint does not write: its factor (style.Paint.Alpha) times the alpha of its color, its own or the theme's. A paint laid over a color of the theme (style.Paint.Over) is opaque, as Paint writes the mix; one that draws nothing is 0.

func (*Writer) Paint

func (w *Writer) Paint(p style.Paint)

Paint writes a paint as an opaque color: a variable of the theme's, or a color, or none. The rest of its opacity is Opacity, which PaintAttr writes with it.

func (*Writer) PaintAttr

func (w *Writer) PaintAttr(name string, p style.Paint)

PaintAttr writes an attribute of paint, name="…" as Paint writes it, and name-opacity with its Opacity when that is under 1: for "fill", fill="…" fill-opacity="…".

func (*Writer) Parts

func (w *Writer) Parts(it *scene.Item, st style.Style)

Parts writes the parts of an item's outline: paths, and boxes as <rect>s, the boxes' corners rounded by the style's radius when they are Rounded, each filled and stroked as its Paint says. SVG takes a radius too large for a box as half its width across and half its height down, so that a narrow box's corners are elliptical; the limumygo package takes the smaller of the two both ways.

func (*Writer) Path

func (w *Writer) Path(p *scene.Path)

Path writes the path's steps, as the d of a <path>.

func (*Writer) Picture

func (w *Writer) Picture(it *scene.Item, st style.Style)

Picture writes an item's picture: an image, if the options allow its address, or an icon through Options.IconMarkup, in the color of the item's text.

func (*Writer) Raw

func (w *Writer) Raw(s string)

Raw writes markup as it is.

func (*Writer) Text

func (w *Writer) Text(s string)

Text writes text, escaped for an attribute or an element.

Jump to

Keyboard shortcuts

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