Module rsvg::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§

Enums§

Constants§

Traits§

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

Functions§

Type Aliases§

  • Alias for CssLength types that can have negative values
  • Alias for CssLength types that are non negative