render#

Import

from scenet import render

Defined in

scenet.emit.svg (source)

Install

pip install scenet

Since

0.1

Stability

Public: follows semantic versioning. Below 1.0, a minor release may change it, and the CHANGELOG says how.

scenet.emit.svg.render(core, *, metrics=None, fonts=None, live_text=False, id_prefix='', aria=True, embed=None, mono=False)[source]#

Render a compiled panel as a standalone SVG document.

Parameters:
  • core (PanelCore) – The compiled panel.

  • metrics (FontMetrics | None) – The regular face the lettering was measured in, in place of the shipped one, for a Core compiled with the same metrics.

  • fonts (Mapping[str, FontMetrics] | None) – The declared fonts the lettering was measured in, by digest – what CompileResult.fonts holds. Each face PanelCore.fonts names must be here.

  • live_text (bool) – Emit lettering as <text> rather than glyph outlines.

  • id_prefix (str) – Put in front of every id the panel writes, and every reference to one. Nothing a single panel needs; it is what lets a strip hold several panels in one document, where ids must be unique. Empty by default, so a panel on its own is byte-identical to what it always was.

  • aria (bool) – Make the panel one image a screen reader can read, named with what it shows and then everything said in it, in reading order – see accessible_name(). False writes none of it, for anyone who post-processes the SVG: exactly what was written before it existed.

  • embed (Mapping[str, bytes] | None) – The supplied pictures’ bytes, by digest – what CompileResult.images holds. Given, each picture is written into the SVG as a data: URI, and must be here; left out, it is linked by the path the document wrote, which a viewer reads from beside the SVG.

  • mono (bool) – Draw every value as its grey and ignore its colour, as for a black-and-white edition. Every decision was made on the grey, so this draws exactly what palette: mono would; see PanelCore.as_mono.

Return type:

str

Returns:

One SVG document, as text. The same Core and arguments give the same text.

Raises:

RenderError – The Core was lettered in a font not handed back as fonts, or a supplied picture is to be embedded and its bytes are not in embed.

Note

The renderer makes no layout decision: everything it draws is in the Core. Glyph outlines need no font where the SVG is shown; live_text letters in <text>, which is smaller and selectable, and is only right where the font is installed.

Example

>>> from scenet import compile_source, render
>>> result = compile_source(
...     "cast: {a: {reference: alice}}\nscript: [{say: {by: a, text: Hello.}}]"
... )
>>> svg = render(result.core, fonts=result.fonts)
>>> svg.splitlines()[0]
'<?xml version="1.0" encoding="UTF-8"?>'
>>> svg == render(result.core, fonts=result.fonts)
True

See also

render_debug, for why it looks like that. render_strip, for several panels in one SVG. render_pdf, for print.

Added in version 0.10: The id_prefix parameter.

Added in version 0.11: The fonts parameter.

Added in version 0.12: The aria parameter.

Added in version 0.12: The embed parameter.

Added in version 0.13: The mono parameter.