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?

The RGB part of a CSS <color> (alpha reads the rest), in sRGB: hex, a named colour, or rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() or color() of CSS Color 4, clipped to sRGB (#606). Null for transparent, inherit, currentcolor, 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. vw and vh resolve against refPt here; length with a viewport resolves them as CSS asks.

fun length(raw: String, fontSizePt: Double, rootPt: Double, refPt: Double, viewportWidthPt: Double, viewportHeightPt: Double): Double?

length, with the viewport units against a viewport of viewportWidthPt by viewportHeightPt, whatever the property: 1vw is 1% of its width, 1vh 1% of its height, and vmin and vmax the smaller and larger of the two (CSS Values and Units 4, 6.1.2; #849).