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"
|
| 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...
|
|
|
using | Element = std::variant<Simple, Translate> |
| | A transform or a deferred operation.
|
|
|
| CssTransform ()=default |
| | Construct an empty transform set to identity.
|
| | CssTransform (const Transform2d &transform) |
| | Construct a transform initialized with the given transform.
|
| Transform2d | compute (const Box2d &viewBox, FontMetrics fontMetrics) const |
| | Compute the final transform from the list of transforms and deferred operations.
|
| void | appendTransform (const Transform2d &transform) |
| | Append a transform to the transform chain.
|
| void | appendTranslate (Lengthd x, Lengthd y) |
| | Append a translate() operation to the transform chain.
|
| bool | isFinite () const |
| | Returns true if every component of the stored transform chain is finite.
|
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.
◆ donner::svg::CssTransform::Simple
| struct donner::svg::CssTransform::Simple |
Stores a precomputed transform.
| Class Members |
|
Transform2d |
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).
◆ CssTransform()
| donner::svg::CssTransform::CssTransform |
( |
const Transform2d & | transform | ) |
|
|
inlineexplicit |
Construct a transform initialized with the given transform.
- Parameters
-
| transform | Initial transform. |
◆ appendTransform()
| void donner::svg::CssTransform::appendTransform |
( |
const Transform2d & | transform | ) |
|
|
inline |
Append a transform to the transform chain.
- Parameters
-
| transform | Transform to append. |
◆ appendTranslate()
| void donner::svg::CssTransform::appendTranslate |
( |
Lengthd | x, |
|
|
Lengthd | y ) |
|
inline |
Append a translate() operation to the transform chain.
- Parameters
-
◆ compute()
Compute the final transform from the list of transforms and deferred operations.
- Parameters
-
| viewBox | ViewBox size, used to resolve percentage units. |
| fontMetrics | Font metrics, used to resolve 'em' and other font-relative units. |
◆ isFinite()
| bool donner::svg::CssTransform::isFinite |
( |
| ) |
const |
|
inline |
Returns true if every component of the stored transform chain is finite.
Parsers use this to reject transforms whose values overflowed, so infinite or NaN values never reach layout.
This is tracked as elements are appended, so checking it after every append stays linear in the length of the chain.
The documentation for this class was generated from the following file: