CssValues

object CssValues

CSS value parsers: lengths to points, and colours to RgbColor. Shared by the EPUB cascade and the SVG renderer, which read the same syntax.

They take the raw token text and no context, so each caller interprets a value against the right reference (font size, root size, containing width).

Length model: 1 CSS px = 1/96 in, 1 pt = 1/72 in, so px → pt is ×0.75. em is relative to the caller's fontSizePt (the parent's size when resolving font-size itself, else the element's own), rem to rootPt, % to refPt (parent size for font-size, containing width for margins, etc.).

Functions

Link copied to clipboard
fun alpha(raw: String): Double?

The alpha of a CSS <color>, from 0 (transparent) to 1 (opaque). color reads only the RGB part, so a painter that honours transparency asks for both.

Link copied to clipboard
fun color(raw: String): RgbColor?

Parse the RGB part of a CSS <color> (alpha reads the rest); null for transparent, inherit, or unrecognised.

Link copied to clipboard
fun fontSizeKeyword(raw: String, parentPt: Double, mediumPt: Double): Double?

Absolute/relative font-size keywords → points. mediumPt is the base size.

Link copied to clipboard
fun length(raw: String, fontSizePt: Double, rootPt: Double, refPt: Double): Double?

Parse a CSS <length>/<percentage> to points, or null if not a length.