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

Handles SVG's preserveAspectRatio attribute. More...

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

Public Types

enum class  Align {
  None ,
  XMinYMin ,
  XMidYMin ,
  XMaxYMin ,
  XMinYMid ,
  XMidYMid ,
  XMaxYMid ,
  XMinYMax ,
  XMidYMax ,
  XMaxYMax
}
 Alignment options for preserveAspectRatio. More...
 
enum class  MeetOrSlice {
  Meet ,
  Slice
}
 Scaling methods for preserveAspectRatio. More...
 

Public Member Functions

double alignMultiplierX () const
 Calculates the horizontal alignment factor.
 
double alignMultiplierY () const
 Calculates the vertical alignment factor.
 
Transformd computeTransform (const Boxd &size, std::optional< Boxd > viewbox) const
 Computes the transform for the given viewbox.
 
bool operator== (const PreserveAspectRatio &other) const
 Equality operator.
 

Static Public Member Functions

static PreserveAspectRatio None ()
 Creates a PreserveAspectRatio with 'none' alignment.
 

Public Attributes

Align align = Align::XMidYMid
 Default: XMidYMid per SVG spec.
 
MeetOrSlice meetOrSlice = MeetOrSlice::Meet
 Default: Meet per SVG spec.
 

Friends

std::ostream & operator<< (std::ostream &os, const PreserveAspectRatio &value)
 Outputs a string representation of PreserveAspectRatio to a stream.
 

Detailed Description

Handles SVG's preserveAspectRatio attribute.

Member Enumeration Documentation

◆ Align

Alignment options for preserveAspectRatio.

Enumerator
None 

No forced uniform scaling.

XMinYMin 

Left-top alignment.

XMidYMin 

Center-top alignment.

XMaxYMin 

Right-top alignment.

XMinYMid 

Left-center alignment.

XMidYMid 

Center-center alignment.

XMaxYMid 

Right-center alignment.

XMinYMax 

Left-bottom alignment.

XMidYMax 

Center-bottom alignment.

XMaxYMax 

Right-bottom alignment.

◆ MeetOrSlice

Scaling methods for preserveAspectRatio.

Enumerator
Meet 

Scale to fit within viewport.

Slice 

Scale to cover entire viewport, clipping the content if necessary.

Member Function Documentation

◆ alignMultiplierX()

double donner::svg::PreserveAspectRatio::alignMultiplierX ( ) const
inline

Calculates the horizontal alignment factor.

Returns
0 for left, 0.5 for center, 1 for right alignment.

◆ alignMultiplierY()

double donner::svg::PreserveAspectRatio::alignMultiplierY ( ) const
inline

Calculates the vertical alignment factor.

Returns
0 for top, 0.5 for middle, 1 for bottom alignment.

◆ computeTransform()

Transformd donner::svg::PreserveAspectRatio::computeTransform ( const Boxd & size,
std::optional< Boxd > viewbox ) const

Computes the transform for the given viewbox.

Implements the algorithm from the SVG spec for viewport transform calculation.

See also
https://www.w3.org/TR/SVG2/coords.html#ComputingAViewportsTransform.
Parameters
sizeElement's position and size
viewboxElement's viewbox (if any)
Returns
Computed transform

◆ None()

static PreserveAspectRatio donner::svg::PreserveAspectRatio::None ( )
inlinestatic

Creates a PreserveAspectRatio with 'none' alignment.

Useful for scenarios where aspect ratio should be ignored.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const PreserveAspectRatio & value )
friend

Outputs a string representation of PreserveAspectRatio to a stream.

Format: "PreserveAspectRatio {<align>, <meetOrSlice>}" Example: "PreserveAspectRatio {Align::XMidYMid, MeetOrSlice::Meet}"


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