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 ¶
- func Render(sc *scene.Scene, o *Options) string
- type Options
- type Writer
- func (w *Writer) Ends(it *scene.Item, st style.Style)
- func (w *Writer) Item(it *scene.Item, st style.Style)
- func (w *Writer) Label(it *scene.Item, st style.Style)
- func (w *Writer) Num(f float64)
- func (w *Writer) Opacity(p style.Paint) float64
- func (w *Writer) Paint(p style.Paint)
- func (w *Writer) PaintAttr(name string, p style.Paint)
- func (w *Writer) Parts(it *scene.Item, st style.Style)
- func (w *Writer) Path(p *scene.Path)
- func (w *Writer) Picture(it *scene.Item, st style.Style)
- func (w *Writer) Raw(s string)
- func (w *Writer) Text(s string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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) Opacity ¶
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 ¶
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 ¶
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 ¶
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.