Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::CssTransform Class Reference

Compared to an SVG transform, CSS transforms have additional features, such as the ability to add units to the translate() function, such as translate(1em 30px). More...

#include "donner/svg/core/CssTransform.h"

Classes

struct  Simple
 Stores a precomputed transform. More...
 
struct  Translate
 Stores a deferred translate() operation, which can have two <length-percentage> arguments, such as translate(1em 30px). More...
 

Public Types

using Element = std::variant<Simple, Translate>
 A transform or a deferred operation.
 

Public Member Functions

 CssTransform ()=default
 Construct an empty transform set to identity.
 
 CssTransform (const Transformd &transform)
 Construct a transform initialized with the given transform.
 
Transformd compute (const Boxd &viewbox, FontMetrics fontMetrics) const
 Compute the final transform from the list of transforms and deferred operations.
 
void addTransform (const Transformd &transform)
 Append a transform to the transform chain.
 
void addTranslate (Lengthd x, Lengthd y)
 Append a translate() operation to the transform chain.
 

Detailed Description

Compared to an SVG transform, CSS transforms have additional features, such as the ability to add units to the translate() function, such as translate(1em 30px).

translate() = translate( <length-percentage> [, <length-percentage> ]? )

To resolve translate(), we need to know the font size and the viewbox size, which is context-dependent, so we cannot precompute the transform from the transform function list. Instead, store a chain of of transforms and deferred operations, and compute the final transform when needed, inside the CssTransform::compute() function.

See https://www.w3.org/TR/css-transforms-1/#two-d-transform-functions for more details about CSS transforms.

CssTransform is parsed by donner::svg::parser::CssTransformParser.


Class Documentation

◆ donner::svg::CssTransform::Simple

struct donner::svg::CssTransform::Simple

Stores a precomputed transform.

Collaboration diagram for donner::svg::CssTransform::Simple:
[legend]
Class Members
Transformd transform Transform to apply.

◆ donner::svg::CssTransform::Translate

struct donner::svg::CssTransform::Translate

Stores a deferred translate() operation, which can have two <length-percentage> arguments, such as translate(1em 30px).

Collaboration diagram for donner::svg::CssTransform::Translate:
[legend]
Class Members
Lengthd x X offset.
Lengthd y Y offset.

Constructor & Destructor Documentation

◆ CssTransform()

donner::svg::CssTransform::CssTransform ( const Transformd & transform)
inlineexplicit

Construct a transform initialized with the given transform.

Parameters
transformInitial transform.

Member Function Documentation

◆ addTransform()

void donner::svg::CssTransform::addTransform ( const Transformd & transform)
inline

Append a transform to the transform chain.

Parameters
transformTransform to add.

◆ addTranslate()

void donner::svg::CssTransform::addTranslate ( Lengthd x,
Lengthd y )
inline

Append a translate() operation to the transform chain.

Parameters
xX offset.
yY offset.

◆ compute()

Transformd donner::svg::CssTransform::compute ( const Boxd & viewbox,
FontMetrics fontMetrics ) const
inline

Compute the final transform from the list of transforms and deferred operations.

Parameters
viewboxViewbox size, used to resolve percentage units.
fontMetricsFont metrics, used to resolve 'em' and other font-relative units.

The documentation for this class was generated from the following file: