SvgImage

class SvgImage

An SVG image, painted as vectors into the shared KiteCanvas rather than rasterised, so it stays crisp at any scale. This is what draws the illustrations, cover art and diagrams that ship inside EPUBs and comics; SvgDocument wraps it when the .svg file IS the document.

val svg = SvgImage.parse(bytes) ?: return
svg.render(canvas, KiteMatrix.scaling(2.0, 2.0))

Drawn: <svg> (width/height/viewBox), <g>, <use>, <path> (every d command including elliptical arcs), <rect> (+ rx/ry), <circle>, <ellipse>, <line>, <polyline>, <polygon>, <text> and <image>; fill, stroke, stroke-width, opacity, fill-opacity, stroke-opacity, fill-rule, display and visibility with inheritance; transform (translate/scale/rotate/skewX/skewY/matrix); linear and radial gradients as paint; and clip-path. Embedded <style> rules support type, universal, class and ID selectors, their compounds and comma lists, with specificity, source order and !important (SVG 1.1, section 6). Combinators, attribute/pseudo selectors, CSS escapes, at-rules and external stylesheets are not interpreted.

Text is measured against standard-font metrics and drawn through a host typeface, because SVG ships no font file of its own.

Not drawn: patterns, masks, filters, and animation.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Intrinsic size in px (from width/height, else the viewBox extent, else 300x150).

Functions

Link copied to clipboard
fun render(canvas: KiteCanvas, ctm: KiteMatrix, loadResource: (String) -> ByteArray?? = null)

Paint the SVG into canvas; ctm maps the (0,0)-(width,height) viewport to device space.