Module length

Source
Expand description

CSS length values.

CssLength is the struct librsvg uses to represent CSS lengths. See its documentation for examples of how to construct it.

CssLength values need to know whether they will be normalized with respect to the width, height, or both dimensions of the current viewport. CssLength values can be signed or unsigned. So, a CssLength has two type parameters, Normalize and Validate; the full type is CssLength<N: Normalize, V: Validate>. We provide Horizontal, Vertical, and Both implementations of Normalize; these let length values know how to normalize themselves with respect to the current viewport. We also provide Signed and Unsigned implementations of Validate.

For ease of use, we define two type aliases Length and ULength corresponding to signed and unsigned.

For example, the implementation of Circle defines this structure with fields for the (center_x, center_y, radius):

pub struct Circle {
    cx: Length<Horizontal>,
    cy: Length<Vertical>,
    r: ULength<Both>,
}

This means that:

  • cx and cy define the center of the circle, they can be positive or negative, and they will be normalized with respect to the current viewport’s width and height, respectively. If the SVG document specified <circle cx="50%" cy="30%">, the values would be normalized to be at 50% of the the viewport’s width, and 30% of the viewport’s height.

  • r is non-negative and needs to be resolved against the normalized diagonal of the current viewport.

The N type parameter of CssLength<N, I> is enough to know how to normalize a length value; the CssLength::to_user method will handle it automatically.

Structs§

Both
Allows declaring CssLength<Both>.
CssLength
A CSS length value.
Horizontal
Allows declaring CssLength<Horizontal>.
NormalizeParams
Parameters to normalize Length values to user-space distances.
NormalizeValues
Parameters for length normalization extracted from ComputedValues.
RsvgLength
A CSS length value.
Signed
Unsigned
Vertical
Allows declaring CssLength<Vertical>.

Enums§

LengthOrAuto
LengthUnit
Units for length values.

Constants§

CM_PER_INCH 🔒
MM_PER_INCH 🔒
PICA_PER_INCH 🔒
POINTS_PER_INCH

Traits§

Normalize
Used for the N type parameter of CssLength<N: Normalize, V: Validate>.
Validate
Used for the V type parameter of CssLength<N: Normalize, V: Validate>.

Functions§

font_size_from_values 🔒
viewport_percentage 🔒

Type Aliases§

Length
Alias for CssLength types that can have negative values
ULength
Alias for CssLength types that are non negative